Exemplo n.º 1
0
            public void SendsPackageOwnerRequestConfirmationUrl()
            {
                var to = new User {
                    Username = "******", EmailAddress = "*****@*****.**", EmailAllowed = true
                };
                var from = new User {
                    Username = "******", EmailAddress = "*****@*****.**"
                };
                var package = new PackageRegistration {
                    Id = "CoolStuff"
                };
                const string packageUrl      = "http://nuget.local/packages/CoolStuff";
                const string confirmationUrl = "http://example.com/confirmation-token-url";
                const string userMessage     = "Hello World!";

                var messageService = TestableMessageService.Create(
                    GetService <AuthenticationService>(),
                    GetConfigurationService());

                messageService.SendPackageOwnerRequest(from, to, package, packageUrl, confirmationUrl, userMessage, string.Empty);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal("*****@*****.**", message.To[0].Address);
                Assert.Equal(TestGalleryNoReplyAddress.Address, message.From.Address);
                Assert.Equal("*****@*****.**", message.ReplyToList.Single().Address);
                Assert.Equal("[Joe Shmoe] The user 'Existing' would like to add you as an owner of the package 'CoolStuff'.", message.Subject);
                Assert.Contains("The user 'Existing' added the following message for you", message.Body);
                Assert.Contains(userMessage, message.Body);
                Assert.Contains(confirmationUrl, message.Body);
                Assert.Contains(userMessage, message.Body);
                Assert.Contains("The user 'Existing' wants to add you as an owner of the package 'CoolStuff'.", message.Body);
            }
            public void WillNotSendEmailToOwnerThatOptsOut()
            {
                var from    = new MailAddress("*****@*****.**", "flossy");
                var package = new PackageRegistration
                {
                    Id     = "smangit",
                    Owners = new[]
                    {
                        new User {
                            EmailAddress = "*****@*****.**", EmailAllowed = true
                        },
                        new User {
                            EmailAddress = "*****@*****.**", EmailAllowed = false
                        }
                    }
                };

                var messageService = new TestableMessageService();

                messageService.SendContactOwnersMessage(from, package, "Test message", "http://someurl/", false);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal("*****@*****.**", message.To[0].Address);
                Assert.Equal(1, message.To.Count);
            }
Exemplo n.º 3
0
            public void WillNotCopySenderIfNoOwnersAllow()
            {
                var from    = new MailAddress("*****@*****.**", "flossy");
                var package = new PackageRegistration {
                    Id = "smangit"
                };

                package.Owners = new[]
                {
                    new User {
                        EmailAddress = "*****@*****.**", EmailAllowed = false
                    },
                    new User {
                        EmailAddress = "*****@*****.**", EmailAllowed = false
                    }
                };

                var messageService = TestableMessageService.Create(
                    GetService <AuthenticationService>(),
                    GetConfigurationService());

                messageService.SendContactOwnersMessage(from, package, "Test message", "http://someurl/", false);

                Assert.Empty(messageService.MockMailSender.Sent);
            }
            public void UsesProviderNounToDescribeCredentialIfPresent()
            {
                var user = new User {
                    EmailAddress = "*****@*****.**", Username = "******"
                };
                var          cred = new CredentialBuilder().CreateExternalCredential("MicrosoftAccount", "abc123", "Test User");
                const string MicrosoftAccountCredentialName = "Microsoft Account";

                var messageService = new TestableMessageService();

                messageService.MockAuthService
                .Setup(a => a.DescribeCredential(cred))
                .Returns(new CredentialViewModel
                {
                    AuthUI = new AuthenticatorUI("sign in", MicrosoftAccountCredentialName, MicrosoftAccountCredentialName)
                });

                messageService.SendCredentialAddedNotice(user, cred);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal(user.ToMailAddress(), message.To[0]);
                Assert.Equal(TestGalleryOwner, message.From);
                Assert.Equal(string.Format(Strings.Emails_CredentialAdded_Subject, TestGalleryOwner.DisplayName, MicrosoftAccountCredentialName), message.Subject);
                Assert.Contains(string.Format(Strings.Emails_CredentialAdded_Body, MicrosoftAccountCredentialName), message.Body);
            }
            public void ApiKeyAddedMessageIsCorrect()
            {
                var user = new User {
                    EmailAddress = "*****@*****.**", Username = "******"
                };
                var cred = new CredentialBuilder().CreateApiKey(TimeSpan.FromDays(1));

                cred.Description = "new api key";
                var messageService = new TestableMessageService();

                messageService.MockAuthService
                .Setup(a => a.DescribeCredential(cred))
                .Returns(new CredentialViewModel
                {
                    Description = cred.Description
                });

                messageService.SendCredentialAddedNotice(user, cred);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal(user.ToMailAddress(), message.To[0]);
                Assert.Equal(TestGalleryOwner, message.From);
                Assert.Equal(string.Format(Strings.Emails_CredentialAdded_Subject, TestGalleryOwner.DisplayName, Strings.CredentialType_ApiKey), message.Subject);
                Assert.Contains(string.Format(Strings.Emails_ApiKeyAdded_Body, cred.Description), message.Body);
            }
