Skip to content

Commit

Permalink
Use NormalizedVersion in URLs contained in PackageAddedNotice (#3886)
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierdecoster committed May 12, 2017
1 parent de0f917 commit c9e80c7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/NuGetGallery/Controllers/ApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ await AuditingService.SaveAuditRecordAsync(

// Notify user of push
MessageService.SendPackageAddedNotice(package,
Url.Action("DisplayPackage", "Packages", routeValues: new { id = package.PackageRegistration.Id, version = package.Version }, protocol: Request.Url.Scheme),
Url.Action("ReportMyPackage", "Packages", routeValues: new { id = package.PackageRegistration.Id, version = package.Version }, protocol: Request.Url.Scheme),
Url.Action("DisplayPackage", "Packages", routeValues: new { id = package.PackageRegistration.Id, version = package.NormalizedVersion }, protocol: Request.Url.Scheme),
Url.Action("ReportMyPackage", "Packages", routeValues: new { id = package.PackageRegistration.Id, version = package.NormalizedVersion }, protocol: Request.Url.Scheme),
Url.Action("Account", "Users", routeValues: null, protocol: Request.Url.Scheme));

TelemetryService.TrackPackagePushEvent(package, user, User.Identity);
Expand Down
4 changes: 2 additions & 2 deletions src/NuGetGallery/Controllers/PackagesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1229,8 +1229,8 @@ await _auditingService.SaveAuditRecordAsync(

// notify user
_messageService.SendPackageAddedNotice(package,
Url.Action("DisplayPackage", "Packages", routeValues: new { id = package.PackageRegistration.Id, version = package.Version }, protocol: Request.Url.Scheme),
Url.Action("ReportMyPackage", "Packages", routeValues: new { id = package.PackageRegistration.Id, version = package.Version }, protocol: Request.Url.Scheme),
Url.Action("DisplayPackage", "Packages", routeValues: new { id = package.PackageRegistration.Id, version = package.NormalizedVersion }, protocol: Request.Url.Scheme),
Url.Action("ReportMyPackage", "Packages", routeValues: new { id = package.PackageRegistration.Id, version = package.NormalizedVersion }, protocol: Request.Url.Scheme),
Url.Action("Account", "Users", routeValues: null, protocol: Request.Url.Scheme));
}

Expand Down
23 changes: 17 additions & 6 deletions tests/NuGetGallery.Facts/Services/MessageServiceFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using NuGetGallery.Framework;
using NuGetGallery.Infrastructure.Authentication;
using Xunit;
using NuGet.Versioning;

namespace NuGetGallery
{
Expand Down Expand Up @@ -576,10 +577,17 @@ public void ApiKeyAddedMessageIsCorrect()

public class TheSendPackageAddedNoticeMethod
{
[Fact]
public void WillSendEmailToAllOwners()
[Theory]
[InlineData("1.2.3")]
[InlineData("1.2.3-alpha")]
[InlineData("1.2.3-alpha.1")]
[InlineData("1.2.3+metadata")]
[InlineData("1.2.3-alpha+metadata")]
[InlineData("1.2.3-alpha.1+metadata")]
public void WillSendEmailToAllOwners(string version)
{
// Arrange
var nugetVersion = new NuGetVersion(version);
var packageRegistration = new PackageRegistration
{
Id = "smangit",
Expand All @@ -591,24 +599,27 @@ public void WillSendEmailToAllOwners()
};
var package = new Package
{
Version = "1.2.3",
Version = version,
PackageRegistration = packageRegistration
};
packageRegistration.Packages.Add(package);

// Act
var messageService = new TestableMessageService();
messageService.SendPackageAddedNotice(package, "http://dummy1", "http://dummy2", "http://dummy3");
var packageUrl = $"https://localhost/packages/{packageRegistration.Id}/{nugetVersion.ToNormalizedString()}";
var supportUrl = $"https://localhost/packages/{packageRegistration.Id}/{nugetVersion.ToNormalizedString()}/ReportMyPackage";
var emailSettingsUrl = "https://localhost/account";
messageService.SendPackageAddedNotice(package, packageUrl, supportUrl, emailSettingsUrl);

// Assert
var message = messageService.MockMailSender.Sent.Last();

Assert.Equal("yung@example.com", message.To[0].Address);
Assert.Equal("flynt@example.com", message.To[1].Address);
Assert.Equal(TestGalleryNoReplyAddress, message.From);
Assert.Contains("[Joe Shmoe] Package published - smangit 1.2.3", message.Subject);
Assert.Contains($"[Joe Shmoe] Package published - {packageRegistration.Id} {nugetVersion.ToNormalizedString()}", message.Subject);
Assert.Contains(
"The package [smangit 1.2.3](http://dummy1) was just published on Joe Shmoe. If this was not intended, please [contact support](http://dummy2).", message.Body);
$"The package [{packageRegistration.Id} {nugetVersion.ToFullString()}]({packageUrl}) was just published on Joe Shmoe. If this was not intended, please [contact support]({supportUrl}).", message.Body);
}

[Fact]
Expand Down

0 comments on commit c9e80c7

Please sign in to comment.