}
//pairs of rules for test with mixed cases, different length and mixed order
-const char *rules_tab[] = {
- "reader1", "-", "-----",
- "reader2", "--------", "-----",
- "reader3", "RwXaT", "rwxat",
- "reader4", "RrrXXXXTTT", "r-x-t",
- "reader5", "-r-w-a-t", "rw-at",
- "reader6", "", "-----",
- "reader7", "xa--Rt---W", "rwxat",
- "reader8", "#Ax[T].!~W@1}", "-wxat"
+std::vector< std::vector<std::string> > correct_rules = {
+ { "reader1", "-", "------" },
+ { "reader2", "--------", "------" },
+ { "reader3", "RwXaTl", "rwxatl" },
+ { "reader4", "RrrXXXXTTT", "r-x-t-" },
+ { "reader5", "-r-w-a-t-", "rw-at-" },
+ { "reader6", "", "------" },
+ { "reader7", "xa--Rt---W--L", "rwxatl" },
};
RUNNER_TEST_SMACK(smack03_mixed_rule_string_add)
struct smack_accesses *rules = NULL; //rules prepared in this test case
int result; //for storing functions results
- int i;
int expected;
result = smack_accesses_new(&rules); //rules struct init
RUNNER_ASSERT_MSG_BT(result == 0, "Unable to create smack_accesses instance");
//adding test rules with mixed string
- for (i = 0; i < (3 * 8); i += 3) {
- result = smack_accesses_add(rules, rules_tab[i], "book", rules_tab[i + 1]); //using mixed rules from table
+ for (auto rule=correct_rules.begin(); rule != correct_rules.end(); ++rule) {
+ //using mixed rules from table
+ result = smack_accesses_add(rules,
+ (*rule)[0].c_str(),
+ "book",
+ (*rule)[1].c_str());
RUNNER_ASSERT_MSG_BT(result == 0, "Unable to add smack rules");
}
RUNNER_ASSERT_MSG_BT(result == 0, "Unable to apply rules into kernel");
//checking accesses using normal rules
- for (i = 0; i < (3 * 8); i += 3) {
- if (!strcmp(rules_tab[i + 2], "-----"))
+ for (auto rule=correct_rules.begin(); rule != correct_rules.end(); ++rule) {
+ if ((*rule)[2] == "------")
expected = 0;
else
expected = 1;
- result = smack_have_access(rules_tab[i], "book", rules_tab[i + 2]); //using normal rules from table
+ //using normal rules from table
+ result = smack_have_access((*rule)[0].c_str(),
+ "book",
+ (*rule)[2].c_str());
RUNNER_ASSERT_MSG_BT(result == expected, "Error while checking Smack access");
}
//In this test case we checking previous aplied rules but for compare mixed strings are used
int result;
- int i;
int expected;
//rules were added in previous RUNNER_TEST section
//checking accesses using mixed rules
- for (i = 0; i < (3 * 8); i += 3) {
- if (!strcmp(rules_tab[i + 2], "-----"))
+ for (auto rule=correct_rules.begin(); rule != correct_rules.end(); ++rule) {
+ if ((*rule)[2] == "------")
expected = 0;
else
expected = 1;
- result = smack_have_access(rules_tab[i], "book", rules_tab[i + 1]); //using mixed rules from table
+ //using mixed rules from table
+ result = smack_have_access((*rule)[0].c_str(),
+ "book",
+ (*rule)[1].c_str());
RUNNER_ASSERT_MSG_BT(result == expected, "Error while checking Smack access");
}
}
// Adding rules from file
result = smack_accesses_add_from_file(rulesBasic, fd);
close(fd);
- RUNNER_ASSERT_MSG_BT(result == 0, "Accesses were loaded from file");
+ RUNNER_ASSERT_MSG_BT(result == 0, "Error importing accesses from file");
// Applying rules
result = smack_accesses_apply(rulesBasic);
// Checking rules
RUNNER_ASSERT_MSG_BT(checkNoAccesses("test_subject_01", "test_object_01"),
" Error while checking smack access loaded from /etc/smack/test_smack_rules2. Accesses exist.");
- result = smack_have_access("test_subject_01", "test_object_02", "rwat");
+ result = smack_have_access("test_subject_01", "test_object_02", "rwatl");
RUNNER_ASSERT_MSG_BT(result == 1,
" Error while checking smack access loaded from /etc/smack/test_smack_rules2. Result: " << result );
result = smack_have_access("test_subject_01", "test_object_03", "wat");
" Error while checking smack access loaded from /etc/smack/test_smack_rules2. Result: " << result );
RUNNER_ASSERT_MSG_BT(checkNoAccesses("test_subject_02", "test_object_01"),
" Error while checking smack access loaded from /etc/smack/test_smack_rules2. Accesses exist.");
- result = smack_have_access("test_subject_02", "test_object_02", "wa-ft");
+ result = smack_have_access("test_subject_02", "test_object_02", "wa-lt");
RUNNER_ASSERT_MSG_BT(result == 1,
" Error while checking smack access loaded from /etc/smack/test_smack_rules2. Result: " << result );
result = smack_have_access("test_subject_02", "test_object_03", "wr");
result = smack_have_access("test_subject_03", "test_object_02", "rwat");
RUNNER_ASSERT_MSG_BT(result == 1,
" Error while checking smack access loaded from /etc/smack/test_smack_rules2. Result: " << result );
- result = smack_have_access("test_subject_03", "test_object_03", "w");
+ result = smack_have_access("test_subject_03", "test_object_03", "w---l-");
RUNNER_ASSERT_MSG_BT(result == 1,
" Error while checking smack access loaded from /etc/smack/test_smack_rules2. Result: " << result );
close(fd);
RUNNER_ASSERT_MSG_BT(result != 0, "Accesses were loaded from file");
- // Applying rules
- result = smack_accesses_apply(rulesBasic);
- RUNNER_ASSERT_MSG_BT(result == 0, "Error while applying accesses. Result: " << result);
-
- // Checking rules
- result = smack_have_access("test_subject_01", "test_object_01", "rwat");
- RUNNER_ASSERT_MSG_BT(result == 1,
- " Error while checking smack access loaded from /etc/smack/test_smack_rules3. Result: " << result );
- RUNNER_ASSERT_MSG_BT(checkNoAccesses("test_subject_01", "test_object_02"),
- " Error while checking smack access loaded from /etc/smack/test_smack_rules3. Accesses exist.");
- result = smack_have_access("test_subject_01", "test_object_03", "x");
- RUNNER_ASSERT_MSG_BT(result == 0,
- " Error while checking smack access loaded from /etc/smack/test_smack_rules3. Result: " << result );
-
// Removing rules
removeAccessesAll();
close(fd);
RUNNER_ASSERT_MSG_BT(result != 0, "Accesses were loaded from file");
- // Applying rules
- result = smack_accesses_apply(rulesBasic);
- RUNNER_ASSERT_MSG_BT(result == 0, "Error while applying accesses. Result: " << result);
-
- // Checking rules
- result = smack_have_access("test_subject_01", "test_object_01", "rxwat");
- RUNNER_ASSERT_MSG_BT(result == 1,
- " Error while checking smack access loaded from /etc/smack/test_smack_rules4. Result: " << result );
- RUNNER_ASSERT_MSG_BT(checkNoAccesses("test_subject_01", "test_object_02"),
- " Error while checking smack access loaded from /etc/smack/test_smack_rules4. Accesses exist.");
- result = smack_have_access("test_subject_01", "test_object_03", "a");
- RUNNER_ASSERT_MSG_BT(result == 0,
- " Error while checking smack access loaded from /etc/smack/test_smack_rules4. Result: " << result );
-
// Removing rules
removeAccessesAll();