Beispiel #1
0
        public async Task ContextHandler_TC06()
        {
            // Arrange
            string testCase = "AltinnApps0006";

            XacmlContextRequest request = TestSetupUtil.CreateXacmlContextRequest(testCase);
            XacmlContextRequest expectedEnrichedRequest = TestSetupUtil.GetEnrichedRequest(testCase);

            // Act
            Instance    instance = TestSetupUtil.GetInstanceData("26133fb5-a9f2-45d4-90b1-f6d93ad40713.json");
            List <Role> roles    = TestSetupUtil.GetRoles(1, 1000);

            _policyInformationRepositoryMock.Setup(p => p.GetInstance(It.Is <string>(s => s.Equals("1000/26133fb5-a9f2-45d4-90b1-f6d93ad40713")))).ReturnsAsync(instance);
            _rolesMock.Setup(p => p.GetDecisionPointRolesForUser(It.Is <int>(s => s.Equals(1)), It.Is <int>(p => p.Equals(1000)))).ReturnsAsync(roles);

            XacmlContextRequest enrichedRequest = await _contextHandler.Enrich(request);

            var a = JsonConvert.SerializeObject(enrichedRequest);
            var b = JsonConvert.SerializeObject(expectedEnrichedRequest);

            // Assert
            Assert.NotNull(enrichedRequest);
            Assert.NotNull(expectedEnrichedRequest);
            AssertionUtil.AssertEqual(expectedEnrichedRequest, enrichedRequest);
        }
        public void PDP_AuthorizeAccess_IIA007()
        {
            bool   contextRequstIsEnriched = false;
            string testCase = "IIA007";

            XacmlContextResponse contextResponeExpected = XacmlTestDataParser.ParseResponse(testCase + "Response.xml", GetConformancePath());
            XacmlContextResponse xacmlResponse          = SetuUpPolicyDecisionPoint(testCase, contextRequstIsEnriched);

            AssertionUtil.AssertEqual(contextResponeExpected, xacmlResponse);
        }
Beispiel #3
0
        public void PDP_AuthorizeAccess_AltinnApps0003()
        {
            bool   contextRequstIsEnriched = true;
            string testCase = "AltinnApps0003";

            XacmlContextResponse contextResponeExpected = XacmlTestDataParser.ParseResponse(testCase + "Response.xml", GetAltinnAppsPath());
            XacmlContextResponse xacmlResponse          = SetuUpPolicyDecisionPoint(testCase, contextRequstIsEnriched);

            AssertionUtil.AssertEqual(contextResponeExpected, xacmlResponse);
        }
Beispiel #4
0
        public async Task PDP_Decision_AltinnApps0005()
        {
            string               testCase           = "AltinnApps0005";
            HttpClient           client             = GetTestClient();
            HttpRequestMessage   httpRequestMessage = TestSetupUtil.CreateXacmlRequest(testCase);
            XacmlContextResponse expected           = TestSetupUtil.ReadExpectedResponse(testCase);

            // Act
            XacmlContextResponse contextResponse = await TestSetupUtil.GetXacmlContextResponseAsync(client, httpRequestMessage);

            // Assert
            AssertionUtil.AssertEqual(expected, contextResponse);
        }
        public async Task PDP_Decision_JsonProfile_IIA001()
        {
            string             testCase           = "IIA001";
            HttpClient         client             = GetTestClient();
            HttpRequestMessage httpRequestMessage = TestSetupUtil.CreateJsonProfileXacmlRequest(testCase);
            XacmlJsonResponse  expected           = TestSetupUtil.ReadExpectedJsonProfileResponse(testCase);

            // Act
            XacmlJsonResponse contextResponse = await TestSetupUtil.GetXacmlJsonProfileContextResponseAsync(client, httpRequestMessage);

            // Assert
            AssertionUtil.AssertEqual(expected, contextResponse);
        }
Beispiel #6
0
        public async Task PDP_Decision_DelegationPolicy_AltinnAppsOrg1App1_UserDelegation_Deleted_NotApplicable()
        {
            string             testCase           = "AltinnAppsOrg1App1_UserDelegation_Deleted";
            HttpClient         client             = GetTestClient();
            HttpRequestMessage httpRequestMessage = TestSetupUtil.CreateJsonProfileXacmlRequest(testCase);
            XacmlJsonResponse  expected           = TestSetupUtil.ReadExpectedJsonProfileResponse(testCase);

            // Act
            XacmlJsonResponse contextResponse = await TestSetupUtil.GetXacmlJsonProfileContextResponseAsync(client, httpRequestMessage);

            // Assert
            AssertionUtil.AssertEqual(expected, contextResponse);
        }
