2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
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.
14 #include "auth/AclMaxUserIp.h"
15 #include "auth/UserRequest.h"
16 #include "ConfigParser.h"
17 #include "tests/testACLMaxUserIP.h"
18 #include "unitTestMain.h"
22 CPPUNIT_TEST_SUITE_REGISTRATION( testACLMaxUserIP
);
24 /* globals required to resolve link issues */
25 AnyP::PortCfgPointer HttpPortList
;
28 testACLMaxUserIP::testDefaults()
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());
40 testACLMaxUserIP::setUp()
42 CPPUNIT_NS::TestFixture::setUp();
43 Acl::RegisterMaker("max_user_ip", [](Acl::TypeName name
)->ACL
* { return new ACLMaxUserIP(name
); });
47 testACLMaxUserIP::testParseLine()
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");
52 ConfigParser::SetCfgLine(line
);
54 ConfigParser LegacyParser
;
55 ACL::ParseAclLine(LegacyParser
, &anACL
);
56 ACLMaxUserIP
*maxUserIpACL
= dynamic_cast<ACLMaxUserIP
*>(anACL
);
57 CPPUNIT_ASSERT(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());