Skip to content

Commit 062e845

Browse files
authored
All MockBPA Tests Passing (#45)
1 parent 4b07bc9 commit 062e845

11 files changed

Lines changed: 100 additions & 150 deletions

mock-bpa-test/_generate_simple_bundles.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,13 @@ def add_bcb_to_bundle_over_x(bundle, x):
152152

153153
b = [
154154
[7, 0, 0, [2, [1, 2]], [2, [2, 1]], [2, [2, 1]], [0, 40], 1000000],
155-
[1, 1, 0, 0, '526561647920746F2067656E657261746520612033322D62797465207061796C6F6164']
155+
[1, 1, 0, 0, '526561647920746F2067656E657261746520612033322D62797465207061796C6F6164'],
156+
[192, 2, 0, 0, '676f20647261676f6e666c7921']
156157
]
157158

158159

159160
print (f"ORIGINAL BUNDLE: {b}")
160-
b = add_bib_to_bundle_over_x(b, 0)
161+
b = add_bib_to_bundle_over_x(b, 2)
161162
print(f'BUNDLE AFTER BIB: {b}')
162163
#b = add_bcb_to_bundle_over_x(b, 1)
163164
print(f'FINAL BUNDLE: {b}')

mock-bpa-test/_test_util.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,21 @@ class DataFormat(Enum):
3030
# "structure" to hold a simple test case
3131
class _TestCase:
3232
'''
33-
@param input_data list representation of bundle | TODO hex option / fully hex?
34-
@param expected_output either list representation of expected output bundle OR tuple for outcome (FAILURE_CODE, N), (NO_OUTPUT, N), etc.
35-
@param policy_config decimal digit representing uint32 for policy configuration | TODO switch to a hex string?
36-
@param impl - boolean, true if test is implemented, false if not (placeholder for empty test fixtures)
37-
@param success - boolean, true if input bundle is expected to have an output bundle, false if error/no output
33+
@param input_data: list representation of bundle
34+
@param expected_output: either list representation of expected output bundle OR a string to search log output for match
35+
@param policy_config: decimal digit representing uint32 for policy configuration
36+
@param is_working: True if test working
37+
@param input/output_data_format: data format of input/output
3838
'''
39-
def __init__(self, input_data, expected_output, policy_config,
40-
is_implemented : bool, is_working: bool, expect_success: bool,
39+
def __init__(self, input_data, expected_output, policy_config, is_working: bool,
4140
input_data_format : DataFormat, expected_output_format : DataFormat):
4241
self.input_data = input_data
4342
self.expected_output = expected_output
4443
self.policy_config = policy_config
4544

46-
# can be removed once all tests are implemeneted
47-
self.is_implemented = is_implemented
48-
4945
# can be removed once all tests are wworking
5046
self.is_working = is_working
5147

52-
# true if test expected to succeed (return output bundle with no errors)
53-
self.expect_success = expect_success
54-
5548
self.input_data_format = input_data_format
5649
self.expected_output_format = expected_output_format
5750

mock-bpa-test/requirements_tests.py

Lines changed: 58 additions & 91 deletions
Large diffs are not rendered by default.

mock-bpa-test/test_bpa.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,10 @@ def _single_test(self, testcase: _TestCase):
173173

174174
LOGGER.warning('Check log output to validate reason for no data!!')
175175

176-
# Currently hard-coded for test case 19 but no other instances of DataFormat.NONE
177-
case_19_str = r".*Delete bundle due to failed security operation"
176+
output_str = testcase.expected_output
178177

179-
LOGGER.debug("Searching test runner logger for failure string: %s", case_19_str)
180-
found = self._agent.wait_for_text(case_19_str)
178+
LOGGER.debug("Searching test runner logger for failure string: %s", output_str)
179+
found = self._agent.wait_for_text(output_str)
181180
LOGGER.debug("\nFOUND OCCURENCE: %s", found)
182181
self.assertTrue(found != "")
183182

@@ -192,8 +191,7 @@ def _single_test(self, testcase: _TestCase):
192191

193192
LOGGER.warning('Check log output to validate expected error')
194193

195-
# TBD - this logic is not used yet
196-
err_case_str = r"tbd"
194+
err_case_str = testcase.expected_output
197195

198196
LOGGER.debug("Searching test runner logger for error string: %s", err_case_str)
199197
found = self._agent.wait_for_text(err_case_str)
@@ -208,7 +206,7 @@ def _add_tests(new_tests: _TestSet):
208206

209207
def decorator(cls):
210208
for id, tc in new_tests.cases.items():
211-
if tc.is_implemented and tc.is_working:
209+
if tc.is_working:
212210

213211
def _test(cls, id=id):
214212
cls._single_test(new_tests.cases[id])

src/backend/PublicInterfaceImpl.c

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,6 @@ int BSL_API_ApplySecurity(const BSL_LibCtx_t *bsl, BSL_SecurityResponseSet_t *re
197197
int finalize_status = BSL_PolicyRegistry_FinalizeActions(bsl, policy_actions, bundle, response_output);
198198
BSL_LOG_INFO("Completed finalize: status=%d", finalize_status);
199199

200-
bool must_drop = false;
201-
202200
BSL_SecActionList_it_t act_it;
203201
for (BSL_SecActionList_it(act_it, policy_actions->actions); !BSL_SecActionList_end_p(act_it);
204202
BSL_SecActionList_next(act_it))
@@ -239,7 +237,9 @@ int BSL_API_ApplySecurity(const BSL_LibCtx_t *bsl, BSL_SecurityResponseSet_t *re
239237
{
240238
BSL_LOG_WARNING("Deleting bundle due to block target num %lu security failure",
241239
sec_oper->target_block_num);
242-
must_drop = true;
240+
// Drop the bundle and return operation error
241+
BSL_LOG_WARNING("***** Delete bundle due to failed security operation *******");
242+
BSL_BundleCtx_DeleteBundle(bundle);
243243
break;
244244
}
245245
case BSL_POLICYACTION_UNDEFINED:
@@ -248,21 +248,9 @@ int BSL_API_ApplySecurity(const BSL_LibCtx_t *bsl, BSL_SecurityResponseSet_t *re
248248
BSL_LOG_ERR("Unhandled policy action: %lu", err_action_code);
249249
}
250250
}
251-
252-
if (must_drop)
253-
{
254-
break;
255-
}
256251
}
257252
}
258253

259-
if (must_drop)
260-
{
261-
// Drop the bundle and return operation error
262-
BSL_LOG_WARNING("***** Delete bundle due to failed security operation *******");
263-
BSL_BundleCtx_DeleteBundle(bundle);
264-
}
265-
266254
// TODO CHK_POSTCONDITION
267-
return (must_drop) ? BSL_ERR_SECURITY_OPERATION_FAILED : BSL_SUCCESS;
255+
return BSL_SUCCESS;
268256
}

