]> git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testACLMaxUserIP.cc
f709ff26414705111e11defd217b34ac38f8ae79
[thirdparty/squid.git] / src / tests / testACLMaxUserIP.cc
1 /*
2 * Copyright (C) 1996-2022 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 "acl/Acl.h"
14 #include "auth/AclMaxUserIp.h"
15 #include "auth/UserRequest.h"
16 #include "ConfigParser.h"
17 #include "tests/testACLMaxUserIP.h"
18 #include "unitTestMain.h"
19
20 #include <stdexcept>
21
22 CPPUNIT_TEST_SUITE_REGISTRATION( testACLMaxUserIP );
23
24 /* globals required to resolve link issues */
25 AnyP::PortCfgPointer HttpPortList;
26
27 void
28 testACLMaxUserIP::testDefaults()
29 {
30 ACLMaxUserIP anACL("max_user_ip");
31 /* 0 is not a valid maximum, so we start at 0 */
32 CPPUNIT_ASSERT_EQUAL(0,anACL.getMaximum());
33 /* and we have no option to turn strict OFF, so start ON. */
34 CPPUNIT_ASSERT_EQUAL(false, static_cast<bool>(anACL.beStrict));
35 /* an unparsed acl must not be valid - there is no sane default */
36 CPPUNIT_ASSERT_EQUAL(false,anACL.valid());
37 }
38
39 void
40 testACLMaxUserIP::setUp()
41 {
42 CPPUNIT_NS::TestFixture::setUp();
43 Acl::RegisterMaker("max_user_ip", [](Acl::TypeName name)->ACL* { return new ACLMaxUserIP(name); });
44 }
45
46 void
47 testACLMaxUserIP::testParseLine()
48 {
49 /* a config line to pass with a lead-in token to seed the parser. */
50 char * line = xstrdup("test max_user_ip -s 1");
51 /* seed the parser */
52 ConfigParser::SetCfgLine(line);
53 ACL *anACL = nullptr;
54 ConfigParser LegacyParser;
55 ACL::ParseAclLine(LegacyParser, &anACL);
56 ACLMaxUserIP *maxUserIpACL = dynamic_cast<ACLMaxUserIP *>(anACL);
57 CPPUNIT_ASSERT(maxUserIpACL);
58 if (maxUserIpACL) {
59 /* we want a maximum of one, and strict to be true */
60 CPPUNIT_ASSERT_EQUAL(1, maxUserIpACL->getMaximum());
61 CPPUNIT_ASSERT_EQUAL(true, static_cast<bool>(maxUserIpACL->beStrict));
62 /* the acl must be vaid */
63 CPPUNIT_ASSERT_EQUAL(true, maxUserIpACL->valid());
64 }
65 delete anACL;
66 xfree(line);
67 }
68
69 #endif /* USE_AUTH */
70