]>
Commit | Line | Data |
---|---|---|
4bc2a552 RG |
1 | #!/usr/bin/env python |
2 | import base64 | |
3 | import dns | |
4 | from socket import error as SocketError | |
5 | from dnsdisttests import DNSDistTest | |
6 | ||
7 | class TestConsoleAllowed(DNSDistTest): | |
8 | ||
9 | _consoleKey = DNSDistTest.generateConsoleKey() | |
10 | _consoleKeyB64 = base64.b64encode(_consoleKey).decode('ascii') | |
11 | ||
12 | _config_params = ['_consoleKeyB64', '_consolePort', '_testServerPort'] | |
13 | _config_template = """ | |
14 | setKey("%s") | |
15 | controlSocket("127.0.0.1:%s") | |
16 | newServer{address="127.0.0.1:%d"} | |
17 | """ | |
18 | ||
19 | def testConsoleAllowed(self): | |
20 | """ | |
21 | Console: Allowed | |
22 | """ | |
23 | version = self.sendConsoleCommand('showVersion()') | |
24 | self.assertTrue(version.startswith('dnsdist ')) | |
25 | ||
26 | class TestConsoleNotAllowed(DNSDistTest): | |
27 | ||
28 | _consoleKey = DNSDistTest.generateConsoleKey() | |
29 | _consoleKeyB64 = base64.b64encode(_consoleKey).decode('ascii') | |
30 | ||
31 | _config_params = ['_consoleKeyB64', '_consolePort', '_testServerPort'] | |
32 | _config_template = """ | |
33 | setKey("%s") | |
34 | controlSocket("127.0.0.1:%s") | |
35 | setConsoleACL({'192.0.2.1'}) | |
36 | newServer{address="127.0.0.1:%d"} | |
37 | """ | |
38 | ||
39 | def testConsoleAllowed(self): | |
40 | """ | |
41 | Console: Not allowed by the ACL | |
42 | """ | |
8bd4a94a | 43 | self.assertRaises(SocketError, self.sendConsoleCommand, 'showVersion()') |
9c9b4998 RG |
44 | |
45 | class TestConsoleNoKey(DNSDistTest): | |
46 | ||
47 | _consoleKey = DNSDistTest.generateConsoleKey() | |
48 | _consoleKeyB64 = base64.b64encode(_consoleKey).decode('ascii') | |
49 | ||
50 | _config_params = ['_consolePort', '_testServerPort'] | |
51 | _config_template = """ | |
52 | controlSocket("127.0.0.1:%s") | |
53 | newServer{address="127.0.0.1:%d"} | |
54 | """ | |
55 | ||
56 | def testConsoleAllowed(self): | |
57 | """ | |
58 | Console: No key, the connection should not be allowed | |
59 | """ | |
60 | self.assertRaises(SocketError, self.sendConsoleCommand, 'showVersion()') |