-
Notifications
You must be signed in to change notification settings - Fork 4k
Add AttestationTestRunner and replace AttestationController #18076
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method invocation is not necessary. Please remove it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not all tests can pass after removed any of them. Message is: Exception calling "Invoke" with "2" argument(s): "TestManagementClientHelper class wasn't initialized with the ResourceManagementClient client." |
||
GetAttestationClient | ||
) | ||
.Build(); | ||
} | ||
|
||
private static ResourceManagementClient GetResourceManagementClient(MockContext context) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method definition is not necessary. Please remove it |
||
{ | ||
return context.GetServiceClient<ResourceManagementClient>(TestEnvironmentFactory.GetTestEnvironment()); | ||
} | ||
|
||
private static AttestationManagementClient GetAttestationManagementClient(MockContext context) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method definition is not necessary. Please remove it |
||
{ | ||
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()); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method invocation is not necessary. Please remove it