Esempio n. 1
0
        public async Task SetJwt_ShouldSucceed()
        {
            string jwtToken        = null;
            string arangodbBaseUrl = $"http://{_fixture.ArangoDbHost}:8529/";

            using (var transport = HttpApiTransport.UsingNoAuth(
                       new Uri(arangodbBaseUrl),
                       nameof(HttpApiTransportTest)))
            {
                var authClient = new AuthApiClient(transport);

                var jwtTokenResponse = await authClient.GetJwtTokenAsync(
                    new JwtTokenRequestBody
                {
                    Username = _fixture.Username,
                    Password = _fixture.Password
                });

                jwtToken = jwtTokenResponse.Jwt;

                // Use token in current transport
                transport.SetJwtToken(jwtToken);
                var databaseApi = new DatabaseApiClient(transport);

                var userDatabasesResponse = await databaseApi.GetUserDatabasesAsync();

                Assert.NotEmpty(userDatabasesResponse.Result);
            }
        }
Esempio n. 2
0
        public async Task UsingJwtAuth_ShouldSucceed()
        {
            string jwtToken        = null;
            string arangodbBaseUrl = $"http://{_fixture.ArangoDbHost}:8529/";

            using (var transport = HttpApiTransport.UsingNoAuth(
                       new Uri(arangodbBaseUrl),
                       nameof(HttpApiTransportTest)))
            {
                var authClient = new AuthApiClient(transport);
                authClient.ThrowErrorsAsExceptions = true;

                var jwtTokenResponse = await authClient.GetJwtTokenAsync(
                    new JwtTokenRequestBody
                {
                    Username = _fixture.Username,
                    Password = _fixture.Password
                });

                jwtToken = jwtTokenResponse.Jwt;

                DatabaseApiClient databaseApi = new DatabaseApiClient(transport)
                {
                    ThrowErrorsAsExceptions = true
                };

                // Not authorized, should throw.
                var ex = await Assert.ThrowsAsync <ApiErrorException>(async() =>
                                                                      await databaseApi.GetCurrentDatabaseInfoAsync());
            }

            // Use token in a new transport created via `UsingJwtAuth`.
            using (var transport = HttpApiTransport.UsingJwtAuth(
                       new Uri(arangodbBaseUrl),
                       nameof(HttpApiTransportTest),
                       jwtToken))
            {
                var databaseApi           = new DatabaseApiClient(transport);
                var userDatabasesResponse = await databaseApi.GetUserDatabasesAsync();

                Assert.NotEmpty(userDatabasesResponse.Results);
            }
        }