示例#1
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());
        }