Exemplo n.º 6
0
            public void SendsPackageOwnerRemovedNotice()
            {
                var to = new User {
                    Username = "******", EmailAddress = "*****@*****.**", EmailAllowed = true
                };
                var from = new User {
                    Username = "******", EmailAddress = "*****@*****.**"
                };
                var package = new PackageRegistration {
                    Id = "CoolStuff"
                };

                var messageService = TestableMessageService.Create(
                    GetService <AuthenticationService>(),
                    GetConfigurationService());

                messageService.SendPackageOwnerRemovedNotice(from, to, package);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal("*****@*****.**", message.To[0].Address);
                Assert.Equal(TestGalleryNoReplyAddress.Address, message.From.Address);
                Assert.Equal("*****@*****.**", message.ReplyToList.Single().Address);
                Assert.Contains("The user 'Existing' has removed you as an owner of the package 'CoolStuff'.", message.Subject);
                Assert.Contains("The user 'Existing' removed you as an owner of the package 'CoolStuff'", message.Body);
            }
            public void SendsPackageOwnerRequestConfirmationUrl()
            {
                var to = new User {
                    Username = "******", EmailAddress = "*****@*****.**", EmailAllowed = true
                };
                var from = new User {
                    Username = "******", EmailAddress = "*****@*****.**"
                };
                var package = new PackageRegistration {
                    Id = "CoolStuff"
                };
                const string confirmationUrl = "http://example.com/confirmation-token-url";

                var messageService = new TestableMessageService();

                messageService.SendPackageOwnerRequest(from, to, package, confirmationUrl);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal("*****@*****.**", message.To[0].Address);
                Assert.Equal(TestGalleryOwner.Address, message.From.Address);
                Assert.Equal("*****@*****.**", message.ReplyToList.Single().Address);
                Assert.Equal("[Joe Shmoe] The user 'Existing' wants to add you as an owner of the package 'CoolStuff'.", message.Subject);
                Assert.Contains(confirmationUrl, message.Body);
                Assert.Contains("The user 'Existing' wants to add you as an owner of the package 'CoolStuff'.", message.Body);
            }
            public void WillNotAttemptToSendIfNoOwnersAllow()
            {
                // Arrange
                var packageRegistration = new PackageRegistration
                {
                    Id     = "smangit",
                    Owners = new[]
                    {
                        new User {
                            EmailAddress = "*****@*****.**", EmailAllowed = false
                        },
                        new User {
                            EmailAddress = "*****@*****.**", EmailAllowed = false
                        }
                    }
                };
                var package = new Package
                {
                    Version             = "1.2.3",
                    PackageRegistration = packageRegistration
                };

                packageRegistration.Packages.Add(package);

                // Act
                var messageService = new TestableMessageService();

                messageService.SendPackageAddedNotice(package, "http://dummy1", "http://dummy2", "http://dummy3");

                // Assert
                Assert.Empty(messageService.MockMailSender.Sent);
            }
            public void WillCopySenderIfAsked()
            {
                var from = new MailAddress("*****@*****.**", "too");
                var package = new Package
                {
                    PackageRegistration = new PackageRegistration { Id = "smangit" },
                    Version = "1.42.0.1",
                };

                var messageService = new TestableMessageService();

                var reportPackageRequest = new ReportPackageRequest
                {
                    AlreadyContactedOwners = true,
                    FromAddress = from,
                    Message = "Abuse!",
                    Package = package,
                    Reason = "Reason!",
                    RequestingUser = new User
                    {
                        Username = "******",
                        EmailAddress = "*****@*****.**"
                    },
                    Url = TestUtility.MockUrlHelper(),
                    CopySender = true,
                };
                messageService.ReportAbuse(reportPackageRequest);

                var message = messageService.MockMailSender.Sent.Single();
                Assert.Equal(TestGalleryOwner, message.To.Single());
                Assert.Equal(TestGalleryOwner, message.From);
                Assert.Equal(reportPackageRequest.FromAddress, message.ReplyToList.Single());
                Assert.Equal(reportPackageRequest.FromAddress, message.CC.Single());
                Assert.DoesNotContain("Owners", message.Body);
            }
            public void WillNotSendEmailToOwnerThatOptsOut()
            {
                // Arrange
                var packageRegistration = new PackageRegistration
                {
                    Id     = "smangit",
                    Owners = new[]
                    {
                        new User {
                            EmailAddress = "*****@*****.**", NotifyPackagePushed = true
                        },
                        new User {
                            EmailAddress = "*****@*****.**", NotifyPackagePushed = false
                        }
                    }
                };
                var package = new Package
                {
                    Version             = "1.2.3",
                    PackageRegistration = packageRegistration
                };

                packageRegistration.Packages.Add(package);

                // Act
                var messageService = new TestableMessageService();

                messageService.SendPackageAddedNotice(package, "http://dummy1", "http://dummy2", "http://dummy3");

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

                Assert.Equal("*****@*****.**", message.To[0].Address);
                Assert.Equal(1, message.To.Count);
            }
Exemplo n.º 11
0
            public void WillCopySenderIfAsked()
            {
                var from    = new MailAddress("*****@*****.**", "flossy");
                var package = new PackageRegistration {
                    Id = "smangit"
                };

                package.Owners = new[]
                {
                    new User {
                        EmailAddress = "*****@*****.**", EmailAllowed = true
                    },
                    new User {
                        EmailAddress = "*****@*****.**", EmailAllowed = true
                    }
                };
                var messageService = new TestableMessageService();

                messageService.SendContactOwnersMessage(from, package, "Test message", "http://someurl/", true);

                var messages = messageService.MockMailSender.Sent;

                Assert.Equal(2, messages.Count);
                Assert.Equal(package.Owners.Count, messages[0].To.Count);
                Assert.Equal(1, messages[1].To.Count);
                Assert.Equal("*****@*****.**", messages[0].To[0].Address);
                Assert.Equal("*****@*****.**", messages[0].To[1].Address);
                Assert.Equal(messages[1].ReplyToList.Single(), messages[1].To.First());
                Assert.Equal(TestGalleryOwner, messages[0].From);
                Assert.Equal(TestGalleryOwner, messages[1].From);
                Assert.Equal("*****@*****.**", messages[0].ReplyToList.Single().Address);
                Assert.Equal("*****@*****.**", messages[1].ReplyToList.Single().Address);
            }
Exemplo n.º 12
0
            public void SendsPackageOwnerAddedNotice()
            {
                // Arrange
                var toUser = new User {
                    Username = "******", EmailAddress = "*****@*****.**", EmailAllowed = true
                };
                var newUser = new User {
                    Username = "******", EmailAddress = "*****@*****.**"
                };
                var package = new PackageRegistration {
                    Id = "CoolStuff"
                };
                var messageService = TestableMessageService.Create(
                    GetService <AuthenticationService>(),
                    GetConfigurationService());

                // Act
                messageService.SendPackageOwnerAddedNotice(toUser, newUser, package, "packageUrl", "policyMessage");

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

                Assert.Equal("*****@*****.**", message.To[0].Address);
                Assert.Equal(TestGalleryNoReplyAddress.Address, "*****@*****.**");
                Assert.Contains("The user 'Noob' is now an owner of the package 'CoolStuff'.", message.Subject);
                Assert.Contains("This is to inform you that 'Noob' is now an owner of the package", message.Body);
                Assert.Contains("policyMessage", message.Body);
            }
            public void WillSendEmailToAllOwners()
            {
                var from    = new MailAddress("*****@*****.**", "flossy");
                var package = new PackageRegistration
                {
                    Id     = "smangit",
                    Owners = new[]
                    {
                        new User {
                            EmailAddress = "*****@*****.**", EmailAllowed = true
                        },
                        new User {
                            EmailAddress = "*****@*****.**", EmailAllowed = true
                        }
                    }
                };

                var messageService = new TestableMessageService();

                messageService.SendContactOwnersMessage(from, package, "Test message", "http://someurl/", false);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal("*****@*****.**", message.To[0].Address);
                Assert.Equal("*****@*****.**", message.To[1].Address);
                Assert.Equal(TestGalleryOwner, message.From);
                Assert.Equal("*****@*****.**", message.ReplyToList.Single().Address);
                Assert.Contains("[Joe Shmoe] Message for owners of the package 'smangit'", message.Subject);
                Assert.Contains("Test message", message.Body);
                Assert.Contains(
                    "User flossy &lt;[email protected]&gt; sends the following message to the owners of Package 'smangit'.", message.Body);
            }
Exemplo n.º 14
0
            public void WillSendEmailToNewUser()
            {
                var to = new MailAddress("*****@*****.**", "too");

                var messageService = new TestableMessageService();

                messageService.SendNewAccountEmail(to, "http://example.com/confirmation-token-url");
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal("*****@*****.**", message.To[0].Address);
                Assert.Equal(TestGalleryNoReplyAddress.Address, message.From.Address);
                Assert.Equal("[Joe Shmoe] Please verify your account.", message.Subject);
                Assert.Contains("http://example.com/confirmation-token-url", message.Body);
            }
Exemplo n.º 15
0
            public void WillSendEmailToGalleryOwner()
            {
                var from  = new MailAddress("*****@*****.**", "too");
                var owner = new User
                {
                    Username     = "******",
                    EmailAddress = "*****@*****.**",
                };
                var package = new Package
                {
                    PackageRegistration = new PackageRegistration
                    {
                        Id     = "smangit",
                        Owners = new Collection <User> {
                            owner
                        }
                    },
                    Version = "1.42.0.1"
                };

                var messageService = TestableMessageService.Create(
                    GetService <AuthenticationService>(),
                    GetConfigurationService());

                messageService.ReportMyPackage(
                    new ReportPackageRequest
                {
                    FromAddress    = from,
                    Message        = "Abuse!",
                    Package        = package,
                    Reason         = "Reason!",
                    RequestingUser = owner,
                    Signature      = "Joe Schmoe",
                    Url            = TestUtility.MockUrlHelper(),
                });

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

                Assert.Equal(TestGalleryOwner, message.To[0]);
                Assert.Equal(TestGalleryOwner, message.From);
                Assert.Equal("*****@*****.**", message.ReplyToList.Single().Address);
                Assert.Equal("[Joe Shmoe] Owner Support Request for 'smangit' version 1.42.0.1 (Reason: Reason!)", message.Subject);
                Assert.Contains("Reason!", message.Body);
                Assert.Contains("Abuse!", message.Body);
                Assert.Contains("too ([email protected])", message.Body);
                Assert.Contains("smangit", message.Body);
                Assert.Contains("1.42.0.1", message.Body);
            }
Exemplo n.º 16
0
            public void WillSendInstructions()
            {
                var user = new User {
                    EmailAddress = "*****@*****.**", Username = "******"
                };

                var messageService = new TestableMessageService();

                messageService.SendPasswordResetInstructions(user, "http://example.com/pwd-reset-token-url", true);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal("*****@*****.**", message.To[0].Address);
                Assert.Equal(TestGalleryNoReplyAddress.Address, message.From.Address);
                Assert.Equal("[Joe Shmoe] Please reset your password.", message.Subject);
                Assert.Contains("Click the following link within the next", message.Body);
                Assert.Contains("http://example.com/pwd-reset-token-url", message.Body);
            }
Exemplo n.º 17
0
            public void WillSendEmailToAllOwners(string version)
            {
                // Arrange
                var nugetVersion        = new NuGetVersion(version);
                var packageRegistration = new PackageRegistration
                {
                    Id     = "smangit",
                    Owners = new[]
                    {
                        new User {
                            EmailAddress = "*****@*****.**", NotifyPackagePushed = true
                        },
                        new User {
                            EmailAddress = "*****@*****.**", NotifyPackagePushed = true
                        }
                    }
                };
                var package = new Package
                {
                    Version             = version,
                    PackageRegistration = packageRegistration
                };

                packageRegistration.Packages.Add(package);

                // Act
                var messageService = TestableMessageService.Create(
                    GetService <AuthenticationService>(),
                    GetConfigurationService());
                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("*****@*****.**", message.To[0].Address);
                Assert.Equal("*****@*****.**", message.To[1].Address);
                Assert.Equal(TestGalleryNoReplyAddress, message.From);
                Assert.Contains($"[Joe Shmoe] Package published - {packageRegistration.Id} {nugetVersion.ToNormalizedString()}", message.Subject);
                Assert.Contains(
                    $"The package [{packageRegistration.Id} {nugetVersion.ToFullString()}]({packageUrl}) was just published on Joe Shmoe. If this was not intended, please [contact support]({supportUrl}).", message.Body);
            }
