Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Preserve secure and httponly headers in ResponseCookies #905

Merged
merged 1 commit into from
Aug 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Microsoft.AspNetCore.Http/Internal/ResponseCookies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ public void Delete(string key, CookieOptions options)
Path = options.Path,
Domain = options.Domain,
Expires = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc),
Secure = options.Secure,
HttpOnly = options.HttpOnly,
SameSite = options.SameSite
});
}
}
Expand Down
30 changes: 30 additions & 0 deletions test/Microsoft.AspNetCore.Http.Tests/ResponseCookiesTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Text;
using Microsoft.AspNetCore.Http.Internal;
using Microsoft.Extensions.ObjectPool;
Expand All @@ -27,6 +28,35 @@ public void DeleteCookieShouldSetDefaultPath()
Assert.Contains("expires=Thu, 01 Jan 1970 00:00:00 GMT", cookieHeaderValues[0]);
}

[Fact]
public void DeleteCookieWithCookieOptionsShouldKeepPropertiesOfCookieOptions()
{
var headers = new HeaderDictionary();
var cookies = new ResponseCookies(headers, null);
var testcookie = "TestCookie";
var time = new DateTimeOffset(2000, 1, 1, 1, 1, 1, 1, TimeSpan.Zero);
var options = new CookieOptions
{
Secure = true,
HttpOnly = true,
Path = "/",
Expires = time,
Domain = "example.com",
SameSite = SameSiteMode.Lax
};

cookies.Delete(testcookie, options);

var cookieHeaderValues = headers[HeaderNames.SetCookie];
Assert.Equal(1, cookieHeaderValues.Count);
Assert.StartsWith(testcookie, cookieHeaderValues[0]);
Assert.Contains("path=/", cookieHeaderValues[0]);
Assert.Contains("expires=Thu, 01 Jan 1970 00:00:00 GMT", cookieHeaderValues[0]);
Assert.Contains("secure", cookieHeaderValues[0]);
Assert.Contains("httponly", cookieHeaderValues[0]);
Assert.Contains("samesite", cookieHeaderValues[0]);
}

[Fact]
public void NoParamsDeleteRemovesCookieCreatedByAdd()
{
Expand Down