diff --git a/src/NuGetGallery/Controllers/AuthenticationController.cs b/src/NuGetGallery/Controllers/AuthenticationController.cs index 2ca9d00256..c60d330c4d 100644 --- a/src/NuGetGallery/Controllers/AuthenticationController.cs +++ b/src/NuGetGallery/Controllers/AuthenticationController.cs @@ -93,9 +93,6 @@ public virtual ActionResult Register(RegisterRequest request, string returnUrl) return View(); } - // TODO: consider client-side validation for unique username - // TODO: add email validation - User user; try { diff --git a/src/NuGetGallery/Helpers/HttpContextBaseExtensions.cs b/src/NuGetGallery/Helpers/HttpContextBaseExtensions.cs index 17a17b8925..463e63122d 100644 --- a/src/NuGetGallery/Helpers/HttpContextBaseExtensions.cs +++ b/src/NuGetGallery/Helpers/HttpContextBaseExtensions.cs @@ -21,7 +21,12 @@ public static void SetConfirmationContext(this HttpContextBase httpContext, stri public static string GetConfirmationReturnUrl(this HttpContextBase httpContext) { - var cookie = httpContext.Request.Cookies.Get("ConfirmationContext"); + HttpCookie cookie = null; + if (httpContext.Request.Cookies != null) + { + cookie = httpContext.Request.Cookies.Get("ConfirmationContext"); + } + if (cookie == null) { return null; diff --git a/tests/NuGetGallery.Facts/Controllers/AuthenticationControllerFacts.cs b/tests/NuGetGallery.Facts/Controllers/AuthenticationControllerFacts.cs index f930718192..49b93fbcb4 100644 --- a/tests/NuGetGallery.Facts/Controllers/AuthenticationControllerFacts.cs +++ b/tests/NuGetGallery.Facts/Controllers/AuthenticationControllerFacts.cs @@ -210,13 +210,13 @@ public void WillInvalidateModelStateAndShowTheViewWhenAnEntityExceptionIsThrow() .Setup(x => x.Create(It.IsAny(), It.IsAny(), It.IsAny())) .Throws(new EntityException("aMessage")); - var result = controller.Register( - new RegisterRequest - { - Username = "theUsername", - Password = "thePassword", - EmailAddress = "theEmailAddress", - }, null); + var request = new RegisterRequest + { + Username = "theUsername", + Password = "thePassword", + EmailAddress = "theEmailAddress", + }; + var result = controller.Register(request, null); ResultAssert.IsView(result); Assert.False(controller.ModelState.IsValid); diff --git a/tests/NuGetGallery.Facts/Controllers/UsersControllerFacts.cs b/tests/NuGetGallery.Facts/Controllers/UsersControllerFacts.cs index 69e38463da..f977322d5b 100644 --- a/tests/NuGetGallery.Facts/Controllers/UsersControllerFacts.cs +++ b/tests/NuGetGallery.Facts/Controllers/UsersControllerFacts.cs @@ -118,18 +118,20 @@ public void Returns404WhenTokenIsEmpty() public void ReturnsConfirmedWhenTokenMatchesUser() { var user = new User - { - UnconfirmedEmailAddress = "email@example.com", - EmailConfirmationToken = "the-token" - }; + { + Username = "username", + UnconfirmedEmailAddress = "email@example.com", + EmailConfirmationToken = "the-token" + }; var controller = GetController(); + controller.SetUser(user); + GetMock() .Setup(u => u.FindByUsername("username")) .Returns(user); GetMock() .Setup(u => u.ConfirmEmailAddress(user, "the-token")) .Returns(true); - controller.SetUser(user); var model = (controller.Confirm("username", "the-token") as ViewResult).Model as ConfirmationViewModel; @@ -140,20 +142,22 @@ public void ReturnsConfirmedWhenTokenMatchesUser() public void SendsAccountChangedNoticeWhenConfirmingChangedEmail() { var user = new User - { - EmailAddress = "old@example.com", - UnconfirmedEmailAddress = "new@example.com", - EmailConfirmationToken = "the-token" - }; + { + Username = "username", + EmailAddress = "old@example.com", + UnconfirmedEmailAddress = "new@example.com", + EmailConfirmationToken = "the-token" + }; var controller = GetController(); + controller.SetUser(user); + GetMock() .Setup(u => u.FindByUsername("username")) .Returns(user); GetMock() .Setup(u => u.ConfirmEmailAddress(user, "the-token")) .Returns(true); - controller.SetUser(user); - + var model = (controller.Confirm("username", "the-token") as ViewResult).Model as ConfirmationViewModel; Assert.True(model.SuccessfulConfirmation); @@ -167,6 +171,7 @@ public void DoesntSendAccountChangedEmailsWhenNoOldConfirmedAddress() { var user = new User { + Username = "username", EmailAddress = null, UnconfirmedEmailAddress = "new@example.com", EmailConfirmationToken = "the-token" diff --git a/tests/NuGetGallery.Facts/TestUtils/ResultAssert.cs b/tests/NuGetGallery.Facts/TestUtils/ResultAssert.cs index a5c1ec59b9..6e41442288 100644 --- a/tests/NuGetGallery.Facts/TestUtils/ResultAssert.cs +++ b/tests/NuGetGallery.Facts/TestUtils/ResultAssert.cs @@ -38,10 +38,6 @@ public static ViewResult IsView(ActionResult result, string viewName = "", strin { DictionariesMatch(new RouteValueDictionary(viewData), view.ViewData); } - else - { - Assert.Equal(0, view.ViewData.Count); - } return view; } @@ -67,6 +63,12 @@ public static void IsStatusCode(ActionResult result, HttpStatusCode code) public static void IsStatusCode(ActionResult result, int code) { + if (result is EmptyResult) + { + Assert.Equal(code, 200); + return; + } + var statusCodeResult = Assert.IsAssignableFrom(result); Assert.Equal(code, statusCodeResult.StatusCode); }