public void CanRemoveSecretWithPassThruTest() { SecureString secureSecretValue = SecretValue.ConvertToSecureString(); Secret expected = new Secret() { Name = SecretName, VaultName = VaultName, SecretValue = secureSecretValue }; keyVaultClientMock.Setup(kv => kv.DeleteSecret(VaultName, SecretName)).Returns(expected).Verifiable(); // Mock the should process to return true commandRuntimeMock.Setup(cr => cr.ShouldProcess(SecretName, It.IsAny<string>())).Returns(true); cmdlet.Name = SecretName; cmdlet.Force = true; cmdlet.PassThru = true; cmdlet.ExecuteCmdlet(); keyVaultClientMock.VerifyAll(); commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Once()); //No force but should continue commandRuntimeMock.Setup(cr => cr.ShouldProcess(SecretName, It.IsAny<string>())).Returns(true); commandRuntimeMock.Setup(cr => cr.ShouldContinue(It.IsAny<string>(), It.IsAny<string>())).Returns(true); cmdlet.Force = false; cmdlet.PassThru = true; cmdlet.ExecuteCmdlet(); keyVaultClientMock.VerifyAll(); commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Exactly(2)); }
public void CanRemoveSecretWithPassThruTest() { SecureString secureSecretValue = SecretValue.ConvertToSecureString(); Cmdlet.Secret expected = new Cmdlet.Secret() { Name = SecretName, VaultName = VaultName, SecretValue = secureSecretValue }; keyVaultClientMock.Setup(kv => kv.DeleteSecret(VaultName, SecretName)).Returns(expected).Verifiable(); // Mock the should process to return true commandRuntimeMock.Setup(cr => cr.ShouldProcess(SecretName, It.IsAny <string>())).Returns(true); cmdlet.Name = SecretName; cmdlet.Force = true; cmdlet.PassThru = true; cmdlet.ExecuteCmdlet(); keyVaultClientMock.VerifyAll(); commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Once()); //No force but should continue commandRuntimeMock.Setup(cr => cr.ShouldProcess(SecretName, It.IsAny <string>())).Returns(true); commandRuntimeMock.Setup(cr => cr.ShouldContinue(It.IsAny <string>(), It.IsAny <string>())).Returns(true); cmdlet.Force = false; cmdlet.PassThru = true; cmdlet.ExecuteCmdlet(); keyVaultClientMock.VerifyAll(); commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Exactly(2)); }
public void CanSetSecretTest() { SecureString secureSecretValue = SecretValue.ConvertToSecureString(); Cmdlet.Secret expected = new Cmdlet.Secret() { Name = SecretName, VaultName = VaultName, SecretValue = secureSecretValue, Version = SecretVersion }; keyVaultClientMock.Setup(kv => kv.SetSecret(VaultName, SecretName, secureSecretValue)).Returns(expected).Verifiable(); cmdlet.Name = SecretName; cmdlet.SecretValue = secureSecretValue; cmdlet.ExecuteCmdlet(); // Assert keyVaultClientMock.VerifyAll(); commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Once()); }
internal SecretIdentityItem(Secret secret) { if (secret == null) throw new ArgumentNullException("secret"); if (secret.Attributes == null) throw new ArgumentException(KeyVaultProperties.Resources.InvalidSecretAttributes); SetObjectIdentifier(secret); Enabled = secret.Attributes.Enabled; Expires = secret.Attributes.Expires; NotBefore = secret.Attributes.NotBefore; Created = secret.Attributes.Created; Updated = secret.Attributes.Updated; Tags = secret.Attributes.Tags; }
public void CanRemoveSecretWithNoPassThruTest() { SecureString secureSecretValue = SecretValue.ConvertToSecureString(); Cmdlet.Secret expected = new Cmdlet.Secret() { Name = SecretName, VaultName = VaultName, SecretValue = secureSecretValue }; keyVaultClientMock.Setup(kv => kv.DeleteSecret(VaultName, SecretName)).Returns(expected).Verifiable(); // Mock the should process to return true commandRuntimeMock.Setup(cr => cr.ShouldProcess(SecretName, It.IsAny<string>())).Returns(true); cmdlet.Name = SecretName; cmdlet.Force = true; cmdlet.ExecuteCmdlet(); keyVaultClientMock.VerifyAll(); // Without PassThru never call WriteObject commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Never()); }
public void CannotRemoveSecretWithoutShouldProcessOrForceConfirmationTest() { Cmdlet.Secret expected = null; cmdlet.Name = SecretName; cmdlet.PassThru = true; cmdlet.ExecuteCmdlet(); // Write object should be called with null input commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Once()); // Should process but without force commandRuntimeMock.Setup(cr => cr.ShouldProcess(SecretName, It.IsAny <string>())).Returns(true); cmdlet.ExecuteCmdlet(); // Write object should be called with null input commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Exactly(2)); }
public SetKeyVaultSecretTests() { base.SetupTest(); secretAttributes = new SecretAttributes(true, null, null, null, null); secureSecretValue = SecretValue.ConvertToSecureString(); secret = new Secret() { VaultName = VaultName, Name = SecretName, Version = SecretVersion, SecretValue = secureSecretValue, Attributes = secretAttributes }; cmdlet = new SetAzureKeyVaultSecret() { CommandRuntime = commandRuntimeMock.Object, DataServiceClient = keyVaultClientMock.Object, VaultName = secret.VaultName, Name = secret.Name, SecretValue = secret.SecretValue, Disable = new SwitchParameter(!(secretAttributes.Enabled.Value)), Expires = secretAttributes.Expires, NotBefore = secretAttributes.NotBefore, ContentType = secretAttributes.ContentType, Tag = secretAttributes.Tags }; }
public SetKeyVaultSecretAttributeTests() { base.SetupTest(); secretAttributes = new SecretAttributes(true, DateTime.UtcNow.AddYears(2), DateTime.UtcNow, "contenttype", null); secret = new Secret() { VaultName = VaultName, Name = SecretName, Version = SecretVersion, SecretValue = null, Attributes = secretAttributes }; cmdlet = new SetAzureKeyVaultSecretAttribute() { CommandRuntime = commandRuntimeMock.Object, DataServiceClient = keyVaultClientMock.Object, VaultName = secret.VaultName, Name = secret.Name, Version = secret.Version, Enable = secretAttributes.Enabled, Expires = secretAttributes.Expires, NotBefore = secretAttributes.NotBefore, ContentType = secretAttributes.ContentType, Tags = secretAttributes.Tags, PassThru = true }; }