]> git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testACLMaxUserIP.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / tests / testACLMaxUserIP.cc
1 /*
2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #include "squid.h"
10
11 #if USE_AUTH
12
13 #include "auth/AclMaxUserIp.h"
14 #include "ConfigParser.h"
15 #include "testACLMaxUserIP.h"
16 #include "unitTestMain.h"
17
18 #include <stdexcept>
19
20 CPPUNIT_TEST_SUITE_REGISTRATION( testACLMaxUserIP );
21
22 void
23 testACLMaxUserIP::testDefaults()
24 {
25 ACLMaxUserIP anACL("max_user_ip");
26 /* 0 is not a valid maximum, so we start at 0 */
27 CPPUNIT_ASSERT_EQUAL(0,anACL.getMaximum());
28 /* and we have no option to turn strict OFF, so start ON. */
29 CPPUNIT_ASSERT_EQUAL(false,anACL.getStrict());
30 /* an unparsed acl must not be valid - there is no sane default */
31 CPPUNIT_ASSERT_EQUAL(false,anACL.valid());
32 }
33
34 ACL::Prototype ACLMaxUserIP::RegistryProtoype(&ACLMaxUserIP::RegistryEntry_, "max_user_ip");
35 ACLMaxUserIP ACLMaxUserIP::RegistryEntry_("max_user_ip");
36
37 void
38 testACLMaxUserIP::testParseLine()
39 {
40 /* a config line to pass with a lead-in token to seed the parser. */
41 char * line = xstrdup("test max_user_ip -s 1");
42 /* seed the parser */
43 ConfigParser::SetCfgLine(line);
44 ACL *anACL = NULL;
45 ConfigParser LegacyParser;
46 ACL::ParseAclLine(LegacyParser, &anACL);
47 ACLMaxUserIP *maxUserIpACL = dynamic_cast<ACLMaxUserIP *>(anACL);
48 CPPUNIT_ASSERT(maxUserIpACL);
49 if (maxUserIpACL) {
50 /* we want a maximum of one, and strict to be true */
51 CPPUNIT_ASSERT_EQUAL(1, maxUserIpACL->getMaximum());
52 CPPUNIT_ASSERT_EQUAL(true, maxUserIpACL->getStrict());
53 /* the acl must be vaid */
54 CPPUNIT_ASSERT_EQUAL(true, maxUserIpACL->valid());
55 }
56 delete anACL;
57 xfree(line);
58 }
59
60 #endif /* USE_AUTH */
61