protected override void EstablishContext()
        {
            suppliedContextData = new RelationshipsAuthorizationContextData
            {
                StudentUSI = 11111
            };

            _suppliedEdFiResourceClaimValue = new EdFiResourceClaimValue(
                "manage",
                new List <int>
            {
                1, 2, 3
            });

            suppliedClaims = new List <Claim>
            {
                JsonClaimHelper.CreateClaim(
                    "http://ed-fi.org/ods/identity/claims/domains/generalData",
                    _suppliedEdFiResourceClaimValue)
            };

            _educationOrganizationCache = Stub <IEducationOrganizationCache>();

            _educationOrganizationCache.Stub(
                x =>
                x.GetEducationOrganizationIdentifiers(Arg <int> .Is.Anything))
            .Return(new EducationOrganizationIdentifiers(0, "LocalEducationAgency"));
        }
예제 #2
0
            public void Should_have_no_errors_when_supplying_only_the_action()
            {
                var suppliedEdFiClaimValue = new EdFiResourceClaimValue("action");
                var result = JsonClaimHelper.CreateClaim(SuppliedClaimType, suppliedEdFiClaimValue);

                result.ShouldNotBeNull();
            }
예제 #3
0
            public void Should_have_no_errors_when_suppling_only_the_action()
            {
                var suppliedEdFiClaimValue = new EdFiResourceClaimValue("action");
                var thrown = TestForException <Exception>(() => JsonClaimHelper.CreateClaim(SuppliedClaimType, suppliedEdFiClaimValue));

                thrown.ShouldBeNull();
            }
예제 #4
0
            public void Should_have_no_errors()
            {
                var suppliedEdFiClaimValue = new EdFiResourceClaimValue(ExpectedAction);
                var claim  = JsonClaimHelper.CreateClaim(ExpectedClaimType, suppliedEdFiClaimValue);
                var actual = claim.ToEdFiResourceClaimValue();

                Assert.IsTrue(actual.EducationOrganizationIds.Count == 0);
            }
예제 #5
0
            public void Should_have_no_errors()
            {
                var suppliedEdFiClaimValue = new EdFiResourceClaimValue(ExpectedAction);
                var claim  = JsonClaimHelper.CreateClaim(ExpectedClaimType, suppliedEdFiClaimValue);
                var thrown = TestForException <Exception>(() => claim.ToEdFiResourceClaimValue());

                thrown.ShouldBeNull();
            }
예제 #6
0
            public void Should_create_claim_when_supplying_only_the_action()
            {
                var suppliedEdFiClaimValue = new EdFiResourceClaimValue("action");
                var actualClaim            = JsonClaimHelper.CreateClaim(SuppliedClaimType, suppliedEdFiClaimValue);

                var expectedClaim = new Claim(SuppliedClaimType, "{\"Actions\":[{\"Name\":\"action\"}]}", "application/json");

                actualClaim.Type.ShouldBe(expectedClaim.Type);
                actualClaim.ValueType.ShouldBe(expectedClaim.ValueType);
                actualClaim.Value.ShouldBe(expectedClaim.Value);
            }
예제 #7
0
            public void Should_create_a_EdFiClaimValue()
            {
                var suppliedEdFiClaimValue = new EdFiResourceClaimValue(ExpectedAction, expectedLocalEducationAgencyIds);
                var claim  = JsonClaimHelper.CreateClaim(ExpectedClaimType, suppliedEdFiClaimValue);
                var actual = claim.ToEdFiResourceClaimValue();

                actual.Actions.Select(x => x.Name)
                .Single()
                .ShouldBe(ExpectedAction);

                actual.EducationOrganizationIds.ShouldBe(expectedLocalEducationAgencyIds);
            }
예제 #8
0
            public void Should_have_no_errors()
            {
                var suppliedEdFiClaimValue = new EdFiResourceClaimValue(
                    "action",
                    new List <int>
                {
                    1, 2
                });
                var result = JsonClaimHelper.CreateClaim(SuppliedClaimType, suppliedEdFiClaimValue);

                result.ShouldNotBeNull();
            }
예제 #9
0
            public void Should_create_a_EdFiClaimValue_when_only_action_is_supplied()
            {
                var suppliedEdFiClaimValue = new EdFiResourceClaimValue(ExpectedAction);
                var claim  = JsonClaimHelper.CreateClaim(ExpectedClaimType, suppliedEdFiClaimValue);
                var actual = claim.ToEdFiResourceClaimValue();

                actual.Actions.Select(x => x.Name)
                .Single()
                .ShouldBe(ExpectedAction);

                actual.EducationOrganizationIds.ShouldBeEmpty();
            }
