11// Copyright (c) .NET Foundation. All rights reserved.
22// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
4- using System ;
4+ using System . Linq ;
55using Xunit ;
66
77namespace Microsoft . Owin . Tests
@@ -11,8 +11,8 @@ public class RequestCookieTests
1111 [ Theory ]
1212 [ InlineData ( "key=value" , "key" , "value" ) ]
1313 [ InlineData ( "__secure-key=value" , "__secure-key" , "value" ) ]
14- [ InlineData ( "key%2C=%21value" , "key, " , "!value" ) ]
15- [ InlineData ( "ke%23y%2C=val%5Eue" , "ke#y, " , "val^ue" ) ]
14+ [ InlineData ( "key%2C=%21value" , "key%2C " , "!value" ) ]
15+ [ InlineData ( "ke%23y%2C=val%5Eue" , "ke%23y%2C " , "val^ue" ) ]
1616 [ InlineData ( "base64=QUI%2BREU%2FRw%3D%3D" , "base64" , "QUI+REU/Rw==" ) ]
1717 [ InlineData ( "base64=QUI+REU/Rw==" , "base64" , "QUI+REU/Rw==" ) ]
1818 public void UnEscapesValues ( string input , string expectedKey , string expectedValue )
@@ -22,8 +22,39 @@ public void UnEscapesValues(string input, string expectedKey, string expectedVal
2222 var cookies = context . Cookies ;
2323
2424 var cookie = Assert . Single ( cookies ) ;
25- Assert . Equal ( Uri . EscapeDataString ( expectedKey ) , cookie . Key ) ;
25+ Assert . Equal ( expectedKey , cookie . Key ) ;
2626 Assert . Equal ( expectedValue , cookies [ expectedKey ] ) ;
2727 }
28+
29+ [ Theory ]
30+ [ InlineData ( "key" , null , null ) ]
31+ [ InlineData ( "=,key=value" , new [ ] { "" } , new [ ] { ",key=value" } ) ]
32+ [ InlineData ( ",key=value" , new [ ] { ",key" } , new [ ] { "value" } ) ]
33+ [ InlineData ( ",key=value; key=value2" , new [ ] { ",key" , "key" } , new [ ] { "value" , "value2" } ) ]
34+ [ InlineData ( "key=value; ,key2=value2" , new [ ] { "key" , ",key2" } , new [ ] { "value" , "value2" } ) ]
35+ [ InlineData ( "%6bey=value; key=value2" , new [ ] { "%6bey" , "key" } , new [ ] { "value" , "value2" } ) ]
36+ [ InlineData ( "key=value; key2=value2" , new [ ] { "key" , "key2" } , new [ ] { "value" , "value2" } ) ]
37+ [ InlineData ( "key=value; key=value2" , new [ ] { "key" } , new [ ] { "value" } ) ]
38+ public void ParseCookies ( string input , string [ ] expectedKeys , string [ ] expectedValues )
39+ {
40+ var context = new OwinRequest ( ) ;
41+ context . Headers [ "Cookie" ] = input ;
42+ var cookies = context . Cookies . ToArray ( ) ;
43+
44+ if ( expectedKeys == null )
45+ {
46+ Assert . Empty ( cookies ) ;
47+ }
48+ else
49+ {
50+ Assert . Equal ( expectedKeys . Length , cookies . Length ) ;
51+
52+ for ( var i = 0 ; i < expectedKeys . Length ; i ++ )
53+ {
54+ Assert . Equal ( expectedKeys [ i ] , cookies [ i ] . Key ) ;
55+ Assert . Equal ( expectedValues [ i ] , cookies [ i ] . Value ) ;
56+ }
57+ }
58+ }
2859 }
2960}
0 commit comments