Skip to content

Commit ba9a3ce

Browse files
authored
Making the MIM test recipe for Security Baseline module test in full ASB v2, including confirming audits passing (#718)
1 parent bf8da10 commit ba9a3ce

File tree

3 files changed

+61
-10
lines changed

3 files changed

+61
-10
lines changed

src/modules/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ add_library(testlib Module.c)
88
target_link_libraries(testlib
99
${CMAKE_DL_LIBS}
1010
commonutils
11+
asb
1112
logging
1213
pthread
1314
parsonlib)

src/modules/test/Common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <CommonUtils.h>
2020
#include <Logging.h>
21+
#include <Asb.h>
2122
#include <Mmi.h>
2223
#include <version.h>
2324

src/modules/test/main.c

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#define RECIPE_JSON "Json"
2626
#define RECIPE_STATUS "ExpectedResult"
2727
#define RECIPE_WAIT_SECONDS "WaitSeconds"
28+
#define SECURITY_BASELINE "SecurityBaseline"
2829

2930
#define RECIPE_RUN_COMMAND "RunCommand"
3031

@@ -382,13 +383,25 @@ int RunCommand(const COMMAND_STEP* command)
382383

383384
int RunTestStep(const TEST_STEP* test, const MANAGEMENT_MODULE* module)
384385
{
385-
int result = 0;
386+
const char* skippedAudits[] = {
387+
"auditEnsureKernelSupportForCpuNx",
388+
"auditEnsureDefaultDenyFirewallPolicyIsSet",
389+
"auditEnsureAuthenticationRequiredForSingleUserMode",
390+
"auditEnsureAllBootloadersHavePasswordProtectionEnabled"
391+
};
392+
int numSkippedAudits = ARRAY_SIZE(skippedAudits);
393+
394+
const char* audit = "audit";
395+
const char* reason = NULL;
386396
JSON_Value* actualJsonValue = NULL;
387397
JSON_Value* expectedJsonValue = NULL;
388398
MMI_JSON_STRING payload = NULL;
389399
char* payloadString = NULL;
400+
bool asbAudit = false;
390401
int payloadSize = 0;
402+
int i = 0;
391403
int mmiStatus = 0;
404+
int result = 0;
392405

393406
if (test == NULL)
394407
{
@@ -418,36 +431,72 @@ int RunTestStep(const TEST_STEP* test, const MANAGEMENT_MODULE* module)
418431
LOG_ERROR("Failed to parse JSON payload: %s", payloadString);
419432
result = EINVAL;
420433
}
434+
else if ((0 == strcmp(test->component, SECURITY_BASELINE)) &&
435+
(0 == strncmp(test->object, audit, strlen(audit))))
436+
{
437+
asbAudit = true;
438+
439+
for (i = 0; i < numSkippedAudits; i++)
440+
{
441+
if (0 == strcmp(test->object, skippedAudits[i]))
442+
{
443+
asbAudit = false;
444+
break;
445+
}
446+
}
447+
}
421448
}
422449
}
423450

424-
if (test->payload != NULL)
451+
if (test->payload || asbAudit)
425452
{
426-
if (actualJsonValue != NULL)
453+
if (asbAudit)
454+
{
455+
if (NULL == (reason = json_value_get_string(actualJsonValue)))
456+
{
457+
LOG_ERROR("Assertion failed, json_value_get_string('%s') failed", json_serialize_to_string(actualJsonValue));
458+
result = -1;
459+
}
460+
else if (0 != strncmp(reason, SECURITY_AUDIT_PASS, strlen(SECURITY_AUDIT_PASS)))
461+
{
462+
LOG_ERROR("Assertion failed, expected: '%s...', actual: '%s'", SECURITY_AUDIT_PASS, reason);
463+
result = EFAULT;
464+
}
465+
else
466+
{
467+
LOG_INFO("Assertion passed with reason: '%s'", reason + strlen(SECURITY_AUDIT_PASS));
468+
}
469+
}
470+
else if (actualJsonValue != NULL)
427471
{
428472
if (NULL == (expectedJsonValue = json_parse_string(test->payload)))
429473
{
430474
LOG_ERROR("Failed to parse expected JSON payload: %s", test->payload);
431-
result = EINVAL;
475+
result = EFAULT;
432476
}
433-
else if (!json_value_equals(expectedJsonValue, actualJsonValue))
477+
else if (0 == json_value_equals(expectedJsonValue, actualJsonValue))
434478
{
435-
LOG_ERROR("Assertion failed, expected: '%s', actual: '%s'", json_serialize_to_string(expectedJsonValue), json_serialize_to_string(actualJsonValue));
436-
result = -1;
479+
LOG_ERROR("Assertion failed, expected: '%s', actual: '%s'",
480+
json_serialize_to_string(expectedJsonValue), json_serialize_to_string(actualJsonValue));
481+
result = EFAULT;
437482
}
438483
}
439484
else
440485
{
441486
LOG_ERROR("Assertion failed, expected: '%s', actual: (null)", test->payload);
442-
result = -1;
487+
result = EFAULT;
443488
}
444489
}
445490

446491
if (test->status != mmiStatus)
447492
{
448493
LOG_ERROR("Assertion failed, expected result '%d', actual '%d'", test->status, mmiStatus);
449-
result = -1;
494+
result = EFAULT;
450495
}
496+
497+
json_value_free(expectedJsonValue);
498+
json_value_free(actualJsonValue);
499+
FREE_MEMORY(payloadString);
451500
}
452501
else if (test->type == DESIRED)
453502
{
@@ -456,7 +505,7 @@ int RunTestStep(const TEST_STEP* test, const MANAGEMENT_MODULE* module)
456505
if (test->status != mmiStatus)
457506
{
458507
LOG_ERROR("Assertion failed, expected result '%d', actual '%d'", test->status, mmiStatus);
459-
result = -1;
508+
result = EFAULT;
460509
}
461510
}
462511
else

0 commit comments

Comments
 (0)