示例#1
0
        public async Task ReadSecretID_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 - GenerateSecretID with True setting performs the ReadSecret
            AppRoleSecret appRoleSecret = await _appRoleAuthEngine.GenerateSecretID(roleA.Name, false, metadata);

            Assert.NotNull(appRoleSecret, "A10:  appRoleSecret was null.");
            Assert.IsNotEmpty(appRoleSecret.ID, "A20:  Secret ID was empty.");
            Assert.IsNotEmpty(appRoleSecret.Accessor, "A30:  Secret Accessor was not set to a valid value");

            // Now read the secret back.
            AppRoleSecret secretFull = await _appRoleAuthEngine.ReadSecretID(roleA.Name, appRoleSecret.ID);

            Assert.AreEqual(appRoleSecret.ID, secretFull.ID, "A40:  Secret ID's were not the same");
            CollectionAssert.AreEquivalent(metadata, secretFull.Metadata, "A50:  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);
            }
        }