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

Send e-mail when a new API key is created #3634

Merged
merged 2 commits into from
Mar 8, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/NuGetGallery/Controllers/UsersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,8 @@ public virtual async Task<ActionResult> GenerateApiKey(string description, strin
var credentialViewModel = _authService.DescribeCredential(newCredential);
credentialViewModel.Value = newCredential.Value;

_messageService.SendCredentialAddedNotice(GetCurrentUser(), newCredential);

return Json(credentialViewModel);
}

Expand Down
20 changes: 20 additions & 0 deletions tests/NuGetGallery.Facts/Controllers/UsersControllerFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,26 @@ public async Task ReturnsNewCredentialJson()
Assert.Equal(apiKey.Description, credentialViewModel.Description);
Assert.Equal(apiKey.Expires, credentialViewModel.Expires);
}

[Fact]
public async Task SendsNotificationMailToUser()
{
var user = new User { Username = "the-username" };

var controller = GetController<UsersController>();
controller.SetCurrentUser(user);

var result = await controller.GenerateApiKey(
description: "description",
scopes: new[] { NuGetScopes.PackageUnlist, NuGetScopes.PackagePush },
subjects: new[] { "a" },
expirationInDays: 90);

var apiKey = user.Credentials.FirstOrDefault(x => x.Type == CredentialTypes.ApiKey.V2);

GetMock<IMessageService>()
.Verify(m => m.SendCredentialAddedNotice(user, apiKey));
}
}

public class TheChangeEmailAction : TestContainer
Expand Down