Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only provision and test Managed HSM when opted in #16554

Merged
3 commits merged into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sdk/core/Azure.Core.TestFramework/src/RecordedTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Linq;
using System.Reflection;
using NUnit.Framework;
using NUnit.Framework.Interfaces;

namespace Azure.Core.TestFramework
{
Expand Down Expand Up @@ -136,7 +137,7 @@ public virtual void StartTestRecording()
[TearDown]
public virtual void StopTestRecording()
{
bool save = TestContext.CurrentContext.Result.FailCount == 0;
bool save = TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Passed;
#if DEBUG
save |= SaveDebugRecordingsOnFailure;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ protected AdministrationTestBase(bool isAsync, RecordedTestMode? mode)
/// <summary>
/// Gets the endpoint to connect. By default it is <see cref="KeyVaultTestEnvironment.ManagedHsmUrl"/>.
/// </summary>
public virtual Uri Uri => new Uri(TestEnvironment.ManagedHsmUrl);
public Uri Uri =>
Uri.TryCreate(TestEnvironment.ManagedHsmUrl, UriKind.Absolute, out Uri uri)
? uri
// If the AZURE_MANAGEDHSM_URL variable is not defined, we didn't provision one
// due to limitations: https://github.com/Azure/azure-sdk-for-net/issues/16531
: throw new IgnoreException($"Required variable 'AZURE_MANAGEDHSM_URL' is not defined");

/// <summary>
/// Gets a polling interval based on whether we're playing back recorded tests (0s) or not (2s).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public void ClearChallengeCacheforRecord()
// is always made. This allows tests to be replayed independently and in any order
if (Mode == RecordedTestMode.Record || Mode == RecordedTestMode.Playback)
{
Client = GetClient();

ChallengeBasedAuthenticationPolicy.AuthenticationChallenge.ClearCache();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public void ClearChallengeCacheforRecord()
// is always made. This allows tests to be replayed independently and in any order
if (Mode == RecordedTestMode.Record || Mode == RecordedTestMode.Playback)
{
Client = GetClient();

ChallengeBasedAuthenticationPolicy.AuthenticationChallenge.ClearCache();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public abstract class KeysTestBase : RecordedTestBase<KeyVaultTestEnvironment>
? TimeSpan.Zero
: TimeSpan.FromSeconds(2);

public KeyClient Client { get; set; }
public KeyClient Client { get; private set; }

public virtual Uri Uri => new Uri(TestEnvironment.KeyVaultUrl);

Expand All @@ -34,7 +34,7 @@ public abstract class KeysTestBase : RecordedTestBase<KeyVaultTestEnvironment>
private KeyVaultTestEventListener _listener;

protected KeysTestBase(bool isAsync, KeyClientOptions.ServiceVersion serviceVersion, RecordedTestMode? mode)
: base(isAsync, mode ?? RecordedTestUtilities.GetModeFromEnvironment())
: base(isAsync, mode ?? RecordedTestUtilities.GetModeFromEnvironment() /* RecordedTestMode.Record */)
{
_serviceVersion = serviceVersion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using Azure.Core.TestFramework;
using NUnit.Framework;

namespace Azure.Security.KeyVault.Keys.Tests
{
Expand All @@ -13,6 +14,11 @@ public ManagedHsmLiveTests(bool isAsync, KeyClientOptions.ServiceVersion service
{
}

public override Uri Uri => new Uri(TestEnvironment.ManagedHsmUrl);
public override Uri Uri =>
Uri.TryCreate(TestEnvironment.ManagedHsmUrl, UriKind.Absolute, out Uri uri)
? uri
// If the AZURE_MANAGEDHSM_URL variable is not defined, we didn't provision one
// due to limitations: https://github.com/Azure/azure-sdk-for-net/issues/16531
: throw new IgnoreException($"Required variable 'AZURE_MANAGEDHSM_URL' is not defined");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public KeyVaultTestEnvironment() : base("keyvault")
/// <summary>
/// Gets the URI to Managed HSM.
/// </summary>
public string ManagedHsmUrl => GetRecordedVariable("AZURE_MANAGEDHSM_URL");
public string ManagedHsmUrl => GetRecordedOptionalVariable("AZURE_MANAGEDHSM_URL");

/// <summary>
/// Gets an OID for the client within the tenant.
Expand Down
7 changes: 3 additions & 4 deletions sdk/keyvault/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ Before running or recording live tests you need to create [live test resources][

```powershell
eng\common\TestResources\New-TestResources.ps1 `
-BaseName 'myusername' `
-ServiceDirectory 'keyvault' `
-TestApplicationId $sp.ApplicationId `
-TestApplicationSecret (ConvertFrom-SecureString $sp.Secret -AsPlainText) `
-AdditionalParameters @{
enableSoftDelete = $false # Enable or disable soft delete. Default is $true (enabled).
# Enable Managed HSM provisioning and testing.
# Disabled by default due to limitations: https://github.com/Azure/azure-sdk-for-net/issues/16531
enableHsm = $true
}
```

Expand Down
2 changes: 1 addition & 1 deletion sdk/keyvault/test-resources-post.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ $wrappingFiles = foreach ($i in 0..2) {

# TODO: Use Az module when available; for now, assumes Azure CLI is installed and in $Env:PATH.
Log "Logging '$username' into the Azure CLI"
az login --service-principal --tenant $tenant --username $username --password $password
az login --service-principal --tenant "$tenant" --username "$username" --password="$password"

Log "Downloading security domain from '$hsmUrl'"

Expand Down
9 changes: 9 additions & 0 deletions sdk/keyvault/test-resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
"description": "The location of the Managed HSM. By default, this is 'southcentralus'."
}
},
"enableHsm": {
"type": "bool",
"defaultValue": false,
"metadata": {
"description": "Whether to enable deployment of Managed HSM. The default is false."
}
},
"enableSoftDelete": {
"type": "bool",
"defaultValue": true,
Expand Down Expand Up @@ -165,6 +172,7 @@
"type": "Microsoft.KeyVault/managedHSMs",
"apiVersion": "[variables('hsmApiVersion')]",
"name": "[variables('hsmName')]",
"condition": "[parameters('enableHsm')]",
"location": "[parameters('hsmLocation')]",
"sku": {
"family": "B",
Expand Down Expand Up @@ -236,6 +244,7 @@
},
"AZURE_MANAGEDHSM_URL": {
"type": "string",
"condition": "[parameters('enableHsm')]",
"value": "[reference(variables('hsmName')).hsmUri]"
},
"KEYVAULT_SKU": {
Expand Down