Ejemplo n.º 1
0
        private async Task TokenTests()
        {
            var secret1 = await _authenticatedVaultClient.CreateTokenAsync();

            Assert.NotNull(secret1);

            var secret2 = await _authenticatedVaultClient.CreateTokenAsync(new TokenCreationOptions { NoParent = true });

            Assert.NotNull(secret2);

            var accessors = await _authenticatedVaultClient.GetTokenAccessorListAsync();

            Assert.True(accessors.Data.Keys.Any());

            var tokenInfoByAccessor = await _authenticatedVaultClient.GetTokenInfoByAccessorAsync(accessors.Data.Keys.First());

            Assert.NotNull(tokenInfoByAccessor);

            await _authenticatedVaultClient.RevokeTokenByAccessorAsync(accessors.Data.Keys.First());

            var accessors2 = await _authenticatedVaultClient.GetTokenAccessorListAsync();

            Assert.True(accessors.Data.Keys.Count - 1 == accessors2.Data.Keys.Count);

            var secret3 = await _authenticatedVaultClient.CreateTokenAsync(new TokenCreationOptions { NoParent = true });

            Assert.NotNull(secret3);

            var callingTokenInfo = await _authenticatedVaultClient.GetCallingTokenInfoAsync();

            Assert.Equal(_masterCredentials.RootToken, callingTokenInfo.Data.Id);

            var tokenInfo1 = await _authenticatedVaultClient.GetTokenInfoAsync(secret1.AuthorizationInfo.ClientToken);

            Assert.Equal(secret1.AuthorizationInfo.ClientToken, tokenInfo1.Data.Id);

            var tokenInfo2 = await _authenticatedVaultClient.GetTokenInfoAsync(secret2.AuthorizationInfo.ClientToken);

            Assert.Equal(secret2.AuthorizationInfo.ClientToken, tokenInfo2.Data.Id);

            await _authenticatedVaultClient.RevokeTokenAsync(secret1.AuthorizationInfo.ClientToken, true);

            await Assert.ThrowsAsync <Exception>(() => _authenticatedVaultClient.GetTokenInfoAsync(secret1.AuthorizationInfo.ClientToken));

            // check if renewal of same token calls renew-self.
            // do it with lease id.

            // await _authenticatedVaultClient.RenewTokenAsync(_masterCredentials.RootToken);

            // renew calls need a lease id. raja todo
        }