public void WhenPackageHasOneOwnerAndItIsTheCurrentUser_WhenRequiredSignerIsNull() { var package = new Package() { PackageRegistration = new PackageRegistration() { Owners = new List <User>() { _currentUser } }, Version = "1.0.0" }; _securityPolicyService.Setup(x => x.IsSubscribed( It.Is <User>(user => user == _currentUser), It.Is <string>(policyName => policyName == ControlRequiredSignerPolicy.PolicyName))) .Returns(false); var target = new ListPackageItemRequiredSignerViewModelFactory(_securityPolicyService.Object, Mock.Of <IIconUrlProvider>()); var viewModel = target.Create( package, _currentUser, wasAADLoginOrMultiFactorAuthenticated: true); Assert.Equal(_currentUser.Username, viewModel.RequiredSigner.Username); Assert.Equal($"{_currentUser.Username} (0 certificates)", viewModel.RequiredSigner.DisplayText); Assert.Null(viewModel.RequiredSignerMessage); Assert.Empty(viewModel.AllSigners); Assert.True(viewModel.ShowRequiredSigner); Assert.True(viewModel.ShowTextBox); Assert.False(viewModel.CanEditRequiredSigner); _securityPolicyService.VerifyAll(); }
public void WhenPackageHasThreeOwnersAndTheCurrentUserIsAnOwner_WhenTwoOtherOwnersHaveRequiredSignerControl() { var otherUser2 = new User() { Key = 3, Username = "******" }; var package = new Package() { PackageRegistration = new PackageRegistration() { Owners = new List <User>() { _currentUser, _otherUser, otherUser2 }, RequiredSigners = new HashSet <User>() { _currentUser } }, Version = "1.0.0" }; var target = new ListPackageItemRequiredSignerViewModelFactory( _securityPolicyService.Object, Mock.Of <IIconUrlProvider>(), Mock.Of <IPackageVulnerabilitiesService>()); _securityPolicyService.Setup( x => x.IsSubscribed( It.Is <User>(u => u == _currentUser), It.Is <string>(s => s == ControlRequiredSignerPolicy.PolicyName))) .Returns(false); _securityPolicyService.Setup( x => x.IsSubscribed( It.Is <User>(u => u == _otherUser), It.Is <string>(s => s == ControlRequiredSignerPolicy.PolicyName))) .Returns(true); _securityPolicyService.Setup( x => x.IsSubscribed( It.Is <User>(u => u == otherUser2), It.Is <string>(s => s == ControlRequiredSignerPolicy.PolicyName))) .Returns(true); var viewModel = target.Create( package, _currentUser, wasAADLoginOrMultiFactorAuthenticated: true); Assert.Equal(_currentUser.Username, viewModel.RequiredSigner.Username); Assert.Equal($"{_currentUser.Username} (0 certificates)", viewModel.RequiredSigner.DisplayText); Assert.Equal($"The signing owner is managed by the '{_otherUser.Username}' and '{otherUser2.Username}' accounts.", viewModel.RequiredSignerMessage); VerifySigners(new[] { _currentUser }, viewModel.AllSigners, expectAnySigner: false); Assert.True(viewModel.ShowRequiredSigner); Assert.False(viewModel.ShowTextBox); Assert.False(viewModel.CanEditRequiredSigner); _securityPolicyService.VerifyAll(); }
public void WhenPackageIsNull_Throws() { var target = new ListPackageItemRequiredSignerViewModelFactory(_securityPolicyService.Object, Mock.Of <IIconUrlProvider>()); var exception = Assert.Throws <ArgumentNullException>(() => target.Create( package: null, currentUser: _currentUser, wasAADLoginOrMultiFactorAuthenticated: true)); Assert.Equal("package", exception.ParamName); }
public void WhenPackageHasOneOwnerAndTheCurrentUserIsACollaborator_WhenRequiredSignerIsNull() { var organization = new Organization() { Key = 7, Username = "******" }; organization.Members.Add(new Membership() { OrganizationKey = organization.Key, Organization = organization, MemberKey = _currentUser.Key, Member = _currentUser, IsAdmin = false }); var package = new Package() { PackageRegistration = new PackageRegistration() { Owners = new List <User>() { organization } }, Version = "1.0.0" }; var target = new ListPackageItemRequiredSignerViewModelFactory( _securityPolicyService.Object, Mock.Of <IIconUrlProvider>(), Mock.Of <IPackageVulnerabilitiesService>()); _securityPolicyService.Setup( x => x.IsSubscribed( It.IsNotNull <User>(), It.Is <string>(s => s == ControlRequiredSignerPolicy.PolicyName))) .Returns(false); var viewModel = target.Create( package, _currentUser, wasAADLoginOrMultiFactorAuthenticated: true); Assert.Equal("c", viewModel.RequiredSigner.Username); Assert.Equal($"{organization.Username} (0 certificates)", viewModel.RequiredSigner.DisplayText); Assert.Null(viewModel.RequiredSignerMessage); VerifySigners(package.PackageRegistration.Owners, viewModel.AllSigners, expectAnySigner: false); Assert.True(viewModel.ShowRequiredSigner); Assert.True(viewModel.ShowTextBox); Assert.False(viewModel.CanEditRequiredSigner); _securityPolicyService.VerifyAll(); }
public void WhenCurrentUserIsNull_Throws() { var package = new Package() { PackageRegistration = new PackageRegistration(), Version = "1.0.0" }; var target = new ListPackageItemRequiredSignerViewModelFactory( _securityPolicyService.Object, Mock.Of <IIconUrlProvider>(), Mock.Of <IPackageVulnerabilitiesService>()); var exception = Assert.Throws <ArgumentNullException>( () => target.Create( package, currentUser: null, wasAADLoginOrMultiFactorAuthenticated: true)); Assert.Equal("currentUser", exception.ParamName); }
public void WhenPackageHasTwoOwnersAndTheCurrentUserIsAnOwner_WhenRequiredSignerIsAnotherUser() { var package = new Package() { PackageRegistration = new PackageRegistration() { Owners = new List <User>() { _currentUser, _otherUser }, RequiredSigners = new HashSet <User>() { _otherUser } }, Version = "1.0.0" }; var target = new ListPackageItemRequiredSignerViewModelFactory( _securityPolicyService.Object, Mock.Of <IIconUrlProvider>(), Mock.Of <IPackageVulnerabilitiesService>()); _securityPolicyService.Setup( x => x.IsSubscribed( It.IsNotNull <User>(), It.Is <string>(s => s == ControlRequiredSignerPolicy.PolicyName))) .Returns(false); var viewModel = target.Create( package, _currentUser, wasAADLoginOrMultiFactorAuthenticated: true); Assert.Equal(_otherUser.Username, viewModel.RequiredSigner.Username); Assert.Equal($"{_otherUser.Username} (0 certificates)", viewModel.RequiredSigner.DisplayText); Assert.Null(viewModel.RequiredSignerMessage); VerifySigners(package.PackageRegistration.Owners, viewModel.AllSigners, expectAnySigner: true); Assert.True(viewModel.ShowRequiredSigner); Assert.False(viewModel.ShowTextBox); Assert.True(viewModel.CanEditRequiredSigner); _securityPolicyService.VerifyAll(); }
public void WhenPackageHasMultipleOwners_WhenOwnersHaveVaryingCertificateCounts() { User currentUser = new User() { Key = 1, Username = "******", UserCertificates = new List <UserCertificate>() { new UserCertificate() { Key = 1 } } }; User otherUser1 = new User() { Key = 2, Username = "******" }; User otherUser2 = new User() { Key = 3, Username = "******", UserCertificates = new List <UserCertificate>() { new UserCertificate() { Key = 2 }, new UserCertificate() { Key = 3 } } }; var package = new Package() { PackageRegistration = new PackageRegistration() { Owners = new List <User>() { otherUser1, currentUser, otherUser2 }, RequiredSigners = new HashSet <User>() { currentUser } }, Version = "1.0.0" }; var target = new ListPackageItemRequiredSignerViewModelFactory( _securityPolicyService.Object, Mock.Of <IIconUrlProvider>(), Mock.Of <IPackageVulnerabilitiesService>()); _securityPolicyService.Setup( x => x.IsSubscribed( It.IsNotNull <User>(), It.Is <string>(s => s == ControlRequiredSignerPolicy.PolicyName))) .Returns(false); var viewModel = target.Create( package, currentUser, wasAADLoginOrMultiFactorAuthenticated: true); Assert.Equal(currentUser.Username, viewModel.RequiredSigner.Username); Assert.Equal($"{currentUser.Username} (1 certificate)", viewModel.RequiredSigner.DisplayText); Assert.Null(viewModel.RequiredSignerMessage); VerifySigners(package.PackageRegistration.Owners, viewModel.AllSigners, expectAnySigner: true); Assert.True(viewModel.ShowRequiredSigner); Assert.False(viewModel.ShowTextBox); Assert.True(viewModel.CanEditRequiredSigner); _securityPolicyService.Verify(); }