Пример #1
0
        public void CanRetrieveTheDependenciesThaAreGoingToBeIndirectlyUsedToBuildTheTestInstance()
        {
            GivenTheTestScopeIs(TestScopes.Namespace <PublicClassWithConcreteNamespaceDependencies>());
            GivenTheDependencyProviderIs(FakeDependencyProvider);

            var dependency1 = TestInstance.GetDependency <IDependency <One> >();
            var dependency2 = TestInstance.GetDependency <IDependency <Two> >();
            var dependency3 = TestInstance.GetDependency <IDependency <Three> >();

            WhenATestInstanceIsRequested <PublicClassWithConcreteNamespaceDependencies>(out var result);

            result.ShouldSatisfyAllConditions(
                () => result.ConcreteDependency.Dependency1.ShouldBe(dependency1),
                () => result.ConcreteDependency.Dependency2.ShouldBe(dependency2),
                () => result.ConcreteDependency.Dependency3.ShouldBe(dependency3)
                );
        }
Пример #2
0
        public void CanRetrieveTheDependenciesThatAreGoingToBeUsedToBuildTheTestInstance()
        {
            GivenTheTestScopeIs(TestScopes.Class <PublicClassWithMultipleConstructorDependencies>());
            GivenTheDependencyProviderIs(FakeDependencyProvider);

            var dependency1 = TestInstance.GetDependency <IDependency <One> >();
            var dependency2 = TestInstance.GetDependency <IDependency <Two> >();
            var dependency3 = TestInstance.GetDependency <IDependency <Three> >();

            WhenATestInstanceIsRequested <PublicClassWithMultipleConstructorDependencies>(out var result);

            result.ShouldSatisfyAllConditions(
                () => result.Dependency1.ShouldBe(dependency1),
                () => result.Dependency2.ShouldBe(dependency2),
                () => result.Dependency3.ShouldBe(dependency3)
                );
        }
        public static TokenRequestValidator CreateTokenValidator(
            CoreSettings settings = null,
            ILogger logger        = null,
            IScopeService scopes  = null,
            IAuthorizationCodeStore authorizationCodeStore = null,
            IUserService userService = null,
            IAssertionGrantValidator assertionGrantValidator = null,
            ICustomRequestValidator customRequestValidator   = null)
        {
            if (settings == null)
            {
                settings = new TestSettings();
            }

            if (scopes == null)
            {
                scopes = new InMemoryScopeService(TestScopes.Get());
            }

            if (logger == null)
            {
                logger = new DebugLogger();
            }

            if (userService == null)
            {
                userService = new TestUserService();
            }

            if (customRequestValidator == null)
            {
                customRequestValidator = new DefaultCustomRequestValidator();
            }

            if (assertionGrantValidator == null)
            {
                assertionGrantValidator = new TestAssertionValidator();
            }

            return(new TokenRequestValidator(settings, logger, authorizationCodeStore, userService, scopes, assertionGrantValidator, customRequestValidator));
        }
        public static TokenRequestValidator CreateTokenValidator(
            IdentityServerOptions options = null,
            IScopeStore scopes            = null,
            IAuthorizationCodeStore authorizationCodeStore = null,
            IRefreshTokenStore refreshTokens = null,
            IUserService userService         = null,
            IAssertionGrantValidator assertionGrantValidator = null,
            ICustomRequestValidator customRequestValidator   = null)
        {
            if (options == null)
            {
                options = Thinktecture.IdentityServer.Tests.TestIdentityServerOptions.Create();
            }

            if (scopes == null)
            {
                scopes = new InMemoryScopeStore(TestScopes.Get());
            }

            if (userService == null)
            {
                userService = new TestUserService();
            }

            if (customRequestValidator == null)
            {
                customRequestValidator = new DefaultCustomRequestValidator();
            }

            if (assertionGrantValidator == null)
            {
                assertionGrantValidator = new TestAssertionValidator();
            }

            if (refreshTokens == null)
            {
                refreshTokens = new InMemoryRefreshTokenStore();
            }

            return(new TokenRequestValidator(options, authorizationCodeStore, refreshTokens, userService, scopes, assertionGrantValidator, customRequestValidator));
        }
        public static AuthorizeRequestValidator CreateAuthorizeValidator(
            CoreSettings settings  = null,
            IScopeService scopes   = null,
            IClientService clients = null,
            ILogger logger         = null,
            IUserService users     = null,
            ICustomRequestValidator customValidator = null)
        {
            if (settings == null)
            {
                settings = new TestSettings();
            }

            if (scopes == null)
            {
                scopes = new InMemoryScopeService(TestScopes.Get());
            }

            if (clients == null)
            {
                clients = new InMemoryClientService(TestClients.Get());
            }

            if (logger == null)
            {
                logger = new DebugLogger();
            }

            if (customValidator == null)
            {
                customValidator = new DefaultCustomRequestValidator();
            }

            if (users == null)
            {
                users = new TestUserService();
            }

            return(new AuthorizeRequestValidator(settings, scopes, clients, logger, users, customValidator));
        }
