def test_remove_name(self): """ Tests that a name can be removed from the list of names. This will verify that the list of names is correct. It will verify that updating this object removes the name from the database. """ names = ['bowser', 'frumpy', 'big fat cat'] remove_index = 1 cert = X509Certificate(self.bytes_a, name=names[0]) cert.names.append(names[1]) cert.names.append(names[2]) cert.names.pop(remove_index) self.assertEquals(3, cert.name_index) expected_names = list() expected_mo_names = list() for i, name in enumerate(names): if i != remove_index: expected_names.append(name) expected_mo_names.append(sqltypes.ManagedObjectName(name, i)) self.assertEquals(expected_names, cert.names) self.assertEquals(expected_mo_names, cert._names) Session = sessionmaker(bind=self.engine) session = Session() session.add(cert) session.commit() session = Session() get_obj = session.query(X509Certificate).filter( ManagedObject.unique_identifier == cert.unique_identifier).one() session.commit() self.assertEquals(expected_names, get_obj.names) self.assertEquals(expected_mo_names, get_obj._names)
def test_add_multiple_names(self): """ Test that multiple names can be added to a managed object. This verifies a few properties. First this verifies that names can be added using simple strings. It also verifies that the index for each subsequent string is set accordingly. Finally this tests that the names can be saved and retrieved from the database. """ expected_names = ['bowser', 'frumpy', 'big fat cat'] key = PublicKey(enums.CryptographicAlgorithm.RSA, 2048, self.bytes_2048, enums.KeyFormatType.PKCS_1, name=expected_names[0]) key.names.append(expected_names[1]) key.names.append(expected_names[2]) self.assertEquals(3, key.name_index) expected_mo_names = list() for i, name in enumerate(expected_names): expected_mo_names.append(sqltypes.ManagedObjectName(name, i)) self.assertEquals(expected_mo_names, key._names) Session = sessionmaker(bind=self.engine) session = Session() session.add(key) session.commit() session = Session() get_obj = session.query(PublicKey).filter( ManagedObject.unique_identifier == key.unique_identifier).one() session.commit() self.assertEquals(expected_mo_names, get_obj._names)
def test_add_multiple_names(self): """ Test that multiple names can be added to a managed object. This verifies a few properties. First this verifies that names can be added using simple strings. It also verifies that the index for each subsequent string is set accordingly. Finally this tests that the names can be saved and retrieved from the database. """ expected_names = ['bowser', 'frumpy', 'big fat cat'] cert = X509Certificate(self.bytes_a, name=expected_names[0]) cert.names.append(expected_names[1]) cert.names.append(expected_names[2]) self.assertEquals(3, cert.name_index) expected_mo_names = list() for i, name in enumerate(expected_names): expected_mo_names.append(sqltypes.ManagedObjectName(name, i)) self.assertEquals(expected_mo_names, cert._names) Session = sessionmaker(bind=self.engine) session = Session() session.add(cert) session.commit() session = Session() get_obj = session.query(X509Certificate).filter( ManagedObject.unique_identifier == cert.unique_identifier).one() session.commit() self.assertEquals(expected_mo_names, get_obj._names)
def test_update_with_remove_and_add_name(self): """ Tests that an OpaqueObject already stored in the database can be updated. This will store an OpaqueObject in the database. It will remove a name and add another one to it in one session, and then retrieve it in another session to verify that it has all of the correct names. This simulates multiple operation being sent for the same object. """ names = ['bowser', 'frumpy', 'big fat cat'] key = PublicKey(enums.CryptographicAlgorithm.RSA, 2048, self.bytes_2048, enums.KeyFormatType.PKCS_1, name=names[0]) key.names.append(names[1]) key.names.append(names[2]) Session = sessionmaker(bind=self.engine) session = Session() session.add(key) session.commit() session = Session() update_key = session.query(PublicKey).filter( ManagedObject.unique_identifier == key.unique_identifier).one() update_key.names.pop() update_key.names.pop() update_key.names.append('dog') session.commit() expected_names = ['bowser', 'dog'] expected_mo_names = list() expected_mo_names.append( sqltypes.ManagedObjectName(expected_names[0], 0)) expected_mo_names.append( sqltypes.ManagedObjectName(expected_names[1], 3)) session = Session() get_obj = session.query(PublicKey).filter( ManagedObject.unique_identifier == key.unique_identifier).one() session.commit() self.assertEquals(expected_names, get_obj.names) self.assertEquals(expected_mo_names, get_obj._names)
def test_update_with_remove_and_add_name(self): """ Tests that a SecretData already stored in the database can be updated. This will store a SecretData in the database. It will remove a name and add another one to it in one session, and then retrieve it in another session to verify that it has all of the correct names. This simulates multiple operation being sent for the same object. """ names = ['bowser', 'frumpy', 'big fat cat'] obj = SecretData(self.bytes_a, enums.SecretDataType.PASSWORD, name=names[0]) obj.names.append(names[1]) obj.names.append(names[2]) Session = sessionmaker(bind=self.engine) session = Session() session.add(obj) session.commit() session = Session() update_obj = session.query(SecretData).filter( ManagedObject.unique_identifier == obj.unique_identifier).one() update_obj.names.pop() update_obj.names.pop() update_obj.names.append('dog') session.commit() expected_names = ['bowser', 'dog'] expected_mo_names = list() expected_mo_names.append( sqltypes.ManagedObjectName(expected_names[0], 0)) expected_mo_names.append( sqltypes.ManagedObjectName(expected_names[1], 3)) session = Session() get_obj = session.query(SecretData).filter( ManagedObject.unique_identifier == obj.unique_identifier).one() session.commit() self.assertEquals(expected_names, get_obj.names) self.assertEquals(expected_mo_names, get_obj._names)
def test_remove_and_add_name(self): """ Tests that names can be removed from the list of names and more added. This will verify that the list of names is correct. It will verify that updating this object removes the name from the database. It will verify that the indices for the removed names are not reused. """ names = ['bowser', 'frumpy', 'big fat cat'] key = PublicKey(enums.CryptographicAlgorithm.RSA, 2048, self.bytes_2048, enums.KeyFormatType.PKCS_1, name=names[0]) key.names.append(names[1]) key.names.append(names[2]) key.names.pop() key.names.pop() key.names.append('dog') self.assertEquals(4, key.name_index) expected_names = ['bowser', 'dog'] expected_mo_names = list() expected_mo_names.append( sqltypes.ManagedObjectName(expected_names[0], 0)) expected_mo_names.append( sqltypes.ManagedObjectName(expected_names[1], 3)) self.assertEquals(expected_names, key.names) self.assertEquals(expected_mo_names, key._names) Session = sessionmaker(bind=self.engine) session = Session() session.add(key) session.commit() session = Session() get_obj = session.query(PublicKey).filter( ManagedObject.unique_identifier == key.unique_identifier).one() session.commit() self.assertEquals(expected_names, get_obj.names) self.assertEquals(expected_mo_names, get_obj._names)
def test_remove_and_add_name(self): """ Tests that names can be removed from the list of names and more added. This will verify that the list of names is correct. It will verify that updating this object removes the name from the database. It will verify that the indices for the removed names are not reused. """ names = ['bowser', 'frumpy', 'big fat cat'] obj = SecretData(self.bytes_a, enums.SecretDataType.PASSWORD, name=names[0]) obj.names.append(names[1]) obj.names.append(names[2]) obj.names.pop() obj.names.pop() obj.names.append('dog') self.assertEquals(4, obj.name_index) expected_names = ['bowser', 'dog'] expected_mo_names = list() expected_mo_names.append( sqltypes.ManagedObjectName(expected_names[0], 0)) expected_mo_names.append( sqltypes.ManagedObjectName(expected_names[1], 3)) self.assertEquals(expected_names, obj.names) self.assertEquals(expected_mo_names, obj._names) Session = sessionmaker(bind=self.engine) session = Session() session.add(obj) session.commit() session = Session() get_obj = session.query(SecretData).filter( ManagedObject.unique_identifier == obj.unique_identifier).one() session.commit() self.assertEquals(expected_names, get_obj.names) self.assertEquals(expected_mo_names, get_obj._names)
def test_update_with_add_name(self): """ Tests that an OpaqueObject already stored in the database can be updated. This will store an OpaqueObject in the database. It will add a name to it in one session, and then retrieve it in another session to verify that it has all of the correct names. This test and the subsequent test_udpate_* methods are different than the name tests above because these are updating objects already stored in the database. This tests will simulate what happens when the KMIP client calls an add attribute method. """ first_name = 'bowser' key = PublicKey(enums.CryptographicAlgorithm.RSA, 2048, self.bytes_2048, enums.KeyFormatType.PKCS_1, name=first_name) Session = sessionmaker(bind=self.engine) session = Session() session.add(key) session.commit() added_name = 'frumpy' expected_names = [first_name, added_name] expected_mo_names = list() for i, name in enumerate(expected_names): expected_mo_names.append(sqltypes.ManagedObjectName(name, i)) session = Session() update_key = session.query(PublicKey).filter( ManagedObject.unique_identifier == key.unique_identifier).one() update_key.names.append(added_name) session.commit() session = Session() get_obj = session.query(PublicKey).filter( ManagedObject.unique_identifier == key.unique_identifier).one() session.commit() self.assertEquals(expected_names, get_obj.names) self.assertEquals(expected_mo_names, get_obj._names)
def test_update_with_remove_name(self): """ Tests that an OpaqueObject already stored in the database can be updated. This will store an OpaqueObject in the database. It will remove a name from it in one session, and then retrieve it in another session to verify that it has all of the correct names. """ names = ['bowser', 'frumpy', 'big fat cat'] remove_index = 1 key = PrivateKey(enums.CryptographicAlgorithm.RSA, 2048, self.bytes_2048, enums.KeyFormatType.PKCS_1, name=names[0]) key.names.append(names[1]) key.names.append(names[2]) Session = sessionmaker(bind=self.engine) session = Session() session.add(key) session.commit() expected_names = list() expected_mo_names = list() for i, name in enumerate(names): if i != remove_index: expected_names.append(name) expected_mo_names.append(sqltypes.ManagedObjectName(name, i)) session = Session() update_key = session.query(PrivateKey).filter( ManagedObject.unique_identifier == key.unique_identifier).one() update_key.names.pop(remove_index) session.commit() session = Session() get_obj = session.query(PrivateKey).filter( ManagedObject.unique_identifier == key.unique_identifier).one() session.commit() self.assertEquals(expected_names, get_obj.names) self.assertEquals(expected_mo_names, get_obj._names)
def test_update_with_remove_name(self): """ Tests that a SecretData already stored in the database can be updated. This will store a SecretData in the database. It will remove a name from it in one session, and then retrieve it in another session to verify that it has all of the correct names. """ names = ['bowser', 'frumpy', 'big fat cat'] remove_index = 1 obj = SecretData(self.bytes_a, enums.SecretDataType.PASSWORD, name=names[0]) obj.names.append(names[1]) obj.names.append(names[2]) Session = sessionmaker(bind=self.engine) session = Session() session.add(obj) session.commit() expected_names = list() expected_mo_names = list() for i, name in enumerate(names): if i != remove_index: expected_names.append(name) expected_mo_names.append(sqltypes.ManagedObjectName(name, i)) session = Session() update_obj = session.query(SecretData).filter( ManagedObject.unique_identifier == obj.unique_identifier).one() update_obj.names.pop(remove_index) session.commit() session = Session() get_obj = session.query(SecretData).filter( ManagedObject.unique_identifier == obj.unique_identifier).one() session.commit() self.assertEquals(expected_names, get_obj.names) self.assertEquals(expected_mo_names, get_obj._names)
def test_update_with_add_name(self): """ Tests that a SecretData already stored in the database can be updated. This will store a SecretData in the database. It will add a name to it in one session, and then retrieve it in another session to verify that it has all of the correct names. This test and the subsequent test_udpate_* methods are different than the name tests above because these are updating objects already stored in the database. This tests will simulate what happens when the KMIP client calls an add attribute method. """ first_name = 'bowser' obj = SecretData(self.bytes_a, enums.SecretDataType.PASSWORD, name=first_name) Session = sessionmaker(bind=self.engine) session = Session() session.add(obj) session.commit() added_name = 'frumpy' expected_names = [first_name, added_name] expected_mo_names = list() for i, name in enumerate(expected_names): expected_mo_names.append(sqltypes.ManagedObjectName(name, i)) session = Session() update_obj = session.query(SecretData).filter( ManagedObject.unique_identifier == obj.unique_identifier).one() update_obj.names.append(added_name) session.commit() session = Session() get_obj = session.query(SecretData).filter( ManagedObject.unique_identifier == obj.unique_identifier).one() session.commit() self.assertEquals(expected_names, get_obj.names) self.assertEquals(expected_mo_names, get_obj._names)
def test_remove_name(self): """ Tests that a name can be removed from the list of names. This will verify that the list of names is correct. It will verify that updating this object removes the name from the database. """ names = ['bowser', 'frumpy', 'big fat cat'] remove_index = 1 key = PublicKey(enums.CryptographicAlgorithm.RSA, 2048, self.bytes_2048, enums.KeyFormatType.PKCS_1, name=names[0]) key.names.append(names[1]) key.names.append(names[2]) key.names.pop(remove_index) self.assertEquals(3, key.name_index) expected_names = list() expected_mo_names = list() for i, name in enumerate(names): if i != remove_index: expected_names.append(name) expected_mo_names.append(sqltypes.ManagedObjectName(name, i)) self.assertEquals(expected_names, key.names) self.assertEquals(expected_mo_names, key._names) Session = sessionmaker(bind=self.engine) session = Session() session.add(key) session.commit() session = Session() get_obj = session.query(PublicKey).filter( ManagedObject.unique_identifier == key.unique_identifier).one() session.commit() self.assertEquals(expected_names, get_obj.names) self.assertEquals(expected_mo_names, get_obj._names)