Ejemplo n.º 1
0
        public async Task SecretInfo_Success()
        {
            string           secretName = _uniqueKey.GetKey("SIS");
            VaultSecretEntry secretA    = new VaultSecretEntry(_noCASMount, secretName, "");

            secretA.Attributes.Add("KeyA", "ValueA");
            bool success = await secretA.VSE_Save();

            Assert.IsTrue(success);

            // Update Secret and save 2x, to create multiple versions
            secretA.Attributes.Add("KeyB", "ValueB");
            success = await secretA.VSE_Save();

            Assert.IsTrue(success, "A20: 2nd Save Failed");

            // Update Secret and save 2x, to create multiple versions
            secretA.Attributes.Add("KeyC", "ValueC");
            success = await secretA.VSE_Save();

            Assert.IsTrue(success, "A30: 3rd Save Failed");


            // Get secret Info
            success = await secretA.VSE_Info();

            Assert.IsTrue(success, "A40:  Retrieval of Secret Info failed");
            Assert.AreEqual(3, secretA.Info.Versions.Count, "A50:  Number of versions was unexpected");
            Assert.AreEqual(3, secretA.Info.CurrentVersion, "A60:  Current Version of Secret was incorrect.");
        }
Ejemplo n.º 2
0
        public void BoolAttributeGet_Success(string value, bool expectedValue)
        {
            string           attrName = "AttrB";
            VaultSecretEntry vseA     = new VaultSecretEntry();

            vseA.Attributes [attrName] = value;
            Assert.AreEqual(expectedValue, vseA.GetBoolAttributeDefault(attrName));
        }
Ejemplo n.º 3
0
        public async Task Save_Success()
        {
            string           secretName = _uniqueKey.GetKey("SN");
            VaultSecretEntry secretA    = new VaultSecretEntry(_noCASMount, secretName, "");
            bool             success    = await secretA.VSE_Save();

            Assert.IsTrue(success);
        }
Ejemplo n.º 4
0
        public async Task Exists_ReturnsFalse_IfSecretDoesNotExist()
        {
            string           secretName = _uniqueKey.GetKey("SNExistsF");
            VaultSecretEntry secretA    = new VaultSecretEntry(_noCASMount, secretName, "");

            // Now see if it exists in the Vault.
            Assert.IsFalse(await secretA.VSE_Exists());
        }
Ejemplo n.º 5
0
        public async Task VSE_Read_ThrowsError_IfEngineNotDefined()
        {
            string           secretName = _uniqueKey.GetKey("Des");
            VaultSecretEntry secretA    = new VaultSecretEntry();

            secretA.Name = "test";
            secretA.Attributes.Add("KeyA", "ValueA");
            Assert.ThrowsAsync <ApplicationException>(() => secretA.VSE_Save());
        }
Ejemplo n.º 6
0
        public void BoolAttributeSet_Success(bool value, string expectedValue)
        {
            string           attrName = "boolA";
            VaultSecretEntry vseA     = new VaultSecretEntry();

            // Save Value
            vseA.SetBoolAttribute(attrName, value);

            Assert.AreEqual(expectedValue, vseA.Attributes[attrName]);
        }
Ejemplo n.º 7
0
        public async Task Read_Failure()
        {
            string secretName = _uniqueKey.GetKey("SNRead");

            // Now create a new VSE with same name and path.  We should be able to read it from Vault and get the same secret as the one we just saved
            VaultSecretEntry secretB = new VaultSecretEntry(_noCASMount, secretName, "");
            bool             success = await secretB.VSE_Read();

            Assert.IsFalse(success, "A10:Failed to successfull read the secret back");
        }
Ejemplo n.º 8
0
        public void ShortAttributeSet_Success(short value)
        {
            string           attrName = "AttrA";
            VaultSecretEntry vseA     = new VaultSecretEntry();

            // Save value
            vseA.SetShortAttribute(attrName, value);

            string lookupValue = vseA.Attributes[attrName];

            Assert.AreEqual(value.ToString(), lookupValue);
        }
Ejemplo n.º 9
0
        public void StringAttributeGetNullable_ReturnsEmpty()
        {
            string           attrName = "AttrA";
            VaultSecretEntry vseA     = new VaultSecretEntry();

            // We do not save anything in the Attributes, to force a null

            // Get Value
            string answer = vseA.GetStringAttributeDefault(attrName);

            Assert.IsEmpty(answer);
        }