src/backend/SecurityContext.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,7 @@ int BSL_SecCtx_ExecutePolicyActionSet(BSL_LibCtx_t *lib, BSL_SecurityResponseSet
473473
* - BCB will be a special case, since it actively manipulates the BTSD
474474
*
475475
*/
476-
size_t fail_count = 0;
477-
BSL_SecOutcome_t *outcome = calloc(BSL_SecOutcome_Sizeof(), 1);
476+
BSL_SecOutcome_t *outcome = calloc(BSL_SecOutcome_Sizeof(), 1);
478477

479478
BSL_SecActionList_it_t act_it;
480479
for (BSL_SecActionList_it(act_it, action_set->actions); !BSL_SecActionList_end_p(act_it);
@@ -514,19 +513,16 @@ int BSL_SecCtx_ExecutePolicyActionSet(BSL_LibCtx_t *lib, BSL_SecurityResponseSet
514513

515514
if (errcode != 0)
516515
{
517-
fail_count += 1;
518516
BSL_LOG_ERR("Security Op failed: %d", errcode);
519517
BSL_SecOper_SetConclusion(sec_oper, BSL_SECOP_CONCLUSION_FAILURE);
520-
continue;
518+
break; // stop processing secops if there is a failure
521519
}
522520
BSL_SecOper_SetConclusion(sec_oper, BSL_SECOP_CONCLUSION_SUCCESS);
523521
}
524522
}
525523
free(outcome);
526524

527-
output_response->failure_count = fail_count;
528-
529-
return fail_count == 0 ? BSL_SUCCESS : BSL_ERR_SECURITY_CONTEXT_PARTIAL_FAIL;
525+
return BSL_SUCCESS;
530526
}
531527

