Exemple #1
0
TEST(hackrestrict, CantRemoveDefaultEntry) {
	sockaddr_u resaddr = create_sockaddr_u(54321, "0.0.0.0");
	sockaddr_u resmask = create_sockaddr_u(54321, "0.0.0.0");

	hack_restrict(RESTRICT_REMOVE, &resaddr, &resmask, 0, 0, 0);

	TEST_ASSERT_EQUAL(0, restrictions(&resaddr));
}
Exemple #2
0
void
test_CantRemoveDefaultEntry(void) {
	sockaddr_u resaddr = create_sockaddr_u(AF_INET, 54321, "0.0.0.0");
	sockaddr_u resmask = create_sockaddr_u(AF_INET, 54321, "0.0.0.0");

	hack_restrict(RESTRICT_REMOVE, &resaddr, &resmask, 0, 0, 0);

	TEST_ASSERT_EQUAL(0, restrictions(&resaddr));
}
Exemple #3
0
TEST(hackrestrict, RestrictUnflagWorks) {
	sockaddr_u resaddr = create_sockaddr_u(54321, "11.22.30.20");
	sockaddr_u resmask = create_sockaddr_u(54321, "255.255.0.0");

	hack_restrict(RESTRICT_FLAGS, &resaddr, &resmask, 0, 11, 0);

	hack_restrict(RESTRICT_UNFLAG, &resaddr, &resmask, 0, 10, 0);

	TEST_ASSERT_EQUAL(1, restrictions(&resaddr));
}
Exemple #4
0
TEST(hackrestrict, AddingNewRestriction) {
	sockaddr_u resaddr = create_sockaddr_u(54321, "11.22.33.44");
	sockaddr_u resmask = create_sockaddr_u(54321, "128.0.0.0");

	const u_short flags = 42;

	hack_restrict(RESTRICT_FLAGS, &resaddr, &resmask, 0, flags, 0);

	TEST_ASSERT_EQUAL(flags, restrictions(&resaddr));
}
Exemple #5
0
TEST(hackrestrict, HackingDefaultRestriction) {
	/*
	*	We change the flag of the default restriction,
	*	and check if restriction() returns that flag
	*/
	const u_short flags = 42;

	sockaddr_u resaddr = create_sockaddr_u(54321, "0.0.0.0");
	sockaddr_u resmask = create_sockaddr_u(54321, "0.0.0.0");

	hack_restrict(RESTRICT_FLAGS, &resaddr, &resmask, 0, flags, 0);

	sockaddr_u sockaddr = create_sockaddr_u(54321, "111.123.251.124");

	TEST_ASSERT_EQUAL(flags, restrictions(&sockaddr));
}
Exemple #6
0
TEST(hackrestrict, ReturnsCorrectDefaultRestrictions) {
	sockaddr_u sockaddr = create_sockaddr_u(54321, "63.161.169.137");

	u_short retval = restrictions(&sockaddr);

	TEST_ASSERT_EQUAL(0, retval);
}
Exemple #7
0
void
test_ReturnsCorrectDefaultRestrictions(void) {
	sockaddr_u sockaddr = create_sockaddr_u(AF_INET,
		54321, "63.161.169.137");

	u_short retval = restrictions(&sockaddr);

	TEST_ASSERT_EQUAL(0, retval);
}
Exemple #8
0
TEST(hackrestrict, TheMostFittingRestrictionIsMatched) {
	sockaddr_u resaddr_target = create_sockaddr_u(54321, "11.22.33.44");

	sockaddr_u resaddr_not_matching = create_sockaddr_u(54321, "11.99.33.44");
	sockaddr_u resmask_not_matching = create_sockaddr_u(54321, "255.255.0.0");

	sockaddr_u resaddr_best_match = create_sockaddr_u(54321, "11.22.30.20");
	sockaddr_u resmask_best_match = create_sockaddr_u(54321, "255.255.0.0");

	/* it also matches, but we prefer the one above, as it's more specific */
	sockaddr_u resaddr_second_match = create_sockaddr_u(54321, "11.99.33.44");
	sockaddr_u resmask_second_match = create_sockaddr_u(54321, "255.0.0.0");

	hack_restrict(RESTRICT_FLAGS, &resaddr_not_matching, &resmask_not_matching, 0, 11, 0);
	hack_restrict(RESTRICT_FLAGS, &resaddr_best_match, &resmask_best_match, 0, 22, 0);
	hack_restrict(RESTRICT_FLAGS, &resaddr_second_match, &resmask_second_match, 0, 128, 0);

	TEST_ASSERT_EQUAL(22, restrictions(&resaddr_target));
}
Exemple #9
0
TEST(hackrestrict, DeletedRestrictionIsNotMatched) {
	sockaddr_u resaddr_target = create_sockaddr_u(54321, "11.22.33.44");

	sockaddr_u resaddr_not_matching = create_sockaddr_u(54321, "11.99.33.44");
	sockaddr_u resmask_not_matching = create_sockaddr_u(54321, "255.255.0.0");

	sockaddr_u resaddr_best_match = create_sockaddr_u(54321, "11.22.30.20");
	sockaddr_u resmask_best_match = create_sockaddr_u(54321, "255.255.0.0");

	sockaddr_u resaddr_second_match = create_sockaddr_u(54321, "11.99.33.44");
	sockaddr_u resmask_second_match = create_sockaddr_u(54321, "255.0.0.0");

	hack_restrict(RESTRICT_FLAGS, &resaddr_not_matching, &resmask_not_matching, 0, 11, 0);
	hack_restrict(RESTRICT_FLAGS, &resaddr_best_match, &resmask_best_match, 0, 22, 0);
	hack_restrict(RESTRICT_FLAGS, &resaddr_second_match, &resmask_second_match, 0, 128, 0);

	/* deleting the best match*/
	hack_restrict(RESTRICT_REMOVE, &resaddr_best_match, &resmask_best_match, 0, 22, 0);

	TEST_ASSERT_EQUAL(128, restrictions(&resaddr_target));
}