Ejemplo n.º 10
0
        public void DateTimeOffsetAttributeGetNullable_ReturnsNull()
        {
            string           attrName = "AttrA";
            VaultSecretEntry vseA     = new VaultSecretEntry();

            // We do not save anything in the Attributes, to force a null

            // Get Value
            DateTimeOffset?answer = vseA.GetDateTimeOffsetAttributeNullable(attrName);

            Assert.IsNull(answer);
        }
Ejemplo n.º 11
0
        public void CreateWithNoSecretEngine()
        {
            string secretName = _uniqueKey.GetKey("CWNSE");
            string path       = "pathB";

            VaultSecretEntry secretA = new VaultSecretEntry(secretName, path);

            Assert.AreEqual(secretName, secretA.Name, "A10:  Secret Name incorrect");
            Assert.AreEqual(path, secretA.Path, "A20: Secret Path incorrect ");
            secretA.SecretEngine = _noCASMount;
            Assert.AreEqual(_noCASMount.Name, secretA.SecretEngine.Name, "A30:  Secret Engine Mount is not same as SecretEngine");
        }
Ejemplo n.º 12
0
        public async Task Exists_ReturnsTrue_IfSecretExists()
        {
            string           secretName = _uniqueKey.GetKey("SNExistsT");
            VaultSecretEntry secretA    = new VaultSecretEntry(_noCASMount, secretName, "");

            secretA.Attributes.Add("KeyA", "ValueA");
            bool success = await secretA.VSE_Save();

            Assert.IsTrue(success);

            // Now see if it exists in the Vault.
            Assert.IsTrue(await secretA.VSE_Exists());
        }
Ejemplo n.º 13
0
        public void ShortAttributeGetNullable_Success(short value)
        {
            string           attrName = "AttrA";
            VaultSecretEntry vseA     = new VaultSecretEntry();

            // Save value
            vseA.SetIntAttribute(attrName, value);

            // Get Value
            int?answer = vseA.GetIntAttributeNullable(attrName);

            Assert.NotNull(answer, "A10:  Expected a number, not a Null value");
            Assert.AreEqual(value, answer);
        }
Ejemplo n.º 14
0
        public void StringAttributeGet_ReturnsValue()
        {
            string attrName = "AttrA";
            string value    = "abcXYZ";

            VaultSecretEntry vseA = new VaultSecretEntry();

            vseA.Attributes [attrName] = value;

            // Get Value
            string answer = vseA.GetStringAttributeDefault(attrName);

            Assert.AreEqual(value, answer);
        }
Ejemplo n.º 15
0
        public void DateTimeOffsetGetNullable_ReturnsNullOnEmptyString_Success()
        {
            string attrName = "AttrA";
            string value    = "";

            VaultSecretEntry vseA = new VaultSecretEntry();

            vseA.Attributes[attrName] = value;


            // Get Value
            DateTimeOffset?answer = vseA.GetDateTimeOffsetAttributeNullable(attrName);

            Assert.IsNull(answer, "A10:  Expected a null value when string is empty");
        }
Ejemplo n.º 16
0
        public async Task DestroyAllSuccess()
        {
            string           secretName = _uniqueKey.GetKey("Des");
            VaultSecretEntry secretA    = new VaultSecretEntry(_noCASMount, secretName, "");

            secretA.Attributes.Add("KeyA", "ValueA");
            bool success = await secretA.VSE_Save();

            Assert.IsTrue(success);

            // Now Destory All it
            Assert.IsTrue(await secretA.VSE_DestroyAll());

            // Try to read it
            Assert.IsFalse(await secretA.VSE_Read());
        }
Ejemplo n.º 17
0
        public async Task ConstructorTests(string scenario, string name, string path, string expectedName, string expectedPath, string expectedFullPath)
        {
            VaultSecretEntry vse = null;

            if (path == null)
            {
                vse = new VaultSecretEntry(_noCASMount, name);
            }
            else
            {
                vse = new VaultSecretEntry(_noCASMount, name, path);
            }

            Assert.AreEqual(expectedName, vse.Name, "A10");
            Assert.AreEqual(expectedPath, vse.Path, "A20");
            Assert.AreEqual(expectedFullPath, vse.FullPath, "A30");
        }
