def testLoadCertificateFromBase64(self): """Test LoadCertificateFromBase64().""" self.mox.StubOutWithMock(x509.base64, 'b64decode') self.mox.StubOutWithMock(x509, 'BASE64_RE') x509.BASE64_RE.search('b64str').AndReturn(True) x509.base64.b64decode('b64str').AndReturn('binary') mock_x509 = self.mox.CreateMockAnything() self.stubs.Set(x509, 'X509Certificate', mock_x509) mock_x509().AndReturn(mock_x509) mock_x509.LoadFromByteString('binary').AndReturn(None) self.mox.ReplayAll() self.assertEqual(mock_x509, x509.LoadCertificateFromBase64('b64str')) self.mox.VerifyAll()
def testLoadCertificateFromPEM(self): """Test LoadCertificateFromPEM().""" header = 'BEGIN CERTIFICATE' footer = 'END CERTIFICATE' pem_input = 'pem_input' pem_output = ['---header---', 'base64', '---footer---'] self.mox.StubOutWithMock(x509, 'LoadPemGeneric') self.mox.StubOutWithMock(x509, 'LoadCertificateFromBase64') x509.LoadPemGeneric(pem_input, header, footer).AndReturn(pem_output) x509.LoadCertificateFromBase64('base64').AndReturn('ok') self.mox.ReplayAll() self.assertEqual(x509.LoadCertificateFromPEM(pem_input), 'ok') self.mox.VerifyAll()