Exemplo n.º 1
0
        public void Unauthenticated_User_Should_Return_AuthenticationContext_With_Anonymous_AuthenticationMethod()
        {
            //Arrange
            var authenticationContextFactory = new OwinAuthenticationContextFactory(Mock.Of <ILogger>(), MakeMockContext(authType: null, defaultOrg: "invalid", userId: "1", isAuthenticated: "false"), Mock.Of <IUserRepository>());

            //Act
            var authContext = authenticationContextFactory.Create();

            //Assert
            Assert.Equal(AuthenticationMethod.Anonymous, authContext.Method);
        }
Exemplo n.º 2
0
        public void Unauthenticated_User_Can_Not_Have_Api_Access()
        {
            //Arrange
            var authenticationContextFactory = new OwinAuthenticationContextFactory(Mock.Of <ILogger>(), MakeMockContext(authType: null, defaultOrg: "invalid", userId: "1", isAuthenticated: "false"), Mock.Of <IUserRepository>());

            //Act
            var authContext = authenticationContextFactory.Create();

            //Assert
            Assert.False(authContext.HasApiAccess);
        }
Exemplo n.º 3
0
        public void Invalid_UserId_Returns_Null()
        {
            //Arrange
            var owinContext    = MakeMockContext(authType: TokenAuth, defaultOrg: "1", userId: "invalid", isAuthenticated: "true");
            var userRepository = MakeMockUserRepository(false, _validUserId);
            var authenticationContextFactory = new OwinAuthenticationContextFactory(Mock.Of <ILogger>(), owinContext, userRepository);

            //Act
            var authContext = authenticationContextFactory.Create();

            //Assert
            Assert.Null(authContext.UserId);
        }
Exemplo n.º 4
0
        public void Invalid_Organization_Claim_Value_Returns_Null()
        {
            //Arrange
            var owinContext    = MakeMockContext(authType: TokenAuth, defaultOrg: "invalid", userId: _validUserId.ToString(), isAuthenticated: "true");
            var userRepository = MakeMockUserRepository(false, _validUserId);
            var authenticationContextFactory = new OwinAuthenticationContextFactory(Mock.Of <ILogger>(), owinContext, userRepository);

            //Act
            var authContext = authenticationContextFactory.Create();

            //Assert
            Assert.Equal(AuthenticationMethod.KitosToken, authContext.Method);
        }
Exemplo n.º 5
0
        public void Authenticated_User_Can_Have_Api_Access(bool apiAccess)
        {
            //Arrange
            var owinContext    = MakeMockContext(authType: TokenAuth, defaultOrg: "1", userId: _validUserId.ToString(), isAuthenticated: "true");
            var userRepository = MakeMockUserRepository(apiAccess, _validUserId);
            var authenticationContextFactory = new OwinAuthenticationContextFactory(Mock.Of <ILogger>(), owinContext, userRepository);

            //Act
            var authContext = authenticationContextFactory.Create();

            //Assert
            Assert.Equal(_validUserId, authContext.UserId);
            Assert.Equal(apiAccess, authContext.HasApiAccess);
        }
Exemplo n.º 6
0
        public void Authenticated_User_Should_Return_AuthenticationContext_With_AuthenticationMethod(AuthenticationMethod authMethod, string authType, int?defaultOrg)
        {
            //Arrange
            var owinContext    = MakeMockContext(authType: authType, defaultOrg: defaultOrg?.ToString() ?? A <string>(), userId: _validUserId.ToString(), isAuthenticated: "true");
            var userRepository = MakeMockUserRepository(false, _validUserId, defaultOrg);
            var authenticationContextFactory = new OwinAuthenticationContextFactory(Mock.Of <ILogger>(), owinContext, userRepository);

            //Act
            var authContext = authenticationContextFactory.Create();

            //Assert
            Assert.Equal(authMethod, authContext.Method);
            Assert.Equal(_validUserId, authContext.UserId);
        }