public void ReadMetadata(WsFederationMetadataTheoryData theoryData) { var context = TestUtilities.WriteHeader($"{this}.ReadMetadata", theoryData); try { var config = ReferenceMetadata.AADCommonEndpoint; var configuration = new WsFederationConfiguration(); if (!string.IsNullOrEmpty(theoryData.Metadata)) { var reader = XmlReader.Create(new StringReader(theoryData.Metadata)); configuration = theoryData.Serializer.ReadMetadata(reader); } else { var reader = XmlReader.Create(theoryData.MetadataPath); configuration = theoryData.Serializer.ReadMetadata(reader); } if (theoryData.SigingKey != null) { configuration.Signature.Verify(theoryData.SigingKey, theoryData.SigingKey.CryptoProviderFactory); } theoryData.ExpectedException.ProcessNoException(context); IdentityComparer.AreWsFederationConfigurationsEqual(configuration, theoryData.Configuration, context); } catch (Exception ex) { theoryData.ExpectedException.ProcessException(ex, context); } TestUtilities.AssertFailIfErrors(context); }
public void WriteMetadata(WsFederationMetadataTheoryData theoryData) { TestUtilities.WriteHeader($"{this}.WriteMetadata", theoryData); var context = new CompareContext($"{this}.WriteMetadata, {theoryData.TestId}"); try { var settings = new XmlWriterSettings(); var builder = new StringBuilder(); if (theoryData.UseNullWriter) { theoryData.Serializer.WriteMetadata(null, theoryData.Configuration); theoryData.ExpectedException.ProcessNoException(context); } else { using (var writer = XmlWriter.Create(builder, settings)) { // add signingCredentials so we can created signed metadata. if (theoryData.Configuration != null) { theoryData.Configuration.SigningCredentials = KeyingMaterial.DefaultX509SigningCreds_2048_RsaSha2_Sha2; } // write configuration content into metadata and sign the metadata var serializer = new WsFederationMetadataSerializer(); serializer.WriteMetadata(writer, theoryData.Configuration); writer.Flush(); var metadata = builder.ToString(); // read the created metadata into a new configuration var reader = XmlReader.Create(new StringReader(metadata)); var configuration = theoryData.Serializer.ReadMetadata(reader); // assign signingcredentials and verify the signature of created metadata configuration.SigningCredentials = theoryData.Configuration.SigningCredentials; if (configuration.SigningCredentials != null) { configuration.Signature.Verify(configuration.SigningCredentials.Key, configuration.SigningCredentials.Key.CryptoProviderFactory); } // remove the signature and do the comparison configuration.Signature = null; theoryData.ExpectedException.ProcessNoException(context); IdentityComparer.AreWsFederationConfigurationsEqual(configuration, theoryData.Configuration, context); } } } catch (Exception ex) { theoryData.ExpectedException.ProcessException(ex, context); } TestUtilities.AssertFailIfErrors(context); }
public void ReadKeyDescriptorForSigningKeyUse(WsFederationMetadataTheoryData theoryData) { var context = TestUtilities.WriteHeader($"{this}.ReadKeyDescriptorForSigningKeyUse", theoryData); var serializer = new WsFederationMetadataSerializerPublic(); try { serializer.ReadKeyDescriptorForSigningPublic(XmlReader.Create(new StringReader(theoryData.Metadata))); theoryData.ExpectedException.ProcessNoException(context); } catch (Exception ex) { theoryData.ExpectedException.ProcessException(ex, context); } TestUtilities.AssertFailIfErrors(context); }
public void ReadSecurityTokenEndpoint(WsFederationMetadataTheoryData theoryData) { var context = TestUtilities.WriteHeader($"{this}.ReadSecurityTokenEndpoint", theoryData); var serializer = new WsFederationMetadataSerializerPublic(); try { XmlReader reader = null; if (theoryData.Metadata != null) { reader = XmlReader.Create(new StringReader(theoryData.Metadata)); } serializer.ReadSecurityTokenEndpointPublic(reader); theoryData.ExpectedException.ProcessNoException(context); } catch (Exception ex) { theoryData.ExpectedException.ProcessException(ex, context); } TestUtilities.AssertFailIfErrors(context); }