saml-profiles §8.2.4: under the X.500/LDAP profile each carries x500:Encoding="LDAP" in the X500 profile namespace.
(t *testing.T)
| 73 | // saml-profiles §8.2.4: under the X.500/LDAP profile each <AttributeValue> |
| 74 | // carries x500:Encoding="LDAP" in the X500 profile namespace. |
| 75 | func TestAttributeValueEncodingRoundTrip(t *testing.T) { |
| 76 | av := AttributeValue{Type: "xs:string", Encoding: X500EncodingLDAP, Value: "alice"} |
| 77 | el := av.Element() |
| 78 | s := attributeValueString(t, el) |
| 79 | assert.Check(t, is.Equal(`<saml:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" `+ |
| 80 | `xmlns:x500="urn:oasis:names:tc:SAML:2.0:profiles:attribute:X500" xsi:type="xs:string" x500:Encoding="LDAP">alice</saml:AttributeValue>`, s)) |
| 81 | attr := el.SelectAttr("x500:Encoding") |
| 82 | assert.Assert(t, attr != nil) |
| 83 | assert.Check(t, is.Equal(X500AttributeNamespace, attr.NamespaceURI())) |
| 84 | |
| 85 | got := attributeValueParse(t, `<saml:Attribute xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" Name="a">`+s+`</saml:Attribute>`) |
| 86 | assert.Check(t, is.DeepEqual(av, got)) |
| 87 | |
| 88 | // The prefix is not significant, only the namespace. |
| 89 | got = attributeValueParse(t, `<saml:Attribute xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:p="urn:oasis:names:tc:SAML:2.0:profiles:attribute:X500" Name="a">`+ |
| 90 | `<saml:AttributeValue p:Encoding="LDAP">v</saml:AttributeValue></saml:Attribute>`) |
| 91 | assert.Check(t, is.Equal("LDAP", got.Encoding)) |
| 92 | |
| 93 | // An unqualified Encoding attribute is not x500:Encoding. |
| 94 | got = attributeValueParse(t, `<saml:Attribute xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" Name="a">`+ |
| 95 | `<saml:AttributeValue Encoding="LDAP">v</saml:AttributeValue></saml:Attribute>`) |
| 96 | assert.Check(t, is.Equal("", got.Encoding)) |
| 97 | |
| 98 | // Without Encoding nothing is written. |
| 99 | el = (&AttributeValue{Value: "v"}).Element() |
| 100 | assert.Check(t, el.SelectAttr("x500:Encoding") == nil) |
| 101 | assert.Check(t, el.SelectAttr("xmlns:x500") == nil) |
| 102 | |
| 103 | // encoding/xml round trip too. |
| 104 | buf, err := xml.Marshal(Attribute{Name: "a", Values: []AttributeValue{av}}) |
| 105 | assert.NilError(t, err) |
| 106 | got = attributeValueParse(t, string(buf)) |
| 107 | assert.Check(t, is.Equal(X500EncodingLDAP, got.Encoding)) |
| 108 | } |
| 109 | |
| 110 | // saml-profiles §8.2.2: the FriendlyName SHOULD be one of the defined |
| 111 | // descriptors; for urn:oid:1.3.6.1.4.1.5923.1.1.1.9 that is |
nothing calls this directly
no test coverage detected