public async Task ParseLogoutRequest_redirect_binding() { //ARRANGE var logoutRequestUrl = await SamlRedirectRequestProviderMock.BuildLogoutRequestRedirectUrl(); Func <Type, IMetadataHandler> metadataHandlerFactory = t => new MetadataEntitityDescriptorHandler(); var xmlSerialiser = new XMLSerialiser(); var compressor = new DeflateCompressor(); var encoder = new MessageEncoding(compressor); var logger = new LogProviderMock(); var serialiser = new RequestSerialiser(xmlSerialiser, encoder, logger) as IRequestSerialiser; var certManager = new CertificateManager(logger); var signatureManager = new XmlSignatureManager(); Func <IEnumerable <RequestValidationRule> > rulesResolver = () => new[] { new SignatureValidRule(logger, certManager, signatureManager) }; var requestValidator = new Federation.Protocols.Request.Validation.RequestValidator(logger, new RuleFactory(rulesResolver)); var configurationRetrieverMock = new ConfigurationRetrieverMock(); var federationPartyContextBuilderMock = new FederationPartyContextBuilderMock(); var configurationManger = new ConfigurationManager <MetadataBase>(federationPartyContextBuilderMock, configurationRetrieverMock); var requestParser = new RequestParser(metadataHandlerFactory, t => new LogoutRequestParser(serialiser, logger), configurationManger, logger, requestValidator); var redirectBindingDecoder = new RedirectBindingDecoder(logger, encoder); var message = await redirectBindingDecoder.Decode(logoutRequestUrl); var context = new SamlInboundContext { Message = message, DescriptorResolver = m => metadataHandlerFactory(typeof(object)).GetIdentityProviderSingleSignOnDescriptor(m).Single().Roles.Single() }; //ACT var result = await requestParser.Parse(context); //ASSERT Assert.IsTrue(result.IsValidated); }
public async Task DecodeTest() { string url = String.Empty; var builders = new List <IRedirectClauseBuilder>(); var requestUri = new Uri("http://localhost:59611/"); var federationPartyContextBuilder = new FederationPartyContextBuilderMock(); var federationContex = federationPartyContextBuilder.BuildContext("local"); var spDescriptor = federationContex.MetadataContext.EntityDesriptorConfiguration.SPSSODescriptors.First(); var certContext = spDescriptor.KeyDescriptors.Where(x => x.Use == KeyUsage.Signing && x.IsDefault) .Select(x => x.CertificateContext) .First(); var supportedNameIdentifierFormats = new List <Uri> { new Uri(NameIdentifierFormats.Transient) }; var authnRequestContext = new AuthnRequestContext(requestUri, new Uri("http://localhost"), federationContex, supportedNameIdentifierFormats); authnRequestContext.RelyingState.Add("relayState", "Test state"); var xmlSerialiser = new XMLSerialiser(); var compressor = new DeflateCompressor(); var encoder = new MessageEncoding(compressor); var logger = new LogProviderMock(); var serialiser = new RequestSerialiser(xmlSerialiser, encoder, logger); RequestHelper.GetAuthnRequestBuilders = AuthnRequestBuildersFactoryMock.GetAuthnRequestBuildersFactory(); var authnBuilder = new SamlRequestBuilder(serialiser); builders.Add(authnBuilder); //request compression builder var encodingBuilder = new RequestEncoderBuilder(encoder); builders.Add(encodingBuilder); //relay state builder var jsonSerialiser = new NSJsonSerializer(new DefaultSettingsProvider()); var relayStateSerialiser = new RelaystateSerialiser(jsonSerialiser, encoder, logger) as IRelayStateSerialiser; var relayStateBuilder = new RelayStateBuilder(relayStateSerialiser); builders.Add(relayStateBuilder); //signature builder var certificateManager = new CertificateManager(logger); var signatureBuilder = new SignatureBuilder(certificateManager, logger); builders.Add(signatureBuilder); var bindingContext = new RequestBindingContext(authnRequestContext); foreach (var b in builders) { await b.Build(bindingContext); } var decoder = new RedirectBindingDecoder(logger, encoder); //ACT var message = await decoder.Decode(bindingContext.GetDestinationUrl()); var stateFromResult = message.Elements[HttpRedirectBindingConstants.RelayState]; var requestFromContext = bindingContext.RequestParts[HttpRedirectBindingConstants.SamlRequest]; var decoded = await encoder.DecodeMessage(requestFromContext); //ASSERT Assert.IsNotNull(stateFromResult); Assert.AreEqual(bindingContext.RequestParts[HttpRedirectBindingConstants.RelayState], message.Elements[HttpRedirectBindingConstants.RelayState]); Assert.AreEqual(decoded, message.Elements[HttpRedirectBindingConstants.SamlRequest]); }