| 33 | </md:EntityDescriptor>` |
| 34 | |
| 35 | func TestMetadataExtensions(t *testing.T) { |
| 36 | var ed EntityDescriptor |
| 37 | assert.NilError(t, xml.Unmarshal([]byte(extensionsTestMetadata), &ed)) |
| 38 | |
| 39 | assert.Assert(t, ed.Extensions != nil) |
| 40 | assert.Check(t, is.DeepEqual(ed.Extensions.DigestMethods, []DigestMethod{{ |
| 41 | XMLName: xml.Name{Space: AlgSupportNamespace, Local: "DigestMethod"}, |
| 42 | Algorithm: "http://www.w3.org/2001/04/xmlenc#sha256", |
| 43 | }})) |
| 44 | assert.Check(t, is.DeepEqual(ed.Extensions.SigningMethods, []SigningMethod{{ |
| 45 | XMLName: xml.Name{Space: AlgSupportNamespace, Local: "SigningMethod"}, |
| 46 | Algorithm: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256", |
| 47 | MinKeySize: 2048, |
| 48 | MaxKeySize: 4096, |
| 49 | }})) |
| 50 | assert.Check(t, is.Len(ed.Extensions.Other, 0)) |
| 51 | |
| 52 | assert.Assert(t, is.Len(ed.IDPSSODescriptors, 1)) |
| 53 | idp := ed.IDPSSODescriptors[0] |
| 54 | assert.Assert(t, idp.Extensions != nil) |
| 55 | assert.Assert(t, is.Len(idp.Extensions.SigningMethods, 1)) |
| 56 | assert.Check(t, is.Equal(idp.Extensions.SigningMethods[0].Algorithm, "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256")) |
| 57 | |
| 58 | assert.Check(t, is.DeepEqual(idp.Extensions.ShibbolethScopes, []ShibbolethScope{{ |
| 59 | XMLName: xml.Name{Space: ShibbolethMetadataNamespace, Local: "Scope"}, |
| 60 | Value: "example.com", |
| 61 | }})) |
| 62 | |
| 63 | // Extension elements without a field of their own are kept, with their |
| 64 | // namespaces, attributes, text and children. |
| 65 | assert.Check(t, is.DeepEqual(idp.Extensions.Other, []ExtensionElement{ |
| 66 | { |
| 67 | XMLName: xml.Name{Space: "urn:oasis:names:tc:SAML:metadata:ui", Local: "UIInfo"}, |
| 68 | Children: []ExtensionElement{{ |
| 69 | XMLName: xml.Name{Space: "urn:oasis:names:tc:SAML:metadata:ui", Local: "DisplayName"}, |
| 70 | Attrs: []xml.Attr{{Name: xml.Name{Space: "http://www.w3.org/XML/1998/namespace", Local: "lang"}, Value: "en"}}, |
| 71 | CharData: "Example IdP", |
| 72 | }}, |
| 73 | }, |
| 74 | { |
| 75 | // The namespace declaration is not kept as an attribute. |
| 76 | XMLName: xml.Name{Space: "urn:example:x", Local: "Flag"}, |
| 77 | }, |
| 78 | })) |
| 79 | |
| 80 | assert.Assert(t, is.Len(idp.KeyDescriptors, 1)) |
| 81 | assert.Assert(t, is.Len(idp.KeyDescriptors[0].EncryptionMethods, 1)) |
| 82 | keySize := idp.KeyDescriptors[0].EncryptionMethods[0].KeySize |
| 83 | assert.Assert(t, keySize != nil) |
| 84 | assert.Check(t, is.Equal(*keySize, 128)) |
| 85 | |
| 86 | // Everything survives marshalling and parsing again. |
| 87 | buf, err := xml.Marshal(ed) |
| 88 | assert.NilError(t, err) |
| 89 | var ed2 EntityDescriptor |
| 90 | assert.NilError(t, xml.Unmarshal(buf, &ed2)) |
| 91 | assert.Check(t, is.DeepEqual(ed2.Extensions, ed.Extensions)) |
| 92 | assert.Assert(t, is.Len(ed2.IDPSSODescriptors, 1)) |