public SetKeyVaultSecretTests() { base.SetupTest(); secretAttributes = new PSKeyVaultSecretAttributes(true, null, null, null, null); secureSecretValue = SecretValue.ConvertToSecureString(); secret = new PSKeyVaultSecret() { 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 PSKeyVaultSecretAttributes(true, DateTime.UtcNow.AddYears(2), DateTime.UtcNow, "contenttype", null); secret = new PSKeyVaultSecret() { VaultName = VaultName, Name = SecretName, Version = SecretVersion, SecretValue = null, Attributes = secretAttributes }; cmdlet = new UpdateAzureKeyVaultSecret() { 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, Tag = secretAttributes.Tags, PassThru = true }; }
private void WriteSecret(PSKeyVaultSecret secret) { if (AsPlainText) { WriteObject(ConvertFromSecureString(secret?.SecretValue)); } else { WriteObject(secret); } }
public override void ExecuteCmdlet() { if (InputObject != null) { VaultName = InputObject.VaultName; Name = InputObject.Name; } if (ShouldProcess(Name, Properties.Resources.RecoverSecret)) { PSKeyVaultSecret secret = DataServiceClient.RecoverSecret(VaultName, Name); WriteObject(secret); } }
public void CannotRemoveSecretWithoutShouldProcessOrForceConfirmationTest() { // Should process but without force commandRuntimeMock.Setup(cr => cr.ShouldProcess(SecretName, It.IsAny <string>())).Returns(true); PSKeyVaultSecret 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()); cmdlet.ExecuteCmdlet(); // Write object should be called with null input commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Exactly(2)); }
public void CanSetSecretTest() { PSKeyVaultSecret expected = secret; keyVaultClientMock.Setup(kv => kv.SetSecret(VaultName, SecretName, secureSecretValue, It.Is <PSKeyVaultSecretAttributes>(st => st.Enabled == secretAttributes.Enabled && st.Expires == secretAttributes.Expires && st.NotBefore == secretAttributes.NotBefore && st.ContentType == secretAttributes.ContentType && st.Tags == secretAttributes.Tags))).Returns(expected).Verifiable(); // Mock the should process to return true commandRuntimeMock.Setup(cr => cr.ShouldProcess(SecretName, It.IsAny <string>())).Returns(true); cmdlet.ExecuteCmdlet(); // Assert keyVaultClientMock.VerifyAll(); commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Once()); }