public void CookieTokenizer_SimpleCookieRequest_Parsed() { Request request = new Request(new Uri("http://test.com"), HttpMethod.Get); request.Content = ""; List <String> cookieHeaderVals = new List <string> { "test1=test2;test3=test4" }; request.Headers.Add("Cookie", cookieHeaderVals); CookieTokenizer tokenizer = new CookieTokenizer(); TokenCollection tokens = tokenizer.ExtractTokens(request); Assert.Equal(2, tokens.Count()); IToken token = tokens.GetByName("test1")[0]; Assert.Equal("test1", token.Name); Assert.Equal("test2", token.Value); token = tokens.GetByName("test3")[0]; Assert.Equal("test3", token.Name); Assert.Equal("test4", token.Value); }
public void CookieTokenizer_MultiCookieResponse_Parsed() { Response response = new Response(System.Net.HttpStatusCode.OK, ""); response.Headers.Add("Set-Cookie", new List <string> { "test_name=test_value; HttpOnly", "test_name2=test_value2; SameSite=Strict", "test_name3=test_value3; SameSite=Strict; HttpOnly" }); CookieTokenizer tokenizer = new CookieTokenizer(); TokenCollection tokens = tokenizer.ExtractTokens(response); Assert.Equal(3, tokens.Count()); IToken token = tokens.GetByName("test_name")[0]; Assert.Equal("test_name", token.Name); Assert.Equal("test_value", token.Value); token = tokens.GetByName("test_name2")[0]; Assert.Equal("test_name2", token.Name); Assert.Equal("test_value2", token.Value); token = tokens.GetByName("test_name3")[0]; Assert.Equal("test_name3", token.Name); Assert.Equal("test_value3", token.Value); }
public void JsonTokenizer_SimpleJson_Tokenized() { Request addItemToCart = new Request(new Uri(@"http://localhost/api/BasketItems/"), HttpMethod.Post); addItemToCart.Content = "{\"ProductId\":24,\"BasketId\":\"7\",\"quantity\":1}"; List <IRequestTokenizer> request_tokenizers = new List <IRequestTokenizer>(); request_tokenizers.Add(new JsonTokenizer()); TokenCollection tokens = addItemToCart.GetRequirements(request_tokenizers); Assert.Equal(3, tokens.Count()); IToken token = tokens.GetByName("ProductId")[0]; Assert.Equal("24", token.Value); Assert.Equal(Types.Integer, token.SupportedTypes); token = tokens.GetByName("BasketId")[0]; Assert.Equal("7", token.Value); Assert.Equal(Types.Integer | Types.String, token.SupportedTypes); token = tokens.GetByName("quantity")[0]; Assert.Equal("1", token.Value); Assert.Equal(Types.Integer, token.SupportedTypes); }
public void HtmlForm_NoToken_NoTokensExtracted() { string content = ""; Request request = new Request(new Uri("http://test.com"), HttpMethod.Get, content); request.Headers.Add("Content-Type", new List <string> { "application/x-www-form-urlencoded" }); HtmlFormTokenizer tokenizer = new HtmlFormTokenizer(); TokenCollection results = tokenizer.ExtractTokens(request); Assert.Equal(0, results.Count()); }