2 * Copyright (C) 1996-2018 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 "testACLMaxUserIP.h"
18 #include "unitTestMain.h"
22 CPPUNIT_TEST_SUITE_REGISTRATION( testACLMaxUserIP
);
25 testACLMaxUserIP::testDefaults()
27 ACLMaxUserIP
anACL("max_user_ip");
28 /* 0 is not a valid maximum, so we start at 0 */
29 CPPUNIT_ASSERT_EQUAL(0,anACL
.getMaximum());
30 /* and we have no option to turn strict OFF, so start ON. */
31 CPPUNIT_ASSERT_EQUAL(false, static_cast<bool>(anACL
.beStrict
));
32 /* an unparsed acl must not be valid - there is no sane default */
33 CPPUNIT_ASSERT_EQUAL(false,anACL
.valid());
37 testACLMaxUserIP::setUp()
39 CPPUNIT_NS::TestFixture::setUp();
40 Acl::RegisterMaker("max_user_ip", [](Acl::TypeName name
)->ACL
* { return new ACLMaxUserIP(name
); });
44 testACLMaxUserIP::testParseLine()
46 /* a config line to pass with a lead-in token to seed the parser. */
47 char * line
= xstrdup("test max_user_ip -s 1");
49 ConfigParser::SetCfgLine(line
);
51 ConfigParser LegacyParser
;
52 ACL::ParseAclLine(LegacyParser
, &anACL
);
53 ACLMaxUserIP
*maxUserIpACL
= dynamic_cast<ACLMaxUserIP
*>(anACL
);
54 CPPUNIT_ASSERT(maxUserIpACL
);
56 /* we want a maximum of one, and strict to be true */
57 CPPUNIT_ASSERT_EQUAL(1, maxUserIpACL
->getMaximum());
58 CPPUNIT_ASSERT_EQUAL(true, static_cast<bool>(maxUserIpACL
->beStrict
));
59 /* the acl must be vaid */
60 CPPUNIT_ASSERT_EQUAL(true, maxUserIpACL
->valid());