public async Task Secret_DeleteSecret_FromSecretObject_Success() { // Create a Secret that has attributes. KeyValueSecret A = new KeyValueSecret(); KeyValuePair <string, string> kv1 = new KeyValuePair <string, string>("test", "testValue"); KeyValuePair <string, string> kv2 = new KeyValuePair <string, string>("abc", "123e"); KeyValuePair <string, string> kv3 = new KeyValuePair <string, string>("ZYX", "88g8g9dfkj df"); A.Attributes.Add(kv1.Key, kv1.Value); A.Attributes.Add(kv2.Key, kv2.Value); A.Attributes.Add(kv3.Key, kv3.Value); A.Path = await Secret_Init_Create(A); // Store path for later use. string thePath = A.Path; // Now delete secret. Should return True AND set secret to NULL. Assert.True(await _keyValueSecretEngine.DeleteSecret(A)); Assert.AreEqual("", A.Path); Assert.AreEqual(0, A.Attributes.Count); // Try to read the secret. Assert.Null(await _keyValueSecretEngine.ReadSecret(thePath)); }
public async Task Secret_UpdateSecret_Success() { KeyValueSecret A = new KeyValueSecret(); KeyValuePair <string, string> kv1 = new KeyValuePair <string, string>("test", "testValue"); KeyValuePair <string, string> kv2 = new KeyValuePair <string, string>("abc", "123e"); KeyValuePair <string, string> kv3 = new KeyValuePair <string, string>("ZYX", "88g8g9dfkj df"); A.Attributes.Add(kv1.Key, kv1.Value); A.Attributes.Add(kv2.Key, kv2.Value); A.Attributes.Add(kv3.Key, kv3.Value); A.Path = await Secret_Init_Create(A); KeyValueSecret A2 = await _keyValueSecretEngine.ReadSecret(A); Assert.AreEqual(A.Path, A2.Path); Assert.AreEqual(A.Attributes.Count + 1, A2.Attributes.Count); // Now lets change some values. A2.Attributes[kv1.Key] = kv1.Key; A2.Attributes[kv2.Key] = kv2.Key; A2.Attributes[kv3.Key] = kv3.Key; KeyValueSecret B = await _keyValueSecretEngine.UpdateSecret(A2); Assert.NotNull(B); Assert.AreEqual(A2.Attributes.Count, B.Attributes.Count); Assert.AreEqual(kv1.Key, B.Attributes[kv1.Key]); Assert.AreEqual(kv2.Key, B.Attributes[kv2.Key]); Assert.AreEqual(kv3.Key, B.Attributes[kv3.Key]); }
public async Task Secret_IfExists_IfNoSecret_ShouldReturnFalse() { string secret = Guid.NewGuid().ToString(); KeyValueSecret A = new KeyValueSecret(secret); Assert.False(await _keyValueSecretEngine.IfExists(A)); }
public async Task Secret_ListSecrets_WithSubSubSecrets_Success() { // Create a generic seceret object. KeyValueSecret z = new KeyValueSecret(); KeyValueSecret y = new KeyValueSecret(); try { // Create 2 secrets each with 2 sub secrets. string startPath = "Test/Level"; z.Path = startPath; for (int i = 1; i < 3; i++) { z.Path = startPath + "/Level" + i.ToString(); Assert.True(await _keyValueSecretEngine.CreateOrUpdateSecretAndReturn(z)); for (int j = 1; j < 3; j++) { y.Path = z.Path + "/SubLevel" + j.ToString(); Assert.True(await _keyValueSecretEngine.CreateOrUpdateSecretAndReturn(y)); } } // Now list those secrets List <string> secrets = await _keyValueSecretEngine.ListSecrets(startPath); Assert.AreEqual(4, secrets.Count); } catch (Exception e) { Console.WriteLine("Error - {0}", e.Message); } }
public async Task Secret_CreateSecret_FromJustSecretName_ReturnsSecretObject() { String secretName = "Test/D/myothersec"; KeyValueSecret B = await _keyValueSecretEngine.CreateOrUpdateSecret(secretName); Assert.NotNull(B); Assert.AreEqual(secretName, B.Path); }
private async Task <string> Secret_Init_Create(KeyValueSecret val) { string sec = _uniqueKeys.GetKey("SEC"); val.Path = sec; Assert.True(await _keyValueSecretEngine.CreateOrUpdateSecretAndReturn(val)); return(sec); }
public async Task Secret_IfExists_SecretExistsSecretPath_ShouldReturnTrue() { // Create a Secret. KeyValueSecret A = new KeyValueSecret(); A.Path = await Secret_Init_Create(A); Assert.True(await _keyValueSecretEngine.IfExists(A.Path)); }
public async Task Secret_CreateSecret_FromSecretObject_ReturnsTrue() { KeyValueSecret A = new KeyValueSecret(); string secretName = "Test/B/mysecret"; A.Path = secretName; Assert.True(await _keyValueSecretEngine.CreateOrUpdateSecretAndReturn(A)); }
public async Task Secret_ListSecrets_NoSubSecrets_Success() { KeyValueSecret A = new KeyValueSecret(); A.Path = await Secret_Init_Create(A); List <string> secrets = await _keyValueSecretEngine.ListSecrets(A.Path); Assert.AreEqual(0, secrets.Count); }
public async Task Secret_CreateSecret() { KeyValueSecret A = new KeyValueSecret(); string secretName = "Test/A/mysecret"; A.Path = secretName; A.Attributes.Add("conn", "db1-Myconn"); A.Attributes.Add("user", "dbuserAdmin"); Assert.True(await _keyValueSecretEngine.CreateOrUpdateSecretAndReturn(A)); }
public async Task Secret_ReadSecret_PassingSecretObject() { // Create a Secret. KeyValueSecret A = new KeyValueSecret(); KeyValuePair <string, string> kv1 = new KeyValuePair <string, string>("test", "testValue"); A.Attributes.Add(kv1.Key, kv1.Value); A.Path = await Secret_Init_Create(A); // Now read the secrt. KeyValueSecret B = await(_keyValueSecretEngine.ReadSecret(A)); Assert.NotNull(B); Assert.Contains(kv1.Key, B.Attributes.Keys); Assert.AreEqual(kv1.Value, B.Attributes.GetValueOrDefault(kv1.Key)); Assert.AreEqual(A.Path, B.Path); }
public async Task Secret_DeleteSecret_SpecifyingPath_Success() { // Create a Secret that has attributes. KeyValueSecret A = new KeyValueSecret(); KeyValuePair <string, string> kv1 = new KeyValuePair <string, string>("test", "testValue"); KeyValuePair <string, string> kv2 = new KeyValuePair <string, string>("abc", "123e"); KeyValuePair <string, string> kv3 = new KeyValuePair <string, string>("ZYX", "88g8g9dfkj df"); A.Attributes.Add(kv1.Key, kv1.Value); A.Attributes.Add(kv2.Key, kv2.Value); A.Attributes.Add(kv3.Key, kv3.Value); A.Path = await Secret_Init_Create(A); Assert.True(await _keyValueSecretEngine.DeleteSecret(A.Path)); // Try to read the secret. Assert.Null(await _keyValueSecretEngine.ReadSecret(A)); }
public async Task Secret_CreateSecret_Success() { String secretName = "Test/F/bkbk"; KeyValueSecret A = new KeyValueSecret(secretName); KeyValuePair <string, string> kv1 = new KeyValuePair <string, string>("user", "FredFlinstone"); KeyValuePair <string, string> kv2 = new KeyValuePair <string, string>("house", "rubbles"); A.Attributes.Add(kv1.Key, kv1.Value); A.Attributes.Add(kv2.Key, kv2.Value); KeyValueSecret secret = await _keyValueSecretEngine.CreateSecret(A); Assert.NotNull(secret); // 3 because all secrets saved to Vault have a TTL value that is added as an attribute. Assert.AreEqual(3, secret.Attributes.Count); }
public async Task Secret_CreateSecret_ExistingSecret_ReturnsNull() { String secretName = "Test/F/hhyhyk"; KeyValueSecret A = new KeyValueSecret(secretName); KeyValuePair <string, string> kv1 = new KeyValuePair <string, string>("user", "FredFlinstone"); KeyValuePair <string, string> kv2 = new KeyValuePair <string, string>("house", "rubbles"); A.Attributes.Add(kv1.Key, kv1.Value); A.Attributes.Add(kv2.Key, kv2.Value); KeyValueSecret secret = await _keyValueSecretEngine.CreateSecret(A); Assert.NotNull(secret); // Now try to create it again. Should fail. KeyValueSecret secret2 = await _keyValueSecretEngine.CreateSecret(A); Assert.Null(secret2); }