Azure AD sends the Assertion and its Signature unprefixed, each declaring its own default namespace. The serialized assertion must keep both namespaces rather than emitting xmlns:="..." (issue #527).
(t *testing.T)
| 107 | // its own default namespace. The serialized assertion must keep both |
| 108 | // namespaces rather than emitting xmlns:="..." (issue #527). |
| 109 | func TestElementToBytesAzureOwnDefaultNamespaces(t *testing.T) { |
| 110 | const response = `<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" ID="r" Version="2.0">` + |
| 111 | `<Issuer xmlns="urn:oasis:names:tc:SAML:2.0:assertion">idp</Issuer>` + |
| 112 | `<Assertion xmlns="urn:oasis:names:tc:SAML:2.0:assertion" ID="a" IssueInstant="2023-07-13T06:41:21.540Z" Version="2.0">` + |
| 113 | `<Issuer>idp</Issuer><Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo/></Signature>` + |
| 114 | `<Subject><NameID>alice</NameID></Subject></Assertion></samlp:Response>` |
| 115 | el := mustFindElement(t, response, "//Assertion") |
| 116 | assertStandalone(t, el) |
| 117 | |
| 118 | buf, err := elementToBytes(el) |
| 119 | assert.Assert(t, err) |
| 120 | out := etree.NewDocument() |
| 121 | assert.Assert(t, out.ReadFromBytes(buf)) |
| 122 | assert.Check(t, is.Equal("urn:oasis:names:tc:SAML:2.0:assertion", out.Root().NamespaceURI())) |
| 123 | assert.Check(t, is.Equal("http://www.w3.org/2000/09/xmldsig#", out.FindElement("//Signature").NamespaceURI())) |
| 124 | |
| 125 | var assertion Assertion |
| 126 | assert.Assert(t, unmarshalElement(el, &assertion)) |
| 127 | assert.Check(t, assertion.Signature != nil) |
| 128 | assert.Assert(t, assertion.Subject != nil && assertion.Subject.NameID != nil) |
| 129 | assert.Check(t, is.Equal("alice", assertion.Subject.NameID.Value)) |
| 130 | } |
nothing calls this directly
no test coverage detected