|
1 | 1 | from arrowhead_client.client.implementations import SyncClient
|
2 | 2 | from arrowhead_client.client import provided_service
|
3 | 3 |
|
4 |
| -def test_provided_service(): |
| 4 | + |
| 5 | +def test_provided_service_insecure_with_service_descriptor(): |
| 6 | + class CustomClient(SyncClient): |
| 7 | + def __init__(self, *args, format='', **kwargs): |
| 8 | + super().__init__(*args, **kwargs) |
| 9 | + self.format = format |
| 10 | + |
| 11 | + @provided_service( |
| 12 | + service_definition='hello-arrowhead', |
| 13 | + service_uri='hello', |
| 14 | + protocol='HTTP', |
| 15 | + method='GET', |
| 16 | + payload_format='JSON', |
| 17 | + access_policy='NOT_SECURE', |
| 18 | + ) |
| 19 | + def service_function(self, request): |
| 20 | + return {'fmt': self.format} |
| 21 | + |
| 22 | + test_client = CustomClient.create( |
| 23 | + 'custom_client', '127.0.0.1', 1337, format='1Ab') |
| 24 | + |
| 25 | + test_client.setup() |
| 26 | + |
| 27 | + rule = list(test_client.registration_rules)[0] |
| 28 | + |
| 29 | + assert rule.service_definition == 'hello-arrowhead' |
| 30 | + assert rule.provided_service.interface.dto() == "HTTP-INSECURE-JSON" |
| 31 | + assert rule.provided_service.access_policy == "NOT_SECURE" |
| 32 | + |
| 33 | + |
| 34 | +def test_provided_service_secure_with_service_descriptor(): |
5 | 35 | class CustomClient(SyncClient):
|
6 | 36 | def __init__(self, *args, format='', **kwargs):
|
7 | 37 | super().__init__(*args, **kwargs)
|
8 | 38 | self.format = format
|
9 | 39 |
|
10 | 40 | @provided_service(
|
11 |
| - service_definition='hello-arrowhead', |
12 |
| - service_uri='hello', |
13 |
| - protocol='HTTP', |
14 |
| - method='GET', |
15 |
| - payload_format='JSON', |
16 |
| - access_policy='NOT_SECURE', |
| 41 | + service_definition='hello-arrowhead', |
| 42 | + service_uri='hello', |
| 43 | + protocol='HTTP', |
| 44 | + method='GET', |
| 45 | + payload_format='JSON', |
| 46 | + access_policy='CERTIFICATE', |
17 | 47 | )
|
18 | 48 | def service_function(self, request):
|
19 | 49 | return {'fmt': self.format}
|
20 | 50 |
|
21 |
| - test_client = CustomClient.create('custom_client', '127.0.0.1', 1337, format='1Ab') |
| 51 | + test_client = CustomClient.create( |
| 52 | + 'custom_client', '127.0.0.1', 1337, format='1Ab') |
22 | 53 |
|
23 | 54 | test_client.setup()
|
24 | 55 |
|
25 | 56 | rule = list(test_client.registration_rules)[0]
|
26 | 57 |
|
27 | 58 | assert rule.service_definition == 'hello-arrowhead'
|
| 59 | + assert rule.provided_service.interface.dto() == "HTTP-SECURE-JSON" |
| 60 | + assert rule.provided_service.access_policy == "CERTIFICATE" |
| 61 | + |
| 62 | + |
| 63 | +def test_provided_service_insecure_with_function_decorator(): |
| 64 | + class CustomClient(SyncClient): |
| 65 | + def __init__(self, *args, format='', **kwargs): |
| 66 | + super().__init__(*args, **kwargs) |
| 67 | + self.format = format |
| 68 | + |
| 69 | + test_client = CustomClient.create( |
| 70 | + 'custom_client', '127.0.0.1', 1337, format='1Ab') |
| 71 | + |
| 72 | + @test_client.provided_service( |
| 73 | + service_definition='hello-arrowhead', |
| 74 | + service_uri='hello', |
| 75 | + protocol='HTTP', |
| 76 | + method='GET', |
| 77 | + payload_format='JSON', |
| 78 | + access_policy='NOT_SECURE', |
| 79 | + ) |
| 80 | + def service_function(request): |
| 81 | + return {'fmt': '1Ab'} |
| 82 | + |
| 83 | + rule = list(test_client.registration_rules)[0] |
| 84 | + |
| 85 | + assert rule.service_definition == 'hello-arrowhead' |
| 86 | + assert rule.provided_service.interface.dto() == "HTTP-INSECURE-JSON" |
| 87 | + assert rule.provided_service.access_policy == "NOT_SECURE" |
| 88 | + |
| 89 | + |
| 90 | +def test_provided_service_secure_with_function_decorator(): |
| 91 | + class CustomClient(SyncClient): |
| 92 | + def __init__(self, *args, format='', **kwargs): |
| 93 | + super().__init__(*args, **kwargs) |
| 94 | + self.format = format |
| 95 | + |
| 96 | + test_client = CustomClient.create( |
| 97 | + 'custom_client', '127.0.0.1', 1337, format='1Ab') |
| 98 | + |
| 99 | + @test_client.provided_service( |
| 100 | + service_definition='hello-arrowhead', |
| 101 | + service_uri='hello', |
| 102 | + protocol='HTTP', |
| 103 | + method='GET', |
| 104 | + payload_format='JSON', |
| 105 | + access_policy='CERTIFICATE', |
| 106 | + ) |
| 107 | + def service_function(request): |
| 108 | + return {'fmt': '1Ab'} |
| 109 | + |
| 110 | + rule = list(test_client.registration_rules)[0] |
| 111 | + |
| 112 | + assert rule.service_definition == 'hello-arrowhead' |
| 113 | + assert rule.provided_service.interface.dto() == "HTTP-SECURE-JSON" |
| 114 | + assert rule.provided_service.access_policy == "CERTIFICATE" |
0 commit comments