532528
bool BSL_SecCtx_ValidatePolicyActionSet(BSL_LibCtx_t *lib, const BSL_BundleRef_t *bundle,

src/mock_bpa/policy_config.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ static void mock_bpa_register_policy(const bsl_mock_policy_configuration_t polic
455455
BSL_LOG_DEBUG("\nPolicy: 0x%X - Bundle Block Type: PAYLOAD", policy_bits);
456456
break;
457457
case 2:
458-
bundle_block_enum = BSL_BLOCK_TYPE_BIB;
459-
BSL_LOG_DEBUG("\nPolicy: 0x%X - Bundle Block Type: BIB", policy_bits);
458+
bundle_block_enum = 192;
459+
BSL_LOG_DEBUG("\nPolicy: 0x%X - Bundle Block Type: PRIVATE (192)", policy_bits);
460460
break;
461461
case 3:
462462
bundle_block_enum = BSL_BLOCK_TYPE_BUNDLE_AGE;

src/mock_bpa/policy_config.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,15 @@ extern "C" {
6161
* Policy Action: 00 - nothing, 01 - drop block, -| | | |
6262
* 10 - drop bundle, 11: undefined -| | | |
6363
* | | |
64-
* Target Block Type: 00 - primary, 01 payload -| | |
65-
* 10 - bib, 11 - bundle age -| | |
64+
* Target Block Type: 00 - primary, 01 - payload, -| | |
65+
* 10 - private/experimental (192), 11 - bundle age -| | |
6666
* | |
6767
* Target Block Type: -| | |
6868
* Policy Location: 0 - CLOUT, 1 - CLIN -| |
6969
* |
7070
* Sec Block Type: 0 - BIB, 1 - BCB -|
7171
*
72+
*
7273
* @endcode
7374
*/
7475
typedef uint32_t bsl_mock_policy_configuration_t;

src/policy_provider/SamplePolicyProvider.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ int BSLP_QueryPolicy(const void *user_data, BSL_SecurityActionSet_t *output_acti
156156
for (i = 0; i < BSLP_SecOperPtrList_size(secops); i++)
157157
{
158158
BSL_SecOper_t **comp = BSLP_SecOperPtrList_get(secops, i);
159-
BSL_LOG_INFO("NEW SECOP (tgt=%d)(bib?=%d)(secblk=%d)", BSL_SecOper_GetTargetBlockNum(sec_oper),
160-
BSL_SecOper_IsBIB(sec_oper), BSL_SecOper_GetSecurityBlockNum(sec_oper));
161-
BSL_LOG_INFO("comp SECOP (tgt=%d)(bib?=%d)(secblk=%d)", BSL_SecOper_GetTargetBlockNum(*comp),
162-
BSL_SecOper_IsBIB(*comp), BSL_SecOper_GetSecurityBlockNum(*comp));
159+
BSL_LOG_DEBUG("NEW SECOP (tgt=%d)(bib?=%d)(secblk=%d)", BSL_SecOper_GetTargetBlockNum(sec_oper),
160+
BSL_SecOper_IsBIB(sec_oper), BSL_SecOper_GetSecurityBlockNum(sec_oper));
161+
BSL_LOG_DEBUG("comp SECOP (tgt=%d)(bib?=%d)(secblk=%d)", BSL_SecOper_GetTargetBlockNum(*comp),
162+
BSL_SecOper_IsBIB(*comp), BSL_SecOper_GetSecurityBlockNum(*comp));
163163
if (BSL_SecOper_GetTargetBlockNum(*comp) == BSL_SecOper_GetTargetBlockNum(sec_oper))
164164
{
165165
// Both BIBs or BCBs
@@ -171,12 +171,12 @@ int BSLP_QueryPolicy(const void *user_data, BSL_SecurityActionSet_t *output_acti
171171
// true if ACC BIB or SRC BCB
172172
if (BSL_SecOper_IsBIB(sec_oper) ^ BSL_SecOper_IsRoleSource(sec_oper))
173173
{
174-
BSL_LOG_INFO("NEW OP AFTER COMP");
174+
BSL_LOG_DEBUG("NEW OP AFTER COMP");
175175
BSLP_SecOperPtrList_push_at(secops, i + 1, sec_oper);
176176
}
177177
else
178178
{
179-
BSL_LOG_INFO("NEW OP BEFORE COMP");
179+
BSL_LOG_DEBUG("NEW OP BEFORE COMP");
180180
BSLP_SecOperPtrList_push_at(secops, i, sec_oper);
181181
}
182182
break;

test/test_BackendSecurityContext.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,13 @@ void test_SecurityContext_BIB_Verifier_Failure(void)
188188
BSL_SecurityActionSet_t *malloced_actionset = BSL_TestUtils_InitMallocBIBActionSet(&bib_test_context);
189189
BSL_SecurityResponseSet_t *malloced_responseset = BSL_TestUtils_MallocEmptyPolicyResponse();
190190

191-
TEST_ASSERT_NOT_EQUAL(BSL_SUCCESS,
192-
BSL_SecCtx_ExecutePolicyActionSet(&LocalTestCtx.bsl, malloced_responseset,
193-
&mock_bpa_ctr->bundle_ref, malloced_actionset));
191+
TEST_ASSERT_EQUAL(BSL_SUCCESS, BSL_SecCtx_ExecutePolicyActionSet(&LocalTestCtx.bsl, malloced_responseset,
192+
&mock_bpa_ctr->bundle_ref, malloced_actionset));
193+
194+
TEST_ASSERT_EQUAL(
195+
BSL_SecurityAction_GetSecOperAtIndex(BSL_SecurityActionSet_GetActionAtIndex(malloced_actionset, 0), 0)
196+
->conclusion,
197+
BSL_SECOP_CONCLUSION_FAILURE);
194198

195199
BSL_SecurityActionSet_Deinit(malloced_actionset);
196200
free(malloced_actionset);

0 commit comments

Comments
 (0)