Esempio n. 1
0
        public static async Task <InvokeTestApplication> InitUserAsync(
            Func <Task <Guid> > setupAccountAsync)
        {
            var invocation = InvokeTestApplication.Init();
            await invocation.LoginAsync(setupAccountAsync);

            return(invocation);
        }
        public void AccessTokenAccountWorks()
        {
            var httpApp = InvokeTestApplication.Init();
            var queryId = Guid.NewGuid();

            var query = httpApp
                        .GetRequest <UrlGeneration.QueryableResource>()
                        .ById(queryId)
                        .Where(qr => qr.text == "match")
                        .Where(qr => !qr.dtOptional.HasValue)
                        .Location();
            var sessionId     = Guid.NewGuid();
            var accountId     = Guid.NewGuid();
            var duration      = TimeSpan.FromSeconds(15);
            var expirationUtc = DateTime.UtcNow + duration;

            Assert.IsTrue(query.SignWithAccessTokenAccount(sessionId, accountId, expirationUtc,
                                                           (signedUrl) =>
            {
                Assert.IsTrue(signedUrl.ValidateAccessTokenAccount(
                                  accessToken =>
                {
                    Assert.AreEqual(sessionId, accessToken.sessionId);
                    Assert.AreEqual(accountId, accessToken.accountId);
                    Assert.IsTrue(Math.Abs((expirationUtc - accessToken.expirationUtc).TotalSeconds) < 2);
                    return(true);
                },
                                  () => false,
                                  () => false));

                Assert.IsTrue(query.ValidateAccessTokenAccount(
                                  (accessToken) => false,
                                  onAccessTokenNotProvided: () => true,
                                  onAccessTokenInvalid: () => false,
                                  onAccessTokenExpired: () => false,
                                  onInvalidSignature: () => false));

                var changedUrl = signedUrl.SetQueryParam(UrlGeneration.QueryableResource.StringPropertyName, "match_diff");
                Assert.IsTrue(changedUrl.ValidateAccessTokenAccount(
                                  (accessToken) => false,
                                  onAccessTokenNotProvided: () => false,
                                  onAccessTokenInvalid: () => false,
                                  onAccessTokenExpired: () => false,
                                  onInvalidSignature: () => true));

                Thread.Sleep(duration + TimeSpan.FromSeconds(1));
                Assert.IsTrue(signedUrl.ValidateAccessTokenAccount(
                                  (accessToken) => false,
                                  onAccessTokenNotProvided: () => false,
                                  onAccessTokenInvalid: () => false,
                                  onAccessTokenExpired: () => true,
                                  onInvalidSignature: () => false));

                return(true);
            }));
        }
Esempio n. 3
0
        public void GenerateUrls()
        {
            var httpApp    = InvokeTestApplication.Init();
            var queryId    = Guid.NewGuid();
            var queryIdStr = queryId.ToString("N");

            var query = httpApp
                        .GetRequest <QueryableResource>()
                        .ById(queryId)
                        //.Where(qr => qr.queryableRef == queryId.AsRef<QueryableResource>())
                        .Where(qr => qr.text == "match")
                        .Where(qr => !qr.dtOptional.HasValue)
                        .Location();

            Assert.AreEqual(
                $"http://example.com/api/MyQueryableResource/{queryIdStr}?string=match&dtOptional=null",
                query.AbsoluteUri);

            //var invocationMessage = await httpApp
            //    .GetRequest<QueryableResource>()
            //    .Where(qr => qr.queryableRef == queryId.AsRef<QueryableResource>())
            //    .FunctionAsync();
        }