private static async Task InitAsync()
        {
            var mailService = new MockMailService(
                (templateName, toAddress, toName, fromAddress, fromName,
                 subject, substitutionsSingle) => true.ToTask());
            var timeService = new BlackBarLabs.Api.Tests.Mocks.MockTimeService();
            var httpConfig  = new HttpConfiguration();

            EastFive.Api.Services.ServiceConfiguration.Initialize(httpConfig,
                                                                  () => mailService, () => timeService);
            var authProviderMock = new EastFive.Api.Tests.ProvideLoginMock();

            Assert.IsTrue(
                await ServiceConfiguration.InitializeAsync(authProviderMock, httpConfig,
                                                           new Func <
                                                               Func <IProvideAuthorization, IProvideAuthorization[]>,
                                                               Func <EastFive.Security.SessionServer.IProvideAuthorization[]>,
                                                               Func <string, EastFive.Security.SessionServer.IProvideAuthorization[]>,
                                                               Task <EastFive.Security.SessionServer.IProvideAuthorization[]> >[]
            {
                ProvideLoginMock.InitializeAsync,
            },
                                                           null,
                                                           null,
                                                           () => true,
                                                           (why) =>
            {
                Assert.Fail(why);
                return(false);
            }));
        }
        public static Redirection GetResponse(string userKey)
        {
            var token = ProvideLoginMock.GetToken(userKey);

            return(new Redirection()
            {
                token = token,
            });
        }
Esempio n. 3
0
        public async Task <Session> LoginAsync(
            Func <Task <Guid> > setupAccountAsync)
        {
            #region Get mock login method

            var accountId = Guid.Empty;

            this.AzureApplication
            .AddOrUpdateInstantiation(typeof(ProvideLoginMock),
                                      (app) =>
            {
                var loginMock        = new ProvideLoginAccountMock();
                loginMock.MapAccount =
                    async(externalKey, extraParameters, authenticationInner, authorization,
                          baseUri, webApiApplication,
                          onCreatedMapping,
                          onAllowSelfServeAccounts,
                          onInterceptProcess,
                          onNoChange) =>
                {
                    accountId = await setupAccountAsync();
                    return(onCreatedMapping(accountId));
                };
                return(loginMock.AsTask <object>());
            });

            var mockAuthenticationMethod = await this
                                           .GetRequest <Method>()
                                           .GetAsync(
                onContents:
                authentications =>
            {
                var matchingAuthentications = authentications
                                              .Where(auth => auth.name == ProvideLoginMock.IntegrationName);
                Assert.IsTrue(matchingAuthentications.Any());
                return(matchingAuthentications.First());
            });

            #endregion

            #region Perform direct link as fastest method for account construction

            var externalSystemUserId = Guid.NewGuid().ToString().Substring(0, 8);
            var responseResource     = ProvideLoginMock.GetResponse(externalSystemUserId);
            var invocation           = this;
            this.SessionMaybe = await await this
                                .GetRequest <EastFive.Api.Tests.Redirection>()
                                .Where(externalSystemUserId)
                                .GetAsync(
                onRedirect:
                async(urlRedirect) =>
            {
                var authIdStr = urlRedirect.GetQueryParam(EastFive.Api.Azure.AzureApplication.QueryRequestIdentfier);
                var authId    = Guid.Parse(authIdStr);
                var authIdRef = authId.AsRef <EastFive.Azure.Auth.Authorization>();

                // TODO: New comms here?
                return(await await invocation
                       .GetRequest <EastFive.Azure.Auth.Authorization>()
                       .Where(auth => auth.authorizationRef == authIdRef)
                       .GetAsync(
                           onContent:
                           (authenticatedAuthorization) =>
                {
                    var session = new Session
                    {
                        sessionId = Guid.NewGuid().AsRef <Session>(),
                        authorization = authenticatedAuthorization.authorizationRef.Optional(),
                    };
                    return invocation.GetRequest <Session>()
                    .PostAsync(session,
                               onCreatedBody:
                               (updated, contentType) =>
                    {
                        return updated;
                    });
                }));
            });

            //Assert.AreEqual(accountId, authorizationToAthenticateSession.account.Value);

            #endregion

            this.Headers.Add(this.SessionMaybe.Value.HeaderName, this.SessionMaybe.Value.token);
            this.AccountIdMaybe = this.SessionMaybe.Value.account;

            return(this.SessionMaybe.Value);
        }