testACLMaxUserIP.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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 "compat/cppunit.h"
17#include "ConfigParser.h"
18#include "unitTestMain.h"
19
20#include <stdexcept>
21
22/*
23 * demonstration test file, as new idioms are made they will
24 * be shown in the TestBoilerplate source.
25 */
26
27class TestACLMaxUserIP : public CPPUNIT_NS::TestFixture
28{
30 /* note the statement here and then the actual prototype below */
34
35protected:
36 void testDefaults();
37 void testParseLine();
38};
40
41/* globals required to resolve link issues */
43
44void
46{
47 ACLMaxUserIP anACL("max_user_ip");
48 /* 0 is not a valid maximum, so we start at 0 */
49 CPPUNIT_ASSERT_EQUAL(0,anACL.getMaximum());
50 /* and we have no option to turn strict OFF, so start ON. */
51 CPPUNIT_ASSERT_EQUAL(false, static_cast<bool>(anACL.beStrict));
52 /* an unparsed acl must not be valid - there is no sane default */
53 CPPUNIT_ASSERT_EQUAL(false,anACL.valid());
54}
55
58{
59public:
60 /* TestProgram API */
61 void startup() override;
62};
63
64void
66{
67 Acl::RegisterMaker("max_user_ip", [](Acl::TypeName name)->ACL* { return new ACLMaxUserIP(name); });
68}
69
70void
72{
73 /* a config line to pass with a lead-in token to seed the parser. */
74 char * line = xstrdup("test max_user_ip -s 1");
75 /* seed the parser */
77 ACL *anACL = nullptr;
80 ACLMaxUserIP *maxUserIpACL = dynamic_cast<ACLMaxUserIP *>(anACL);
81 CPPUNIT_ASSERT(maxUserIpACL);
82 if (maxUserIpACL) {
83 /* we want a maximum of one, and strict to be true */
84 CPPUNIT_ASSERT_EQUAL(1, maxUserIpACL->getMaximum());
85 CPPUNIT_ASSERT_EQUAL(true, static_cast<bool>(maxUserIpACL->beStrict));
86 /* the acl must be vaid */
87 CPPUNIT_ASSERT_EQUAL(true, maxUserIpACL->valid());
88 }
89 delete anACL;
90 xfree(line);
91}
92
93int
94main(int argc, char *argv[])
95{
96 return MyTestProgram().run(argc, argv);
97}
98
99#endif /* USE_AUTH */
100
static ConfigParser LegacyParser
Definition: cache_cf.cc:269
bool valid() const override
Definition: AclMaxUserIp.cc:39
int getMaximum() const
Definition: AclMaxUserIp.h:33
Acl::BooleanOptionValue beStrict
Enforce "one user, one device" policy?
Definition: AclMaxUserIp.h:39
Definition: Acl.h:46
static void ParseAclLine(ConfigParser &parser, ACL **head)
Definition: Acl.cc:191
static void SetCfgLine(char *line)
Set the configuration file line to parse.
customizes our test setup
void startup() override
CPPUNIT_TEST(testDefaults)
CPPUNIT_TEST_SUITE(TestACLMaxUserIP)
CPPUNIT_TEST(testParseLine)
implements test program's main() function while enabling customization
Definition: unitTestMain.h:26
int run(int argc, char *argv[])
Definition: unitTestMain.h:44
void RegisterMaker(TypeName typeName, Maker maker)
use the given ACL Maker for all ACLs of the named type
Definition: Acl.cc:71
const char * TypeName
the ACL type name known to admins
Definition: Acl.h:27
#define xfree
#define xstrdup
int main(int argc, char *argv[])
CPPUNIT_TEST_SUITE_REGISTRATION(TestACLMaxUserIP)
AnyP::PortCfgPointer HttpPortList
list of Squid http(s)_port configured

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors