testACLMaxUserIP.cc
Go to the documentation of this file.
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 
23 
24 /* globals required to resolve link issues */
26 
27 void
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
41 {
42  CPPUNIT_NS::TestFixture::setUp();
43  Acl::RegisterMaker("max_user_ip", [](Acl::TypeName name)->ACL* { return new ACLMaxUserIP(name); });
44 }
45 
46 void
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 */
53  ACL *anACL = NULL;
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 
const char * TypeName
the ACL type name known to admins
Definition: Acl.h:27
static ConfigParser LegacyParser
Definition: cache_cf.cc:268
void RegisterMaker(TypeName typeName, Maker maker)
use the given ACL Maker for all ACLs of the named type
Definition: Acl.cc:71
virtual bool valid() const
Definition: AclMaxUserIp.cc:39
#define xstrdup
#define NULL
Definition: types.h:166
static void ParseAclLine(ConfigParser &parser, ACL **head)
Definition: Acl.cc:165
Acl::BooleanOptionValue beStrict
Enforce "one user, one device" policy?
Definition: AclMaxUserIp.h:39
CPPUNIT_TEST_SUITE_REGISTRATION(testACLMaxUserIP)
#define xfree
Definition: Acl.h:40
int getMaximum() const
Definition: AclMaxUserIp.h:33
static void SetCfgLine(char *line)
Set the configuration file line to parse.
virtual void setUp() override
AnyP::PortCfgPointer HttpPortList
list of Squid http(s)_port configured

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors