Example #1
0
        public void ValidateEdit_WhenPartyIdAndAccessSubjectEmpty_ReturnsNotValid()
        {
            //Arrange
            var policyJson = @"
            {
                ""delegationEvidence"":
                {
                    ""notBefore"": 1509633681,
                    ""notOnOrAfter"": 1509633741,
                    ""policyIssuer"": """",
                    ""target"":
                    {
                        ""accessSubject"": """"
                    }
                }
            }";
            var arId       = "AR.1234567890";
            var claims     = new List <Claim>
            {
                new Claim(ClaimTypes.Role, Constants.Roles.SchemeOwner)
            };
            var identity        = new ClaimsIdentity(claims, "TestAuthType");
            var claimsPrincipal = new ClaimsPrincipal(identity);

            var delegationServiceMock = new Mock <IDelegationService>();
            var sut = new DelegationValidationService(delegationServiceMock.Object);

            //Act
            var result = sut.ValidateEdit(arId, policyJson, claimsPrincipal).Result;

            //Assert
            result.Error.ShouldBe("Policy issuer and access subject are required.");
        }
Example #2
0
        public void ValidateCopy_ForPolicyIssuerAndAccessSubjectNotEmptyOnMatchinEPRole_ReturnsValid()
        {
            //Arrange
            var policyJson = @"
            {
                ""delegationEvidence"":
                {
                    ""notBefore"": 1509633681,
                    ""notOnOrAfter"": 1509633741,
                    ""policyIssuer"": ""EU.EORI.NL812972715"",
                    ""target"":
                    {
                        ""accessSubject"": ""EU.EORI.NL000000001""
                    }
                }
            }";
            var claims     = new List <Claim>
            {
                new Claim(ClaimTypes.Role, Constants.Roles.EntitledPartyCreator),
                new Claim("partyId", "EU.EORI.NL812972715")
            };
            var identity        = new ClaimsIdentity(claims, "TestAuthType");
            var claimsPrincipal = new ClaimsPrincipal(identity);

            var delegationServiceMock = new Mock <IDelegationService>();
            var sut = new DelegationValidationService(delegationServiceMock.Object);

            //Act
            var result = sut.ValidateCopy(policyJson, claimsPrincipal);

            //Assert
            result.Success.ShouldBe(true);
        }
Example #3
0
        public void ValidateCreate_ForNotMatchingPartyIdWithEPRole_ReturnsNotValid()
        {
            //Arrange
            var policyJson = @"
            {
                ""delegationEvidence"":
                {
                    ""notBefore"": 1509633681,
                    ""notOnOrAfter"": 1509633741,
                    ""policyIssuer"": ""EU.EORI.NL812972713"",
                    ""target"":
                    {
                        ""accessSubject"": ""EU.EORI.NL000000001""
                    }
                }
            }";
            var claims     = new List <Claim>
            {
                new Claim(ClaimTypes.Role, Constants.Roles.EntitledPartyCreator),
                new Claim("partyId", "EU.EORI.NL812972715")
            };
            var identity        = new ClaimsIdentity(claims, "TestAuthType");
            var claimsPrincipal = new ClaimsPrincipal(identity);

            var delegationServiceMock = new Mock <IDelegationService>();
            var sut = new DelegationValidationService(delegationServiceMock.Object);

            //Act
            var result = sut.ValidateCreate(policyJson, claimsPrincipal).Result;

            //Assert
            result.Error.ShouldBe("Policy issuer must be equal to your party id.");
        }
Example #4
0
        public async Task ValidateEdit_WhenPolicyIssuerAndAccessSubjectEmpty_ReturnsNotValid()
        {
            //Arrange
            var policyJson = @"
            {
                ""delegationEvidence"":
                {
                    ""notBefore"": 1509633681,
                    ""notOnOrAfter"": 1509633741,
                    ""policyIssuer"": """",
                    ""target"":
                    {
                        ""accessSubject"": """"
                    }
                }
            }";
            var arId       = "AR.1234567890";
            var claims     = new List <Claim>
            {
                new Claim("partyId", "EU.EORI.NL812972715")
            };
            var identity        = new ClaimsIdentity(claims, "TestAuthType");
            var claimsPrincipal = new ClaimsPrincipal(identity);

            var delegationServiceMock = new Mock <IDelegationService>();
            var sut = new DelegationValidationService(delegationServiceMock.Object);

            //Act
            var result = await sut.ValidateEdit(arId, policyJson, claimsPrincipal);

            //Assert
            result.Error.ShouldBe("Policy issuer and access subject are required.");
        }
