1
1
// Copyright (c) .NET Foundation. All rights reserved.
2
2
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
3
4
- using System ;
4
+ using System . Linq ;
5
5
using Xunit ;
6
6
7
7
namespace Microsoft . Owin . Tests
@@ -11,8 +11,8 @@ public class RequestCookieTests
11
11
[ Theory ]
12
12
[ InlineData ( "key=value" , "key" , "value" ) ]
13
13
[ 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" ) ]
16
16
[ InlineData ( "base64=QUI%2BREU%2FRw%3D%3D" , "base64" , "QUI+REU/Rw==" ) ]
17
17
[ InlineData ( "base64=QUI+REU/Rw==" , "base64" , "QUI+REU/Rw==" ) ]
18
18
public void UnEscapesValues ( string input , string expectedKey , string expectedValue )
@@ -22,8 +22,39 @@ public void UnEscapesValues(string input, string expectedKey, string expectedVal
22
22
var cookies = context . Cookies ;
23
23
24
24
var cookie = Assert . Single ( cookies ) ;
25
- Assert . Equal ( Uri . EscapeDataString ( expectedKey ) , cookie . Key ) ;
25
+ Assert . Equal ( expectedKey , cookie . Key ) ;
26
26
Assert . Equal ( expectedValue , cookies [ expectedKey ] ) ;
27
27
}
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
+ }
28
59
}
29
60
}
0 commit comments