|
| 1 | +"""Integration tests for SSL Certificate Command""" |
| 2 | + |
| 3 | +from argparse import Namespace |
| 4 | + |
| 5 | +from check_netscaler.client import NITROClient |
| 6 | +from check_netscaler.commands.sslcert import SSLCertCommand |
| 7 | +from check_netscaler.constants import STATE_CRITICAL, STATE_OK, STATE_WARNING |
| 8 | + |
| 9 | + |
| 10 | +class TestSSLCertCommandIntegration: |
| 11 | + """Test SSL certificate command against mock API""" |
| 12 | + |
| 13 | + def test_sslcert_check_ok(self, mock_nitro_server): |
| 14 | + """Test SSL cert check with OK cert (60 days)""" |
| 15 | + with NITROClient( |
| 16 | + hostname=mock_nitro_server.host, |
| 17 | + port=mock_nitro_server.port, |
| 18 | + username="nsroot", |
| 19 | + password="nsroot", |
| 20 | + ssl=False, |
| 21 | + ) as client: |
| 22 | + args = Namespace( |
| 23 | + command="sslcert", |
| 24 | + objecttype="sslcertkey", |
| 25 | + objectname="cert_web", |
| 26 | + warning="30", |
| 27 | + critical="10", |
| 28 | + filter=None, |
| 29 | + limit=None, |
| 30 | + ) |
| 31 | + |
| 32 | + command = SSLCertCommand(client, args) |
| 33 | + result = command.execute() |
| 34 | + |
| 35 | + assert result.status == STATE_OK |
| 36 | + assert "1 certificate(s) OK" in result.message |
| 37 | + assert "warn=30d" in result.message |
| 38 | + assert "crit=10d" in result.message |
| 39 | + |
| 40 | + def test_sslcert_check_warning(self, mock_nitro_server): |
| 41 | + """Test SSL cert check with warning cert (20 days)""" |
| 42 | + with NITROClient( |
| 43 | + hostname=mock_nitro_server.host, |
| 44 | + port=mock_nitro_server.port, |
| 45 | + username="nsroot", |
| 46 | + password="nsroot", |
| 47 | + ssl=False, |
| 48 | + ) as client: |
| 49 | + args = Namespace( |
| 50 | + command="sslcert", |
| 51 | + objecttype="sslcertkey", |
| 52 | + objectname="cert_warning", |
| 53 | + warning="30", |
| 54 | + critical="10", |
| 55 | + filter=None, |
| 56 | + limit=None, |
| 57 | + ) |
| 58 | + |
| 59 | + command = SSLCertCommand(client, args) |
| 60 | + result = command.execute() |
| 61 | + |
| 62 | + assert result.status == STATE_WARNING |
| 63 | + assert "WARNING:" in result.message |
| 64 | + assert "cert_warning expires in 20 days" in result.message |
| 65 | + |
| 66 | + def test_sslcert_check_critical(self, mock_nitro_server): |
| 67 | + """Test SSL cert check with critical cert (5 days)""" |
| 68 | + with NITROClient( |
| 69 | + hostname=mock_nitro_server.host, |
| 70 | + port=mock_nitro_server.port, |
| 71 | + username="nsroot", |
| 72 | + password="nsroot", |
| 73 | + ssl=False, |
| 74 | + ) as client: |
| 75 | + args = Namespace( |
| 76 | + command="sslcert", |
| 77 | + objecttype="sslcertkey", |
| 78 | + objectname="cert_critical", |
| 79 | + warning="30", |
| 80 | + critical="10", |
| 81 | + filter=None, |
| 82 | + limit=None, |
| 83 | + ) |
| 84 | + |
| 85 | + command = SSLCertCommand(client, args) |
| 86 | + result = command.execute() |
| 87 | + |
| 88 | + assert result.status == STATE_CRITICAL |
| 89 | + assert "CRITICAL:" in result.message |
| 90 | + assert "cert_critical expires in 5 days" in result.message |
0 commit comments