]> git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testACLMaxUserIP.cc
merge from trunk
[thirdparty/squid.git] / src / tests / testACLMaxUserIP.cc
1 #define SQUID_UNIT_TEST 1
2 #include "squid.h"
3
4 #if USE_AUTH
5
6 #include "auth/AclMaxUserIp.h"
7 #include "ConfigParser.h"
8 #include "testACLMaxUserIP.h"
9
10 #include <stdexcept>
11
12 CPPUNIT_TEST_SUITE_REGISTRATION( testACLMaxUserIP );
13
14 void
15 testACLMaxUserIP::testDefaults()
16 {
17 ACLMaxUserIP anACL("max_user_ip");
18 /* 0 is not a valid maximum, so we start at 0 */
19 CPPUNIT_ASSERT_EQUAL(0,anACL.getMaximum());
20 /* and we have no option to turn strict OFF, so start ON. */
21 CPPUNIT_ASSERT_EQUAL(false,anACL.getStrict());
22 /* an unparsed acl must not be valid - there is no sane default */
23 CPPUNIT_ASSERT_EQUAL(false,anACL.valid());
24 }
25
26 ACL::Prototype ACLMaxUserIP::RegistryProtoype(&ACLMaxUserIP::RegistryEntry_, "max_user_ip");
27 ACLMaxUserIP ACLMaxUserIP::RegistryEntry_("max_user_ip");
28
29 void
30 testACLMaxUserIP::testParseLine()
31 {
32 /* a config line to pass with a lead-in token to seed the parser. */
33 char * line = xstrdup("test max_user_ip -s 1");
34 /* seed the parser */
35 ConfigParser::SetCfgLine(line);
36 ACL *anACL = NULL;
37 ConfigParser LegacyParser;
38 ACL::ParseAclLine(LegacyParser, &anACL);
39 ACLMaxUserIP *maxUserIpACL = dynamic_cast<ACLMaxUserIP *>(anACL);
40 CPPUNIT_ASSERT(maxUserIpACL);
41 if (maxUserIpACL) {
42 /* we want a maximum of one, and strict to be true */
43 CPPUNIT_ASSERT_EQUAL(1, maxUserIpACL->getMaximum());
44 CPPUNIT_ASSERT_EQUAL(true, maxUserIpACL->getStrict());
45 /* the acl must be vaid */
46 CPPUNIT_ASSERT_EQUAL(true, maxUserIpACL->valid());
47 }
48 delete anACL;
49 xfree(line);
50 }
51
52 #endif /* USE_AUTH */