Beispiel #7
0
        public void SortRulesByDelegationPolicyPath_ThreeAppsSameOfferedByAndCoveredBy_Success()
        {
            // Arrange
            int    delegatedByUserId = 20001336;
            int    offeredByPartyId  = 50001337;
            string coveredBy         = "20001337";
            string coveredByType     = AltinnXacmlConstants.MatchAttributeIdentifiers.UserAttribute;

            List <Rule> unsortedRules = new List <Rule>
            {
                TestDataHelper.GetRuleModel(delegatedByUserId, offeredByPartyId, coveredBy, coveredByType, "read", "org1", "app1"),
                TestDataHelper.GetRuleModel(delegatedByUserId, offeredByPartyId, coveredBy, coveredByType, "read", "org2", "app1"),
                TestDataHelper.GetRuleModel(delegatedByUserId, offeredByPartyId, coveredBy, coveredByType, "read", "org1", "App2"),
                TestDataHelper.GetRuleModel(delegatedByUserId, offeredByPartyId, coveredBy, coveredByType, "write", "org1", "app1", "task1"),            // Should be sorted together with the first rule
                TestDataHelper.GetRuleModel(delegatedByUserId, offeredByPartyId, coveredBy, coveredByType, "read", "org1", "app1", task: null, "event1") // Should be sorted together with the first rule
            };

            Dictionary <string, List <Rule> > expected = new Dictionary <string, List <Rule> >();

            expected.Add($"org1/app1/{offeredByPartyId}/u{coveredBy}/delegationpolicy.xml", new List <Rule>
            {
                TestDataHelper.GetRuleModel(delegatedByUserId, offeredByPartyId, coveredBy, coveredByType, "read", "org1", "app1"),
                TestDataHelper.GetRuleModel(delegatedByUserId, offeredByPartyId, coveredBy, coveredByType, "write", "org1", "app1", "task1"),
                TestDataHelper.GetRuleModel(delegatedByUserId, offeredByPartyId, coveredBy, coveredByType, "read", "org1", "app1", task: null, "event1")
            });
            expected.Add($"org2/app1/{offeredByPartyId}/u{coveredBy}/delegationpolicy.xml", new List <Rule>
            {
                TestDataHelper.GetRuleModel(delegatedByUserId, offeredByPartyId, coveredBy, coveredByType, "read", "org2", "app1")
            });
            expected.Add($"org1/App2/{offeredByPartyId}/u{coveredBy}/delegationpolicy.xml", new List <Rule>
            {
                TestDataHelper.GetRuleModel(delegatedByUserId, offeredByPartyId, coveredBy, coveredByType, "read", "org1", "App2")
            });

            // Act
            Dictionary <string, List <Rule> > actual = DelegationHelper.SortRulesByDelegationPolicyPath(unsortedRules, out List <Rule> unsortables);

            // Assert
            Assert.NotNull(actual);
            Assert.Empty(unsortables);

            Assert.Equal(expected.Keys.Count, actual.Keys.Count);
            foreach (string expectedPathKey in expected.Keys)
            {
                Assert.True(actual.ContainsKey(expectedPathKey));
                Assert.Equal(expected[expectedPathKey].Count, actual[expectedPathKey].Count);
                AssertionUtil.AssertEqual(expected[expectedPathKey], actual[expectedPathKey]);
            }
        }
Beispiel #8
0
        public void MapToDelegationChangeEventList()
        {
            // Arrange
            EventMapperService mapper = new EventMapperService();

            DateTime now = DateTime.Now;
            DelegationChangeEventList expected = new DelegationChangeEventList
            {
                DelegationChangeEvents = new List <DelegationChangeEvent>
                {
                    new DelegationChangeEvent
                    {
                        EventType        = DelegationChangeEventType.Grant,
                        DelegationChange = new SimpleDelegationChange
                        {
                            DelegationChangeId = 1,
                            AltinnAppId        = "ttd/testapp",
                            OfferedByPartyId   = 123,
                            CoveredByPartyId   = 234,
                            PerformedByUserId  = 567,
                            Created            = now
                        }
                    }
                }
            };

            List <DelegationChange> input = new List <DelegationChange>()
            {
                new DelegationChange()
                {
                    DelegationChangeId    = 1,
                    DelegationChangeType  = DelegationChangeType.Grant,
                    AltinnAppId           = "ttd/testapp",
                    OfferedByPartyId      = 123,
                    CoveredByPartyId      = 234,
                    PerformedByUserId     = 567,
                    BlobStoragePolicyPath = "ttd/testapp/123/p234/delegationpolicy.xml",
                    BlobStorageVersionId  = now.ToString(),
                    Created = now
                }
            };

            // Act
            DelegationChangeEventList actual = mapper.MapToDelegationChangeEventList(input);

            // Assert
            AssertionUtil.AssertEqual(expected, actual);
        }
Beispiel #9
0
        public async Task ContextHandler_TC02()
        {
            // Arrange
            string testCase = "AltinnApps0022";

            XacmlContextRequest request = TestSetupUtil.CreateXacmlContextRequest(testCase);
            XacmlContextRequest expectedEnrichedRequest = TestSetupUtil.GetEnrichedRequest(testCase);

            // Act
            XacmlContextRequest enrichedRequest = await _contextHandler.Enrich(request);

            // Assert
            Assert.NotNull(enrichedRequest);
            Assert.NotNull(expectedEnrichedRequest);
            AssertionUtil.AssertEqual(expectedEnrichedRequest, enrichedRequest);
        }
