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