forked from kevinobee/Sitecore.Ship
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kevinobee#62 from richardszalay/feature/53_whiteli…
…st_does_not_prevent_execution BaseHttpHandler no longer continues execution when authorisation fails (fixes kevinobee#53)
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
tests/unit-test/Sitecore.Ship.AspNet.Test/BaseHttpHandlerUnauthorisedTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using Moq; | ||
using System.Web; | ||
using Xunit; | ||
using System; | ||
using Should; | ||
using Sitecore.Ship.Core.Contracts; | ||
using System.IO; | ||
|
||
namespace Sitecore.Ship.AspNet.Test | ||
{ | ||
public class BaseHttpHandlerUnauthorisedTests | ||
{ | ||
private HttpResponse _response; | ||
private SampleHandler _sut; | ||
|
||
public BaseHttpHandlerUnauthorisedTests() | ||
{ | ||
var authoriser = new Mock<IAuthoriser>(); | ||
authoriser.Setup(x => x.IsAllowed()).Returns(false); | ||
|
||
var request = new HttpRequest("", "http://tempuri.org", ""); | ||
_response = new HttpResponse(new StringWriter()); | ||
|
||
var context = new HttpContext(request, _response); | ||
|
||
_sut = new SampleHandler(authoriser.Object); | ||
_sut.ProcessRequest(context); | ||
} | ||
|
||
[Fact] | ||
public void ReturnsStatusCodeUnauthorized() | ||
{ | ||
_response.StatusCode.ShouldEqual(401); | ||
} | ||
|
||
[Fact] | ||
public void DoesNotCallProcessRequest() | ||
{ | ||
_sut.DidRun.ShouldBeFalse(); | ||
} | ||
|
||
class SampleHandler : BaseHttpHandler | ||
{ | ||
public SampleHandler(IAuthoriser authoriser) | ||
: base(authoriser) | ||
{ | ||
|
||
} | ||
|
||
public override void ProcessRequest(HttpContextBase context) | ||
{ | ||
DidRun = true; | ||
context.Response.StatusDescription = "Failed"; | ||
} | ||
|
||
public bool DidRun; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters