Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Jan 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/NuGetGallery/Controllers/AppController.cs
Expand Up @@ -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)
Expand Down
21 changes: 12 additions & 9 deletions src/NuGetGallery/Controllers/AuthenticationController.cs
Expand Up @@ -135,8 +135,8 @@ public async virtual Task<ActionResult> Register(LogOnViewModel model, string re
}

user = await AuthService.Register(
model.Register.Username,
model.Register.EmailAddress,
model.Register.Username,
model.Register.EmailAddress,
result.Credential);
}
else
Expand All @@ -154,13 +154,16 @@ public async virtual Task<ActionResult> Register(LogOnViewModel model, string re
}

// 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);
Expand Down
Expand Up @@ -372,6 +372,51 @@ public async Task WillCreateAndLogInTheUserWhenNotLinking()
ResultAssert.IsSafeRedirectTo(result, "/theReturnUrl");
}

[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()
{
Expand Down
2 changes: 2 additions & 0 deletions tests/NuGetGallery.Facts/Framework/TestContainer.cs
Expand Up @@ -10,6 +10,7 @@
using Moq;
using Ninject;
using Ninject.Modules;
using NuGetGallery.Configuration;
using Xunit.Extensions;

namespace NuGetGallery.Framework
Expand Down Expand Up @@ -43,6 +44,7 @@ protected TestContainer(IKernel kernel)
if (appCtrl != null)
{
appCtrl.OwinContext = Kernel.Get<IOwinContext>();
appCtrl.NuGetContext.Config = Kernel.Get<ConfigurationService>();
}

return c;
Expand Down