]>
git.ipfire.org Git - thirdparty/pdns.git/blob - regression-tests.dnsdist/test_Console.py
ee3796125127a66ce73453f1df2585dac66fcda4
6 from dnsdisttests
import DNSDistTest
8 class TestConsoleAllowed(DNSDistTest
):
10 _consoleKey
= DNSDistTest
.generateConsoleKey()
11 _consoleKeyB64
= base64
.b64encode(_consoleKey
).decode('ascii')
13 _config_params
= ['_consoleKeyB64', '_consolePort', '_testServerPort']
14 _config_template
= """
16 controlSocket("127.0.0.1:%s")
17 newServer{address="127.0.0.1:%d"}
20 def testConsoleAllowed(self
):
24 version
= self
.sendConsoleCommand('showVersion()')
25 self
.assertTrue(version
.startswith('dnsdist '))
27 class TestConsoleNotAllowed(DNSDistTest
):
29 _consoleKey
= DNSDistTest
.generateConsoleKey()
30 _consoleKeyB64
= base64
.b64encode(_consoleKey
).decode('ascii')
32 _config_params
= ['_consoleKeyB64', '_consolePort', '_testServerPort']
33 _config_template
= """
35 controlSocket("127.0.0.1:%s")
36 setConsoleACL({'192.0.2.1'})
37 newServer{address="127.0.0.1:%d"}
40 def testConsoleAllowed(self
):
42 Console: Not allowed by the ACL
44 self
.assertRaises(socket
.error
, self
.sendConsoleCommand
, 'showVersion()')
46 class TestConsoleNoKey(DNSDistTest
):
48 _consoleKey
= DNSDistTest
.generateConsoleKey()
49 _consoleKeyB64
= base64
.b64encode(_consoleKey
).decode('ascii')
51 _config_params
= ['_consolePort', '_testServerPort']
52 _config_template
= """
53 controlSocket("127.0.0.1:%s")
54 newServer{address="127.0.0.1:%d"}
57 def testConsoleAllowed(self
):
59 Console: No key, the connection should not be allowed
61 self
.assertRaises(socket
.error
, self
.sendConsoleCommand
, 'showVersion()')
63 class TestConsoleConcurrentConnections(DNSDistTest
):
65 _consoleKey
= DNSDistTest
.generateConsoleKey()
66 _consoleKeyB64
= base64
.b64encode(_consoleKey
).decode('ascii')
69 _config_params
= ['_consoleKeyB64', '_consolePort', '_testServerPort', '_maxConns']
70 _config_template
= """
72 controlSocket("127.0.0.1:%s")
73 newServer{address="127.0.0.1:%d"}
74 setConsoleMaximumConcurrentConnections(%d)
77 def testConsoleConnectionsLimit(self
):
79 Console: Check the maximum number of connections
82 # open the maximum number of connections
83 for _
in range(self
._maxConns
):
84 conn
= socket
.socket(socket
.AF_INET
, socket
.SOCK_STREAM
)
85 conn
.connect(("127.0.0.1", self
._consolePort
))
88 # we now hold all the slots, let's try to establish a new connection
89 self
.assertRaises(socket
.error
, self
.sendConsoleCommand
, 'showVersion()')
97 version
= self
.sendConsoleCommand('showVersion()')
98 self
.assertTrue(version
.startswith('dnsdist '))