public void IsSame_should_fail_if_token_differs() { var subject = new EncodedParameters("token1"); var other = new EncodedParameters("token2"); subject.IsSame(other).Should().BeFalse(); }
public void from_json_should_require_param() { var values = new Dictionary <string, object>(); EncodedParameters.FromJson((string)null).Should().BeNull(); EncodedParameters.FromJson("not json").Should().BeNull(); }
public void IsSame_should_succeed_if_tokens_are_same() { var subject = new EncodedParameters("token"); var other = new EncodedParameters("token"); subject.IsSame(other).Should().BeTrue(); }
public async Task ReadEncodedParametersAsync_should_capture_body() { _subject.ValidateBody = true; var pop = new EncodedParameters("token"); using (var ms = new MemoryStream()) { var data = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }; ms.Write(data, 0, data.Length); ms.Seek(0, SeekOrigin.Begin); _context.Request.Body = ms; var result = await _subject.ReadEncodedParametersAsync(_context.Environment, pop); result.BodyHash.Should().Be("vnPfBFvKBXMv9S6m1FMSeSi1VLnnmqYXGr4xk9ImCp8"); result.Host.Should().BeNull(); result.Method.Should().BeNull(); result.Path.Should().BeNull(); result.QueryParameters.Should().BeNull(); result.RequestHeaders.Should().BeNull(); } }
public void decoding_should_parse_access_token() { var values = new Dictionary <string, object>() { { "at", "token" } }; var subject = new EncodedParameters(values); subject.AccessToken.Should().Be("token"); }
public override Task <EncodedParameters> ReadEncodedParametersAsync(IDictionary <string, object> env, EncodedParameters popValues) { var result = Result; if (result == null) { result = popValues; } return(Task.FromResult(result)); }
public void encoding_should_emit_url_path() { var subject = new EncodedParameters("abc"); subject.Path = "/foo"; var values = subject.Encode(); values.Should().ContainKey("p"); values["p"].Should().Be("/foo"); }
public void IsSame_should_work_for_body() { var subject = new EncodedParameters("token"); var other = new EncodedParameters("token"); subject.BodyHash = other.BodyHash = "hash"; subject.IsSame(other).Should().BeTrue(); other.BodyHash = "not_hash"; subject.IsSame(other).Should().BeFalse(); }
public void decoding_should_parse_request_headers() { var values = new Dictionary <string, object>() { { "at", "token" }, { "h", new object[] { new string[] { "a", "b", "c" }, "hash" } } }; var subject = new EncodedParameters(values); subject.RequestHeaders.Should().NotBeNull(); }
public void IsSame_should_work_for_host() { var subject = new EncodedParameters("token"); var other = new EncodedParameters("token"); subject.Host = other.Host = "foo.com"; subject.IsSame(other).Should().BeTrue(); other.Host = "bar.com"; subject.IsSame(other).Should().BeFalse(); }
public void IsSame_should_work_for_path() { var subject = new EncodedParameters("token"); var other = new EncodedParameters("token"); subject.Path = other.Path = "/path"; subject.IsSame(other).Should().BeTrue(); other.Path = "/not_path"; subject.IsSame(other).Should().BeFalse(); }
public void encoding_should_emit_http_method() { var subject = new EncodedParameters("abc"); subject.Method = "POST"; var values = subject.Encode(); values.Should().ContainKey("m"); values["m"].Should().Be("POST"); }
public void IsSame_should_work_for_method() { var subject = new EncodedParameters("token"); var other = new EncodedParameters("token"); subject.Method = other.Method = "POST"; subject.IsSame(other).Should().BeTrue(); other.Method = "GET"; subject.IsSame(other).Should().BeFalse(); }
public void encoding_should_emit_host() { var subject = new EncodedParameters("abc"); subject.Host = "localhost:12345"; var values = subject.Encode(); values.Should().ContainKey("u"); values["u"].Should().Be("localhost:12345"); }
public void decoding_should_parse_body() { var values = new Dictionary <string, object>() { { "at", "token" }, { "b", "body" } }; var subject = new EncodedParameters(values); subject.BodyHash.Should().Be("body"); }
public void decoding_should_parse_host() { var values = new Dictionary <string, object>() { { "at", "token" }, { "u", "foo.com:123" } }; var subject = new EncodedParameters(values); subject.Host.Should().Be("foo.com:123"); }
public void decoding_should_parse_url_path() { var values = new Dictionary <string, object>() { { "at", "token" }, { "p", "/foo/bar" } }; var subject = new EncodedParameters(values); subject.Path.Should().Be("/foo/bar"); }
public void decoding_should_parse_http_method() { var values = new Dictionary <string, object>() { { "at", "token" }, { "m", "PUT" } }; var subject = new EncodedParameters(values); subject.Method.Should().Be("PUT"); }
public void decoding_should_parse_timestamp() { var values = new Dictionary <string, object>() { { "at", "token" }, { "ts", 5000 } }; var subject = new EncodedParameters(values); subject.TimeStamp.Should().HaveValue(); subject.TimeStamp.Value.Should().Be(5000); }
public void encoding_should_emit_body() { var subject = new EncodedParameters("abc"); subject.BodyHash = "hash"; var values = subject.Encode(); values.Should().ContainKey("b"); var body = (string)values["b"]; body.Should().Be("hash"); }
public void encoding_should_contain_basic_values() { var subject = new EncodedParameters("abc"); subject.TimeStamp = 456; var values = subject.Encode(); values.Keys.Count.Should().Be(2); values.Should().ContainKey("at"); values["at"].Should().Be("abc"); values.Should().ContainKey("ts"); ((long)values["ts"]).Should().Be(456); }
public async Task ReadEncodedParametersAsync_should_capture_query_in_same_order_as_pop_token() { _subject.QueryParametersToValidate = new string[] { "a", "b" }; var pop = new EncodedParameters("token"); pop.QueryParameters = new EncodedList(new string[] { "b", "b", "b", "a" }, "hash"); _context.Request.QueryString = new QueryString("a=apple&b=carrot&b=duck&b=banana"); var result = await _subject.ReadEncodedParametersAsync(_context.Environment, pop); result.QueryParameters.Should().NotBeNull(); result.QueryParameters.Keys.Should().ContainInOrder(new string[] { "b", "b", "b", "a" }); result.QueryParameters.HashedValue.Should().Be("GCDxUdmJ6mfoSmV1oWnKKgx2Utrksk32XoDb3HtAMns"); }
public async Task ReadEncodedParametersAsync_should_capture_minimal_values() { var pop = new EncodedParameters("token"); var result = await _subject.ReadEncodedParametersAsync(_context.Environment, pop); result.AccessToken.Should().Be("token"); result.Host.Should().BeNull(); result.Method.Should().BeNull(); result.Path.Should().BeNull(); result.QueryParameters.Should().BeNull(); result.RequestHeaders.Should().BeNull(); result.BodyHash.Should().BeNull(); }
public async Task ReadEncodedParametersAsync_should_capture_headers_in_same_order_as_pop_token() { _subject.RequestHeadersToValidate = new string[] { "a", "b" }; var pop = new EncodedParameters("token"); pop.RequestHeaders = new EncodedList(new string[] { "b", "b", "b", "a" }, "hash"); _context.Request.Headers.Add("a", new string[] { "apple" }); _context.Request.Headers.Add("b", new string[] { "carrot", "banana", "duck" }); var result = await _subject.ReadEncodedParametersAsync(_context.Environment, pop); result.RequestHeaders.Should().NotBeNull(); result.RequestHeaders.Keys.Should().ContainInOrder(new string[] { "b", "b", "b", "a" }); result.RequestHeaders.HashedValue.Should().Be("LmIpLHakIGUwuRPeDqQGhT_2EWlm66qgf_7ekw-LC7U"); }
public async Task ReadEncodedParametersAsync_should_capture_method() { _subject.ValidateMethod = true; var pop = new EncodedParameters("token"); _context.Request.Method = "PUT"; var result = await _subject.ReadEncodedParametersAsync(_context.Environment, pop); result.Method.Should().Be("PUT"); result.Host.Should().BeNull(); result.Path.Should().BeNull(); result.QueryParameters.Should().BeNull(); result.RequestHeaders.Should().BeNull(); result.BodyHash.Should().BeNull(); }
public async Task ReadEncodedParametersAsync_should_capture_query() { _subject.QueryParametersToValidate = new string[] { "a", "b", "z" }; var pop = new EncodedParameters("token"); _context.Request.QueryString = new QueryString("a=apple&b=carrot&b=duck&b=banana&c=foo"); var result = await _subject.ReadEncodedParametersAsync(_context.Environment, pop); result.QueryParameters.Should().NotBeNull(); result.QueryParameters.Keys.Should().ContainInOrder(new string[] { "a", "b", "b", "b" }); result.QueryParameters.HashedValue.Should().Be("yo_hLZrWnia7ghdlOkEjUoW-dzfMIUW3hgJg1h3ZkfU"); result.Host.Should().BeNull(); result.Method.Should().BeNull(); result.Path.Should().BeNull(); result.RequestHeaders.Should().BeNull(); result.BodyHash.Should().BeNull(); }
public void encoding_should_emit_query_params() { var subject = new EncodedParameters("abc"); var list = new EncodedList(new string[] { "foo", "foo" }, "hash"); subject.QueryParameters = list; var values = subject.Encode(); values.Should().ContainKey("q"); values["q"].Should().BeAssignableTo <object[]>(); var parts = (object[])values["q"]; var keys = (IEnumerable <string>)parts[0]; keys.Count().Should().Be(2); keys.Should().ContainInOrder(new string[] { "foo", "foo" }); var value = (string)parts[1]; value.Should().Be("hash"); }
public async Task ReadEncodedParametersAsync_should_capture_headers() { _subject.RequestHeadersToValidate = new string[] { "a", "b", "z" }; var pop = new EncodedParameters("token"); _context.Request.Headers.Add("a", new string[] { "apple" }); _context.Request.Headers.Add("b", new string[] { "carrot", "banana", "duck" }); _context.Request.Headers.Add("c", new string[] { "foo" }); var result = await _subject.ReadEncodedParametersAsync(_context.Environment, pop); result.RequestHeaders.Should().NotBeNull(); result.RequestHeaders.Keys.Should().ContainInOrder(new string[] { "a", "b", "b", "b" }); result.RequestHeaders.HashedValue.Should().Be("DPgVz1VB3aU4gmnSYPl69woLEij0XlKVvYhZVTS5hd0"); result.Host.Should().BeNull(); result.Method.Should().BeNull(); result.Path.Should().BeNull(); result.QueryParameters.Should().BeNull(); result.BodyHash.Should().BeNull(); }
public async Task ReadEncodedParametersAsync_should_capture_path() { _subject.ValidatePath = true; var pop = new EncodedParameters("token"); _context.Request.Scheme = "http"; _context.Request.Host = new HostString("foo.com"); _context.Request.PathBase = new PathString("/base"); _context.Request.Path = new PathString("/path"); var result = await _subject.ReadEncodedParametersAsync(_context.Environment, pop); result.Path.Should().Be("/base/path"); result.Host.Should().BeNull(); result.Method.Should().BeNull(); result.QueryParameters.Should().BeNull(); result.RequestHeaders.Should().BeNull(); result.BodyHash.Should().BeNull(); }
public void IsSame_should_work_for_header() { var subject = new EncodedParameters("token"); var other = new EncodedParameters("token"); var list = new EncodedList(new string[] { "a" }, "hash"); subject.RequestHeaders = other.RequestHeaders = list; subject.IsSame(other).Should().BeTrue(); other.RequestHeaders = null; subject.IsSame(other).Should().BeFalse(); other.RequestHeaders = list; subject.RequestHeaders = null; subject.IsSame(other).Should().BeFalse(); other.RequestHeaders = null; subject.RequestHeaders = null; subject.IsSame(other).Should().BeTrue(); }