public void Setup()
        {
            var principal      = new ClaimsPrincipal();
            var claimsIdentity = new ClaimsIdentity();

            claimsIdentity.AddClaim(new Claim(ClaimTypes.UserData, ClaimsTransformation.GetProjectClaimValue(ProjectName)));
            principal.AddIdentity(claimsIdentity);
            var claimsProviderMock = new Mock <IClaimsProvider>();

            claimsProviderMock.Setup(c => c.GetCurrentUser()).Returns(principal);

            _dut = new ProjectAccessChecker(claimsProviderMock.Object);
        }
        public void Setup()
        {
            _plantProviderMock = new Mock <IPlantProvider>();
            _plantProviderMock.SetupGet(p => p.Plant).Returns(Plant1);

            _plantCacheMock = new Mock <IPlantCache>();
            _plantCacheMock.Setup(p => p.HasUserAccessToPlantAsync(Plant1, Oid)).Returns(Task.FromResult(true));
            _plantCacheMock.Setup(p => p.HasUserAccessToPlantAsync(Plant2, Oid)).Returns(Task.FromResult(true));

            var permissionCacheMock = new Mock <IPermissionCache>();

            permissionCacheMock.Setup(p => p.GetPermissionsForUserAsync(Plant1, Oid))
            .Returns(Task.FromResult <IList <string> >(new List <string> {
                Permission1_Plant1, Permission2_Plant1
            }));
            permissionCacheMock.Setup(p => p.GetProjectsForUserAsync(Plant1, Oid))
            .Returns(Task.FromResult <IList <string> >(new List <string> {
                Project1_Plant1, Project2_Plant1
            }));
            permissionCacheMock.Setup(p => p.GetContentRestrictionsForUserAsync(Plant1, Oid))
            .Returns(Task.FromResult <IList <string> >(new List <string> {
                Restriction1_Plant1, Restriction2_Plant1
            }));

            permissionCacheMock.Setup(p => p.GetPermissionsForUserAsync(Plant2, Oid))
            .Returns(Task.FromResult <IList <string> >(new List <string> {
                Permission1_Plant2
            }));
            permissionCacheMock.Setup(p => p.GetProjectsForUserAsync(Plant2, Oid))
            .Returns(Task.FromResult <IList <string> >(new List <string> {
                Project1_Plant2
            }));
            permissionCacheMock.Setup(p => p.GetContentRestrictionsForUserAsync(Plant2, Oid))
            .Returns(Task.FromResult <IList <string> >(new List <string> {
                Restriction1_Plant2
            }));

            var loggerMock = new Mock <ILogger <ClaimsTransformation> >();

            _principalWithOid = new ClaimsPrincipal();
            var claimsIdentity = new ClaimsIdentity();

            claimsIdentity.AddClaim(new Claim(ClaimsExtensions.Oid, Oid.ToString()));
            _principalWithOid.AddIdentity(claimsIdentity);

            _dut = new ClaimsTransformation(
                _plantProviderMock.Object,
                _plantCacheMock.Object,
                permissionCacheMock.Object,
                loggerMock.Object);
        }
        public void Setup()
        {
            _normalContentRestrictionClaim = new Claim(ClaimTypes.UserData, ClaimsTransformation.GetContentRestrictionClaimValue(ContentRestriction));
            _explicitNoRestrictionsClaim   = new Claim(ClaimTypes.UserData, ClaimsTransformation.GetContentRestrictionClaimValue(ClaimsTransformation.NoRestrictions));

            var principal = new ClaimsPrincipal();

            _claimsIdentity = new ClaimsIdentity();
            principal.AddIdentity(_claimsIdentity);
            var claimsProviderMock = new Mock <IClaimsProvider>();

            claimsProviderMock.Setup(u => u.GetCurrentUser()).Returns(principal);

            _dut = new ContentRestrictionsChecker(claimsProviderMock.Object);
        }
        public async Task TransformAsync_OnSecondPlant_ShouldClearAllClaimsForFirstPlant()
        {
            var result = await _dut.TransformAsync(_principalWithOid);

            AssertRoleClaimsForPlant1(result.Claims);
            AssertProjectClaimsForPlant1(result.Claims);

            _plantProviderMock.SetupGet(p => p.Plant).Returns(Plant2);
            result = await _dut.TransformAsync(_principalWithOid);

            var claims = GetRoleClaims(result.Claims);

            Assert.AreEqual(1, claims.Count);
            Assert.IsNotNull(claims.SingleOrDefault(r => r.Value == Permission1_Plant2));

            claims = GetProjectClaims(result.Claims);
            Assert.AreEqual(1, claims.Count);
            Assert.IsNotNull(claims.SingleOrDefault(r => r.Value == ClaimsTransformation.GetProjectClaimValue(Project1_Plant2)));
        }
Пример #5
0
        public void Setup()
        {
            _plantProviderMock = new Mock <IPlantProvider>();
            _plantProviderMock.SetupGet(p => p.Plant).Returns(Plant);

            _plantCacheMock = new Mock <IPlantCache>();
            _plantCacheMock.Setup(p => p.IsValidPlantForUserAsync(Plant, Oid)).Returns(Task.FromResult(true));

            var permissionCacheMock = new Mock <IPermissionCache>();

            permissionCacheMock.Setup(p => p.GetPermissionsForUserAsync(Plant, Oid))
            .Returns(Task.FromResult <IList <string> >(new List <string> {
                _tagReadPermission, Permissions.LIBRARY_GENERAL_READ, Permissions.LIBRARY_GENERAL_WRITE
            }));

            _principalWithOid = new ClaimsPrincipal();
            var claimsIdentity = new ClaimsIdentity();

            claimsIdentity.AddClaim(new Claim(ClaimsExtensions.OidType, Oid.ToString()));
            _principalWithOid.AddIdentity(claimsIdentity);

            _dut = new ClaimsTransformation(_plantProviderMock.Object, _plantCacheMock.Object, permissionCacheMock.Object);
        }