Beispiel #10
0
        public void SortRulesByDelegationPolicyPath_Unsortables_Success()
        {
            // Arrange
            int delegatedByUserId = 20001336;
            int offeredByPartyId  = 50001337;

            List <Rule> unsortedRules = new List <Rule>
            {
                TestDataHelper.GetRuleModel(delegatedByUserId, offeredByPartyId, "20001337", AltinnXacmlConstants.MatchAttributeIdentifiers.UserAttribute, "read", "org1", "app1", "task1"),
                TestDataHelper.GetRuleModel(delegatedByUserId, offeredByPartyId, "20001337", AltinnXacmlConstants.MatchAttributeIdentifiers.UserAttribute, "read", null, "app1"),
                TestDataHelper.GetRuleModel(delegatedByUserId, offeredByPartyId, "20001337", AltinnXacmlConstants.MatchAttributeIdentifiers.UserAttribute, "write", "org1", "app1")
            };

            Dictionary <string, List <Rule> > expected = new Dictionary <string, List <Rule> >();

            expected.Add($"org1/app1/{offeredByPartyId}/u20001337/delegationpolicy.xml", new List <Rule>
            {
                TestDataHelper.GetRuleModel(delegatedByUserId, offeredByPartyId, "20001337", AltinnXacmlConstants.MatchAttributeIdentifiers.UserAttribute, "read", "org1", "app1", "task1"),
                TestDataHelper.GetRuleModel(delegatedByUserId, offeredByPartyId, "20001337", AltinnXacmlConstants.MatchAttributeIdentifiers.UserAttribute, "write", "org1", "app1")
            });

            List <Rule> expectedUnsortable = new List <Rule>
            {
                TestDataHelper.GetRuleModel(delegatedByUserId, offeredByPartyId, "20001337", AltinnXacmlConstants.MatchAttributeIdentifiers.UserAttribute, "read", null, "app1")
            };

            // Act
            Dictionary <string, List <Rule> > actual = DelegationHelper.SortRulesByDelegationPolicyPath(unsortedRules, out List <Rule> unsortables);

            // Assert
            Assert.NotNull(actual);

            Assert.Equal(expectedUnsortable.Count, unsortables.Count);
            AssertionUtil.AssertEqual(expectedUnsortable, unsortables);

            Assert.Equal(expected.Keys.Count, actual.Keys.Count);
            foreach (string expectedPathKey in expected.Keys)
            {
                Assert.True(actual.ContainsKey(expectedPathKey));
                Assert.Equal(expected[expectedPathKey].Count, actual[expectedPathKey].Count);
                AssertionUtil.AssertEqual(expected[expectedPathKey], actual[expectedPathKey]);
            }
        }
Beispiel #11
0
        public async Task ContextHandler_TC05()
        {
            // Arrange
            string testCase = "AltinnApps0004";

            XacmlContextRequest request = TestSetupUtil.CreateXacmlContextRequest(testCase);
            XacmlContextRequest expectedEnrichedRequest = TestSetupUtil.GetEnrichedRequest(testCase);

            // Act

            List <Role> roles = TestSetupUtil.GetRoles(1, 1000);

            _rolesMock.Setup(p => p.GetDecisionPointRolesForUser(It.Is <int>(s => s.Equals(1)), It.Is <int>(p => p.Equals(1000)))).ReturnsAsync(roles);

            XacmlContextRequest enrichedRequest = await _contextHandler.Enrich(request);

            // Assert
            Assert.NotNull(enrichedRequest);
            Assert.NotNull(expectedEnrichedRequest);
            AssertionUtil.AssertEqual(expectedEnrichedRequest, enrichedRequest);
        }
Beispiel #12
0
        public async Task ContextHanler_TC01()
        {
            // Arrange
            string testCase = "AltinnApps0001";

            XacmlContextRequest request = TestSetupUtil.CreateXacmlContextRequest(testCase);
            XacmlContextRequest expectedEnrichedRequest = TestSetupUtil.GetEnrichedRequest(testCase);

            // Act

            Instance    instance = TestSetupUtil.GetInstanceData("7dd3c208-0062-4ff6-9ef7-2384e9199a6c.json");
            List <Role> roles    = TestSetupUtil.GetRoles(1, 1000);

            _policyInformationRepositoryMock.Setup(p => p.GetInstance(It.Is <string>(s => s.Equals("1000/7dd3c208-0062-4ff6-9ef7-2384e9199a6c")))).ReturnsAsync(instance);
            _rolesMock.Setup(p => p.GetDecisionPointRolesForUser(It.Is <int>(s => s.Equals(1)), It.Is <int>(p => p.Equals(1000)))).ReturnsAsync(roles);

            XacmlContextRequest enrichedRequest = await _contextHandler.Enrich(request);


            // Assert
            Assert.NotNull(enrichedRequest);
            Assert.NotNull(expectedEnrichedRequest);
            AssertionUtil.AssertEqual(expectedEnrichedRequest, enrichedRequest);
        }