Esempio n. 1
0
 private static List <UserSecurityPolicy> InitializePoliciesList()
 {
     return(new List <UserSecurityPolicy>()
     {
         RequirePackageMetadataCompliancePolicy.CreatePolicy(
             Name,
             MicrosoftUsername,
             allowedCopyrightNotices: AllowedCopyrightNotices,
             isLicenseUrlRequired: true,
             isProjectUrlRequired: true,
             errorMessageFormat: Strings.SecurityPolicy_RequireMicrosoftPackageMetadataComplianceForPush)
     });
 }
Esempio n. 2
0
        public async Task Evaluate_CompliantPackageAuthors_CreatesSuccessResult()
        {
            // Arrange
            var nugetUser = new User("NuGet");
            var newPackageRegistration = new PackageRegistration {
                Id = "NewPackageId", Owners = new List <User> {
                    nugetUser
                }
            };
            var packageAuthors   = new[] { MicrosoftTeamSubscription.MicrosoftUsername, "The Most-Awesome Package Authors" };
            var compliantPackage = Fakes.CreateCompliantPackage("1.0.0", newPackageRegistration, packageAuthors);

            var policy = RequirePackageMetadataCompliancePolicy.CreatePolicy(
                MicrosoftTeamSubscription.Name,
                MicrosoftTeamSubscription.MicrosoftUsername,
                allowedCopyrightNotices: MicrosoftTeamSubscription.AllowedCopyrightNotices,
                allowedAuthors: packageAuthors,
                isLicenseUrlRequired: true,
                isProjectUrlRequired: true,
                errorMessageFormat: Strings.SecurityPolicy_RequireMicrosoftPackageMetadataComplianceForPush);

            var policyHandler = new RequirePackageMetadataCompliancePolicy();

            var packageOwnershipManagementService = new Mock <IPackageOwnershipManagementService>();

            packageOwnershipManagementService.Setup(m => m.AddPackageOwnerAsync(newPackageRegistration, It.IsAny <User>(), false)).Returns(Task.CompletedTask);

            var context = CreateTestContext(
                true,
                new[] { policy },
                compliantPackage,
                packageRegistrationAlreadyExists: false,
                sourceAccount: nugetUser,
                targetAccount: nugetUser,
                packageOwnershipManagementService: packageOwnershipManagementService.Object);

            // Act
            var result = await policyHandler.EvaluateAsync(context);

            // Assert
            Assert.True(result.Success);
            packageOwnershipManagementService.Verify(s => s.AddPackageOwnerAsync(newPackageRegistration, Fakes.RequiredCoOwner, false), Times.Once);
        }
Esempio n. 3
0
        public async Task Evaluate_DuplicatePackageAuthor_CreatesErrorResult()
        {
            // Arrange
            var nugetUser = new User("NuGet");
            var newPackageRegistration = new PackageRegistration {
                Id = "NewPackageId", Owners = new List <User> {
                    nugetUser
                }
            };
            var packageAuthors      = new[] { MicrosoftTeamSubscription.MicrosoftUsername, MicrosoftTeamSubscription.MicrosoftUsername };
            var nonCompliantPackage = Fakes.CreateCompliantPackage("1.0.0", newPackageRegistration, packageAuthors);

            var policy = RequirePackageMetadataCompliancePolicy.CreatePolicy(
                MicrosoftTeamSubscription.Name,
                MicrosoftTeamSubscription.MicrosoftUsername,
                allowedCopyrightNotices: MicrosoftTeamSubscription.AllowedCopyrightNotices,
                allowedAuthors: new[] { MicrosoftTeamSubscription.MicrosoftUsername },
                isLicenseUrlRequired: true,
                isProjectUrlRequired: true,
                errorMessageFormat: Strings.SecurityPolicy_RequireMicrosoftPackageMetadataComplianceForPush);

            var policyHandler = new RequirePackageMetadataCompliancePolicy();

            var context = CreateTestContext(
                true,
                new[] { policy },
                nonCompliantPackage,
                packageRegistrationAlreadyExists: false,
                sourceAccount: nugetUser,
                targetAccount: nugetUser);

            // Act
            var result = await policyHandler.EvaluateAsync(context);

            // Assert
            Assert.False(result.Success);
            Assert.Null(newPackageRegistration.Owners.SingleOrDefault(u => u.Username == MicrosoftTeamSubscription.MicrosoftUsername));
            Assert.False(newPackageRegistration.IsVerified);
        }