-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AttestationTestRunner and replace AttestationController (#18076)
* Add AttestationTestRunner and replace AttestationController * Add AttestationTestRunner and replace AttestationController Co-authored-by: Ziyue Zheng <[email protected]>
- Loading branch information
1 parent
ec77d18
commit 81c1fea
Showing
5 changed files
with
122 additions
and
233 deletions.
There are no files selected for viewing
187 changes: 0 additions & 187 deletions
187
src/Attestation/Attestation.Test/ScenarioTests/AttestationController.cs
This file was deleted.
Oops, something went wrong.
100 changes: 100 additions & 0 deletions
100
src/Attestation/Attestation.Test/ScenarioTests/AttestationTestRunner.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using Microsoft.Azure.Attestation; | ||
using Microsoft.Azure.Management.Attestation; | ||
using Microsoft.Azure.Test.HttpRecorder; | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Azure.Management.Internal.Resources; | ||
using Microsoft.IdentityModel.Clients.ActiveDirectory; | ||
using Microsoft.Rest.ClientRuntime.Azure.TestFramework; | ||
using Microsoft.Azure.Commands.TestFx; | ||
using Xunit.Abstractions; | ||
|
||
namespace Microsoft.Azure.Commands.Attestation.Test.ScenarioTests | ||
{ | ||
public class AttestationTestRunner | ||
{ | ||
protected readonly ITestRunner TestRunner; | ||
|
||
protected AttestationTestRunner(ITestOutputHelper output) | ||
{ | ||
TestRunner = TestManager.CreateInstance(output) | ||
.WithNewPsScriptFilename($"{GetType().Name}.ps1") | ||
.WithProjectSubfolderForTests("ScenarioTests") | ||
.WithCommonPsScripts(new[] | ||
{ | ||
@"Common.ps1", | ||
@"../AzureRM.Resources.ps1" | ||
}) | ||
.WithNewRmModules(helper => new[] | ||
{ | ||
helper.RMProfileModule, | ||
helper.GetRMModulePath("Az.Attestation.psd1") | ||
}) | ||
.WithNewRecordMatcherArguments( | ||
userAgentsToIgnore: new Dictionary<string, string> | ||
{ | ||
{"Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"}, | ||
{"Microsoft.Azure.Management.ResourceManager.ResourceManagementClient", "2017-05-10"} | ||
}, | ||
resourceProviders: new Dictionary<string, string> | ||
{ | ||
{"Microsoft.Resources", null}, | ||
{"Microsoft.Features", null}, | ||
{"Microsoft.Authorization", null} | ||
} | ||
).WithManagementClients( | ||
GetResourceManagementClient, | ||
GetAttestationManagementClient, | ||
GetAttestationClient | ||
) | ||
.Build(); | ||
} | ||
|
||
private static ResourceManagementClient GetResourceManagementClient(MockContext context) | ||
{ | ||
return context.GetServiceClient<ResourceManagementClient>(TestEnvironmentFactory.GetTestEnvironment()); | ||
} | ||
|
||
private static AttestationManagementClient GetAttestationManagementClient(MockContext context) | ||
{ | ||
return context.GetServiceClient<AttestationManagementClient>(TestEnvironmentFactory.GetTestEnvironment()); | ||
} | ||
|
||
private static AttestationClient GetAttestationClient(MockContext context) | ||
{ | ||
string environmentConnectionString = Environment.GetEnvironmentVariable("TEST_CSM_ORGID_AUTHENTICATION"); | ||
string accessToken = "fakefakefake"; | ||
|
||
// When recording, we should have a connection string passed into the code from the environment | ||
if (!string.IsNullOrEmpty(environmentConnectionString)) | ||
{ | ||
// Gather test client credential information from the environment | ||
var connectionInfo = new ConnectionString(Environment.GetEnvironmentVariable("TEST_CSM_ORGID_AUTHENTICATION")); | ||
string servicePrincipal = connectionInfo.GetValue<string>(ConnectionStringKeys.ServicePrincipalKey); | ||
string servicePrincipalSecret = connectionInfo.GetValue<string>(ConnectionStringKeys.ServicePrincipalSecretKey); | ||
string aadTenant = connectionInfo.GetValue<string>(ConnectionStringKeys.AADTenantKey); | ||
|
||
// Create credentials | ||
var clientCredentials = new ClientCredential(servicePrincipal, servicePrincipalSecret); | ||
var authContext = new AuthenticationContext($"https://login.windows.net/{aadTenant}", TokenCache.DefaultShared); | ||
accessToken = authContext.AcquireTokenAsync("https://attest.azure.net", clientCredentials).Result.AccessToken; | ||
} | ||
|
||
return new AttestationClient(new AttestationCredentials(accessToken), HttpMockServer.CreateInstance()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.