Пример #6
0
 public ScopeStoreTests()
 {
     Factory.ConfigureScope(RavenOptions);
     TestScopes.Get().LoadTo(Store);
     WaitForIndexing(Store);
 }
Пример #7
0
 public BigUnitTest() : base(
         TestScopes.Namespace <T>(),
         new MoqDependencyProvider())
 {
 }
Пример #8
0
    public static TokenRequestValidator CreateTokenRequestValidator(
        IdentityServerOptions options                          = null,
        IIssuerNameService issuerNameService                   = null,
        IResourceStore resourceStore                           = null,
        IAuthorizationCodeStore authorizationCodeStore         = null,
        IRefreshTokenStore refreshTokenStore                   = null,
        IResourceOwnerPasswordValidator resourceOwnerValidator = null,
        IProfileService profile = null,
        IDeviceCodeValidator deviceCodeValidator = null,
        IBackchannelAuthenticationRequestIdValidator backchannelAuthenticationRequestIdValidator = null,
        IEnumerable <IExtensionGrantValidator> extensionGrantValidators = null,
        ICustomTokenRequestValidator customRequestValidator             = null,
        IRefreshTokenService refreshTokenService = null,
        IResourceValidator resourceValidator     = null)
    {
        if (options == null)
        {
            options = TestIdentityServerOptions.Create();
        }

        if (issuerNameService == null)
        {
            issuerNameService = new TestIssuerNameService(options.IssuerUri);
        }

        if (resourceStore == null)
        {
            resourceStore = new InMemoryResourcesStore(TestScopes.GetIdentity(), TestScopes.GetApis(), TestScopes.GetScopes());
        }

        if (resourceOwnerValidator == null)
        {
            resourceOwnerValidator = new TestResourceOwnerPasswordValidator();
        }

        if (profile == null)
        {
            profile = new TestProfileService();
        }

        if (deviceCodeValidator == null)
        {
            deviceCodeValidator = new TestDeviceCodeValidator();
        }

        if (backchannelAuthenticationRequestIdValidator == null)
        {
            backchannelAuthenticationRequestIdValidator = new TestBackchannelAuthenticationRequestIdValidator();
        }

        if (customRequestValidator == null)
        {
            customRequestValidator = new DefaultCustomTokenRequestValidator();
        }

        ExtensionGrantValidator aggregateExtensionGrantValidator;

        if (extensionGrantValidators == null)
        {
            aggregateExtensionGrantValidator = new ExtensionGrantValidator(new[] { new TestGrantValidator() }, TestLogger.Create <ExtensionGrantValidator>());
        }
        else
        {
            aggregateExtensionGrantValidator = new ExtensionGrantValidator(extensionGrantValidators, TestLogger.Create <ExtensionGrantValidator>());
        }

        if (authorizationCodeStore == null)
        {
            authorizationCodeStore = CreateAuthorizationCodeStore();
        }

        if (refreshTokenStore == null)
        {
            refreshTokenStore = CreateRefreshTokenStore();
        }

        if (resourceValidator == null)
        {
            resourceValidator = CreateResourceValidator(resourceStore);
        }

        if (refreshTokenService == null)
        {
            refreshTokenService = CreateRefreshTokenService(
                refreshTokenStore,
                profile);
        }

        return(new TokenRequestValidator(
                   options,
                   issuerNameService,
                   authorizationCodeStore,
                   resourceOwnerValidator,
                   profile,
                   deviceCodeValidator,
                   backchannelAuthenticationRequestIdValidator,
                   aggregateExtensionGrantValidator,
                   customRequestValidator,
                   resourceValidator,
                   resourceStore,
                   refreshTokenService,
                   new TestEventService(),
                   new StubClock(),
                   TestLogger.Create <TokenRequestValidator>()));
    }
