public void SendDirectMessageResponseHonorsHttpStatusCodes() { IProtocolMessage message = MessagingTestBase.GetStandardTestMessage(MessagingTestBase.FieldFill.AllRequired); OutgoingWebResponse directResponse = this.channel.PrepareDirectResponseTestHook(message); Assert.AreEqual(HttpStatusCode.OK, directResponse.Status); var httpMessage = new TestDirectResponseMessageWithHttpStatus(); MessagingTestBase.GetStandardTestMessage(MessagingTestBase.FieldFill.AllRequired, httpMessage); httpMessage.HttpStatusCode = HttpStatusCode.NotAcceptable; directResponse = this.channel.PrepareDirectResponseTestHook(httpMessage); Assert.AreEqual(HttpStatusCode.NotAcceptable, directResponse.Status); }
public async Task BadRequestsGenerateValidErrorResponses() { this.RegisterAutoProvider(); var rp = this.CreateRelyingParty(); var nonOpenIdMessage = new Mocks.TestDirectedMessage { Recipient = OPUri, HttpMethods = HttpDeliveryMethods.PostRequest }; MessagingTestBase.GetStandardTestMessage(MessagingTestBase.FieldFill.AllRequired, nonOpenIdMessage); var response = await rp.Channel.RequestAsync <DirectErrorResponse>(nonOpenIdMessage, CancellationToken.None); Assert.IsNotNull(response.ErrorMessage); Assert.AreEqual(Protocol.Default.Version, response.Version); }
public async Task DirectResponsesSentUsingKeyValueForm() { IProtocolMessage message = MessagingTestBase.GetStandardTestMessage(MessagingTestBase.FieldFill.AllRequired); MessageDictionary messageFields = this.MessageDescriptions.GetAccessor(message); byte[] expectedBytes = KeyValueFormEncoding.GetBytes(messageFields); string expectedContentType = OpenIdChannel.KeyValueFormContentType; var directResponse = this.channel.PrepareDirectResponseTestHook(message); Assert.AreEqual(expectedContentType, directResponse.Content.Headers.ContentType.MediaType); byte[] actualBytes = await directResponse.Content.ReadAsByteArrayAsync(); Assert.IsTrue(MessagingUtilities.AreEquivalent(expectedBytes, actualBytes)); }
public void DirectResponsesSentUsingKeyValueForm() { IProtocolMessage message = MessagingTestBase.GetStandardTestMessage(MessagingTestBase.FieldFill.AllRequired); MessageDictionary messageFields = this.MessageDescriptions.GetAccessor(message); byte[] expectedBytes = KeyValueFormEncoding.GetBytes(messageFields); string expectedContentType = OpenIdChannel.KeyValueFormContentType; OutgoingWebResponse directResponse = this.channel.PrepareDirectResponseTestHook(message); Assert.AreEqual(expectedContentType, directResponse.Headers[HttpResponseHeader.ContentType]); byte[] actualBytes = new byte[directResponse.ResponseStream.Length]; directResponse.ResponseStream.Read(actualBytes, 0, actualBytes.Length); Assert.IsTrue(MessagingUtilities.AreEquivalent(expectedBytes, actualBytes)); }
public void BadRequestsGenerateValidErrorResponses() { var coordinator = new OpenIdCoordinator( rp => { var nonOpenIdMessage = new Mocks.TestDirectedMessage(); nonOpenIdMessage.Recipient = OPUri; nonOpenIdMessage.HttpMethods = HttpDeliveryMethods.PostRequest; MessagingTestBase.GetStandardTestMessage(MessagingTestBase.FieldFill.AllRequired, nonOpenIdMessage); var response = rp.Channel.Request <DirectErrorResponse>(nonOpenIdMessage); Assert.IsNotNull(response.ErrorMessage); Assert.AreEqual(Protocol.Default.Version, response.Version); }, AutoProvider); coordinator.Run(); }
public void BadRequestsGenerateValidErrorResponsesHosted() { try { using (AspNetHost host = AspNetHost.CreateHost(TestWebDirectory)) { Uri opEndpoint = new Uri(host.BaseUri, "/OpenIdProviderEndpoint.ashx"); var rp = new OpenIdRelyingParty(null); var nonOpenIdMessage = new Mocks.TestDirectedMessage(); nonOpenIdMessage.Recipient = opEndpoint; nonOpenIdMessage.HttpMethods = HttpDeliveryMethods.PostRequest; MessagingTestBase.GetStandardTestMessage(MessagingTestBase.FieldFill.AllRequired, nonOpenIdMessage); var response = rp.Channel.Request <DirectErrorResponse>(nonOpenIdMessage); Assert.IsNotNull(response.ErrorMessage); } } catch (FileNotFoundException ex) { Assert.Inconclusive("Unable to execute hosted ASP.NET tests because {0} could not be found. {1}", ex.FileName, ex.FusionLog); } }