def test_certificate_operation(self): fixture = self.fixture pibImpl = PibMemory() key11 = PibKeyImpl(fixture.id1Key1Name, fixture.id1Key1.toBytes(), pibImpl) try: PibKeyImpl(fixture.id1Key1Name, pibImpl) except Exception as ex: self.fail("Unexpected exception: " + str(ex)) # The key should not have any certificates. self.assertEqual(0, key11._certificates.size()) # Getting a non-existing certificate should throw Pib.Error. try: key11.getCertificate(fixture.id1Key1Cert1.getName()) self.fail("Did not throw the expected exception") except Pib.Error: pass else: self.fail("Did not throw the expected exception") # Getting the non-existing default certificate should throw Pib.Error. try: key11.getDefaultCertificate() self.fail("Did not throw the expected exception") except Pib.Error: pass else: self.fail("Did not throw the expected exception") # Setting a non-existing certificate as the default should throw Pib.Error. try: key11.setDefaultCertificate(fixture.id1Key1Cert1.getName()) self.fail("Did not throw the expected exception") except Pib.Error: pass else: self.fail("Did not throw the expected exception") # Add a certificate. key11.addCertificate(fixture.id1Key1Cert1) try: key11.getCertificate(fixture.id1Key1Cert1.getName()) except Exception as ex: self.fail("Unexpected exception: " + str(ex)) # The new certificate becomes the default when there was no default. try: key11.getDefaultCertificate() except Exception as ex: self.fail("Unexpected exception: " + str(ex)) defaultCert0 = key11.getDefaultCertificate() self.assertTrue(fixture.id1Key1Cert1.getName().equals( defaultCert0.getName())) # Use the wire encoding to check equivalence. self.assertTrue(fixture.id1Key1Cert1.wireEncode().equals( defaultCert0.wireEncode())) # Remove the certificate. key11.removeCertificate(fixture.id1Key1Cert1.getName()) try: key11.getCertificate(fixture.id1Key1Cert1.getName()) self.fail("Did not throw the expected exception") except Pib.Error: pass else: self.fail("Did not throw the expected exception") try: key11.getDefaultCertificate() self.fail("Did not throw the expected exception") except Pib.Error: pass else: self.fail("Did not throw the expected exception") # Set the default certificate directly. try: key11.setDefaultCertificate(fixture.id1Key1Cert1) except Exception as ex: self.fail("Unexpected exception: " + str(ex)) try: key11.getDefaultCertificate() except Exception as ex: self.fail("Unexpected exception: " + str(ex)) try: key11.getCertificate(fixture.id1Key1Cert1.getName()) except Exception as ex: self.fail("Unexpected exception: " + str(ex)) # Check the default cert. defaultCert1 = key11.getDefaultCertificate() self.assertTrue(fixture.id1Key1Cert1.getName().equals( defaultCert1.getName())) self.assertTrue(defaultCert1.wireEncode().equals( fixture.id1Key1Cert1.wireEncode())) # Add another certificate. key11.addCertificate(fixture.id1Key1Cert2) self.assertEqual(2, key11._certificates.size()) # Set the default certificate using a name. try: key11.setDefaultCertificate(fixture.id1Key1Cert2.getName()) except Exception as ex: self.fail("Unexpected exception: " + str(ex)) try: key11.getDefaultCertificate() except Exception as ex: self.fail("Unexpected exception: " + str(ex)) defaultCert2 = key11.getDefaultCertificate() self.assertTrue(fixture.id1Key1Cert2.getName().equals( defaultCert2.getName())) self.assertTrue(defaultCert2.wireEncode().equals( fixture.id1Key1Cert2.wireEncode())) # Remove a certificate. key11.removeCertificate(fixture.id1Key1Cert1.getName()) try: key11.getCertificate(fixture.id1Key1Cert1.getName()) self.fail("Did not throw the expected exception") except Pib.Error: pass else: self.fail("Did not throw the expected exception") self.assertEqual(1, key11._certificates.size()) # Set the default certificate directly again, which should change the default. try: key11.setDefaultCertificate(fixture.id1Key1Cert1) except Exception as ex: self.fail("Unexpected exception: " + str(ex)) defaultCert3 = key11.getDefaultCertificate() self.assertTrue(fixture.id1Key1Cert1.getName().equals( defaultCert3.getName())) self.assertTrue(defaultCert3.wireEncode().equals( fixture.id1Key1Cert1.wireEncode())) self.assertEqual(2, key11._certificates.size()) # Remove all certificates. key11.removeCertificate(fixture.id1Key1Cert1.getName()) try: key11.getCertificate(fixture.id1Key1Cert1.getName()) self.fail("Did not throw the expected exception") except Pib.Error: pass else: self.fail("Did not throw the expected exception") self.assertEqual(1, key11._certificates.size()) key11.removeCertificate(fixture.id1Key1Cert2.getName()) try: key11.getCertificate(fixture.id1Key1Cert2.getName()) self.fail("Did not throw the expected exception") except Pib.Error: pass else: self.fail("Did not throw the expected exception") try: key11.getDefaultCertificate() self.fail("Did not throw the expected exception") except Pib.Error: pass else: self.fail("Did not throw the expected exception") self.assertEqual(0, key11._certificates.size())
def test_certificate_operation(self): fixture = self.fixture pibImpl = PibMemory() key11 = PibKeyImpl( fixture.id1Key1Name, fixture.id1Key1.toBytes(), pibImpl) try: PibKeyImpl(fixture.id1Key1Name, pibImpl) except Exception as ex: self.fail("Unexpected exception: " + str(ex)) # The key should not have any certificates. self.assertEqual(0, key11._certificates.size()) # Getting a non-existing certificate should throw Pib.Error. try: key11.getCertificate(fixture.id1Key1Cert1.getName()) self.fail("Did not throw the expected exception") except Pib.Error: pass else: self.fail("Did not throw the expected exception") # Getting the non-existing default certificate should throw Pib.Error. try: key11.getDefaultCertificate() self.fail("Did not throw the expected exception") except Pib.Error: pass else: self.fail("Did not throw the expected exception") # Setting a non-existing certificate as the default should throw Pib.Error. try: key11.setDefaultCertificate(fixture.id1Key1Cert1.getName()) self.fail("Did not throw the expected exception") except Pib.Error: pass else: self.fail("Did not throw the expected exception") # Add a certificate. key11.addCertificate(fixture.id1Key1Cert1) try: key11.getCertificate(fixture.id1Key1Cert1.getName()) except Exception as ex: self.fail("Unexpected exception: " + str(ex)) # The new certificate becomes the default when there was no default. try: key11.getDefaultCertificate() except Exception as ex: self.fail("Unexpected exception: " + str(ex)) defaultCert0 = key11.getDefaultCertificate() self.assertTrue(fixture.id1Key1Cert1.getName().equals (defaultCert0.getName())) # Use the wire encoding to check equivalence. self.assertTrue(fixture.id1Key1Cert1.wireEncode().equals (defaultCert0.wireEncode())) # Remove the certificate. key11.removeCertificate(fixture.id1Key1Cert1.getName()) try: key11.getCertificate(fixture.id1Key1Cert1.getName()) self.fail("Did not throw the expected exception") except Pib.Error: pass else: self.fail("Did not throw the expected exception") try: key11.getDefaultCertificate() self.fail("Did not throw the expected exception") except Pib.Error: pass else: self.fail("Did not throw the expected exception") # Set the default certificate directly. try: key11.setDefaultCertificate(fixture.id1Key1Cert1) except Exception as ex: self.fail("Unexpected exception: " + str(ex)) try: key11.getDefaultCertificate() except Exception as ex: self.fail("Unexpected exception: " + str(ex)) try: key11.getCertificate(fixture.id1Key1Cert1.getName()) except Exception as ex: self.fail("Unexpected exception: " + str(ex)) # Check the default cert. defaultCert1 = key11.getDefaultCertificate() self.assertTrue(fixture.id1Key1Cert1.getName().equals (defaultCert1.getName())) self.assertTrue(defaultCert1.wireEncode().equals (fixture.id1Key1Cert1.wireEncode())) # Add another certificate. key11.addCertificate(fixture.id1Key1Cert2) self.assertEqual(2, key11._certificates.size()) # Set the default certificate using a name. try: key11.setDefaultCertificate(fixture.id1Key1Cert2.getName()) except Exception as ex: self.fail("Unexpected exception: " + str(ex)) try: key11.getDefaultCertificate() except Exception as ex: self.fail("Unexpected exception: " + str(ex)) defaultCert2 = key11.getDefaultCertificate() self.assertTrue(fixture.id1Key1Cert2.getName().equals (defaultCert2.getName())) self.assertTrue(defaultCert2.wireEncode().equals (fixture.id1Key1Cert2.wireEncode())) # Remove a certificate. key11.removeCertificate(fixture.id1Key1Cert1.getName()) try: key11.getCertificate(fixture.id1Key1Cert1.getName()) self.fail("Did not throw the expected exception") except Pib.Error: pass else: self.fail("Did not throw the expected exception") self.assertEqual(1, key11._certificates.size()) # Set the default certificate directly again, which should change the default. try: key11.setDefaultCertificate(fixture.id1Key1Cert1) except Exception as ex: self.fail("Unexpected exception: " + str(ex)) defaultCert3 = key11.getDefaultCertificate() self.assertTrue(fixture.id1Key1Cert1.getName().equals (defaultCert3.getName())) self.assertTrue(defaultCert3.wireEncode().equals (fixture.id1Key1Cert1.wireEncode())) self.assertEqual(2, key11._certificates.size()) # Remove all certificates. key11.removeCertificate(fixture.id1Key1Cert1.getName()) try: key11.getCertificate(fixture.id1Key1Cert1.getName()) self.fail("Did not throw the expected exception") except Pib.Error: pass else: self.fail("Did not throw the expected exception") self.assertEqual(1, key11._certificates.size()) key11.removeCertificate(fixture.id1Key1Cert2.getName()) try: key11.getCertificate(fixture.id1Key1Cert2.getName()) self.fail("Did not throw the expected exception") except Pib.Error: pass else: self.fail("Did not throw the expected exception") try: key11.getDefaultCertificate() self.fail("Did not throw the expected exception") except Pib.Error: pass else: self.fail("Did not throw the expected exception") self.assertEqual(0, key11._certificates.size())
def test_errors(self): fixture = self.fixture pibImpl = PibMemory() try: PibKeyImpl(fixture.id1Key1Name, pibImpl) self.fail("Did not throw the expected exception") except Pib.Error: pass else: self.fail("Did not throw the expected exception") key11 = PibKeyImpl(fixture.id1Key1Name, fixture.id1Key1.buf(), pibImpl) try: PibKeyImpl(Name("/wrong"), pibImpl) self.fail("Did not throw the expected exception") except ValueError: pass else: self.fail("Did not throw the expected exception") try: PibKeyImpl(Name("/wrong"), fixture.id1Key1.buf(), pibImpl) self.fail("Did not throw the expected exception") except ValueError: pass else: self.fail("Did not throw the expected exception") wrongKey = Blob("") try: PibKeyImpl(fixture.id1Key2Name, wrongKey.toBytes(), pibImpl) self.fail("Did not throw the expected exception") except ValueError: pass else: self.fail("Did not throw the expected exception") key11.addCertificate(fixture.id1Key1Cert1) try: key11.addCertificate(fixture.id1Key2Cert1) self.fail("Did not throw the expected exception") except ValueError: pass else: self.fail("Did not throw the expected exception") try: key11.removeCertificate(fixture.id1Key2Cert1.getName()) self.fail("Did not throw the expected exception") except ValueError: pass else: self.fail("Did not throw the expected exception") try: key11.getCertificate(fixture.id1Key2Cert1.getName()) self.fail("Did not throw the expected exception") except ValueError: pass else: self.fail("Did not throw the expected exception") try: key11.setDefaultCertificate(fixture.id1Key2Cert1) self.fail("Did not throw the expected exception") except ValueError: pass else: self.fail("Did not throw the expected exception") try: key11.setDefaultCertificate(fixture.id1Key2Cert1.getName()) self.fail("Did not throw the expected exception") except ValueError: pass else: self.fail("Did not throw the expected exception")