@@ -60,15 +60,46 @@ def decorated_function(*args, **kwargs):
60
60
def mock_keycloak (mocker ):
61
61
class mock_kc_admin :
62
62
def get_group_by_path (path , search_in_subgroups ):
63
- return {
64
- "id" : "g001"
65
- }
63
+ if path == "/ns/mytest" :
64
+ return {"id" : "g001" }
65
+ elif path == "/ns/mytest2" :
66
+ return {"id" : "g002" }
67
+ elif path == "/ns/mytest3" :
68
+ return {"id" : "g003" }
69
+ elif path == "/ns/customcert" :
70
+ return {"id" : "g004" }
71
+ else :
72
+ return {"id" : "g001" }
66
73
def get_group (id ):
67
- return {
68
- "attributes" : {
69
- "perm-domains" : [ ".api.gov.bc.ca" , ".cluster.local" ]
74
+ if id == "g001" :
75
+ return {
76
+ "attributes" : {
77
+ "perm-domains" : [ ".api.gov.bc.ca" , ".cluster.local" ]
78
+ }
70
79
}
71
- }
80
+ elif id == "g002" :
81
+ return {
82
+ "attributes" : {
83
+ "perm-data-plane" : ["strict-dp" ],
84
+ "perm-upstreams" : [],
85
+ "perm-domains" : [ ".api.gov.bc.ca" , ".cluster.local" ]
86
+ }
87
+ }
88
+ elif id == "g003" :
89
+ return {
90
+ "attributes" : {
91
+ "perm-data-plane" : ["strict-dp" ],
92
+ "perm-upstreams" : ['ns1' ],
93
+ "perm-domains" : [ ".api.gov.bc.ca" , ".cluster.local" ]
94
+ }
95
+ }
96
+ elif id == "g004" :
97
+ return {
98
+ "attributes" : {
99
+ "perm-domains" : [ ".api.gov.bc.ca" , ".custom.gov.bc.ca" ]
100
+ }
101
+ }
102
+
72
103
mocker .patch ("v2.services.namespaces.admin_api" , return_value = mock_kc_admin )
73
104
74
105
def mock_kong (mocker ):
@@ -92,14 +123,35 @@ def json():
92
123
return Response
93
124
elif (path == 'http://kong/certificates?tags=gwa.ns.mytest' or
94
125
path == 'http://kong/certificates?tags=gwa.ns.sescookie' or
95
- path == 'http://kong/certificates?tags=gwa.ns.dclass' ):
126
+ path == 'http://kong/certificates?tags=gwa.ns.dclass' or
127
+ path == 'http://kong/certificates?tags=gwa.ns.customcert' ):
96
128
class Response :
97
129
def json ():
98
130
return {
99
131
"data" : [],
100
132
"next" : None
101
133
}
102
134
return Response
135
+ elif (path == 'http://kong/certificates?tags=ns.customcert' ):
136
+ class Response :
137
+ def json ():
138
+ return {
139
+ "next" : None ,
140
+ "data" : [
141
+ {
142
+ "id" : "41d14845-669f-4dcd-aff2-926fb32a4b25" ,
143
+ "snis" : [
144
+ "test.custom.gov.bc.ca"
145
+ ],
146
+ "tags" : [
147
+ "ns.customcert" ,
148
+ ],
149
+ "cert" : "CERT" ,
150
+ "key" : "KEY"
151
+ }
152
+ ]
153
+ }
154
+ return Response
103
155
104
156
else :
105
157
raise Exception (path )
@@ -157,7 +209,8 @@ class Response:
157
209
"aps.route.dataclass.high" : [],
158
210
"aps.route.dataclass.public" : []
159
211
},
160
- 'select_tag' : 'ns.sescookie.dev'
212
+ 'select_tag' : 'ns.sescookie.dev' ,
213
+ 'certificates' : []
161
214
}
162
215
163
216
assert json .dumps (kwargs ['json' ], sort_keys = True ) == json .dumps (matched , sort_keys = True )
@@ -175,7 +228,39 @@ class Response:
175
228
"aps.route.dataclass.high" : ['myapi.api.gov.bc.ca' ],
176
229
"aps.route.dataclass.public" : []
177
230
},
178
- 'select_tag' : 'ns.dclass.dev'
231
+ 'select_tag' : 'ns.dclass.dev' ,
232
+ 'certificates' : []
233
+ }
234
+
235
+ assert json .dumps (kwargs ['json' ], sort_keys = True ) == json .dumps (matched , sort_keys = True )
236
+ return Response
237
+ elif (url == 'http://kube-api/namespaces/customcert/routes' ):
238
+ class Response :
239
+ status_code = 201
240
+ matched = {
241
+ 'hosts' : ['test.custom.gov.bc.ca' ],
242
+ 'ns_attributes' : {'perm-domains' : ['.api.gov.bc.ca' , '.custom.gov.bc.ca' ]},
243
+ 'overrides' : {
244
+ 'aps.route.session.cookie.enabled' : [],
245
+ "aps.route.dataclass.low" : [],
246
+ "aps.route.dataclass.medium" : [],
247
+ "aps.route.dataclass.high" : [],
248
+ "aps.route.dataclass.public" : []
249
+ },
250
+ 'select_tag' : 'ns.customcert' ,
251
+ 'certificates' : [
252
+ {
253
+ "id" : "41d14845-669f-4dcd-aff2-926fb32a4b25" ,
254
+ "snis" : [
255
+ "test.custom.gov.bc.ca"
256
+ ],
257
+ "tags" : [
258
+ "ns.customcert" ,
259
+ ],
260
+ "cert" : "CERT" ,
261
+ "key" : "KEY"
262
+ }
263
+ ]
179
264
}
180
265
181
266
assert json .dumps (kwargs ['json' ], sort_keys = True ) == json .dumps (matched , sort_keys = True )
@@ -190,24 +275,16 @@ class Response:
190
275
raise Exception (url )
191
276
192
277
def mock_requests_get (self , url , ** kwards ):
193
- if (url == 'http://kube-api/namespaces/mytest/local_tls' ):
194
- class Response :
195
- status_code = 200
196
- def json ():
197
- return {}
198
- return Response
199
- elif (url == 'http://kube-api/namespaces/sescookie/local_tls' ):
200
- class Response :
201
- status_code = 200
202
- def json ():
203
- return {}
204
- return Response
205
- elif (url == 'http://kube-api/namespaces/dclass/local_tls' ):
278
+ if (url == 'http://kube-api/namespaces/mytest/local_tls' or
279
+ url == 'http://kube-api/namespaces/sescookie/local_tls' or
280
+ url == 'http://kube-api/namespaces/dclass/local_tls' or
281
+ url == 'http://kube-api/namespaces/customcert/local_tls' ):
206
282
class Response :
207
283
status_code = 200
208
284
def json ():
209
285
return {}
210
286
return Response
287
+
211
288
else :
212
289
raise Exception (url )
213
290
0 commit comments