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."); }
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)); }
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); }
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()); }
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()); }
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]); }
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"); }
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); }
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); }
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); }
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"); }
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()); }
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); }
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); }
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"); }
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()); }
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"); }
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); }
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); }
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."); }
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); }