Skip to content

Commit 948238e

Browse files
authored
153 Add option to send mock bpa bundles to both appin and clin (#162)
* give option to send bundles to appin or clin for mock bpa tests * rename policy on fail json * apply format ubuntu * Turn testcase into dataclass, make enums IntEnum * apply format ubuntu
1 parent 84c2798 commit 948238e

7 files changed

Lines changed: 88 additions & 45 deletions

File tree

mock-bpa-test/_test_util.py

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,48 @@
1919
# the prime contract 80NM0018D0004 between the Caltech and NASA under
2020
# subcontract 1700763.
2121
#
22-
from enum import Enum
22+
from enum import IntEnum, unique
23+
from dataclasses import dataclass
24+
from typing import Any
2325

2426

25-
class DataFormat(Enum):
27+
@unique
28+
class DataFormat(IntEnum):
2629
BUNDLEARRAY = 0
2730
HEX = 1
2831
ERR = 2
2932
NONE = 3
3033

31-
# "structure" to hold a simple test case
3234

35+
@unique
36+
class BundleDestLoc(IntEnum):
37+
APPIN = 0
38+
CLIN = 1
3339

40+
41+
@dataclass
42+
# Holds a simple test case
3443
class _TestCase:
35-
'''
36-
@param input_data: list representation of bundle
37-
@param expected_output: either list representation of expected output bundle OR a string to search log output for match
38-
@param policy_config: decimal digit representing uint32 for policy configuration OR path to JSON-encoded ION-like policy rules
39-
@param key_set: path to JWK-encoded key set
40-
@param is_working: True if test working
41-
@param input/output_data_format: data format of input/output
42-
'''
43-
44-
def __init__(self, input_data, expected_output: DataFormat, policy_config: str, key_set: str, is_working: bool,
45-
input_data_format: DataFormat, expected_output_format: DataFormat):
46-
self.input_data = input_data
47-
self.expected_output = expected_output
48-
self.policy_config = policy_config
49-
self.key_set = key_set
50-
51-
# can be removed once all tests are working
52-
self.is_working = is_working
53-
54-
self.input_data_format = input_data_format
55-
self.expected_output_format = expected_output_format
44+
# list representation of bundle
45+
input_data: Any
46+
47+
# either list representation of expected output bundle OR a string to search log output for match
48+
expected_output: DataFormat
49+
50+
# decimal digit representing uint32 for policy configuration OR path to JSON-encoded ION-like policy rules
51+
policy_config: str
52+
53+
# path to JWK-encoded key set
54+
key_set: str
55+
56+
# data format of input
57+
input_data_format: DataFormat
58+
59+
# data format of output
60+
expected_output_format: DataFormat
61+
62+
# True if test working (can be removed once all tests are working)
63+
is_working: bool = True
64+
65+
# destination location of the bundle
66+
bundle_dest_loc: BundleDestLoc = BundleDestLoc.CLIN

mock-bpa-test/policy_provider_test.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"rule_id": "1",
88
"role": "s",
99
"tgt": 1,
10-
"loc": "clin",
10+
"loc": "appin",
1111
"sc_id": 1
1212
},
1313
"spec": {
@@ -33,7 +33,7 @@
3333
]
3434
},
3535
"es_ref": "d_integrity",
36-
"_temp_not_ion_spec_policy_action_on_fail": "delete_bundle"
36+
"policy_action_on_fail": "delete_bundle"
3737
},
3838
"event_set": {
3939
"es_ref": "d_integrity",
@@ -52,7 +52,7 @@
5252
"rule_id": "2",
5353
"role": "s",
5454
"tgt": 1,
55-
"loc": "clin",
55+
"loc": "appin",
5656
"sc_id": 2
5757
},
5858
"spec": {
@@ -78,7 +78,7 @@
7878
]
7979
},
8080
"es_ref": "d_confidentiality",
81-
"_temp_not_ion_spec_policy_action_on_fail": "delete_bundle"
81+
"policy_action_on_fail": "delete_bundle"
8282
},
8383
"event_set": {
8484
"es_ref": "d_confidentiality",

mock-bpa-test/test_bpa.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import cbor2
3636

3737
from helpers import CmdRunner, compose_args
38-
from _test_util import _TestCase, DataFormat
38+
from _test_util import _TestCase, DataFormat, BundleDestLoc
3939

4040
OWNPATH = os.path.dirname(os.path.abspath(__file__))
4141
LOGGER = logging.getLogger(__name__)
@@ -141,14 +141,16 @@ def _single_test(self, testcase: Optional[_TestCase]):
141141
tx_data = testcase.input_data if (
142142
testcase.input_data_format == DataFormat.HEX) else self._encode(testcase.input_data)
143143

144-
if (testcase.expected_output_format == DataFormat.BUNDLEARRAY):
144+
test_sock = self._ol_sock if testcase.bundle_dest_loc == BundleDestLoc.APPIN else self._ul_sock
145+
146+
if testcase.expected_output_format == DataFormat.BUNDLEARRAY:
145147
expected_rx = testcase.expected_output if (
146148
testcase.expected_output == "HEX") else self._encode(testcase.expected_output)
147149

148-
self._ul_sock.send(tx_data)
150+
test_sock.send(tx_data)
149151
LOGGER.debug('waiting')
150152

151-
rx_data = self._wait_for(self._ul_sock)
153+
rx_data = self._wait_for(test_sock)
152154

153155
LOGGER.info('\nTransferred data:\n%s\n', binascii.hexlify(tx_data))
154156
LOGGER.info('\nReceived data:\n%s\n', binascii.hexlify(rx_data))
@@ -160,12 +162,12 @@ def _single_test(self, testcase: Optional[_TestCase]):
160162

161163
self.assertEqual(binascii.hexlify(expected_rx), binascii.hexlify(rx_data))
162164

163-
elif (testcase.expected_output_format == DataFormat.NONE):
164-
self._ul_sock.send(tx_data)
165+
elif testcase.expected_output_format == DataFormat.NONE:
166+
test_sock.send(tx_data)
165167
LOGGER.debug('waiting')
166168

167169
with self.assertRaises(TimeoutError):
168-
self._wait_for(self._ul_sock)
170+
self._wait_for(test_sock)
169171

170172
LOGGER.info('\nTransferred data:\n%s\n', binascii.hexlify(tx_data))
171173

@@ -178,12 +180,12 @@ def _single_test(self, testcase: Optional[_TestCase]):
178180
LOGGER.debug("\nFOUND OCCURENCE: %s", found)
179181
self.assertNotEqual("", found)
180182

181-
elif (testcase.expected_output_format == DataFormat.ERR):
182-
self._ul_sock.send(tx_data)
183+
elif testcase.expected_output_format == DataFormat.ERR:
184+
test_sock.send(tx_data)
183185
LOGGER.debug('waiting')
184186

185187
with self.assertRaises(TimeoutError):
186-
self._wait_for(self._ul_sock)
188+
self._wait_for(test_sock)
187189

188190
LOGGER.info('\nTransferred data:\n%s\n', binascii.hexlify(tx_data))
189191

mock-bpa-test/test_ccsds.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import binascii
2525
import tempfile
2626
import json
27-
from _test_util import _TestCase, DataFormat
27+
from _test_util import _TestCase, DataFormat, BundleDestLoc
2828
from test_bpa import TestAgent
2929

3030

@@ -150,14 +150,14 @@ def load_ccsds():
150150
'rule_id': str(i),
151151
'role': sec_role,
152152
'tgt': int(target),
153-
'loc': 'clin',
153+
'loc': 'appin',
154154
'sc_id': sec_ctx,
155155
},
156156
'spec': {
157157
'sc_id': sec_ctx,
158158
'sc_parms': params
159159
},
160-
'_temp_not_ion_spec_policy_action_on_fail': 'delete_bundle'
160+
'policy_action_on_fail': 'delete_bundle'
161161
}
162162
}
163163
print(f'Appending new Policy Rule {pr}')
@@ -178,6 +178,7 @@ def load_ccsds():
178178
expected_output=output if (
179179
output_format == DataFormat.BUNDLEARRAY) else r".*Delete bundle due to failed security operation",
180180
policy_config=finame,
181+
bundle_dest_loc=BundleDestLoc.APPIN,
181182
key_set="mock-bpa-test/key_set_1.json",
182183
is_working=True,
183184
input_data_format=input_format,

mock-bpa-test/test_json_policy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# the prime contract 80NM0018D0004 between the Caltech and NASA under
2020
# subcontract 1700763.
2121
#
22-
from _test_util import _TestCase, DataFormat
22+
from _test_util import _TestCase, DataFormat, BundleDestLoc
2323
from test_bpa import TestAgent
2424

2525
# Test Cases utilizing JSON policy definitions
@@ -46,6 +46,7 @@ def test_json_source_bib_bcb(self):
4646
'3a09c1e63fe23a7f66a59c7303837241e070b02619fc59c5214a22f08cd70795e73e9a')]
4747
],
4848
policy_config='mock-bpa-test/policy_provider_test.json',
49+
bundle_dest_loc=BundleDestLoc.APPIN,
4950
key_set="mock-bpa-test/key_set_1.json",
5051
is_working=True,
5152
input_data_format=DataFormat.BUNDLEARRAY,

0 commit comments

Comments
 (0)