Пример #9
0
    public static AuthorizeRequestValidator CreateAuthorizeRequestValidator(
        IdentityServerOptions options        = null,
        IIssuerNameService issuerNameService = null,
        IResourceStore resourceStore         = null,
        IClientStore clients    = null,
        IProfileService profile = null,
        ICustomAuthorizeRequestValidator customValidator = null,
        IRedirectUriValidator uriValidator               = null,
        IResourceValidator resourceValidator             = null,
        JwtRequestValidator jwtRequestValidator          = null,
        IJwtRequestUriHttpClient jwtRequestUriHttpClient = null)
    {
        if (options == null)
        {
            options = TestIdentityServerOptions.Create();
        }

        if (issuerNameService == null)
        {
            issuerNameService = new TestIssuerNameService(options.IssuerUri);
        }

        if (resourceStore == null)
        {
            resourceStore = new InMemoryResourcesStore(TestScopes.GetIdentity(), TestScopes.GetApis(), TestScopes.GetScopes());
        }

        if (clients == null)
        {
            clients = new InMemoryClientStore(TestClients.Get());
        }

        if (customValidator == null)
        {
            customValidator = new DefaultCustomAuthorizeRequestValidator();
        }

        if (uriValidator == null)
        {
            uriValidator = new StrictRedirectUriValidator();
        }

        if (resourceValidator == null)
        {
            resourceValidator = CreateResourceValidator(resourceStore);
        }

        if (jwtRequestValidator == null)
        {
            jwtRequestValidator = new JwtRequestValidator("https://identityserver", new LoggerFactory().CreateLogger <JwtRequestValidator>());
        }

        if (jwtRequestUriHttpClient == null)
        {
            jwtRequestUriHttpClient = new DefaultJwtRequestUriHttpClient(new HttpClient(new NetworkHandler(new Exception("no jwt request uri response configured"))), options, new LoggerFactory(), new NoneCancellationTokenProvider());
        }


        var userSession = new MockUserSession();

        return(new AuthorizeRequestValidator(
                   options,
                   issuerNameService,
                   clients,
                   customValidator,
                   uriValidator,
                   resourceValidator,
                   userSession,
                   jwtRequestValidator,
                   jwtRequestUriHttpClient,
                   TestLogger.Create <AuthorizeRequestValidator>()));
    }
Пример #10
0
    public static DeviceAuthorizationRequestValidator CreateDeviceAuthorizationRequestValidator(
        IdentityServerOptions options        = null,
        IResourceStore resourceStore         = null,
        IResourceValidator resourceValidator = null)
    {
        if (options == null)
        {
            options = TestIdentityServerOptions.Create();
        }

        if (resourceStore == null)
        {
            resourceStore = new InMemoryResourcesStore(TestScopes.GetIdentity(), TestScopes.GetApis(), TestScopes.GetScopes());
        }

        if (resourceValidator == null)
        {
            resourceValidator = CreateResourceValidator(resourceStore);
        }


        return(new DeviceAuthorizationRequestValidator(
                   options,
                   resourceValidator,
                   TestLogger.Create <DeviceAuthorizationRequestValidator>()));
    }
Пример #11
0
 internal static IResourceValidator CreateResourceValidator(IResourceStore store = null)
 {
     store = store ?? new InMemoryResourcesStore(TestScopes.GetIdentity(), TestScopes.GetApis(), TestScopes.GetScopes());
     return(new DefaultResourceValidator(store, new DefaultScopeParser(TestLogger.Create <DefaultScopeParser>()), TestLogger.Create <DefaultResourceValidator>()));
 }
Пример #12
0
 public override void Initialize()
 {
     TestScopes.AddMenuAction(DisableSelectorValidationScopePart1);
     TestScopes.AddMenuAction(DisableSelectorValidationScopePart2);
 }
Пример #13
0
 protected BaseUnitTest(IDependencyProvider dependencyProvider)
 {
     _bigUnitBuilder = new BigUnitBuilder()
                       .WithTestScope(TestScopes.Class <T>())
                       .WithDependencyProvider(dependencyProvider);
 }
Пример #14
0
 protected BigUnitTest() : base(new NotImplementedDependencyProvider())
 {
     TestScope = TestScopes.Namespace <T>(NamespaceOptions.IncludeChildNamespaces);
 }