コード例 #1
0
        public async Task ChangingToken_ChangesHTTPHeaders()
        {
            // Get current token:
            Token currentToken = await vault.RefreshActiveToken();

            // We will need to create a new token.
            TokenAuthEngine  _tokenAuthEngine = (TokenAuthEngine)vault.ConnectAuthenticationBackend(EnumBackendTypes.A_Token);
            TokenNewSettings tokenNewSettings = new TokenNewSettings();

            tokenNewSettings.Name         = "NewToken";
            tokenNewSettings.MaxTTL       = "60s";
            tokenNewSettings.NumberOfUses = 14;

            Token newToken = await _tokenAuthEngine.CreateToken(tokenNewSettings);

            Assert.NotNull(newToken, "A1:  Created a token, expected it to not be null.");
            Assert.AreNotEqual(currentToken.ID, newToken.ID);

            // Now set token.
            vault.Token = newToken;

            // Now retrieve the current token.  This will force it to go back to the Vault instance with the new token.  should be the same as newToken.
            Token newCurrentToken = await vault.RefreshActiveToken();

            Assert.AreEqual(newToken.ID, newCurrentToken.ID);
            Assert.AreNotEqual(currentToken.ID, newCurrentToken.ID);
        }
コード例 #2
0
        public async Task RevokeSelfTokenSucceeds()
        {
            VaultAgentAPI v1 = await VaultServerRef.ConnectVault("TempVault");

            //new VaultAgentAPI("TempVault", VaultServerRef.ipAddress, VaultServerRef.ipPort, VaultServerRef.rootToken);
            string tokenName = UK.GetKey("tmpTok");

            // Create a new token.
            TokenNewSettings tokenNewSettings = new TokenNewSettings()
            {
                Name = tokenName,
            };

            Token token = await _tokenAuthEngine.CreateToken(tokenNewSettings);

            Assert.NotNull(token, "A1:  Error creating a new token - expected to receive the new token back, instead we received a null value.");

            // Now set vault to use the new token.
            v1.Token = token;
            Assert.AreNotEqual(VaultServerRef.rootToken, token.ID, "A2:  Expected the Vault object to have a different token.  But was still set at initial token.");

            // And then revoke.
            Assert.IsTrue(await v1.RevokeActiveToken());
            Assert.IsNull(v1.Token);

            // Now try and reset the Vault to use the old token. It should fail.
            v1.Token = token;
            Assert.ThrowsAsync <VaultForbiddenException> (async() => await v1.RefreshActiveToken());
        }