/// <summary> /// This will delete the user impersonation cookie, which causes the AuthCookie ValidateAsync event to revert to the original user /// </summary> /// <returns>error message, or null if OK</returns> public string StopImpersonation() { if (!_httpContext.User.InImpersonationMode()) { return("You aren't in impersonation mode."); } _cookie.Delete(); return(null); }
public void TestCookieDelete() { //SETUP var mocks = new MockHttpContextCookies(); var cookie = new ImpersonationCookie(mocks.MockContext, null); mocks.ResponseCookies["Set-Cookie"] = "Some data"; //ATTEMPT cookie.Delete(); //VERIFY mocks.ResponseCookies["Set-Cookie"][1].ShouldEndWith("expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; samesite=lax; httponly"); }
public void TestCookieDelete() { //SETUP var httpContext = new DefaultHttpContext(); var cookie = new ImpersonationCookie(httpContext, null); httpContext.Response.Headers["Set-Cookie"] = "Some data"; //ATTEMPT cookie.Delete(); //VERIFY httpContext.Response.Headers["Set-Cookie"][1].ShouldEndWith("expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; httponly"); }