def encrypt_id(response, xmlsec, key_file, key_file_type, identifier, session_key, node_id=""): """ :param response: The response as a Response class instance :param xmlsec: Where the xmlsec1 binaries reside :param key_file: Which key file to use :param key_file_type: The type of key file :param identifier: The subject identifier :param session_key: The type of key used to encrypt :return: statement with the subject identifier encrypted """ if not response.assertion[0].subject.encrypted_id: response.assertion[0].subject.encrypted_id = saml.EncryptedID( identifier) statement = encrypt_using_xmlsec( xmlsec, "%s" % response, template=template(ident=node_id, session_key=session_key), epath=["Response", "Assertion", "Subject", "NameID"], key_file=key_file, key_file_type=key_file_type, session_key=session_key) return statement
def testAccessors(self): """Test for LogoutRequest accessors""" self.lr.id = "request id" self.lr.version = saml2.VERSION self.lr.issue_instant = "2007-09-14T01:05:02Z" self.lr.destination = "http://www.example.com/Destination" self.lr.consent = saml.CONSENT_UNSPECIFIED self.lr.issuer = saml.Issuer() self.lr.signature = ds.Signature() self.lr.extensions = samlp.Extensions() self.lr.not_on_or_after = "2007-10-14T01:05:02Z" self.lr.reason = "http://www.example.com/Reason" self.lr.base_id = saml.BaseID() self.lr.name_id = saml.NameID() self.lr.encrypted_id = saml.EncryptedID() self.lr.session_index = samlp.SessionIndex() new_lr = samlp.logout_request_from_string(self.lr.to_string()) assert new_lr.id == "request id" assert new_lr.version == saml2.VERSION assert new_lr.issue_instant == "2007-09-14T01:05:02Z" assert new_lr.destination == "http://www.example.com/Destination" assert new_lr.consent == saml.CONSENT_UNSPECIFIED assert isinstance(new_lr.issuer, saml.Issuer) assert isinstance(new_lr.signature, ds.Signature) assert isinstance(new_lr.extensions, samlp.Extensions) assert new_lr.not_on_or_after == "2007-10-14T01:05:02Z" assert new_lr.reason == "http://www.example.com/Reason" assert isinstance(new_lr.base_id, saml.BaseID) assert isinstance(new_lr.name_id, saml.NameID) assert isinstance(new_lr.encrypted_id, saml.EncryptedID) assert isinstance(new_lr.session_index[0], samlp.SessionIndex)