]>
git.ipfire.org Git - thirdparty/pdns.git/blob - regression-tests.dnsdist/test_Console.py
7 from dnsdisttests
import DNSDistTest
9 class TestConsoleAllowed(DNSDistTest
):
11 _consoleKey
= DNSDistTest
.generateConsoleKey()
12 _consoleKeyB64
= base64
.b64encode(_consoleKey
).decode('ascii')
14 _config_params
= ['_consoleKeyB64', '_consolePort', '_testServerPort']
15 _config_template
= """
17 controlSocket("127.0.0.1:%s")
18 newServer{address="127.0.0.1:%d"}
21 def testConsoleAllowed(self
):
25 version
= self
.sendConsoleCommand('showVersion()')
26 self
.assertTrue(version
.startswith('dnsdist '))
28 class TestConsoleAllowedV6(DNSDistTest
):
30 _consoleKey
= DNSDistTest
.generateConsoleKey()
31 _consoleKeyB64
= base64
.b64encode(_consoleKey
).decode('ascii')
33 _config_params
= ['_consoleKeyB64', '_consolePort', '_testServerPort']
34 _config_template
= """
36 controlSocket("[::1]:%s")
37 newServer{address="127.0.0.1:%d"}
40 def testConsoleAllowed(self
):
44 if 'SKIP_IPV6_TESTS' in os
.environ
:
45 raise unittest
.SkipTest('IPv6 tests are disabled')
46 version
= self
.sendConsoleCommand('showVersion()', IPv6
=True)
47 self
.assertTrue(version
.startswith('dnsdist '))
49 class TestConsoleNotAllowed(DNSDistTest
):
51 _consoleKey
= DNSDistTest
.generateConsoleKey()
52 _consoleKeyB64
= base64
.b64encode(_consoleKey
).decode('ascii')
54 _config_params
= ['_consoleKeyB64', '_consolePort', '_testServerPort']
55 _config_template
= """
57 controlSocket("127.0.0.1:%s")
58 setConsoleACL({'192.0.2.1'})
59 newServer{address="127.0.0.1:%d"}
62 def testConsoleAllowed(self
):
64 Console: Not allowed by the ACL
66 self
.assertRaises(socket
.error
, self
.sendConsoleCommand
, 'showVersion()')
68 class TestConsoleNoKey(DNSDistTest
):
70 _consoleKey
= DNSDistTest
.generateConsoleKey()
71 _consoleKeyB64
= base64
.b64encode(_consoleKey
).decode('ascii')
73 _config_params
= ['_consolePort', '_testServerPort']
74 _config_template
= """
75 controlSocket("127.0.0.1:%s")
76 newServer{address="127.0.0.1:%d"}
79 def testConsoleAllowed(self
):
81 Console: No key, the connection should not be allowed
83 self
.assertRaises(socket
.error
, self
.sendConsoleCommand
, 'showVersion()')
85 class TestConsoleConcurrentConnections(DNSDistTest
):
87 _consoleKey
= DNSDistTest
.generateConsoleKey()
88 _consoleKeyB64
= base64
.b64encode(_consoleKey
).decode('ascii')
91 _config_params
= ['_consoleKeyB64', '_consolePort', '_testServerPort', '_maxConns']
92 _config_template
= """
94 controlSocket("127.0.0.1:%s")
95 newServer{address="127.0.0.1:%d"}
96 setConsoleMaximumConcurrentConnections(%d)
99 def testConsoleConnectionsLimit(self
):
101 Console: Check the maximum number of connections
104 # open the maximum number of connections
105 for _
in range(self
._maxConns
):
106 conn
= socket
.socket(socket
.AF_INET
, socket
.SOCK_STREAM
)
107 conn
.connect(("127.0.0.1", self
._consolePort
))
110 # we now hold all the slots, let's try to establish a new connection
111 self
.assertRaises(socket
.error
, self
.sendConsoleCommand
, 'showVersion()')
119 version
= self
.sendConsoleCommand('showVersion()')
120 self
.assertTrue(version
.startswith('dnsdist '))