示例#1
0
        public async Task GenerateSecret_WithMetaData_Success()
        {
            string  rName = _uniqueKeys.GetKey("Role");
            AppRole roleA = new AppRole(rName);

            Assert.True(await _appRoleAuthEngine.SaveRole(roleA));


            // Build a Meta Data object
            Dictionary <string, string> metadata = new Dictionary <string, string>()
            {
                { "testKey", "dev" },
                { "Name", "Bob Jones" }
            };


            // Get a secret for it
            AppRoleSecret appRoleSecret = await _appRoleAuthEngine.GenerateSecretID(roleA.Name, true, metadata);

            Assert.NotNull(appRoleSecret);
            Assert.IsNotEmpty(appRoleSecret.ID);
            Assert.IsNotEmpty(appRoleSecret.Accessor);
            CollectionAssert.AreEquivalent(metadata, appRoleSecret.Metadata, "A10:  Expected the 2 metadata collections to be the same.");

            TestContext.WriteLine("Auth Engine Mount Point:  {0}  |  Mount Point Path:  {1}", _appRoleAuthEngine.MountPoint, _appRoleAuthEngine.MountPointPath);
            TestContext.WriteLine("Role A:     {0}", roleA.Name);
            TestContext.WriteLine("Secret ID:  {0}", appRoleSecret.ID);
            foreach (KeyValuePair <string, string> a in appRoleSecret.Metadata)
            {
                TestContext.WriteLine("MetaData:   {0} - {1}", a.Key, a.Value);
            }
        }
示例#2
0
        public async Task AppRoleLoginConnector_Test()
        {
            // PRE-Test

            VaultSystemBackend vaultSystemBackend = new VaultSystemBackend(_vault.TokenID, _vault);
            string             approleMountName   = _UK.GetKey("AppAuth");

            // Create an AppRole authentication connection.
            AppRoleAuthEngine appRoleAuthEngine = (AppRoleAuthEngine)_vault.ConnectAuthenticationBackend(EnumBackendTypes.A_AppRole, "AppRole", approleMountName);


            // Create an Authentication method of App Role.	- This only needs to be done when the Auth method is created.
            AuthMethod am = new AuthMethod(approleMountName, EnumAuthMethods.AppRole);
            bool       rc = await vaultSystemBackend.AuthEnable(am);

            string  rName = _UK.GetKey("Role");
            AppRole roleA = new AppRole(rName);

            Assert.True(await appRoleAuthEngine.SaveRole(roleA));

            string roleID = await appRoleAuthEngine.ReadRoleID(roleA.Name);

            // Now create the a secret
            AppRoleSecret secret_A = await appRoleAuthEngine.GenerateSecretID(roleA.Name);


            // ACTUAL TEST
            // Create Login Connector
            AppRoleLoginConnector loginConnector = new AppRoleLoginConnector(_vault, approleMountName, "Test AppRole", roleID, secret_A.ID);
            bool result = await loginConnector.Connect(true);

            Assert.IsTrue(result, "A10:  Login Failed");
        }