Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix #1791 by only sending confirmation email if ConfirmEmailAddresses is true #1861

Merged
merged 1 commit into from

1 participant

@anurse
Collaborator

Fixes #1791

Test Notes:

For NuGet.org, we need only test that confirmation emails are still sent (because we set ConfirmEmailAddresses to true). There is no need to spend cycles testing the ConfirmEmailAddresses=false case pre-deployment. We can circle back if necessary and follow up with those who were affected by this issue.

@anurse anurse merged commit d94f770 into from
@anurse anurse deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 29, 2014
  1. @anurse
This page is out of date. Refresh to see the latest.
View
2  src/NuGetGallery/Controllers/AppController.cs
@@ -54,7 +54,7 @@ public class NuGetContext
{
private Lazy<User> _currentUser;
- public ConfigurationService Config { get; private set; }
+ public ConfigurationService Config { get; internal set; }
public User CurrentUser { get { return _currentUser.Value; } }
public NuGetContext(AppController ctrl)
View
21 src/NuGetGallery/Controllers/AuthenticationController.cs
@@ -135,8 +135,8 @@ public virtual ActionResult LogOn(string returnUrl)
}
user = await AuthService.Register(
- model.Register.Username,
- model.Register.EmailAddress,
+ model.Register.Username,
+ model.Register.EmailAddress,
result.Credential);
}
else
@@ -154,13 +154,16 @@ public virtual ActionResult LogOn(string returnUrl)
}
// Send a new account email
- MessageService.SendNewAccountEmail(
- new MailAddress(user.User.UnconfirmedEmailAddress, user.User.Username),
- Url.ConfirmationUrl(
- "Confirm",
- "Users",
- user.User.Username,
- user.User.EmailConfirmationToken));
+ if(NuGetContext.Config.Current.ConfirmEmailAddresses && !String.IsNullOrEmpty(user.User.UnconfirmedEmailAddress))
+ {
+ MessageService.SendNewAccountEmail(
+ new MailAddress(user.User.UnconfirmedEmailAddress, user.User.Username),
+ Url.ConfirmationUrl(
+ "Confirm",
+ "Users",
+ user.User.Username,
+ user.User.EmailConfirmationToken));
+ }
// We're logging in!
AuthService.CreateSession(OwinContext, user.User);
View
45 tests/NuGetGallery.Facts/Controllers/AuthenticationControllerFacts.cs
@@ -373,6 +373,51 @@ public class TheRegisterAction : TestContainer
}
[Fact]
+ public async Task WillNotSendConfirmationEmailWhenConfirmEmailAddressesIsOff()
+ {
+ // Arrange
+ var authUser = new AuthenticatedUser(
+ new User("theUsername")
+ {
+ UnconfirmedEmailAddress = "unconfirmed@example.com",
+ EmailConfirmationToken = "t0k3n"
+ },
+ new Credential());
+ var config = Get<ConfigurationService>();
+ config.Current = new AppConfiguration()
+ {
+ ConfirmEmailAddresses = false
+ };
+ GetMock<AuthenticationService>()
+ .Setup(x => x.Register("theUsername", "unconfirmed@example.com", It.IsAny<Credential>()))
+ .CompletesWith(authUser);
+
+ var controller = GetController<AuthenticationController>();
+
+ GetMock<AuthenticationService>()
+ .Setup(x => x.CreateSession(controller.OwinContext, authUser.User))
+ .Verifiable();
+
+ // Act
+ var result = await controller.Register(
+ new LogOnViewModel()
+ {
+ Register = new RegisterViewModel
+ {
+ Username = "theUsername",
+ Password = "thePassword",
+ EmailAddress = "unconfirmed@example.com",
+ }
+ }, "/theReturnUrl", linkingAccount: false);
+
+ // Assert
+ GetMock<IMessageService>()
+ .Verify(x => x.SendNewAccountEmail(
+ It.IsAny<MailAddress>(),
+ It.IsAny<string>()), Times.Never());
+ }
+
+ [Fact]
public async Task GivenExpiredExternalAuth_ItRedirectsBackToLogOnWithExternalAuthExpiredMessage()
{
// Arrange
View
2  tests/NuGetGallery.Facts/Framework/TestContainer.cs
@@ -10,6 +10,7 @@
using Moq;
using Ninject;
using Ninject.Modules;
+using NuGetGallery.Configuration;
using Xunit.Extensions;
namespace NuGetGallery.Framework
@@ -43,6 +44,7 @@ protected TestContainer(IKernel kernel)
if (appCtrl != null)
{
appCtrl.OwinContext = Kernel.Get<IOwinContext>();
+ appCtrl.NuGetContext.Config = Kernel.Get<ConfigurationService>();
}
return c;
Something went wrong with that request. Please try again.