Exemplo n.º 18
0
            public void DoesNotSendRemovedNoticeIfUserDoesNotAllowEmails()
            {
                var to = new User {
                    Username = "******", EmailAddress = "*****@*****.**", EmailAllowed = false
                };
                var from = new User {
                    Username = "******", EmailAddress = "*****@*****.**"
                };
                var package = new PackageRegistration {
                    Id = "CoolStuff"
                };

                var messageService = new TestableMessageService();

                messageService.SendPackageOwnerRemovedNotice(from, to, package);

                Assert.Empty(messageService.MockMailSender.Sent);
            }
Exemplo n.º 19
0
            public void WillSendEmailToGalleryOwner()
            {
                // Arrange
                var from    = new MailAddress("*****@*****.**", "too");
                var package = new Package
                {
                    PackageRegistration = new PackageRegistration {
                        Id = "smangit"
                    },
                    Version = "1.42.0.1"
                };

                var messageService = TestableMessageService.Create(
                    GetService <AuthenticationService>(),
                    GetConfigurationService());

                // Act
                messageService.ReportAbuse(
                    new ReportPackageRequest
                {
                    AlreadyContactedOwners = true,
                    FromAddress            = from,
                    Message        = "Abuse!",
                    Package        = package,
                    Reason         = "Reason!",
                    RequestingUser = null,
                    Signature      = "Joe Schmoe",
                    Url            = TestUtility.MockUrlHelper(),
                });
                var message = messageService.MockMailSender.Sent.Last();

                // Assert
                Assert.Equal(TestGalleryOwner, message.To.Single());
                Assert.Equal(TestGalleryOwner, message.From);
                Assert.Equal(from, message.ReplyToList.Single());
                Assert.Equal("[Joe Shmoe] Support Request for 'smangit' version 1.42.0.1 (Reason: Reason!)", message.Subject);
                Assert.Contains("Reason!", message.Body);
                Assert.Contains("Abuse!", message.Body);
                Assert.Contains("too ([email protected])", message.Body);
                Assert.Contains("smangit", message.Body);
                Assert.Contains("1.42.0.1", message.Body);
                Assert.Contains("Yes", message.Body);
            }
Exemplo n.º 20
0
            public void SendsPackageOwnerRequestConfirmationUrlWithoutUserMessage()
            {
                var to = new User {
                    Username = "******", EmailAddress = "*****@*****.**", EmailAllowed = true
                };
                var from = new User {
                    Username = "******", EmailAddress = "*****@*****.**"
                };
                var package = new PackageRegistration {
                    Id = "CoolStuff"
                };
                const string confirmationUrl = "http://example.com/confirmation-token-url";
                var          messageService  = new TestableMessageService();

                messageService.SendPackageOwnerRequest(from, to, package, confirmationUrl, string.Empty);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.DoesNotContain("The user 'Existing' added the following message for you", message.Body);
            }
Exemplo n.º 21
0
            public void DoesNotSendRequestIfUserDoesNotAllowEmails()
            {
                var to = new User {
                    Username = "******", EmailAddress = "*****@*****.**", EmailAllowed = false
                };
                var from = new User {
                    Username = "******", EmailAddress = "*****@*****.**"
                };
                var package = new PackageRegistration {
                    Id = "CoolStuff"
                };
                const string confirmationUrl = "http://example.com/confirmation-token-url";

                var messageService = new TestableMessageService();

                messageService.SendPackageOwnerRequest(from, to, package, confirmationUrl);

                Assert.Empty(messageService.MockMailSender.Sent);
            }
Exemplo n.º 22
0
            public void UsesTypeCaptionToDescribeCredentialIfNoProviderNounPresent()
            {
                var user = new User {
                    EmailAddress = "*****@*****.**", Username = "******"
                };
                var cred = new CredentialBuilder().CreatePasswordCredential("bogus");

                var messageService = TestableMessageService.Create(
                    GetService <AuthenticationService>(),
                    GetConfigurationService());

                messageService.SendCredentialAddedNotice(user, cred);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal(user.ToMailAddress(), message.To[0]);
                Assert.Equal(TestGalleryOwner, message.From);
                Assert.Equal(string.Format(Strings.Emails_CredentialAdded_Subject, TestGalleryOwner.DisplayName, Strings.CredentialType_Password), message.Subject);
                Assert.Contains(string.Format(Strings.Emails_CredentialAdded_Body, Strings.CredentialType_Password), message.Body);
            }
Exemplo n.º 23
0
            public void WillCopySenderIfAsked()
            {
                var from    = new MailAddress("*****@*****.**", "too");
                var package = new Package
                {
                    PackageRegistration = new PackageRegistration {
                        Id = "smangit"
                    },
                    Version = "1.42.0.1",
                };

                var messageService = TestableMessageService.Create(
                    GetService <AuthenticationService>(),
                    GetConfigurationService());

                var reportPackageRequest = new ReportPackageRequest
                {
                    AlreadyContactedOwners = true,
                    FromAddress            = from,
                    Message        = "Abuse!",
                    Package        = package,
                    Reason         = "Reason!",
                    RequestingUser = new User
                    {
                        Username     = "******",
                        EmailAddress = "*****@*****.**"
                    },
                    Signature  = "Joe Schmoe",
                    Url        = TestUtility.MockUrlHelper(),
                    CopySender = true,
                };

                messageService.ReportAbuse(reportPackageRequest);

                var message = messageService.MockMailSender.Sent.Single();

                Assert.Equal(TestGalleryOwner, message.To.Single());
                Assert.Equal(TestGalleryOwner, message.From);
                Assert.Equal(reportPackageRequest.FromAddress, message.ReplyToList.Single());
                Assert.Equal(reportPackageRequest.FromAddress, message.CC.Single());
                Assert.DoesNotContain("Owners", message.Body);
            }
