Esempio n. 1
0
        public static async Task Returns_failure_when_token_is_invalid()
        {
            var context = CreateDefaultHttpContext.WithBearerToken("INVALID");

            var handler = CreateHandler();

            await handler.InitializeAsync(new AuthenticationScheme("Default", null, typeof(DefaultAuthenticationHandler)), context);

            var result = await handler.AuthenticateAsync();

            Assert.False(result.Succeeded);
        }
Esempio n. 2
0
        public static async Task Returns_success_when_token_is_set()
        {
            var context = CreateDefaultHttpContext.WithBearerToken(RawTokenValue);

            var handler = CreateHandler();

            await handler.InitializeAsync(new AuthenticationScheme("Default", null, typeof(DefaultAuthenticationHandler)), context);

            var result = await handler.AuthenticateAsync();

            Assert.True(result.Succeeded);
        }
Esempio n. 3
0
        public static async Task Sets_user_from_authorization_header()
        {
            var context = CreateDefaultHttpContext.WithBearerToken(RawTokenValue);

            var handler = CreateHandler();

            await handler.InitializeAsync(new AuthenticationScheme("Default", null, typeof(DefaultAuthenticationHandler)), context);

            var result = await handler.AuthenticateAsync();

            Assert.True(result.Succeeded);

            Assert.NotNull(result.Principal);

            Assert.Equal(3, result.Principal.Claims.Count());

            Assert.Contains(result.Principal.Claims, c => c.Type == "sub" && c.Value == "1234567890");
            Assert.Contains(result.Principal.Claims, c => c.Type == "name" && c.Value == "John Doe");
            Assert.Contains(result.Principal.Claims, c => c.Type == "iat" && c.Value == "1516239022");
        }