Permalink
Browse files

Modifying RequireRemoteHttpsAttribute to return a ActionResult instea…

…d of throwing.
  • Loading branch information...
1 parent b9dbd1f commit 1e3039d6babea0f83a6f98fdf142bb67d7ee1df6 pranavkm committed Dec 2, 2011
Showing with 8 additions and 8 deletions.
  1. +6 −6 Facts/RequireRemoteHttpsAttributeFacts.cs
  2. +2 −2 Website/RequireRemoteHttpsAttribute.cs
@@ -3,7 +3,6 @@
using Moq;
using Xunit;
using Xunit.Extensions;
-using System.Web;
namespace NuGetGallery
{
@@ -75,7 +74,7 @@ public void RequireHttpsAttributeRedirectsGetRequest()
[InlineData(new object[] { "PUT" })]
[InlineData(new object[] { "head" })]
[InlineData(new object[] { "trace" })]
- public void RequireHttpsAttributeThrowsIfNonGetRequest(string method)
+ public void RequireHttpsAttributeReturns403IfNonGetRequest(string method)
{
// Arrange
Mock<AuthorizationContext> mockAuthContext = new Mock<AuthorizationContext>(MockBehavior.Strict);
@@ -88,12 +87,13 @@ public void RequireHttpsAttributeThrowsIfNonGetRequest(string method)
var attribute = new RequireRemoteHttpsAttribute();
// Act
- Exception exception = Record.Exception(() => attribute.OnAuthorization(context));
+ attribute.OnAuthorization(context);
// Assert
- Assert.IsType<HttpException>(exception);
- Assert.Equal(403, ((HttpException)exception).GetHttpCode());
- Assert.Equal("The requested resource can only be accessed via SSL.", exception.Message);
+ Assert.IsType<HttpStatusCodeWithBodyResult>(context.Result);
+ var result = (HttpStatusCodeWithBodyResult)context.Result;
+ Assert.Equal(403, result.StatusCode);
+ Assert.Equal("The requested resource can only be accessed via SSL.", result.StatusDescription);
}
}
}
@@ -1,5 +1,5 @@
using System;
-using System.Web;
+using System.Net;
using System.Web.Mvc;
namespace NuGetGallery
@@ -28,7 +28,7 @@ protected virtual void HandleNonHttpsRequest(AuthorizationContext filterContext)
// body correctly.
if (!String.Equals(filterContext.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
{
- throw new HttpException(403, Strings.SSLRequired);
+ filterContext.Result = new HttpStatusCodeWithBodyResult(HttpStatusCode.Forbidden, Strings.SSLRequired);
}
else
{

0 comments on commit 1e3039d

Please sign in to comment.