Exemplo n.º 24
0
            public void UsesProviderNounToDescribeCredentialIfPresent()
            {
                var user = new User {
                    EmailAddress = "*****@*****.**", Username = "******"
                };
                var          cred = new CredentialBuilder().CreateExternalCredential("MicrosoftAccount", "abc123", "Test User");
                const string MicrosoftAccountCredentialName = "Microsoft account";

                var messageService = TestableMessageService.Create(
                    GetService <AuthenticationService>(),
                    GetConfigurationService());

                messageService.SendCredentialAddedNotice(user, cred);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal(user.ToMailAddress(), message.To[0]);
                Assert.Equal(TestGalleryOwner, message.From);
                Assert.Equal(string.Format(Strings.Emails_CredentialAdded_Subject, TestGalleryOwner.DisplayName, MicrosoftAccountCredentialName), message.Subject);
                Assert.Contains(string.Format(Strings.Emails_CredentialAdded_Body, MicrosoftAccountCredentialName), message.Body);
            }
Exemplo n.º 25
0
            public void WillSendEmailToGalleryOwner()
            {
                var from = new MailAddress("*****@*****.**", "too");
                var owner = new User
                {
                    Username = "******",
                    EmailAddress = "*****@*****.**",
                };
                var package = new Package
                {
                    PackageRegistration = new PackageRegistration
                    {
                        Id = "smangit", 
                        Owners = new Collection<User> { owner }
                    },
                    Version = "1.42.0.1"
                };
                var messageService = new TestableMessageService();

                messageService.ReportMyPackage(
                    new ReportPackageRequest
                    {
                        FromAddress = from,
                        Message = "Abuse!",
                        Package = package,
                        Reason = "Reason!",
                        RequestingUser = owner,
                        Url = TestUtility.MockUrlHelper(),
                    });
                var message = messageService.MockMailSender.LastSent;

                Assert.Equal(TestGalleryOwner.Address, message.To[0].Address);
                Assert.Equal(TestGalleryOwner.Address, message.From.Address);
                Assert.Equal("*****@*****.**", message.ReplyToList.Single().Address);
                Assert.Equal("[Joe Shmoe] Owner Support Request for 'smangit' version 1.42.0.1 (Reason: Reason!)", message.Subject);
                Assert.Contains("Reason!", message.Body);
                Assert.Contains("Abuse!", message.Body);
                Assert.Contains("too ([email protected])", message.Body);
                Assert.Contains("smangit", message.Body);
                Assert.Contains("1.42.0.1", message.Body);
            }
Exemplo n.º 26
0
            public void ApiKeyRemovedMessageIsCorrect()
            {
                var user = new User {
                    EmailAddress = "*****@*****.**", Username = "******"
                };
                var cred = new CredentialBuilder().CreateApiKey(TimeSpan.FromDays(1));

                cred.Description = "new api key";

                var messageService = TestableMessageService.Create(
                    GetService <AuthenticationService>(),
                    GetConfigurationService());

                messageService.SendCredentialRemovedNotice(user, cred);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal(user.ToMailAddress(), message.To[0]);
                Assert.Equal(TestGalleryOwner, message.From);
                Assert.Equal(string.Format(Strings.Emails_CredentialRemoved_Subject, TestGalleryOwner.DisplayName, Strings.CredentialType_ApiKey), message.Subject);
                Assert.Contains(string.Format(Strings.Emails_ApiKeyRemoved_Body, cred.Description), message.Body);
            }
Exemplo n.º 27
0
            public void DoesNotSendPackageOwnerAddedNoticeIfUserDoesNotAllowEmails()
            {
                // Arrange
                var toUser = new User {
                    Username = "******", EmailAddress = "*****@*****.**"
                };
                var newUser = new User {
                    Username = "******", EmailAddress = "*****@*****.**", EmailAllowed = false
                };
                var package = new PackageRegistration {
                    Id = "CoolStuff"
                };

                // Act
                var messageService = new TestableMessageService();

                messageService.SendPackageOwnerAddedNotice(toUser, newUser, package, "packageUrl", "policyMessage");

                // Assert
                Assert.Empty(messageService.MockMailSender.Sent);
            }
