def test_empty_config(self): config = [{}] ret = cert_info.validate(config) self.assertEqual(ret, (False, 'Configuration for cert_info beacon ' 'must contain files option.'))
def test_non_list_config(self): config = {} ret = cert_info.validate(config) self.assertEqual(ret, (False, 'Configuration for cert_info beacon must' ' be a list.'))
def test_empty_config(): config = [{}] ret = cert_info.validate(config) assert ret == ( False, "Configuration for cert_info beacon must contain files option.", )
def test_cert_information(): with patch("salt.utils.files.fopen", mock_open(read_data=_TEST_CERT)): config = [{ "files": ["/etc/pki/tls/certs/mycert.pem"], "notify_days": -1 }] ret = cert_info.validate(config) assert ret == (True, "Valid beacon configuration") _expected_return = [{ "certificates": [{ "cert_path": "/etc/pki/tls/certs/mycert.pem", "extensions": [ { "ext_data": "CA:FALSE", "ext_name": "basicConstraints", }, { "ext_data": "DNS:salttest-01.example.local", "ext_name": "subjectAltName", }, ], "has_expired": False, "issuer": 'CN="salttest-01.example.local"', "issuer_dict": { "CN": "salttest-01.example.local" }, "notAfter": "2029-05-31 20:59:22Z", "notAfter_raw": "20290531205922Z", "notBefore": "2019-06-03 20:59:22Z", "notBefore_raw": "20190603205922Z", "serial_number": 9515119675852487647, "signature_algorithm": "sha256WithRSAEncryption", "subject": 'CN="salttest-01.example.local"', "subject_dict": { "CN": "salttest-01.example.local" }, "version": 2, }] }] ret = cert_info.beacon(config) assert ret == _expected_return
def test_cert_information(self): with patch('salt.utils.files.fopen', mock_open(read_data=_TEST_CERT)): config = [{ 'files': ['/etc/pki/tls/certs/mycert.pem'], 'notify_days': -1 }] ret = cert_info.validate(config) self.assertEqual(ret, (True, 'Valid beacon configuration')) _expected_return = [{ 'certificates': [{ 'cert_path': '/etc/pki/tls/certs/mycert.pem', 'extensions': [{ 'ext_data': 'CA:FALSE', 'ext_name': 'basicConstraints' }, { 'ext_data': 'DNS:salttest-01.example.local', 'ext_name': 'subjectAltName' }], 'has_expired': False, 'issuer': 'CN="salttest-01.example.local"', 'issuer_dict': { 'CN': 'salttest-01.example.local' }, 'notAfter': '2029-05-31 20:59:22Z', 'notAfter_raw': '20290531205922Z', 'notBefore': '2019-06-03 20:59:22Z', 'notBefore_raw': '20190603205922Z', 'serial_number': 9515119675852487647, 'signature_algorithm': 'sha256WithRSAEncryption', 'subject': 'CN="salttest-01.example.local"', 'subject_dict': { 'CN': 'salttest-01.example.local' }, 'version': 2 }] }] ret = cert_info.beacon(config) self.assertEqual(ret, _expected_return)
def test_non_list_config(): config = {} ret = cert_info.validate(config) assert ret == (False, "Configuration for cert_info beacon must be a list.")