Ejemplo n.º 18
0
        public async Task Read_Success()
        {
            string           secretName = _uniqueKey.GetKey("SNRead");
            VaultSecretEntry secretA    = new VaultSecretEntry(_noCASMount, secretName, "");

            secretA.Attributes.Add("KeyA", "ValueA");
            bool success = await secretA.VSE_Save();

            Assert.IsTrue(success);

            // Now create a new VSE with same name and path.  We should be able to read it from Vault and get the same secret as the one we just saved
            VaultSecretEntry secretB = new VaultSecretEntry(_noCASMount, secretName, "");

            success = await secretB.VSE_Read();

            Assert.IsTrue(success, "A20:Failed to successfull read the secret back");
            Assert.AreEqual(secretA.Attributes.Count, secretB.Attributes.Count);
        }
Ejemplo n.º 19
0
        public void DateTimeOffsetAttributeGetDefault_Success(long value)
        {
            string           attrName = "AttrA";
            VaultSecretEntry vseA     = new VaultSecretEntry();

            DateTimeOffset aDate = new DateTimeOffset();

            aDate = DateTimeOffset.FromUnixTimeSeconds(value);

            // Save value
            vseA.SetDateTimeOffsetAttribute(attrName, aDate);

            // Get Value
            DateTimeOffset answer = vseA.GetDateTimeOffsetAttributeDefault(attrName);

            Assert.NotNull(answer, "A10:  Expected a DateTime, not a Null value");

            long unixTimeSeconds = answer.ToUnixTimeSeconds();

            Assert.AreEqual(value, unixTimeSeconds);
        }
Ejemplo n.º 20
0
        public async Task VSE_ReadVersion_Success()
        {
            string           secretName = _uniqueKey.GetKey("RV");
            VaultSecretEntry secretA    = new VaultSecretEntry(_noCASMount, secretName, "");

            secretA.Attributes.Add("KeyA", "ValueA");
            bool success = await secretA.VSE_Save();

            Assert.IsTrue(success);
            int version1 = secretA.Version;

            Assert.AreEqual(1, version1, "A01:  First Save of Secret did not yield a version number of 1");


            // Update Secret and save to create multiple versions
            secretA.Attributes.Add("KeyB", "ValueB");
            success = await secretA.VSE_Save();

            Assert.IsTrue(success, "A20: 2nd Save Failed");

            // Update Secret and save 2x, to create multiple versions
            secretA.Attributes.Add("KeyC", "ValueC");
            success = await secretA.VSE_Save();

            Assert.IsTrue(success, "A30: 3rd Save Failed");

            // Read Version 1.
            success = await secretA.VSE_ReadVersion(version1);

            Assert.IsTrue(success, "A32: Read of specific version did not work");
            Assert.AreEqual(1, secretA.Attributes.Count, "A34:  Attribute count was not expected value.  Appears we did not read back the version we expected.");


            // Get secret Info
            success = await secretA.VSE_Info();

            Assert.IsTrue(success, "A40:  Retrieval of Secret Info failed");
            Assert.AreEqual(3, secretA.Info.Versions.Count, "A50:  Number of versions was unexpected");
            Assert.AreEqual(3, secretA.Info.CurrentVersion, "A60:  Current Version of Secret was incorrect.");
        }
Ejemplo n.º 21
0
        public void DateTimeOffsetSet_Success()
        {
            // 1/27/2020 1:50:35 PM GMT

            // Validate the date is correct
            Assert.AreEqual(1, _theDate.Month);
            Assert.AreEqual(27, _theDate.Day);
            Assert.AreEqual(2020, _theDate.Year);
            Assert.AreEqual(13, _theDate.Hour);
            Assert.AreEqual(50, _theDate.Minute);
            Assert.AreEqual(35, _theDate.Second);


            string           attrName = "AttrA";
            VaultSecretEntry vseA     = new VaultSecretEntry();

            // Save value
            vseA.SetDateTimeOffsetAttribute(attrName, _theDate);

            string lookupValue = vseA.Attributes[attrName];

            Assert.AreEqual(_unixEpochTime.ToString(), lookupValue);
        }