Example #5
0
        public void ValidateEdit_WhenCombinationPolicyIssuerAccessSubjectIsModified_ReturnsNotValid()
        {
            //Arrange
            var policyJson = @"
            {
                ""delegationEvidence"":
                {
                    ""notBefore"": 1509633681,
                    ""notOnOrAfter"": 1509633741,
                    ""policyIssuer"": ""EU.EORI.NL812972711"",
                    ""target"":
                    {
                        ""accessSubject"": ""EU.EORI.NL000000002""
                    }
                }
            }";
            var arId       = "AR.1234567890";
            var claims     = new List <Claim>
            {
                new Claim(ClaimTypes.Role, Constants.Roles.SchemeOwner)
            };
            var identity        = new ClaimsIdentity(claims, "TestAuthType");
            var claimsPrincipal = new ClaimsPrincipal(identity);

            var delegationServiceMock = new Mock <IDelegationService>();

            delegationServiceMock
            .Setup(c => c.GetByARId(arId, claimsPrincipal.GetPartyId()))
            .ReturnsAsync(new Delegation
            {
                PolicyIssuer  = "EU.EORI.NL812972715",
                AccessSubject = "EU.EORI.NL000000001",
            });

            var sut = new DelegationValidationService(delegationServiceMock.Object);

            //Act
            var result = sut.ValidateEdit(arId, policyJson, claimsPrincipal).Result;

            //Assert
            result.Error.ShouldBe("The combination policyIssuer - accessSubject must remain unmodified.");
        }
Example #6
0
        public void ValidateEdit_ForPolicyIssuerAndAccessSubjectNotModified_ReturnsValid()
        {
            //Arrange
            var policyJson      = @"
            {
                ""delegationEvidence"":
                {
                    ""notBefore"": 1509633681,
                    ""notOnOrAfter"": 1509633741,
                    ""policyIssuer"": ""EU.EORI.NL812972715"",
                    ""target"":
                    {
                        ""accessSubject"": ""EU.EORI.NL000000001""
                    }
                }
            }";
            var arId            = "AR.1234567890";
            var identity        = new ClaimsIdentity(new List <Claim>(), "TestAuthType");
            var claimsPrincipal = new ClaimsPrincipal(identity);

            var delegationServiceMock = new Mock <IDelegationService>();

            delegationServiceMock
            .Setup(c => c.GetByARId(arId, claimsPrincipal.GetPartyId()))
            .ReturnsAsync(new Delegation
            {
                PolicyIssuer  = "EU.EORI.NL812972715",
                AccessSubject = "EU.EORI.NL000000001",
            });

            var sut = new DelegationValidationService(delegationServiceMock.Object);

            //Act
            var result = sut.ValidateEdit(arId, policyJson, claimsPrincipal).Result;

            //Assert
            result.Success.ShouldBe(true);
        }
Example #7
0
        public void ValidateCreate_WhenDelegationExists_ReturnsNotValid()
        {
            //Arrange
            var policyJson = @"
            {
                ""delegationEvidence"":
                {
                    ""notBefore"": 1509633681,
                    ""notOnOrAfter"": 1509633741,
                    ""policyIssuer"": ""EU.EORI.NL812972715"",
                    ""target"":
                    {
                        ""accessSubject"": ""EU.EORI.NL000000001""
                    }
                }
            }";
            var claims     = new List <Claim>
            {
                new Claim(ClaimTypes.Role, Constants.Roles.SchemeOwner)
            };
            var identity        = new ClaimsIdentity(claims, "TestAuthType");
            var claimsPrincipal = new ClaimsPrincipal(identity);

            var delegationServiceMock = new Mock <IDelegationService>();

            delegationServiceMock
            .Setup(c => c.DelegationExists("EU.EORI.NL812972715", "EU.EORI.NL000000001"))
            .ReturnsAsync(true);

            var sut = new DelegationValidationService(delegationServiceMock.Object);

            //Act
            var result = sut.ValidateCreate(policyJson, claimsPrincipal).Result;

            //Assert
            result.Error.ShouldBe("The combination policyIssuer - accessSubject already exists.");
        }