Exemplo n.º 28
0
            public void WillSendEmailToAllOwners()
            {
                // Arrange
                var packageRegistration = new PackageRegistration
                {
                    Id     = "smangit",
                    Owners = new[]
                    {
                        new User {
                            EmailAddress = "*****@*****.**", NotifyPackagePushed = true
                        },
                        new User {
                            EmailAddress = "*****@*****.**", NotifyPackagePushed = true
                        }
                    }
                };
                var package = new Package
                {
                    Version             = "1.2.3",
                    PackageRegistration = packageRegistration
                };

                packageRegistration.Packages.Add(package);

                // Act
                var messageService = new TestableMessageService();

                messageService.SendPackageAddedNotice(package, "http://dummy1", "http://dummy2", "http://dummy3");

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

                Assert.Equal("*****@*****.**", message.To[0].Address);
                Assert.Equal("*****@*****.**", message.To[1].Address);
                Assert.Equal(TestGalleryNoReplyAddress, message.From);
                Assert.Contains("[Joe Shmoe] Package published - smangit 1.2.3", 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);
            }
            public void WillSendEmailToGalleryOwner()
            {
                // Arrange
                var from = new MailAddress("*****@*****.**", "too");
                var package = new Package
                    {
                        PackageRegistration = new PackageRegistration { Id = "smangit" },
                        Version = "1.42.0.1"
                    };

                var messageService = new TestableMessageService();

                // Act
                messageService.ReportAbuse(
                    new ReportPackageRequest
                    {
                        AlreadyContactedOwners = true,
                        FromAddress = from,
                        Message = "Abuse!",
                        Package = package,
                        Reason = "Reason!",
                        RequestingUser = null,
                        Signature = "Joe Schmoe",
                        Url = TestUtility.MockUrlHelper(),
                    });
                var message = messageService.MockMailSender.Sent.Last();

                // Assert
                Assert.Equal(TestGalleryOwner, message.To.Single());
                Assert.Equal(TestGalleryOwner, message.From);
                Assert.Equal(from, message.ReplyToList.Single());
                Assert.Equal("[Joe Shmoe] Support Request for 'smangit' version 1.42.0.1 (Reason: Reason!)", message.Subject);
                Assert.Contains("Reason!", message.Body);
                Assert.Contains("Abuse!", message.Body);
                Assert.Contains("too ([email protected])", message.Body);
                Assert.Contains("smangit", message.Body);
                Assert.Contains("1.42.0.1", message.Body);
                Assert.Contains("Yes", message.Body);
            }
Exemplo n.º 30
0
            public void UsesTypeCaptionToDescribeCredentialIfNoProviderNounPresent()
            {
                var user = new User {
                    EmailAddress = "*****@*****.**", Username = "******"
                };
                var cred           = new CredentialBuilder().CreatePasswordCredential("bogus");
                var messageService = new TestableMessageService();

                messageService.MockAuthService
                .Setup(a => a.DescribeCredential(cred))
                .Returns(new CredentialViewModel {
                    TypeCaption = "Password"
                });

                messageService.SendCredentialAddedNotice(user, cred);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal(user.ToMailAddress(), message.To[0]);
                Assert.Equal(TestGalleryOwner, message.From);
                Assert.Equal("[Joe Shmoe] Password added to your account", message.Subject);
                Assert.Contains("A Password was added to your account", message.Body);
            }
Exemplo n.º 31
0
            public void DoesNotSendRequestIfUserDoesNotAllowEmails()
            {
                var to = new User {
                    Username = "******", EmailAddress = "*****@*****.**", EmailAllowed = false
                };
                var from = new User {
                    Username = "******", EmailAddress = "*****@*****.**"
                };
                var package = new PackageRegistration {
                    Id = "CoolStuff"
                };
                const string packageUrl      = "http://nuget.local/packages/CoolStuff";
                const string confirmationUrl = "http://example.com/confirmation-token-url";

                var messageService = TestableMessageService.Create(
                    GetService <AuthenticationService>(),
                    GetConfigurationService());

                messageService.SendPackageOwnerRequest(from, to, package, packageUrl, confirmationUrl, string.Empty, string.Empty);

                Assert.Empty(messageService.MockMailSender.Sent);
            }
Exemplo n.º 32
0
            public void UsesProviderNounToDescribeCredentialIfPresent()
            {
                var user = new User {
                    EmailAddress = "*****@*****.**", Username = "******"
                };
                var cred           = new CredentialBuilder().CreateExternalCredential("MicrosoftAccount", "abc123", "Test User");
                var messageService = new TestableMessageService();

                messageService.MockAuthService
                .Setup(a => a.DescribeCredential(cred))
                .Returns(new CredentialViewModel {
                    AuthUI = new AuthenticatorUI("sign in", "Microsoft Account", "Microsoft Account")
                });

                messageService.SendCredentialAddedNotice(user, cred);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal(user.ToMailAddress(), message.To[0]);
                Assert.Equal(TestGalleryOwner, message.From);
                Assert.Equal("[Joe Shmoe] Microsoft Account added to your account", message.Subject);
                Assert.Contains("A Microsoft Account was added to your account", message.Body);
            }
Exemplo n.º 33
0
            public void WillNotAttemptToSendIfNoOwnersAllow()
            {
                var from    = new MailAddress("*****@*****.**", "flossy");
                var package = new PackageRegistration
                {
                    Id     = "smangit",
                    Owners = new[]
                    {
                        new User {
                            EmailAddress = "*****@*****.**", EmailAllowed = false
                        },
                        new User {
                            EmailAddress = "*****@*****.**", EmailAllowed = false
                        }
                    }
                };

                var messageService = new TestableMessageService();

                messageService.SendContactOwnersMessage(from, package, "Test message", "http://someurl/", false);

                Assert.Empty(messageService.MockMailSender.Sent);
            }
