Files
Umbraco-CMS/src/Umbraco.Tests/Web/AngularIntegration/AngularAntiForgeryTests.cs
T

55 lines
1.6 KiB
C#
Raw Normal View History

2016-02-17 10:59:48 +01:00
using System.IO;
2013-12-03 11:36:17 +11:00
using System.Net;
using System.Security.Principal;
using System.Web;
using NUnit.Framework;
using Umbraco.Web.WebApi.Filters;
2016-02-17 10:59:48 +01:00
namespace Umbraco.Tests.Web.AngularIntegration
2013-12-03 11:36:17 +11:00
{
[TestFixture]
public class AngularAntiForgeryTests
{
[TearDown]
public void TearDown()
{
HttpContext.Current = null;
}
[Test]
public void Can_Validate_Generated_Tokens()
{
using (var writer = new StringWriter())
{
HttpContext.Current = new HttpContext(new HttpRequest("test.html", "http://test/", ""), new HttpResponse(writer));
string cookieToken, headerToken;
AngularAntiForgeryHelper.GetTokens(out cookieToken, out headerToken);
2020-03-20 23:25:32 +11:00
Assert.IsTrue(AngularAntiForgeryHelper.ValidateTokens(cookieToken, headerToken));
2013-12-03 11:36:17 +11:00
}
2017-07-20 11:21:28 +02:00
2013-12-03 11:36:17 +11:00
}
[Test]
public void Can_Validate_Generated_Tokens_With_User()
{
using (var writer = new StringWriter())
{
HttpContext.Current = new HttpContext(new HttpRequest("test.html", "http://test/", ""), new HttpResponse(writer))
{
User = new GenericPrincipal(new HttpListenerBasicIdentity("test", "test"), new string[] {})
};
string cookieToken, headerToken;
AngularAntiForgeryHelper.GetTokens(out cookieToken, out headerToken);
2020-03-20 23:25:32 +11:00
Assert.IsTrue(AngularAntiForgeryHelper.ValidateTokens(cookieToken, headerToken));
2013-12-03 11:36:17 +11:00
}
}
}
}