|
| 1 | +#!/usr/bin/python |
| 2 | + |
| 3 | +import os |
| 4 | +import unittest |
| 5 | +from stormshield.sns.sslclient import SSLClient |
| 6 | + |
| 7 | +APPLIANCE=os.getenv('APPLIANCE', "") |
| 8 | +FQDN = os.getenv('FQDN', "") |
| 9 | +PASSWORD = os.getenv('PASSWORD', "") |
| 10 | +CABUNDLE = os.getenv('CABUNDLE', "") |
| 11 | +CERT = os.getenv('CERT', "") |
| 12 | + |
| 13 | +@unittest.skipIf(APPLIANCE=="", "APPLIANCE env var must be set to the ip/hostname of a running SNS appliance") |
| 14 | +@unittest.skipIf(FQDN=="", "FQDN env var must be set to the firewall fqdn") |
| 15 | +@unittest.skipIf(PASSWORD=="", "PASSWORD env var must be set to the firewall password") |
| 16 | +@unittest.skipIf(CABUNDLE=="", "CABUNDLE env var must be set to the CA bundle file") |
| 17 | +@unittest.skipIf(CERT=="", "CERT env var must be set to the certificate file") |
| 18 | +class TestCert(unittest.TestCase): |
| 19 | + """ Test cabundle / certificate authentication options """ |
| 20 | + |
| 21 | + def test_sslverifypeer(self): |
| 22 | + """ Test sslverifypeer option """ |
| 23 | + |
| 24 | + # by default sslverifypeer is True |
| 25 | + try: |
| 26 | + client = SSLClient(host=APPLIANCE, user='admin', password=PASSWORD) |
| 27 | + self.fail("SSLClient should have failed (untrusted CA)") |
| 28 | + except Exception as exception: |
| 29 | + self.assertTrue(1==1, "SSLClient did not connect (untrusted CA)") |
| 30 | + |
| 31 | + try: |
| 32 | + client = SSLClient(host=APPLIANCE, user='admin', password=PASSWORD, sslverifypeer=False) |
| 33 | + self.assertTrue(1==1, "SSLClient connects with sslverifypeer=True") |
| 34 | + except Exception as exception: |
| 35 | + print(exception) |
| 36 | + self.fail("SSLClient did not connect") |
| 37 | + |
| 38 | + response = client.send_command('LIST') |
| 39 | + self.assertEqual(response.ret, 100) |
| 40 | + |
| 41 | + client.disconnect() |
| 42 | + |
| 43 | + def test_cabundle(self): |
| 44 | + """ Test cabundle option """ |
| 45 | + |
| 46 | + try: |
| 47 | + client = SSLClient(host=FQDN, ip=APPLIANCE, user='admin', password=PASSWORD, sslverifyhost=True, cabundle=CABUNDLE) |
| 48 | + self.assertTrue(1==1, "SSLClient connects with cabundle") |
| 49 | + except Exception as exception: |
| 50 | + print(exception) |
| 51 | + self.fail("SSLClient did not connect") |
| 52 | + |
| 53 | + response = client.send_command('LIST') |
| 54 | + self.assertEqual(response.ret, 100) |
| 55 | + |
| 56 | + client.disconnect() |
| 57 | + |
| 58 | + def test_cert(self): |
| 59 | + """ Test user certificate authentication """ |
| 60 | + |
| 61 | + try: |
| 62 | + client = SSLClient(host=FQDN, ip=APPLIANCE, usercert=CERT, sslverifyhost=True, cabundle=CABUNDLE) |
| 63 | + self.assertTrue(1==1, "SSLClient connects with cabundle") |
| 64 | + except Exception as exception: |
| 65 | + print(exception) |
| 66 | + self.fail("SSLClient did not connect") |
| 67 | + |
| 68 | + response = client.send_command('LIST') |
| 69 | + self.assertEqual(response.ret, 100) |
| 70 | + |
| 71 | + client.disconnect() |
0 commit comments