Exemplo n.º 34
0
            public void SendsPackageOwnerRequestConfirmationUrlWithoutUserMessage()
            {
                var to = new User { Username = "******", EmailAddress = "*****@*****.**", EmailAllowed = true };
                var from = new User { Username = "******", EmailAddress = "*****@*****.**" };
                var package = new PackageRegistration { Id = "CoolStuff" };
                const string confirmationUrl = "http://example.com/confirmation-token-url";
                var messageService = new TestableMessageService();
                messageService.SendPackageOwnerRequest(from, to, package, confirmationUrl, string.Empty);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.DoesNotContain("The user 'Existing' added the following message for you", message.Body);
            }
            public void WillCopySenderIfAsked()
            {
                var from = new MailAddress("*****@*****.**", "flossy");
                var package = new PackageRegistration { Id = "smangit" };
                package.Owners = new[]
                    {
                        new User { EmailAddress = "*****@*****.**", EmailAllowed = true },
                        new User { EmailAddress = "*****@*****.**", EmailAllowed = true }
                    };
                var messageService = new TestableMessageService();

                messageService.SendContactOwnersMessage(from, package, "Test message", "http://someurl/", true);

                var messages = messageService.MockMailSender.Sent;
                Assert.Equal(2, messages.Count);
                Assert.Equal(package.Owners.Count, messages[0].To.Count);
                Assert.Equal(1, messages[1].To.Count);
                Assert.Equal("*****@*****.**", messages[0].To[0].Address);
                Assert.Equal("*****@*****.**", messages[0].To[1].Address);
                Assert.Equal(messages[1].ReplyToList.Single(), messages[1].To.First());
                Assert.Equal(TestGalleryOwner, messages[0].From);
                Assert.Equal(TestGalleryOwner, messages[1].From);
                Assert.Equal("*****@*****.**", messages[0].ReplyToList.Single().Address);
                Assert.Equal("*****@*****.**", messages[1].ReplyToList.Single().Address);
            }
            public void WillSendEmailToAllOwners()
            {
                var from = new MailAddress("*****@*****.**", "flossy");
                var package = new PackageRegistration
                {
                    Id = "smangit",
                    Owners = new[]
                    {
                        new User { EmailAddress = "*****@*****.**", EmailAllowed = true },
                        new User { EmailAddress = "*****@*****.**", EmailAllowed = true }
                    }
                };

                var messageService = new TestableMessageService();
                messageService.SendContactOwnersMessage(from, package, "Test message", "http://someurl/", false);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal("*****@*****.**", message.To[0].Address);
                Assert.Equal("*****@*****.**", message.To[1].Address);
                Assert.Equal(TestGalleryOwner, message.From);
                Assert.Equal("*****@*****.**", message.ReplyToList.Single().Address);
                Assert.Contains("[Joe Shmoe] Message for owners of the package 'smangit'", message.Subject);
                Assert.Contains("Test message", message.Body);
                Assert.Contains(
                    "User flossy &lt;[email protected]&gt; sends the following message to the owners of Package 'smangit'.", message.Body);
            }
            public void WillNotAttemptToSendIfNoOwnersAllow()
            {
                // Arrange
                var packageRegistration = new PackageRegistration
                {
                    Id = "smangit",
                    Owners = new[]
                    {
                        new User { EmailAddress = "*****@*****.**", EmailAllowed = false },
                        new User { EmailAddress = "*****@*****.**", EmailAllowed = false }
                    }
                };
                var package = new Package
                {
                    Version = "1.2.3",
                    PackageRegistration = packageRegistration
                };
                packageRegistration.Packages.Add(package);

                // Act
                var messageService = new TestableMessageService();
                messageService.SendPackageAddedNotice(package, "http://dummy1", "http://dummy2", "http://dummy3");

                // Assert
                Assert.Empty(messageService.MockMailSender.Sent);
            }
            public void WillSendEmailToNewUser()
            {
                var to = new MailAddress("*****@*****.**", "too");

                var messageService = new TestableMessageService();
                messageService.SendNewAccountEmail(to, "http://example.com/confirmation-token-url");
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal("*****@*****.**", message.To[0].Address);
                Assert.Equal(TestGalleryOwner.Address, message.From.Address);
                Assert.Equal("[Joe Shmoe] Please verify your account.", message.Subject);
                Assert.Contains("http://example.com/confirmation-token-url", message.Body);
            }
            public void UsesTypeCaptionToDescribeCredentialIfNoProviderNounPresent()
            {
                var user = new User { EmailAddress = "*****@*****.**", Username = "******" };
                var cred = CredentialBuilder.CreatePbkdf2Password("bogus");
                var messageService = new TestableMessageService();
                messageService.MockAuthService
                    .Setup(a => a.DescribeCredential(cred))
                    .Returns(new CredentialViewModel() {
                        TypeCaption = "Password"
                    });

                messageService.SendCredentialAddedNotice(user, cred);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal(user.ToMailAddress(), message.To[0]);
                Assert.Equal(TestGalleryOwner, message.From);
                Assert.Equal("[Joe Shmoe] Password added to your account", message.Subject);
                Assert.Contains("A Password was added to your account", message.Body);
            }
            public void UsesProviderNounToDescribeCredentialIfPresent()
            {
                var user = new User { EmailAddress = "*****@*****.**", Username = "******" };
                var cred = CredentialBuilder.CreateExternalCredential("MicrosoftAccount", "abc123", "Test User");
                var messageService = new TestableMessageService();
                messageService.MockAuthService
                    .Setup(a => a.DescribeCredential(cred))
                    .Returns(new CredentialViewModel() {
                        AuthUI = new AuthenticatorUI("sign in", "Microsoft Account", "Microsoft Account")
                    });

                messageService.SendCredentialAddedNotice(user, cred);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal(user.ToMailAddress(), message.To[0]);
                Assert.Equal(TestGalleryOwner, message.From);
                Assert.Equal("[Joe Shmoe] Microsoft Account added to your account", message.Subject);
                Assert.Contains("A Microsoft Account was added to your account", message.Body);
            }
            public void WillSendInstructions()
            {
                var user = new User { EmailAddress = "*****@*****.**", Username = "******" };

                var messageService = new TestableMessageService();
                messageService.SendPasswordResetInstructions(user, "http://example.com/pwd-reset-token-url", true);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal("*****@*****.**", message.To[0].Address);
                Assert.Equal(TestGalleryOwner.Address, message.From.Address);
                Assert.Equal("[Joe Shmoe] Please reset your password.", message.Subject);
                Assert.Contains("Click the following link within the next", message.Body);
                Assert.Contains("http://example.com/pwd-reset-token-url", message.Body);
            }
            public void DoesNotSendRemovedNoticeIfUserDoesNotAllowEmails()
            {
                var to = new User { Username = "******", EmailAddress = "*****@*****.**", EmailAllowed = false };
                var from = new User { Username = "******", EmailAddress = "*****@*****.**" };
                var package = new PackageRegistration { Id = "CoolStuff" };

                var messageService = new TestableMessageService();
                messageService.SendPackageOwnerRemovedNotice(from, to, package);

                Assert.Empty(messageService.MockMailSender.Sent);
            }
            public void SendsPackageOwnerRemovedNotice()
            {
                var to = new User { Username = "******", EmailAddress = "*****@*****.**", EmailAllowed = true };
                var from = new User { Username = "******", EmailAddress = "*****@*****.**" };
                var package = new PackageRegistration { Id = "CoolStuff" };

                var messageService = new TestableMessageService();
                messageService.SendPackageOwnerRemovedNotice(from, to, package);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal("*****@*****.**", message.To[0].Address);
                Assert.Equal(TestGalleryOwner.Address, message.From.Address);
                Assert.Equal("*****@*****.**", message.ReplyToList.Single().Address);
                Assert.Contains("The user 'Existing' has removed you as an owner of the package 'CoolStuff'.", message.Subject);
                Assert.Contains("The user 'Existing' removed you as an owner of the package 'CoolStuff'", message.Body);
            }
            public void DoesNotSendRequestIfUserDoesNotAllowEmails()
            {
                var to = new User { Username = "******", EmailAddress = "*****@*****.**", EmailAllowed = false };
                var from = new User { Username = "******", EmailAddress = "*****@*****.**" };
                var package = new PackageRegistration { Id = "CoolStuff" };
                const string confirmationUrl = "http://example.com/confirmation-token-url";

                var messageService = new TestableMessageService();
                messageService.SendPackageOwnerRequest(from, to, package, confirmationUrl);

                Assert.Empty(messageService.MockMailSender.Sent);
            }
            public void SendsPackageOwnerRequestConfirmationUrl()
            {
                var to = new User { Username = "******", EmailAddress = "*****@*****.**", EmailAllowed = true };
                var from = new User { Username = "******", EmailAddress = "*****@*****.**" };
                var package = new PackageRegistration { Id = "CoolStuff" };
                const string confirmationUrl = "http://example.com/confirmation-token-url";

                var messageService = new TestableMessageService();
                messageService.SendPackageOwnerRequest(from, to, package, confirmationUrl);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal("*****@*****.**", message.To[0].Address);
                Assert.Equal(TestGalleryOwner.Address, message.From.Address);
                Assert.Equal("*****@*****.**", message.ReplyToList.Single().Address);
                Assert.Equal("[Joe Shmoe] The user 'Existing' wants to add you as an owner of the package 'CoolStuff'.", message.Subject);
                Assert.Contains(confirmationUrl, message.Body);
                Assert.Contains("The user 'Existing' wants to add you as an owner of the package 'CoolStuff'.", message.Body);
            }
            public void WillNotSendEmailToOwnerThatOptsOut()
            {
                var from = new MailAddress("*****@*****.**", "flossy");
                var package = new PackageRegistration
                {
                    Id = "smangit",
                    Owners = new[]
                    {
                        new User { EmailAddress = "*****@*****.**", EmailAllowed = true },
                        new User { EmailAddress = "*****@*****.**", EmailAllowed = false }
                    }
                };

                var messageService = new TestableMessageService();
                messageService.SendContactOwnersMessage(from, package, "Test message", "http://someurl/", false);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal("*****@*****.**", message.To[0].Address);
                Assert.Equal(1, message.To.Count);
            }
            public void WillNotSendEmailToOwnerThatOptsOut()
            {
                // Arrange
                var packageRegistration = new PackageRegistration
                {
                    Id = "smangit",
                    Owners = new[]
                    {
                        new User { EmailAddress = "*****@*****.**", NotifyPackagePushed = true },
                        new User { EmailAddress = "*****@*****.**", NotifyPackagePushed = false }
                    }
                };
                var package = new Package
                {
                    Version = "1.2.3",
                    PackageRegistration = packageRegistration
                };
                packageRegistration.Packages.Add(package);

                // Act
                var messageService = new TestableMessageService();
                messageService.SendPackageAddedNotice(package, "http://dummy1", "http://dummy2", "http://dummy3");

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

                Assert.Equal("*****@*****.**", message.To[0].Address);
                Assert.Equal(1, message.To.Count);
            }
            public void WillSendEmailToAllOwners()
            {
                // Arrange
                var packageRegistration = new PackageRegistration
                {
                    Id = "smangit",
                    Owners = new[]
                    {
                        new User { EmailAddress = "*****@*****.**", NotifyPackagePushed = true },
                        new User { EmailAddress = "*****@*****.**", NotifyPackagePushed = true }
                    }
                };
                var package = new Package
                {
                    Version = "1.2.3",
                    PackageRegistration = packageRegistration
                };
                packageRegistration.Packages.Add(package);

                // Act
                var messageService = new TestableMessageService();
                messageService.SendPackageAddedNotice(package, "http://dummy1", "http://dummy2", "http://dummy3");

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

                Assert.Equal("*****@*****.**", message.To[0].Address);
                Assert.Equal("*****@*****.**", message.To[1].Address);
                Assert.Equal(TestGalleryOwner, message.From);
                Assert.Contains("[Joe Shmoe] Package published - smangit 1.2.3", 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);
            }
            public void WillNotCopySenderIfNoOwnersAllow()
            {
                var from = new MailAddress("*****@*****.**", "flossy");
                var package = new PackageRegistration { Id = "smangit" };
                package.Owners = new[]
                    {
                        new User { EmailAddress = "*****@*****.**", EmailAllowed = false },
                        new User { EmailAddress = "*****@*****.**", EmailAllowed = false }
                    };

                var messageService = new TestableMessageService();
                messageService.SendContactOwnersMessage(from, package, "Test message", "http://someurl/", false);

                Assert.Empty(messageService.MockMailSender.Sent);
            }