forked from Sustainsys/Saml2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMetadatabaseExtensionsTests.cs
52 lines (45 loc) · 1.92 KB
/
MetadatabaseExtensionsTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sustainsys.Saml2.Metadata;
using System.Xml.Linq;
using System.Security.Cryptography.Xml;
using Sustainsys.Saml2.WebSso;
using FluentAssertions;
using Sustainsys.Saml2.Metadata.Descriptors;
using Sustainsys.Saml2.Metadata.Extensions;
using Sustainsys.Saml2.Metadata.Services;
using Sustainsys.Saml2.TestHelpers;
namespace Sustainsys.Saml2.Tests.Metadata
{
[TestClass]
public class MetadatabaseExtensionsTests
{
[TestMethod]
public void MetadatabaseExtensions_ToXmlString_IncludesKeyInfo()
{
var metadata = new EntityDescriptor
{
EntityId = new EntityId("http://idp.example.com/metadata"),
CacheDuration = new XsdDuration(hours: 1)
};
var idpSsoDescriptor = new IdpSsoDescriptor();
idpSsoDescriptor.ProtocolsSupported.Add(new Uri("urn:oasis:names:tc:SAML:2.0:protocol"));
metadata.RoleDescriptors.Add(idpSsoDescriptor);
idpSsoDescriptor.SingleSignOnServices.Add(new SingleSignOnService
{
Binding = Saml2Binding.HttpRedirectUri,
Location = new Uri("http://idp.example.com/sso")
});
idpSsoDescriptor.Keys.Add(SignedXmlHelper.TestKeyDescriptor);
var subject = XDocument.Parse((metadata.ToXmlString(null, "")));
var ds = XNamespace.Get(SignedXml.XmlDsigNamespaceUrl);
subject.Element(Saml2Namespaces.Saml2Metadata + "EntityDescriptor")
.Element(Saml2Namespaces.Saml2Metadata + "IDPSSODescriptor")
.Element(Saml2Namespaces.Saml2Metadata + "KeyDescriptor")
.Element(ds + "KeyInfo")
.Element(ds + "X509Data")
.Element(ds + "X509Certificate")
.Value.Should().StartWith("MIIDIzCCAg+gAwIBAgIQg7mOjTf994NAVxZu4jqXpzAJBgUrDgM");
}
}
}