-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_gateway.py
More file actions
705 lines (653 loc) · 26.4 KB
/
test_gateway.py
File metadata and controls
705 lines (653 loc) · 26.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
import os
import json
import string
import random
from django.contrib.auth import get_user_model
from django.core.cache import cache
from api.models.app import App
from api.models.base import PTYPE_WEB
from api.models.build import Build
from api.models.gateway import Route
from api.models.release import Release
from api.utils import validate_json
from api.tests import TEST_ROOT, DryccTransactionTestCase
from api.serializers.schemas.rules import SCHEMA as RULES_SCHEMA
User = get_user_model()
class BaseGatewayTest(DryccTransactionTestCase):
fixtures = ['tests.json']
def setUp(self):
self.user = User.objects.get(username='autotest')
self.token = self.get_or_create_token(self.user)
self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.token)
def tearDown(self):
# make sure every test has a clean slate for k8s mocking
cache.clear()
def create_app_with_domain_and_deploy(self):
app_id = self.create_app()
response = self.client.post(
'/v2/apps/{}/domains'.format(app_id),
{'domain': 'test-domain.example.com', 'ptype': PTYPE_WEB}
)
self.assertEqual(response.status_code, 201, response.data)
# check default gateway route
response = self.client.get('/v2/apps/{}/gateways/'.format(app_id))
self.assertEqual(len(response.data["results"]), 0, response.data)
response = self.client.get('/v2/apps/{}/routes/'.format(app_id))
self.assertEqual(len(response.data["results"]), 0, response.data)
# create a release so we can scale
app = App.objects.get(id=app_id)
user = User.objects.get(username='autotest')
build = Build.objects.create(owner=user, app=app, image="qwerty")
# create an initial release
release = Release.objects.create(
version=2,
owner=user,
app=app,
config=app.config_set.latest(),
build=build
)
# deploy
release.deploy()
return app_id
def change_certs_auto(self, app_id, enabled):
data = {'certs_auto_enabled': enabled}
response = self.client.post(f'/v2/apps/{app_id}/tls', data)
self.assertEqual(response.status_code, 201, response.data)
self.assertEqual(response.data.get('certs_auto_enabled'), enabled, response.data)
def create_gateway(self, app_id, name, port, protocol):
response = self.client.post(
'/v2/apps/{}/gateways/'.format(app_id),
{'name': name, 'port': port, 'protocol': protocol}
)
self.assertEqual(response.status_code, 201)
def create_tls_domain(self, app_id):
cert_url = f'/v2/apps/{app_id}/certs'
secret_name = ''.join(random.choice(string.ascii_lowercase) for _ in range(23))
domain = 'autotest.example.com'
with open('{}/certs/{}.key'.format(TEST_ROOT, domain)) as f:
key = f.read()
with open('{}/certs/{}.cert'.format(TEST_ROOT, domain)) as f:
cert = f.read()
response = self.client.post(
cert_url,
{
'name': secret_name,
'certificate': cert,
'key': key
}
)
self.assertEqual(response.status_code, 201)
response = self.client.post(
'/v2/apps/{}/domains'.format(app_id),
{'domain': domain, 'ptype': PTYPE_WEB}
)
self.assertEqual(response.status_code, 201)
response = self.client.post(
'{}/{}/domain/'.format(cert_url, secret_name),
{'domain': domain}
)
self.assertEqual(response.status_code, 201)
return domain, secret_name
class GatewayTest(BaseGatewayTest):
"""Tests push notification from build system"""
def test_create_gateway(self):
app_id = self.create_app()
self.create_gateway(app_id, 'bing-gateway', 8000, "HTTP")
response = self.client.get('/v2/apps/{}/gateways/'.format(app_id))
self.assertEqual(response.data["count"], 1, response.data)
def test_add_listener(self):
app_id = self.create_app()
gateway_name = 'bing-gateway'
self.create_gateway(app_id, gateway_name, 8000, "HTTP")
response = self.client.post(
'/v2/apps/{}/gateways/'.format(app_id),
{'name': gateway_name, 'port': 443, 'protocol': "HTTP"}
)
self.assertEqual(response.status_code, 201)
response = self.client.get('/v2/apps/{}/gateways/'.format(app_id))
actual = None
for result in response.data["results"]:
if result["name"] == gateway_name:
actual = json.loads(json.dumps(result))
break
expect = {
"app": app_id,
"owner": "autotest",
"name": gateway_name,
"listeners": [
{
"name": "tcp-8000-%s" % 0,
"port": 8000,
"protocol": "HTTP",
"allowedRoutes": {"namespaces": {"from": "All"}}
},
{
"name": "tcp-443-%s" % 0,
"port": 443,
"protocol": "HTTP",
"allowedRoutes": {"namespaces": {"from": "All"}}
}
],
"addresses": [{
"type": "IPAddress",
"value": "172.22.108.207"
}]
}
self.assertEqual(expect, actual)
def add_listener(self, app_id, name, protocol, port):
response = self.client.post(
'/v2/apps/{}/gateways/'.format(app_id),
{'name': name, 'port': port, 'protocol': protocol}
)
self.assertEqual(response.status_code, 201)
response = self.client.get('/v2/apps/{}/gateways/'.format(app_id))
return app_id, response.data["results"]
def add_tls_listener(self, name, protocol, port):
app_id = self.create_app(name)
domain, secret_name = self.create_tls_domain(app_id)
app_id, results = self.add_listener(app_id, name, protocol, port)
return app_id, domain, secret_name, results
def test_add_tls_listener(self):
port = 443
name = "tls-gateway"
_, domain, secret_name, results = self.add_tls_listener(name, "TLS", port)
expect = [{
'app': name, 'owner': 'autotest', 'name': name,
'listeners': [{
'allowedRoutes': {'namespaces': {'from': 'All'}},
'name': 'tcp-443-1', 'port': 443, 'hostname': domain,
'protocol': 'TLS',
'tls': {'certificateRefs': [
{'kind': 'Secret', 'name': f"{secret_name}-certificate"}]}
}],
'addresses': [{'type': 'IPAddress', 'value': '172.22.108.207'}]
}]
self.assertEqual(results, expect)
def test_add_https_listener(self):
port = 443
name = "bingo-gateway"
_, domain, secret_name, results = self.add_tls_listener(name, "HTTPS", port)
expect = [{
'app': name,
'owner': 'autotest',
'name': name,
'listeners': [{
'allowedRoutes': {
'namespaces': {
'from': 'All'
}
},
'name': 'mix-%s-1' % port,
'port': port,
'hostname': domain,
'protocol': 'HTTPS',
'tls': {
'certificateRefs': [{
'kind': 'Secret',
'name': f"{secret_name}-certificate"
}]
}
}],
'addresses': [{
'type': 'IPAddress',
'value': '172.22.108.207'
}]
}]
self.assertEqual(results, expect)
def test_add_http_listener(self):
port = 80
name = "bingo-gateway"
_, domain, secret_name, results = self.add_tls_listener(name, "HTTP", port)
expect = [{
'app': 'bingo-gateway', 'owner': 'autotest', 'name': 'bingo-gateway',
'listeners': [
{
'allowedRoutes': {'namespaces': {'from': 'All'}},
'name': 'tcp-80-1',
'port': 80,
'hostname': domain,
'protocol': 'HTTP'
},
{
'allowedRoutes': {'namespaces': {'from': 'All'}},
'name': 'tcp-80-0',
'port': 80,
'protocol': 'HTTP'
},
{
'allowedRoutes': {'namespaces': {'from': 'All'}},
'name': 'mix-443-1',
'port': 443,
'hostname': domain,
'protocol': 'HTTPS',
'tls': {'certificateRefs': [
{'kind': 'Secret', 'name': f"{secret_name}-certificate"}]}
}
],
'addresses': [{'type': 'IPAddress', 'value': '172.22.108.207'}]
}]
self.assertEqual(results, expect)
def test_add_udp_listener(self):
port = 999
name = "bingo-gateway"
app_id = self.create_app(name)
_, results = self.add_listener(app_id, name, "UDP", port)
expect = [{
'app': 'bingo-gateway',
'owner': 'autotest',
'name': 'bingo-gateway',
'listeners': [{
'allowedRoutes': {
'namespaces': {
'from': 'All'
}
},
'name': 'udp-999-0',
'port': 999,
'protocol': 'UDP'
}],
'addresses': [{
'type': 'IPAddress',
'value': '172.22.108.207'
}]
}]
self.assertEqual(results, expect)
def test_remove_domain(self):
app_id, domain, _, _ = self.add_tls_listener("bingo-gateway", "HTTPS", 443)
url = '/v2/apps/{app_id}/domains/{domain}'.format(domain=domain,
app_id=app_id)
response = self.client.delete(url)
self.assertEqual(response.status_code, 204)
response = self.client.get('/v2/apps/{}/gateways/'.format(app_id))
self.assertEqual(response.data["results"][0]["listeners"], [])
def test_remove_tls(self):
app_id, domain, secret_name, _ = self.add_tls_listener("bingo-gateway", "HTTPS", 443)
response = self.client.get('/v2/apps/{}/gateways/'.format(app_id))
self.assertEqual(len(response.data["results"][0]["listeners"]), 1)
response = self.client.delete(
'{}/{}/domain/{}/'.format(f'/v2/apps/{app_id}/certs', secret_name, domain)
)
self.assertEqual(response.status_code, 204)
response = self.client.get('/v2/apps/{}/gateways/'.format(app_id))
self.assertEqual(response.data["results"][0]["listeners"], [])
return app_id
def test_certs_auto_enabled(self):
app_id = self.test_remove_tls()
data = {'certs_auto_enabled': True}
response = self.client.post(
'/v2/apps/{}/tls'.format(app_id),
data)
self.assertEqual(response.status_code, 201, response.data)
response = self.client.get('/v2/apps/{}/gateways/'.format(app_id))
self.assertEqual(len(response.data["results"][0]["listeners"]), 1)
def test_remove_listener(self):
app_id = self.create_app()
self.create_gateway(app_id, 'bing-gateway', 8000, "HTTP")
response = self.client.get('/v2/apps/{}/gateways/'.format(app_id))
self.assertEqual(response.data["count"], 1, response.data)
# delete
response = self.client.delete(
'/v2/apps/{}/gateways/'.format(app_id),
{'name': 'bing-gateway', 'port': 8000, 'protocol': "HTTP"}
)
self.assertEqual(response.status_code, 204)
response = self.client.get('/v2/apps/{}/gateways/'.format(app_id))
self.assertEqual(response.data["count"], 0, response.data)
def test_change_tls(self):
app_id = self.create_app_with_domain_and_deploy()
response = self.client.get('/v2/apps/{}/gateways/'.format(app_id))
expect = [{
'allowedRoutes': {
'namespaces': {
'from': 'All'
}
},
'name': 'tcp-80-0',
'port': 80,
'protocol': 'HTTP'
}]
self.assertEqual(response.data["count"], 1, response.data)
self.assertEqual(response.data["results"][0]["listeners"], expect, response.data)
self.change_certs_auto(app_id, True)
response = self.client.get('/v2/apps/{}/gateways/'.format(app_id))
self.assertEqual(response.data["count"], 1, response.data)
expect = [{
'app': app_id,
'owner': 'autotest',
'name': app_id,
'listeners': [
{
'allowedRoutes': {'namespaces': {'from': 'All'}},
'name': 'tcp-80-1',
'port': 80,
'hostname': 'test-domain.example.com',
'protocol': 'HTTP'
},
{
'allowedRoutes': {'namespaces': {'from': 'All'}},
'name': 'tcp-80-0',
'port': 80,
'protocol': 'HTTP'
},
{
'allowedRoutes': {'namespaces': {'from': 'All'}},
'name': 'mix-443-1',
'port': 443,
'hostname': 'test-domain.example.com',
'protocol': 'HTTPS',
'tls': {'certificateRefs': [{'kind': 'Secret', 'name': f'{app_id}-auto-tls'}]}
}
],
'addresses': [{'type': 'IPAddress', 'value': '172.22.108.207'}]
}]
self.assertEqual(response.data["results"], expect, response.data)
self.change_certs_auto(app_id, False)
response = self.client.get('/v2/apps/{}/gateways/'.format(app_id))
expect = [{
'allowedRoutes': {
'namespaces': {
'from': 'All'
}
},
'name': 'tcp-80-0',
'port': 80,
'protocol': 'HTTP'
}]
self.assertEqual(response.data["count"], 1, response.data)
self.assertEqual(response.json()["results"][0]["listeners"], expect, response.data)
class RouteTest(BaseGatewayTest):
def create_route(self, app_id, route_name="test-route",
ptype="task", kind="HTTPRoute"):
# create service
port = 5000
response = self.client.post(
'/v2/apps/{}/services'.format(app_id),
{
'port': port,
'protocol': 'TCP',
'target_port': port,
'ptype': ptype
}
)
self.assertEqual(response.status_code, 201, response.data)
# create route
response = self.client.post(
'/v2/apps/{}/routes/'.format(app_id),
{
"kind": kind,
"name": route_name,
"rules": [{
"backendRefs": [{
"kind": "Service",
"name": f"{app_id}-{ptype}",
"port": 5000,
"weight": 100,
}],
}],
}
)
self.assertEqual(response.status_code, 201, response.data)
return ptype, port, route_name
def test_create_route(self):
app_id = self.create_app()
self.create_route(app_id)
# create route error
response = self.client.post(
'/v2/apps/{}/routes/'.format(app_id),
{
"port": 5000,
"ptype": "no-exists",
"kind": "HTTPRoute",
"name": "test-route-1",
}
)
self.assertEqual(response.status_code, 404)
response = self.client.get('/v2/apps/{}/routes/'.format(app_id))
self.assertEqual(response.data["count"], 1)
self.assertEqual(len(response.data["results"][0]["rules"]), 1)
def test_hostnames(self):
app_id = self.create_app()
ptype, port, route_name = self.create_route(app_id)
response = self.client.post(
'/v2/apps/{}/domains'.format(app_id),
{'domain': "domain1.test.com", 'ptype': ptype}
)
self.assertEqual(response.status_code, 201)
route = Route.objects.get(app__id=app_id)
self.assertEqual(route.hostnames, ["domain1.test.com"])
response = self.client.post(
'/v2/apps/{}/domains'.format(app_id),
{'domain': "domain2.test.com", 'ptype': "web-1"}
)
self.assertEqual(response.status_code, 201)
route = Route.objects.get(app__id=app_id)
self.assertEqual(route.hostnames, ["domain1.test.com"])
response = self.client.post(
'/v2/apps/{}/domains'.format(app_id),
{'domain': "domain3.test.com", 'ptype': ptype}
)
self.assertEqual(response.status_code, 201)
route = Route.objects.get(app__id=app_id)
self.assertEqual(route.hostnames, ["domain1.test.com", "domain3.test.com"])
def test_route_attach(self):
app_id = self.create_app()
ptype, port, route_name = self.create_route(app_id)
gateway_name_1 = 'bing-gateway-1'
self.create_gateway(app_id, gateway_name_1, 5000, "HTTP")
self.client.patch(
'/v2/apps/{}/routes/{}/attach/'.format(app_id, route_name),
{
"gateway": gateway_name_1,
"port": port
}
)
response = self.client.get('/v2/apps/{}/routes/'.format(app_id))
self.assertEqual(len(response.data["results"][0]["parent_refs"]), 1)
gateway_name_2 = 'bing-gateway-2'
self.create_gateway(app_id, gateway_name_2, 5000, "HTTP")
self.client.patch(
'/v2/apps/{}/routes/{}/attach/'.format(app_id, route_name),
{
"gateway": gateway_name_2,
"port": port
}
)
response = self.client.get('/v2/apps/{}/routes/'.format(app_id))
self.assertEqual(len(response.data["results"][0]["parent_refs"]), 2)
return ptype, app_id, gateway_name_1, gateway_name_2, port, route_name
def test_route_check_parent_ok(self):
app_id = self.create_app()
_, port, route_name = self.create_route(app_id, "myroute1", "test")
gateway_name_1 = 'bing-gateway-1'
self.create_gateway(app_id, gateway_name_1, 5000, "HTTP")
response = self.client.patch(
'/v2/apps/{}/routes/{}/attach/'.format(app_id, route_name),
{
"gateway": gateway_name_1,
"port": port
}
)
self.assertEqual(response.status_code, 204, response.data)
response = self.client.get('/v2/apps/{}/routes/'.format(app_id))
self.assertEqual(len(response.data["results"][0]["parent_refs"]), 1)
# create other route
_, port, route_name = self.create_route(app_id, "myroute2", "mytest")
response = self.client.patch(
'/v2/apps/{}/routes/{}/attach/'.format(app_id, route_name),
{
"gateway": gateway_name_1,
"port": port
}
)
self.assertEqual(response.status_code, 204)
def test_route_check_parent_err(self):
app_id = self.create_app()
_, port, route_name = self.create_route(app_id, "myroute1", "test", "TCPRoute")
gateway_name_1 = 'bing-gateway-1'
self.create_gateway(app_id, gateway_name_1, 5000, "TCP")
self.client.patch(
'/v2/apps/{}/routes/{}/attach/'.format(app_id, route_name),
{
"gateway": gateway_name_1,
"port": port
}
)
response = self.client.get('/v2/apps/{}/routes/'.format(app_id))
self.assertEqual(len(response.data["results"][0]["parent_refs"]), 1)
# create other route
_, port, route_name = self.create_route(app_id, "myroute2", "mytest", "TCPRoute")
response = self.client.patch(
'/v2/apps/{}/routes/{}/attach/'.format(app_id, route_name),
{
"gateway": gateway_name_1,
"port": port
}
)
self.assertEqual(response.status_code, 400)
self.assertEqual(response.data['detail'], 'this listener has already been referenced')
def test_route_detach(self):
_, app_id, gateway_name_1, gateway_name_2, port, route_name = self.test_route_attach()
self.client.patch(
'/v2/apps/{}/routes/{}/detach/'.format(app_id, route_name),
{
"gateway": gateway_name_1,
"port": port
}
)
response = self.client.get('/v2/apps/{}/routes/'.format(app_id))
self.assertEqual(len(response.data["results"][0]["parent_refs"]), 1)
self.client.patch(
'/v2/apps/{}/routes/{}/detach/'.format(app_id, route_name),
{
"gateway": gateway_name_2,
"port": port
}
)
response = self.client.get('/v2/apps/{}/routes/'.format(app_id))
self.assertEqual(len(response.data["results"][0]["parent_refs"]), 0)
response = self.client.patch(
'/v2/apps/{}/routes/{}/detach/'.format(app_id, route_name),
{
"gateway": gateway_name_2,
"port": port
}
)
self.assertEqual(response.status_code, 400)
def test_app_settings_change_routable(self):
_, app_id, _, _, _, route_name = self.test_route_attach()
# Set routable to false
response = self.client.post(
f'/v2/apps/{app_id}/settings',
{'routable': False}
)
self.assertEqual(response.status_code, 201, response.data)
app = App.objects.get(id=app_id)
response = app.scheduler().httproute.get(app_id, route_name, ignore_exception=True)
self.assertEqual(response.status_code, 404)
# Set routable to false
response = self.client.post(
f'/v2/apps/{app_id}/settings',
{'routable': True}
)
response = app.scheduler().httproute.get(app_id, route_name, ignore_exception=True)
self.assertEqual(response.status_code, 200)
def test_route_delete(self):
app_id = self.create_app()
_, _, route_name = self.create_route(app_id)
response = self.client.get('/v2/apps/{}/routes/'.format(app_id))
self.assertEqual(len(response.data["results"]), 1)
response = self.client.delete(
'/v2/apps/{}/routes/{}/'.format(app_id, route_name),
)
self.assertEqual(response.status_code, 204)
response = self.client.get('/v2/apps/{}/routes/'.format(app_id))
self.assertEqual(len(response.data["results"]), 0)
def test_rule_get(self):
app_id = self.create_app()
ptype, _, route_name = self.create_route(app_id)
response = self.client.get(
'/v2/apps/{}/routes/{}/rules/'.format(app_id, route_name),
)
expect = [{
'backendRefs': [{
'kind': 'Service',
'name': '%s-%s' % (app_id, ptype),
'port': 5000,
'weight': 100
}]
}]
self.assertEqual(response.data, expect)
def test_schemas(self):
for rule in os.listdir("{}/rules/".format(TEST_ROOT)):
with open("{}/rules/{}".format(TEST_ROOT, rule)) as f:
data = f.read()
try:
validate_json(json.loads(data), RULES_SCHEMA)
except Exception as e:
raise self.failureException("validate %s rule error: %s" % (rule, str(e)))
def test_rule_set(self):
app_id = self.create_app()
ptype, _, route_name = self.create_route(app_id)
expect = [{
"backendRefs": [{
"kind": "Service",
"name": "%s-%s" % (app_id, ptype),
"port": 5000,
"weight": 100
}]
}]
response = self.client.put(
'/v2/apps/{}/routes/{}/rules/'.format(app_id, route_name),
json.dumps(expect),
content_type="application/json",
)
response = self.client.get(
'/v2/apps/{}/routes/{}/rules/'.format(app_id, route_name),
)
self.assertEqual(json.dumps(response.data), json.dumps(expect))
expect = [{
"backendRefs": [{
"kind": "Service",
"name": "%s-%s-noexits" % (app_id, ptype),
"port": 5000,
"weight": 100
}]
}]
response = self.client.put(
'/v2/apps/{}/routes/{}/rules/'.format(app_id, route_name),
json.dumps(expect),
content_type="application/json",
)
self.assertEqual(response.status_code, 400)
def test_change_tls(self):
app_id = self.create_app_with_domain_and_deploy()
response = self.client.get('/v2/apps/{}/routes/'.format(app_id))
self.assertEqual(len(response.data["results"]), 1, response.data)
expect = [{
'name': f'{app_id}',
'port': 80
}]
# enable tls
self.change_certs_auto(app_id, True)
self.assertEqual(response.data["results"][0]["parent_refs"], expect, response.data)
response = self.client.get('/v2/apps/{}/routes/'.format(app_id))
self.assertEqual(len(response.data["results"]), 1, response.data)
expect = [{
'name': f'{app_id}',
'port': 80
}, {
'name': f'{app_id}',
'port': 443
}]
self.assertEqual(len(response.data["results"]), 1, response.data)
self.assertEqual(response.data["results"][0]["parent_refs"], expect, response.data)
# disable tls
self.change_certs_auto(app_id, False)
response = self.client.get('/v2/apps/{}/routes/'.format(app_id))
self.assertEqual(len(response.data["results"]), 1, response.data)
expect = [{
'name': f'{app_id}',
'port': 80
}]
self.assertEqual(len(response.data["results"]), 1, response.data)
self.assertEqual(response.data["results"][0]["parent_refs"], expect, response.data)