Skip to content

Commit 3a57e80

Browse files
committed
Fix SecurityPolicy isolation issue and add e2e test
1 parent 0b3f3da commit 3a57e80

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Diff for: internal/gatewayapi/securitypolicy_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
package gatewayapi
77

88
import (
9+
"fmt"
910
"regexp"
1011
"testing"
1112

1213
"github.com/stretchr/testify/assert"
1314
"github.com/stretchr/testify/require"
1415

1516
egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
17+
"github.com/envoyproxy/gateway/internal/ir"
1618
)
1719

1820
func Test_wildcard2regex(t *testing.T) {
@@ -490,3 +492,34 @@ func Test_APIKeyAuth(t *testing.T) {
490492
})
491493
}
492494
}
495+
496+
// TestSetDirectResponseForFailingFeatures tests the setDirectResponseForFailingFeatures function
497+
func TestSetDirectResponseForFailingFeatures(t *testing.T) {
498+
// Create a test route
499+
route := &ir.HTTPRoute{}
500+
501+
// Create test security features
502+
basicAuth := &ir.BasicAuth{}
503+
504+
// Create a test error
505+
err := fmt.Errorf("BasicAuth error")
506+
507+
// Call the function
508+
setDirectResponseForFailingFeatures(route, err, basicAuth, nil, nil, nil, nil, nil)
509+
510+
// Verify that the route has a direct response with status code 500
511+
assert.NotNil(t, route.DirectResponse, "Route should have a direct response")
512+
assert.Equal(t, uint32(500), *route.DirectResponse.StatusCode, "Route should have a 500 status code")
513+
514+
// Create a new route
515+
route = &ir.HTTPRoute{}
516+
517+
// Create a test error for a different feature
518+
err = fmt.Errorf("JWT error")
519+
520+
// Call the function with a different feature
521+
setDirectResponseForFailingFeatures(route, err, basicAuth, nil, nil, nil, nil, nil)
522+
523+
// Verify that the route does not have a direct response
524+
assert.Nil(t, route.DirectResponse, "Route should not have a direct response")
525+
}

0 commit comments

Comments
 (0)