<commit_before>/*
 * This tests for partial policy loading.
 *
 * Author: <NAME> <<EMAIL>>
 *
 */
 
#include "test.h"
#include "policy.h"
#include "policy-io.h"

policy_t *policy;

int main(int argc, char **argv)
{
	/* Initialize test framework */
	init_tests(argc, argv);
	
	/* Test loading each policy option flag defined in policy.h */
	TEST("partial loading NONE of a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_NONE, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading ALL of a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_ALL, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading TYPES in a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_TYPES, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading only CLASSES in a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_CLASSES, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading CLASSES/PERMS in a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_OBJECTS, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading EVERYTHING ELSE in a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_OTHER, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading AVRULES, USERS, and ROLES", open_partial_policy("policy/default-v12-policy.conf", 
									      POLOPT_AV_RULES | POLOPT_USERS | POLOPT_ROLES, &policy) == 0);
	free_policy(&policy);
	
	/* TODO: The following policy options need a function for re-validating the specified option flag recursively. */
	/*TEST("partial loading RBAC of a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_RBAC, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading TE_POLICY of a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_TE_POLICY, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading AV_RULES of a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_AV_RULES, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading TYPE_RULES of a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_TYPE_RULES, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading TE_RULES of a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_TE_RULES, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading only PERMS in a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_PERMS, &policy) == 0);
	free_policy(&policy); 
	TEST("partial loading ROLES in a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_ROLES, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading USERS in a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_USERS, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading TE_ALLOW RULES in a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_TE_ALLOW, &policy) == 0);<commit_msg>Fixed handling of policy options for binary policy loading. Added test for partial policy loading of binary policies.<commit_after>/*
 * This tests for partial policy loading.
 *
 * Author: <NAME> <<EMAIL>>
 *
 */
 
#include "test.h"
#include "policy.h"
#include "policy-io.h"

policy_t *policy;

int main(int argc, char **argv)
{
	/* Initialize test framework */
	init_tests(argc, argv);
	
	/* Test loading each policy option flag defined in policy.h */
	TEST("partial loading NONE of a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_NONE, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading ALL of a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_ALL, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading TYPES in a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_TYPES, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading only CLASSES in a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_CLASSES, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading CLASSES/PERMS in a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_OBJECTS, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading EVERYTHING ELSE in a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_OTHER, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading AVRULES, USERS, and ROLES", open_partial_policy("policy/default-v12-policy.conf", 
									      POLOPT_AV_RULES | POLOPT_USERS | POLOPT_ROLES, &policy) == 0);
	free_policy(&policy);
	
	/* Do the same with the binary policy */
	TEST("partial loading NONE of a policy", open_partial_policy("policy/binary_small.17", POLOPT_NONE, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading ALL of a policy", open_partial_policy("policy/binary_small.17", POLOPT_ALL, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading TYPES in a policy", open_partial_policy("policy/binary_small.17", POLOPT_TYPES, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading only CLASSES in a policy", open_partial_policy("policy/binary_small.17", POLOPT_CLASSES, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading CLASSES/PERMS in a policy", open_partial_policy("policy/binary_small.17", POLOPT_OBJECTS, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading EVERYTHING ELSE in a policy", open_partial_policy("policy/binary_small.17", POLOPT_OTHER, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading AVRULES, USERS, and ROLES", open_partial_policy("policy/binary_small.17", 
									      POLOPT_AV_RULES | POLOPT_USERS | POLOPT_ROLES, &policy) == 0);
	free_policy(&policy);
	
	/* TODO: The following policy options need a function for re-validating the specified option flag recursively. */
	/*TEST("partial loading RBAC of a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_RBAC, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading TE_POLICY of a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_TE_POLICY, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading AV_RULES of a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_AV_RULES, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading TYPE_RULES of a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_TYPE_RULES, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading TE_RULES of a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_TE_RULES, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading only PERMS in a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_PERMS, &policy) == 0);
	free_policy(&policy); 
	TEST("partial loading ROLES in a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_ROLES, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading USERS in a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_USERS, &policy) == 0);
	free_policy(&policy);
	TEST("partial loading TE_ALLOW RULES in a policy", open_partial_policy("policy/default-v12-policy.conf", POLOPT_TE_ALLOW, &policy) == 0);
{'fraction_non_alphanumeric': 0.1423388222160201, 'fraction_numerical': 0.01632710019536701, 'mean_word_length': 6.261398176291793, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4913202', 'n_tokens_mistral': 2524, 'n_tokens_neox': 2347, 'n_words': 570}