def testUsingTestData(self): """Test attribute_from_string() using test data""" attribute = saml.attribute_from_string(saml2_data.TEST_ATTRIBUTE) assert attribute.name == "testAttribute" assert attribute.name_format == saml.NAME_FORMAT_UNSPECIFIED assert attribute.friendly_name == "test attribute" assert attribute.attribute_value[0].text.strip() == self.text[1] assert attribute.attribute_value[1].text.strip() == self.text[2] # test again attribute = saml.attribute_from_string(attribute.to_string()) assert attribute.name == "testAttribute" assert attribute.name_format == saml.NAME_FORMAT_UNSPECIFIED assert attribute.friendly_name == "test attribute" assert attribute.attribute_value[0].text.strip() == self.text[1] assert attribute.attribute_value[1].text.strip() == self.text[2]
def test_schac(): attr = attribute_from_string(ava) acs = attribute_converter.ac_factory() for ac in acs: try: res = ac.ava_from(attr) assert res[0] == "schacHomeOrganization" except KeyError: pass
def testAccessors(self): """Test for Attribute accessors""" self.attribute.name = "testAttribute" self.attribute.name_format = saml.NAME_FORMAT_URI self.attribute.friendly_name = "test attribute" self.attribute.attribute_value.append(saml.AttributeValue()) self.attribute.attribute_value[0].text = self.text[0] new_attribute = saml.attribute_from_string(self.attribute.to_string()) assert new_attribute.name == "testAttribute" assert new_attribute.name_format == saml.NAME_FORMAT_URI assert new_attribute.friendly_name == "test attribute" assert new_attribute.attribute_value[0].text.strip() == self.text[0]
def test(self): failures = 0 friendly_name = 'PersonIdentifier' ava_eidas = BuilderAVA(saml_map.EIDAS_NATURALPERSON + friendly_name, friendly_name, saml_map.MAP['identifier']) attr = attribute_from_string(ava_eidas.ava) acs = attribute_converter.ac_factory() for ac in acs: try: res = ac.ava_from(attr) except KeyError: failures += 1 else: assert res[0] == friendly_name assert failures != len(acs)
def test(self): failures = 0 friendly_name = "schacHomeOrganization" ava_schac = BuilderAVA("urn:oid:1.3.6.1.4.1.25178.1.2.9", friendly_name, saml_map.MAP['identifier']) attr = attribute_from_string(ava_schac.ava) acs = attribute_converter.ac_factory() for ac in acs: try: res = ac.ava_from(attr) except KeyError: failures += 1 else: assert res[0] == "schacHomeOrganization" assert failures != len(acs)
def test(self): failures = 0 friendly_name = 'PersonIdentifier' ava_eidas = BuilderAVA( saml_map.EIDAS_NATURALPERSON + friendly_name, friendly_name, saml_map.MAP['identifier']) attr = attribute_from_string(ava_eidas.ava) acs = attribute_converter.ac_factory() for ac in acs: try: res = ac.ava_from(attr) except KeyError: failures += 1 else: assert res[0] == friendly_name assert failures != len(acs)
def test(self): failures = 0 friendly_name = "schacHomeOrganization" ava_schac = BuilderAVA( "urn:oid:1.3.6.1.4.1.25178.1.2.9", friendly_name, saml_map.MAP['identifier']) attr = attribute_from_string(ava_schac.ava) acs = attribute_converter.ac_factory() for ac in acs: try: res = ac.ava_from(attr) except KeyError: failures += 1 else: assert res[0] == "schacHomeOrganization" assert failures != len(acs)
def decrypt_attributes(self, attribute_statement): """ Decrypts possible encrypted attributes and adds the decrypts to the list of attributes. :param attribute_statement: A SAML.AttributeStatement which might contain both encrypted attributes and attributes. """ # _node_name = [ # "urn:oasis:names:tc:SAML:2.0:assertion:EncryptedData", # "urn:oasis:names:tc:SAML:2.0:assertion:EncryptedAttribute"] for encattr in attribute_statement.encrypted_attribute: if not encattr.encrypted_key: _decr = self.sec.decrypt(encattr.encrypted_data) _attr = attribute_from_string(_decr) attribute_statement.attribute.append(_attr) else: _decr = self.sec.decrypt(encattr) enc_attr = encrypted_attribute_from_string(_decr) attrlist = enc_attr.extensions_as_elements("Attribute", saml) attribute_statement.attribute.extend(attrlist)
def test_basic_boolean_false(self): attribute = saml.attribute_from_string(BASIC_BOOLEAN_FALSE_AV) print(attribute) assert attribute.attribute_value[0].text.lower() == "false"
def test_basic_base64(self): attribute = saml.attribute_from_string(BASIC_BASE64_AV) print(attribute) assert attribute.attribute_value[0].text == "VU5JTkVUVA==" assert attribute.attribute_value[0].get_type() == "xs:base64Binary"
def test_basic_int(self): attribute = saml.attribute_from_string(BASIC_INT_AV) print(attribute) assert attribute.attribute_value[0].text == "23"
def test_basic_str(self): attribute = saml.attribute_from_string(BASIC_STR_AV) print(attribute) assert attribute.attribute_value[0].text.strip() == "By-Tor"