public async Task Handle_error(string id_, string jwtResponse, Type expectedExceptionType, int expectedCode, int expectedStatus, string expectedMessage, string expectedDeveloperMessage)
        {
            var testApiKey = ClientApiKeys.Builder()
                             .SetId("2EV70AHRTYF0JOA7OEFO3SM29")
                             .SetSecret("goPUHQMkS4dlKwl5wtbNd91I+UrRehCsEDJrIrMruK8")
                             .Build();
            var fakeRequestExecutor = Substitute.For <IRequestExecutor>();

            fakeRequestExecutor.ApiKey.Returns(testApiKey);

            this.dataStore = TestDataStore.Create(fakeRequestExecutor, Caches.NewInMemoryCacheProvider().Build());

            var request = new DefaultHttpRequest(HttpMethod.Get, new CanonicalUri($"https://foo.bar?{IdSiteClaims.JwtResponse}={jwtResponse}"));

            IIdSiteAsyncCallbackHandler callbackHandler = new DefaultIdSiteAsyncCallbackHandler(this.dataStore, request);

            try
            {
                var accountResult = await callbackHandler.GetAccountResultAsync(CancellationToken.None);

                throw new Exception("Should not reach here. Proper exception was not thrown.");
            }
            catch (IdSiteRuntimeException e) when(expectedExceptionType.IsAssignableFrom(e.GetType()))
            {
                e.Code.ShouldBe(expectedCode);
                e.HttpStatus.ShouldBe(expectedStatus);
                e.Message.ShouldBe(expectedMessage);
                e.DeveloperMessage.ShouldBe(expectedDeveloperMessage);
            }
            catch (Exception e) when(expectedExceptionType.IsAssignableFrom(e.GetType()))
            {
                e.Message.ShouldStartWith(expectedMessage);
            }
        }
        public static IClientApiKey GetApiKey()
        {
            // Expect that API keys are in environment variables. (works with travis-ci)
            var apiKey = ClientApiKeys.Builder().Build();

            apiKey.IsValid().ShouldBe(true, "These integration tests look for a valid API Key and Secret in your local environment variables.");
            return(apiKey);
        }
Example #3
0
        public DefaultIdSiteUrlBuilder_tests()
        {
            this.fakeJtiProvider = Substitute.For <IIdSiteJtiProvider>();
            this.fakeJtiProvider.NewJti().Returns(this.fakeJti);

            this.fakeClock = Substitute.For <IClock>();
            this.fakeClock.Now.Returns(this.fakeNow);

            var testApiKey = ClientApiKeys.Builder()
                             .SetId(FakeApiKeyId)
                             .SetSecret(FakeApiKeySecret)
                             .Build();

            this.fakeClient = Clients.Builder()
                              .SetApiKey(testApiKey)
                              .Build();
        }
        private static IInternalDataStore GetFakeDataStore()
        {
            var fakeApiKey = ClientApiKeys.Builder()
                             .SetId("fake_api_key")
                             .SetSecret("fake_secret")
                             .Build();

            var stubClient = Clients.Builder()
                             .SetApiKey(fakeApiKey)
                             .Build();

            var fakeDataStore = TestDataStore.Create(
                requestExecutor: new StubRequestExecutor(FakeJson.Application, fakeApiKey).Object,
                client: stubClient);

            return(fakeDataStore);
        }
Example #5
0
        public void Handle_response(string id_, string jwtResponse, string expectedStatus, bool isNewAccount, string expectedState)
        {
            IAccountResult accountResultFromListener = null;

            var listener = new InlineIdSiteSyncResultListener(
                onAuthenticated: result =>
            {
                if (expectedStatus == IdSiteResultStatus.Authenticated)
                {
                    accountResultFromListener = result;
                }
                else
                {
                    throw new InvalidOperationException("This method should not have been executed");
                }
            },
                onLogout: result =>
            {
                if (expectedStatus == IdSiteResultStatus.Logout)
                {
                    accountResultFromListener = result;
                }
                else
                {
                    throw new InvalidOperationException("This method should not have been executed");
                }
            },
                onRegistered: result =>
            {
                if (expectedStatus == IdSiteResultStatus.Registered)
                {
                    accountResultFromListener = result;
                }
                else
                {
                    throw new InvalidOperationException("This method should not have been executed");
                }
            });

            var testApiKey          = ClientApiKeys.Builder().SetId("2EV70AHRTYF0JOA7OEFO3SM29").SetSecret("goPUHQMkS4dlKwl5wtbNd91I+UrRehCsEDJrIrMruK8").Build();
            var fakeRequestExecutor = Substitute.For <IRequestExecutor>();

            fakeRequestExecutor.ApiKey.Returns(testApiKey);

            this.dataStore = TestDataStore.Create(fakeRequestExecutor, Caches.NewInMemoryCacheProvider().Build());

            var request = new DefaultHttpRequest(HttpMethod.Get, new CanonicalUri($"https://foo.bar?{IdSiteClaims.JwtResponse}={jwtResponse}"));

            IIdSiteSyncCallbackHandler callbackHandler = new DefaultIdSiteSyncCallbackHandler(this.dataStore, request);

            callbackHandler.SetResultListener(listener);

            var accountResult = callbackHandler.GetAccountResult();

            // Validate result
            (accountResult as DefaultAccountResult).Account.Href.ShouldBe("https://api.stormpath.com/v1/accounts/7Ora8KfVDEIQP38KzrYdAs");
            (accountResultFromListener as DefaultAccountResult).Account.Href.ShouldBe("https://api.stormpath.com/v1/accounts/7Ora8KfVDEIQP38KzrYdAs");

            accountResult.IsNewAccount.ShouldBe(isNewAccount);
            accountResultFromListener.IsNewAccount.ShouldBe(isNewAccount);

            accountResult.State.ShouldBe(expectedState);
            accountResultFromListener.State.ShouldBe(expectedState);

            var expectedResultStatus = IdSiteResultStatus.Parse(expectedStatus);

            accountResult.Status.ShouldBe(expectedResultStatus);
            accountResultFromListener.Status.ShouldBe(expectedResultStatus);
        }
Example #6
0
 public DefaultClientBuilder(IUserAgentBuilder userAgentBuilder)
 {
     this.userAgentBuilder    = userAgentBuilder;
     this.clientApiKeyBuilder = ClientApiKeys.Builder();
 }