def test_get_serial(self): ''' Test getting the serial number from a certificate ''' expected = 'XYZABC' mock = MagicMock(return_value='CertInfo\r\nSerial: XYZABC\r\nOtherStuff') with patch.dict(certutil.__salt__, {'cmd.run': mock}): out = certutil.get_cert_serial('/path/to/cert.cer') mock.assert_called_once_with('certutil.exe -verify /path/to/cert.cer') self.assertEqual(expected, out)
def test_get_serial(self): ''' Test getting the serial number from a certificate ''' expected = '180720d39cd2db3244ba037417241e90' mock = MagicMock(return_value=( 'CertInfo\r\n' 'Cert Serial Number: 180720d39cd2db3244ba037417241e90\r\n' '\r\n' 'OtherStuff')) with patch.dict(certutil.__salt__, {'cmd.run': mock}): out = certutil.get_cert_serial('/path/to/cert.cer') mock.assert_called_once_with( 'certutil.exe -silent -verify /path/to/cert.cer') self.assertEqual(expected, out)
def test_get_serial(self): """ Test getting the serial number from a certificate """ expected = "180720d39cd2db3244ba037417241e90" mock = MagicMock(return_value=( "CertInfo\r\n" "Cert Serial Number: 180720d39cd2db3244ba037417241e90\r\n" "\r\n" "OtherStuff")) with patch.dict(certutil.__salt__, {"cmd.run": mock}): out = certutil.get_cert_serial("/path/to/cert.cer") mock.assert_called_once_with( "certutil.exe -silent -verify /path/to/cert.cer") self.assertEqual(expected, out)
def test_get_serial(): """ Test getting the serial number from a certificate """ expected = "180720d39cd2db3244ba037417241e90" mock = MagicMock(return_value=( "CertInfo\r\n" "Cert Serial Number: 180720d39cd2db3244ba037417241e90\r\n" "\r\n" "OtherStuff")) with patch.dict(certutil.__salt__, {"cmd.run": mock}), patch.dict( certutil.__salt__, {"cp.cache_file": MagicMock(return_value="/path/to/cert.cer")}, ), patch("os.path.exists", MagicMock(return_value=True)): out = certutil.get_cert_serial("/path/to/cert.cer") mock.assert_called_once_with( 'certutil.exe -silent -verify "/path/to/cert.cer"') assert expected == out