예제 #10
0
            public void Should_have_no_errors()
            {
                var suppliedEdFiClaimValue = new EdFiResourceClaimValue(
                    "action",
                    new List <int>
                {
                    1, 2
                });

                var thrown = TestForException <Exception>(() => JsonClaimHelper.CreateClaim(SuppliedClaimType, suppliedEdFiClaimValue));

                thrown.ShouldBeNull();
            }
        protected override void Arrange()
        {
            #region Commented out code for integration testing against SQL Server

            //private IDatabaseConnectionStringProvider connectionStringProvider;

            //connectionStringProvider = mocks.Stub<IDatabaseConnectionStringProvider>();
            //connectionStringProvider.Stub(x => x.GetConnectionString())
            //    .Return(@"Server=(local);Database=database;User Id=user;Password=xxxxx");

            //var executor = new EdFiOdsAuthorizationRulesExecutor(connectionStringProvider);
            //executor.Execute(actualAuthorizationRules);

            #endregion

            _suppliedContextData = new RelationshipsAuthorizationContextData
            {
                SchoolId = 880001,
                StaffUSI = 738953 //340DFAFA-D39B-4A38-BEA4-AD705CC7EB7C
            };

            _suppliedEdFiResourceClaimValue = new EdFiResourceClaimValue(
                "manage",
                new List <int>
            {
                780,
                880,
                980
            });

            _suppliedClaims = new List <Claim>
            {
                JsonClaimHelper.CreateClaim(
                    "http://ed-fi.org/ods/identity/claims/domains/generalData",
                    _suppliedEdFiResourceClaimValue)
            };

            _educationOrganizationCache = Stub <IEducationOrganizationCache>();

            A.CallTo(
                () =>
                _educationOrganizationCache.GetEducationOrganizationIdentifiers(A <int> ._))
            .Returns(new EducationOrganizationIdentifiers(0, "LocalEducationAgency"));
        }
예제 #12
0
            public void Should_create_claim_when_supplying_all_parameters()
            {
                var expected = new Claim(
                    SuppliedClaimType,
                    "{\"Actions\":[{\"Name\":\"action\"}],\"EducationOrganizationIds\":[1,2]}",
                    "application/json");

                var suppliedEdFiClaimValue = new EdFiResourceClaimValue(
                    "action",
                    new List <int>
                {
                    1, 2
                });

                var actual = JsonClaimHelper.CreateClaim(SuppliedClaimType, suppliedEdFiClaimValue);

                actual.Type.ShouldBe(expected.Type);
                actual.ValueType.ShouldBe(expected.ValueType);
                actual.Value.ShouldBe(expected.Value);
            }
        private static IReadOnlyList <ClaimsAuthorizationSegment> GetRelationshipAuthorizationSegments(
            List <int> claimEducationOrganizationIds,
            Action <AuthorizationBuilder <RelationshipsAuthorizationContextData> > buildAuthorizations)
        {
            _suppliedAuthorizationContext = new RelationshipsAuthorizationContextData
            {
                SchoolId = 880001,
                StaffUSI = 738953
            };

            _suppliedClaim = new EdFiResourceClaimValue(
                "manage",
                claimEducationOrganizationIds);

            var suppliedClaims = new List <Claim>
            {
                JsonClaimHelper.CreateClaim(
                    "http://ed-fi.org/ods/identity/claims/domains/generalData",
                    _suppliedClaim)
            };

            var educationOrganizationCache = A.Fake <IEducationOrganizationCache>();

            A.CallTo(() => educationOrganizationCache.GetEducationOrganizationIdentifiers(
                         A <int> .That.Matches(x => x == SuppliedLea1 || x == SuppliedLea2 || x == SuppliedLea3)))
            .Returns(new EducationOrganizationIdentifiers(0, "LocalEducationAgency"));

            A.CallTo(() => educationOrganizationCache.GetEducationOrganizationIdentifiers(SuppliedPostSecondaryInstitutionId))
            .Returns(new EducationOrganizationIdentifiers(0, "PostSecondaryInstitution"));

            var builder = new AuthorizationBuilder <RelationshipsAuthorizationContextData>(
                suppliedClaims,
                educationOrganizationCache,
                _suppliedAuthorizationContext);

            buildAuthorizations(builder);

            return(builder.GetSegments());
        }