Пример #1
0
        public void ValidateAsync_ReturnsInvalidRequestWhenSubjectClaimNotFound()
        {
            // Arrange
            var tokenRequest = new ValidatedTokenRequest {
                Raw = new NameValueCollection()
            };

            tokenRequest.Raw.Add("access_token", "A12345");
            tokenRequest.Raw.Add("client_referer", "http://localhost:12345");

            var tokenValidatorFake = createTokenValidatorFake;

            A.CallTo(() => tokenValidatorFake.ValidateAccessTokenAsync("A12345", null))
            .Returns(Task.FromResult(new TokenValidationResult {
                IsError = false, Claims = new List <Claim>()
            }));

            var validator = new ActAsUserGrantValidator(tokenValidatorFake);

            // Act
            var result = validator.ValidateAsync(tokenRequest).Result;

            // Assert
            result.Error.Should().Be(Constants.TokenErrors.InvalidRequest);

            A.CallTo(() => tokenValidatorFake.ValidateAccessTokenAsync("A12345", null)).MustHaveHappened();
        }
Пример #2
0
        public void ValidateAsync_ReturnsInvalidRequestErrorWhenAccessTokenNotFound()
        {
            // Arrange
            var tokenRequest = new ValidatedTokenRequest {
                Raw = new NameValueCollection()
            };
            var validator = new ActAsUserGrantValidator(null);

            // Act
            var result = validator.ValidateAsync(tokenRequest).Result;

            // Assert
            result.Error.Should().Be(Constants.TokenErrors.InvalidRequest);
        }
Пример #3
0
        public void ValidateAsync_ReturnsResultWhenSubjectClaimFound()
        {
            // Arrange
            var tokenRequest = new ValidatedTokenRequest
            {
                Raw    = new NameValueCollection(),
                Scopes = new List <string> {
                    "scope1", "scope2", "scope3"
                }
            };

            tokenRequest.Raw.Add("access_token", "A12345");
            tokenRequest.Raw.Add("client_referer", "http://localhost:12345");

            var tokenValidatorFake = createTokenValidatorFake;

            A.CallTo(() => tokenValidatorFake.ValidateAccessTokenAsync("A12345", null))
            .Returns(Task.FromResult(new TokenValidationResult
            {
                IsError = false,
                Claims  = new List <Claim>
                {
                    new Claim(Constants.ClaimTypes.Subject, "sun123")
                },
                Client = new Client {
                    RedirectUris = new List <string> {
                        "http://localhost:12345"
                    }
                }
            }));

            var validator = new ActAsUserGrantValidator(tokenValidatorFake);

            // Act
            var result = validator.ValidateAsync(tokenRequest).Result;

            // Assert
            result.Principal.Identity.AuthenticationType.Should().Be("access_token");
            result.Principal.Claims.First().Type.Should().Be(Constants.ClaimTypes.Subject);
            result.Principal.Claims.First().Value.Should().Be("sun123");

            A.CallTo(() => tokenValidatorFake.ValidateAccessTokenAsync("A12345", null)).MustHaveHappened();
        }