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
5
using System . Text ;
5
6
using Microsoft . AspNetCore . Http . Internal ;
6
7
using Microsoft . Extensions . ObjectPool ;
@@ -27,6 +28,35 @@ public void DeleteCookieShouldSetDefaultPath()
27
28
Assert . Contains ( "expires=Thu, 01 Jan 1970 00:00:00 GMT" , cookieHeaderValues [ 0 ] ) ;
28
29
}
29
30
31
+ [ Fact ]
32
+ public void DeleteCookieWithCookieOptionsShouldKeepPropertiesOfCookieOptions ( )
33
+ {
34
+ var headers = new HeaderDictionary ( ) ;
35
+ var cookies = new ResponseCookies ( headers , null ) ;
36
+ var testcookie = "TestCookie" ;
37
+ var time = new DateTimeOffset ( 2000 , 1 , 1 , 1 , 1 , 1 , 1 , TimeSpan . Zero ) ;
38
+ var options = new CookieOptions
39
+ {
40
+ Secure = true ,
41
+ HttpOnly = true ,
42
+ Path = "/" ,
43
+ Expires = time ,
44
+ Domain = "example.com" ,
45
+ SameSite = SameSiteMode . Lax
46
+ } ;
47
+
48
+ cookies . Delete ( testcookie , options ) ;
49
+
50
+ var cookieHeaderValues = headers [ HeaderNames . SetCookie ] ;
51
+ Assert . Equal ( 1 , cookieHeaderValues . Count ) ;
52
+ Assert . StartsWith ( testcookie , cookieHeaderValues [ 0 ] ) ;
53
+ Assert . Contains ( "path=/" , cookieHeaderValues [ 0 ] ) ;
54
+ Assert . Contains ( "expires=Thu, 01 Jan 1970 00:00:00 GMT" , cookieHeaderValues [ 0 ] ) ;
55
+ Assert . Contains ( "secure" , cookieHeaderValues [ 0 ] ) ;
56
+ Assert . Contains ( "httponly" , cookieHeaderValues [ 0 ] ) ;
57
+ Assert . Contains ( "samesite" , cookieHeaderValues [ 0 ] ) ;
58
+ }
59
+
30
60
[ Fact ]
31
61
public void NoParamsDeleteRemovesCookieCreatedByAdd ( )
32
62
{
0 commit comments