Skip to content

Commit 5cc5b5a

Browse files
author
Tim Riffer
committed
restructure test
1 parent ebeb8eb commit 5cc5b5a

File tree

1 file changed

+54
-45
lines changed

1 file changed

+54
-45
lines changed

internal/processing/processors/v2alpha1/reconciliation_test.go

Lines changed: 54 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -26,54 +26,13 @@ const (
2626
)
2727

2828
var _ = Describe("Reconciliation", func() {
29-
jwtConfigJSON := fmt.Sprintf(`{"authentications": [{"issuer": "%s", "jwksUri": "%s"}]}`, jwtIssuer, jwksUri)
30-
jwtV1beta1 := []*gatewayv1beta1.Authenticator{
31-
{
32-
Handler: &gatewayv1beta1.Handler{
33-
Name: gatewayv1beta1.AccessStrategyJwt,
34-
Config: &runtime.RawExtension{
35-
Raw: []byte(jwtConfigJSON),
36-
},
37-
},
38-
},
39-
}
40-
jwtV1beta1Rule := GetRuleFor(path, []gatewayv1beta1.HttpMethod{http.MethodGet}, []*gatewayv1beta1.Mutator{}, jwtV1beta1)
41-
42-
jwtV2alpha1 := gatewayv2alpha1.Rule{
43-
Path: path,
44-
Methods: []gatewayv2alpha1.HttpMethod{http.MethodGet},
45-
Jwt: &gatewayv2alpha1.JwtConfig{
46-
Authentications: []*gatewayv2alpha1.JwtAuthentication{
47-
{
48-
Issuer: jwtIssuer,
49-
JwksUri: jwksUri,
50-
},
51-
},
52-
},
53-
}
54-
55-
noAuthV1beta1 := []*gatewayv1beta1.Authenticator{
56-
{
57-
Handler: &gatewayv1beta1.Handler{
58-
Name: gatewayv1beta1.AccessStrategyNoAuth,
59-
},
60-
},
61-
}
62-
noAuthV1beta1Rule := GetRuleFor(path, []gatewayv1beta1.HttpMethod{http.MethodGet}, []*gatewayv1beta1.Mutator{}, noAuthV1beta1)
63-
64-
noAuthV2alpha1Rule := gatewayv2alpha1.Rule{
65-
Path: path,
66-
Methods: []gatewayv2alpha1.HttpMethod{http.MethodGet},
67-
NoAuth: ptr.To(true),
68-
}
6929

7030
It("with v1beta1 no_auth and v2alpha1 noAuth should provide only Istio VS", func() {
7131
// given
72-
73-
rulesV1beta1 := []gatewayv1beta1.Rule{noAuthV1beta1Rule}
32+
rulesV1beta1 := []gatewayv1beta1.Rule{getNoAuthV1beta1Rule()}
7433
v1beta1ApiRule := GetAPIRuleFor(rulesV1beta1)
7534

76-
rulesV2alpha1 := []gatewayv2alpha1.Rule{noAuthV2alpha1Rule}
35+
rulesV2alpha1 := []gatewayv2alpha1.Rule{getNoAuthV2alpha1Rule()}
7736
v2alpha1ApiRule := getV2alpha1APIRuleFor("test-apirule", "some-namespace", rulesV2alpha1)
7837

7938
service := GetService(ServiceName)
@@ -99,10 +58,10 @@ var _ = Describe("Reconciliation", func() {
9958
It("with v1beta1 jwt and v2alpha1 jwt should provide VirtualService, AuthorizationPolicy and RequestAuthentication", func() {
10059
// given
10160

102-
rulesV1beta1 := []gatewayv1beta1.Rule{jwtV1beta1Rule}
61+
rulesV1beta1 := []gatewayv1beta1.Rule{getJwtV1beta1Rule()}
10362
v1beta1ApiRule := GetAPIRuleFor(rulesV1beta1)
10463

105-
rulesV2alpha1 := []gatewayv2alpha1.Rule{jwtV2alpha1}
64+
rulesV2alpha1 := []gatewayv2alpha1.Rule{getJwtV2alpha1Rule()}
10665
v2alpha1ApiRule := getV2alpha1APIRuleFor("test-apirule", "some-namespace", rulesV2alpha1)
10766

10867
service := GetService(ServiceName)
@@ -174,3 +133,53 @@ func getV2alpha1APIRuleFor(name, namespace string, rules []gatewayv2alpha1.Rule)
174133
}
175134

176135
}
136+
137+
func getJwtV1beta1Rule() gatewayv1beta1.Rule {
138+
jwtConfigJSON := fmt.Sprintf(`{"authentications": [{"issuer": "%s", "jwksUri": "%s"}]}`, jwtIssuer, jwksUri)
139+
jwtV1beta1 := []*gatewayv1beta1.Authenticator{
140+
{
141+
Handler: &gatewayv1beta1.Handler{
142+
Name: gatewayv1beta1.AccessStrategyJwt,
143+
Config: &runtime.RawExtension{
144+
Raw: []byte(jwtConfigJSON),
145+
},
146+
},
147+
},
148+
}
149+
return GetRuleFor(path, []gatewayv1beta1.HttpMethod{http.MethodGet}, []*gatewayv1beta1.Mutator{}, jwtV1beta1)
150+
}
151+
152+
func getNoAuthV1beta1Rule() gatewayv1beta1.Rule {
153+
154+
noAuthV1beta1 := []*gatewayv1beta1.Authenticator{
155+
{
156+
Handler: &gatewayv1beta1.Handler{
157+
Name: gatewayv1beta1.AccessStrategyNoAuth,
158+
},
159+
},
160+
}
161+
return GetRuleFor(path, []gatewayv1beta1.HttpMethod{http.MethodGet}, []*gatewayv1beta1.Mutator{}, noAuthV1beta1)
162+
}
163+
164+
func getJwtV2alpha1Rule() gatewayv2alpha1.Rule {
165+
return gatewayv2alpha1.Rule{
166+
Path: path,
167+
Methods: []gatewayv2alpha1.HttpMethod{http.MethodGet},
168+
Jwt: &gatewayv2alpha1.JwtConfig{
169+
Authentications: []*gatewayv2alpha1.JwtAuthentication{
170+
{
171+
Issuer: jwtIssuer,
172+
JwksUri: jwksUri,
173+
},
174+
},
175+
},
176+
}
177+
}
178+
179+
func getNoAuthV2alpha1Rule() gatewayv2alpha1.Rule {
180+
return gatewayv2alpha1.Rule{
181+
Path: path,
182+
Methods: []gatewayv2alpha1.HttpMethod{http.MethodGet},
183+
NoAuth: ptr.To(true),
184+
}
185+
}

0 commit comments

Comments
 (0)