internal static TestMessage GetStandardTestMessage(FieldFill fill) { TestMessage message = new TestDirectedMessage(); GetStandardTestMessage(fill, message); return(message); }
public async Task SendIndirectMessageFormPost() { // We craft a very large message to force fallback to form POST. // We'll also stick some HTML reserved characters in the string value // to test proper character escaping. var message = new TestDirectedMessage(MessageTransport.Indirect) { Age = 15, Name = "c<b" + new string('a', 10 * 1024), Location = new Uri("http://host/path"), Recipient = new Uri("http://provider/path"), }; var response = await this.Channel.PrepareResponseAsync(message); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "A form redirect should be an HTTP successful response."); Assert.IsNull(response.Headers.Location, "There should not be a redirection header in the response."); string body = await response.Content.ReadAsStringAsync(); StringAssert.Contains("<form ", body); StringAssert.Contains("action=\"http://provider/path\"", body); StringAssert.Contains("method=\"post\"", body); StringAssert.Contains("<input type=\"hidden\" name=\"age\" value=\"15\" />", body); StringAssert.Contains("<input type=\"hidden\" name=\"Location\" value=\"http://host/path\" />", body); StringAssert.Contains("<input type=\"hidden\" name=\"Name\" value=\"" + HttpUtility.HtmlEncode(message.Name) + "\" />", body); StringAssert.Contains(".submit()", body, "There should be some javascript to automate form submission."); }
public void RequestUsingAuthorizationHeaderScattered() { TestDirectedMessage request = new TestDirectedMessage(MessageTransport.Direct) { Age = 15, Name = "Andrew", Location = new Uri("http://hostb/pathB"), Recipient = new Uri("http://localtest"), Timestamp = DateTime.UtcNow, HttpMethods = HttpDeliveryMethods.AuthorizationHeaderRequest, }; // ExtraData should appear in the form since this is a POST request, // and only official message parts get a place in the Authorization header. ((IProtocolMessage)request).ExtraData["appearinform"] = "formish"; request.Recipient = new Uri("http://localhost/?appearinquery=queryish"); request.HttpMethods = HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.PostRequest; HttpWebRequest webRequest = this.channel.InitializeRequest(request); Assert.IsNotNull(webRequest); Assert.AreEqual("POST", webRequest.Method); Assert.AreEqual(request.Recipient, webRequest.RequestUri); var declaredParts = new Dictionary <string, string> { { "age", request.Age.ToString() }, { "Name", request.Name }, { "Location", request.Location.AbsoluteUri }, { "Timestamp", XmlConvert.ToString(request.Timestamp, XmlDateTimeSerializationMode.Utc) }, }; Assert.AreEqual(CreateAuthorizationHeader(declaredParts), webRequest.Headers[HttpRequestHeader.Authorization]); Assert.AreEqual("appearinform=formish", this.webRequestHandler.RequestEntityAsString); }
public void SendIndirectMessageFormPostEmptyRecipient() { TestBadChannel badChannel = new TestBadChannel(); var message = new TestDirectedMessage(MessageTransport.Indirect); badChannel.CreateFormPostResponse(message, new Dictionary <string, string>()); }
public void RequestBadPreferredScheme() { TestDirectedMessage message = new TestDirectedMessage(MessageTransport.Direct); message.Recipient = new Uri("http://localtest"); message.HttpMethods = HttpDeliveryMethods.None; this.channel.Request(message); }
public void SendIndirectMessageFormPostNullFields() { TestBadChannel badChannel = new TestBadChannel(); var message = new TestDirectedMessage(MessageTransport.Indirect); message.Recipient = new Uri("http://someserver"); badChannel.CreateFormPostResponse(message, null); }
public async Task RequestBadPreferredScheme() { TestDirectedMessage message = new TestDirectedMessage(MessageTransport.Direct); message.Recipient = new Uri("http://localtest"); message.HttpMethods = HttpDeliveryMethods.None; await this.channel.RequestAsync(message, CancellationToken.None); }
public async Task SendDirectMessageResponse() { IProtocolMessage message = new TestDirectedMessage { Age = 15, Name = "Andrew", Location = new Uri("http://host/path"), }; await this.Channel.PrepareResponseAsync(message); }
private void ParameterizedRequestTest(HttpDeliveryMethods scheme) { TestDirectedMessage request = new TestDirectedMessage(MessageTransport.Direct) { Age = 15, Name = "Andrew", Location = new Uri("http://hostb/pathB"), Recipient = new Uri("http://localtest"), Timestamp = DateTime.UtcNow, HttpMethods = scheme, }; CachedDirectWebResponse rawResponse = null; this.webRequestHandler.Callback = (req) => { Assert.IsNotNull(req); HttpRequestInfo reqInfo = ConvertToRequestInfo(req, this.webRequestHandler.RequestEntityStream); Assert.AreEqual(MessagingUtilities.GetHttpVerb(scheme), reqInfo.HttpMethod); var incomingMessage = this.channel.ReadFromRequest(reqInfo) as TestMessage; Assert.IsNotNull(incomingMessage); Assert.AreEqual(request.Age, incomingMessage.Age); Assert.AreEqual(request.Name, incomingMessage.Name); Assert.AreEqual(request.Location, incomingMessage.Location); Assert.AreEqual(request.Timestamp, incomingMessage.Timestamp); var responseFields = new Dictionary <string, string> { { "age", request.Age.ToString() }, { "Name", request.Name }, { "Location", request.Location.AbsoluteUri }, { "Timestamp", XmlConvert.ToString(request.Timestamp, XmlDateTimeSerializationMode.Utc) }, }; rawResponse = new CachedDirectWebResponse(); rawResponse.SetResponse(MessagingUtilities.CreateQueryString(responseFields)); return(rawResponse); }; IProtocolMessage response = this.channel.Request(request); Assert.IsNotNull(response); Assert.IsInstanceOf <TestMessage>(response); TestMessage responseMessage = (TestMessage)response; Assert.AreEqual(request.Age, responseMessage.Age); Assert.AreEqual(request.Name, responseMessage.Name); Assert.AreEqual(request.Location, responseMessage.Location); }
public void SendDirectMessageResponse() { IProtocolMessage message = new TestDirectedMessage { Age = 15, Name = "Andrew", Location = new Uri("http://hostb/pathB"), }; OutgoingWebResponse response = this.channel.PrepareResponse(message); Assert.AreSame(message, response.OriginalMessage); Assert.AreEqual(HttpStatusCode.OK, response.Status); Assert.AreEqual(2, response.Headers.Count); NameValueCollection body = HttpUtility.ParseQueryString(response.Body); Assert.AreEqual("15", body["age"]); Assert.AreEqual("Andrew", body["Name"]); Assert.AreEqual("http://hostb/pathB", body["Location"]); }
private async Task ParameterizedRequestTestAsync(HttpDeliveryMethods scheme) { var request = new TestDirectedMessage(MessageTransport.Direct) { Age = 15, Name = "Andrew", Location = new Uri("http://hostb/pathB"), Recipient = new Uri("http://localtest"), Timestamp = DateTime.UtcNow, HttpMethods = scheme, }; Handle(request.Recipient).By( async(req, ct) => { Assert.IsNotNull(req); Assert.AreEqual(MessagingUtilities.GetHttpVerb(scheme), req.Method); var incomingMessage = (await this.channel.ReadFromRequestAsync(req, CancellationToken.None)) as TestMessage; Assert.IsNotNull(incomingMessage); Assert.AreEqual(request.Age, incomingMessage.Age); Assert.AreEqual(request.Name, incomingMessage.Name); Assert.AreEqual(request.Location, incomingMessage.Location); Assert.AreEqual(request.Timestamp, incomingMessage.Timestamp); var responseFields = new Dictionary <string, string> { { "age", request.Age.ToString() }, { "Name", request.Name }, { "Location", request.Location.AbsoluteUri }, { "Timestamp", XmlConvert.ToString(request.Timestamp, XmlDateTimeSerializationMode.Utc) }, }; var rawResponse = new HttpResponseMessage(); rawResponse.Content = new StringContent(MessagingUtilities.CreateQueryString(responseFields)); return(rawResponse); }); IProtocolMessage response = await this.channel.RequestAsync(request, CancellationToken.None); Assert.IsNotNull(response); Assert.IsInstanceOf <TestMessage>(response); TestMessage responseMessage = (TestMessage)response; Assert.AreEqual(request.Age, responseMessage.Age); Assert.AreEqual(request.Name, responseMessage.Name); Assert.AreEqual(request.Location, responseMessage.Location); }
public async Task SendDirectMessageResponse() { IProtocolMessage message = new TestDirectedMessage { Age = 15, Name = "Andrew", Location = new Uri("http://hostb/pathB"), }; var response = await this.channel.PrepareResponseAsync(message); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.AreEqual(Channel.HttpFormUrlEncodedContentType.MediaType, response.Content.Headers.ContentType.MediaType); NameValueCollection body = HttpUtility.ParseQueryString(await response.Content.ReadAsStringAsync()); Assert.AreEqual("15", body["age"]); Assert.AreEqual("Andrew", body["Name"]); Assert.AreEqual("http://hostb/pathB", body["Location"]); }
public void SendIndirectMessage301Get() { TestDirectedMessage message = new TestDirectedMessage(MessageTransport.Indirect); GetStandardTestMessage(FieldFill.CompleteBeforeBindings, message); message.Recipient = new Uri("http://provider/path"); var expected = GetStandardTestFields(FieldFill.CompleteBeforeBindings); OutgoingWebResponse response = this.Channel.PrepareResponse(message); Assert.AreEqual(HttpStatusCode.Redirect, response.Status); StringAssert.StartsWith("http://provider/path", response.Headers[HttpResponseHeader.Location]); foreach (var pair in expected) { string key = MessagingUtilities.EscapeUriDataStringRfc3986(pair.Key); string value = MessagingUtilities.EscapeUriDataStringRfc3986(pair.Value); string substring = string.Format("{0}={1}", key, value); StringAssert.Contains(substring, response.Headers[HttpResponseHeader.Location]); } }
public async Task SendIndirectMessage301Get() { TestDirectedMessage message = new TestDirectedMessage(MessageTransport.Indirect); GetStandardTestMessage(FieldFill.CompleteBeforeBindings, message); message.Recipient = new Uri("http://provider/path"); var expected = GetStandardTestFields(FieldFill.CompleteBeforeBindings); var response = await this.Channel.PrepareResponseAsync(message); Assert.AreEqual(HttpStatusCode.Redirect, response.StatusCode); Assert.AreEqual("text/html; charset=utf-8", response.Content.Headers.ContentType.ToString()); Assert.IsTrue(response.Content != null && response.Content.Headers.ContentLength > 0); // a non-empty body helps get passed filters like WebSense StringAssert.StartsWith("http://provider/path", response.Headers.Location.AbsoluteUri); foreach (var pair in expected) { string key = MessagingUtilities.EscapeUriDataStringRfc3986(pair.Key); string value = MessagingUtilities.EscapeUriDataStringRfc3986(pair.Value); string substring = string.Format("{0}={1}", key, value); StringAssert.Contains(substring, response.Headers.Location.AbsoluteUri); } }
public async Task SendDirectedNoRecipientMessage() { IProtocolMessage message = new TestDirectedMessage(MessageTransport.Indirect); await this.Channel.PrepareResponseAsync(message); }
public async Task SendInvalidMessageTransport() { IProtocolMessage message = new TestDirectedMessage((MessageTransport)100); await this.Channel.PrepareResponseAsync(message); }
public async Task RequestNullRecipient() { IDirectedProtocolMessage message = new TestDirectedMessage(MessageTransport.Direct); await this.channel.RequestAsync(message, CancellationToken.None); }
internal DirectResponseMessageMock(TestDirectedMessage request) { this.OriginatingRequest = request; }
public void RequestNullRecipient() { IDirectedProtocolMessage message = new TestDirectedMessage(MessageTransport.Direct); this.channel.Request(message); }
public void SendDirectedNoRecipientMessage() { IProtocolMessage message = new TestDirectedMessage(MessageTransport.Indirect); this.Channel.PrepareResponse(message); }
public void SendInvalidMessageTransport() { IProtocolMessage message = new TestDirectedMessage((MessageTransport)100); this.Channel.PrepareResponse(message); }