DOWNLOAD:
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Web;
using System.Web.Cors;
using System.Web.Mvc;
namespace WebApiContrib.Test.UnitTests.WebApiContrib
{
[TestClass]
public class CrossDomainTests
{
[TestMethod]
public void CrossDomain_ValidRequest_Allowed()
{
string location = Request.Url.AbsolutePath;
var result = LocationValidator.ValidateCrossDomainRequest(location);
Assert.IsFalse(result);
}
[TestMethod]
public void CrossDomain_InvalidRequest_Forbidden()
{
string location = Request.Url.AbsolutePath;
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET,POST,PUT");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "X-Requested-With");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Credentials", "true");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "");
var result = LocationValidator.ValidateCrossDomainRequest(location);
Assert.IsTrue(result); ac619d1d87
Related links:
Comments