MCPcopy Create free account
hub / github.com/crewjam/saml / TestMetadataExtensionsOmittedWhenUnset

Function TestMetadataExtensionsOmittedWhenUnset

metadata_extensions_test.go:162–186  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

160}
161
162func TestMetadataExtensionsOmittedWhenUnset(t *testing.T) {
163 // md:Extensions comes after ds:Signature and before the other children,
164 // and is not written at all when there are no extensions.
165 buf, err := xml.Marshal(EntityDescriptor{
166 EntityID: "https://example.com/metadata",
167 SPSSODescriptors: []SPSSODescriptor{{SSODescriptor: SSODescriptor{RoleDescriptor: RoleDescriptor{
168 ProtocolSupportEnumeration: "urn:oasis:names:tc:SAML:2.0:protocol",
169 KeyDescriptors: []KeyDescriptor{{Use: "encryption", EncryptionMethods: []EncryptionMethod{{Algorithm: "urn:example:alg"}}}},
170 }}}},
171 })
172 assert.NilError(t, err)
173 assert.Check(t, is.Equal(string(buf), `<EntityDescriptor xmlns="urn:oasis:names:tc:SAML:2.0:metadata" entityID="https://example.com/metadata">`+
174 `<SPSSODescriptor xmlns="urn:oasis:names:tc:SAML:2.0:metadata" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">`+
175 `<KeyDescriptor use="encryption"><KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"><X509Data xmlns="http://www.w3.org/2000/09/xmldsig#"></X509Data></KeyInfo>`+
176 `<EncryptionMethod Algorithm="urn:example:alg"></EncryptionMethod></KeyDescriptor>`+
177 `</SPSSODescriptor></EntityDescriptor>`))
178
179 // Existing metadata without extensions still parses and re-encodes to
180 // the same golden output.
181 var ed EntityDescriptor
182 assert.NilError(t, xml.Unmarshal(golden.Get(t, "TestCanProduceSPMetadata_expected"), &ed))
183 assert.Check(t, ed.Extensions == nil)
184 assert.Assert(t, is.Len(ed.SPSSODescriptors, 1))
185 assert.Check(t, ed.SPSSODescriptors[0].Extensions == nil)
186}

Callers

nothing calls this directly

Calls 2

LenMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected