Ejemplo n.º 1
0
        public void CheckInternalOrOrganisationAccess_ReturnsTrue_WhenUserHasRequiredInternalClaim()
        {
            // Arrange
            Guid organisationID = new Guid("5F3069F4-EDA3-43A3-BDD8-726028CDABB0");
            Guid userId         = Guid.NewGuid();

            IUserContext userContext = A.Fake <IUserContext>();
            WeeeContext  weeeContext =
                MakeFakeWeeeContext(
                    userContext,
                    userId,
                    new List <OrganisationUser> {
                new OrganisationUser(userId, organisationID, UserStatus.Active)
            });

            ClaimsIdentity identity = new ClaimsIdentity();

            identity.AddClaim(new Claim(ClaimTypes.AuthenticationMethod, Claims.CanAccessInternalArea));

            ClaimsPrincipal principal = new ClaimsPrincipal(identity);

            A.CallTo(() => userContext.Principal).Returns(principal);

            WeeeAuthorization authorization = new WeeeAuthorization(weeeContext, userContext);

            // Act
            bool result = authorization.CheckInternalOrOrganisationAccess(organisationID);

            // Assert
            Assert.Equal(true, result);
        }
Ejemplo n.º 2
0
        public void CheckInternalOrOrganisationAccess_ReturnsFalse_WhenUserHasNoClaims()
        {
            // Arrange
            Guid organisationID = new Guid("5F3069F4-EDA3-43A3-BDD8-726028CDABB0");

            IUserContext userContext = A.Fake <IUserContext>();
            WeeeContext  weeeContext = MakeFakeWeeeContext(userContext);

            WeeeAuthorization authorization = new WeeeAuthorization(weeeContext, userContext);

            // Act
            bool result = authorization.CheckInternalOrOrganisationAccess(organisationID);

            // Assert
            Assert.Equal(false, result);
        }
Ejemplo n.º 3
0
        public void CheckInternalOrOrganisationAccess_ReturnsTrue_WhenUserHasRequiredOrganisationClaim()
        {
            // Arrange
            Guid organisationID = new Guid("5F3069F4-EDA3-43A3-BDD8-726028CDABB0");
            Guid userId         = Guid.NewGuid();

            IUserContext userContext = A.Fake <IUserContext>();
            WeeeContext  weeeContext =
                MakeFakeWeeeContext(
                    userContext,
                    userId,
                    new List <OrganisationUser> {
                new OrganisationUser(userId, organisationID, UserStatus.Active)
            });

            WeeeAuthorization authorization = new WeeeAuthorization(weeeContext, userContext);

            // Act
            bool result = authorization.CheckInternalOrOrganisationAccess(organisationID);

            // Assert
            Assert.Equal(true, result);
        }
        public void CheckInternalOrOrganisationAccess_ReturnsTrue_WhenUserHasRequiredInternalClaim()
        {
            // Arrange
            Guid organisationID = new Guid("5F3069F4-EDA3-43A3-BDD8-726028CDABB0");
            Guid userId = Guid.NewGuid();

            IUserContext userContext = A.Fake<IUserContext>();
            WeeeContext weeeContext =
                MakeFakeWeeeContext(
                    userContext,
                    userId,
                    new List<OrganisationUser> { new OrganisationUser(userId, organisationID, UserStatus.Active) });

            ClaimsIdentity identity = new ClaimsIdentity();
            identity.AddClaim(new Claim(ClaimTypes.AuthenticationMethod, Claims.CanAccessInternalArea));

            ClaimsPrincipal principal = new ClaimsPrincipal(identity);
            A.CallTo(() => userContext.Principal).Returns(principal);

            WeeeAuthorization authorization = new WeeeAuthorization(weeeContext, userContext);

            // Act
            bool result = authorization.CheckInternalOrOrganisationAccess(organisationID);

            // Assert
            Assert.Equal(true, result);
        }
        public void CheckInternalOrOrganisationAccess_ReturnsTrue_WhenUserHasRequiredOrganisationClaim()
        {
            // Arrange
            Guid organisationID = new Guid("5F3069F4-EDA3-43A3-BDD8-726028CDABB0");
            Guid userId = Guid.NewGuid();

            IUserContext userContext = A.Fake<IUserContext>();
            WeeeContext weeeContext =
                MakeFakeWeeeContext(
                    userContext,
                    userId,
                    new List<OrganisationUser> { new OrganisationUser(userId, organisationID, UserStatus.Active) });

            WeeeAuthorization authorization = new WeeeAuthorization(weeeContext, userContext);

            // Act
            bool result = authorization.CheckInternalOrOrganisationAccess(organisationID);

            // Assert
            Assert.Equal(true, result);
        }
        public void CheckInternalOrOrganisationAccess_ReturnsFalse_WhenUserHasNoClaims()
        {
            // Arrange
            Guid organisationID = new Guid("5F3069F4-EDA3-43A3-BDD8-726028CDABB0");

            IUserContext userContext = A.Fake<IUserContext>();
            WeeeContext weeeContext = MakeFakeWeeeContext(userContext);

            WeeeAuthorization authorization = new WeeeAuthorization(weeeContext, userContext);

            // Act
            bool result = authorization.CheckInternalOrOrganisationAccess(organisationID);

            // Assert
            Assert.Equal(false, result);
        }