Skip to content

Commit

Permalink
Added ability to create instance with pointer (#3698)
Browse files Browse the repository at this point in the history
* Added ability to create instance with pointer

* Pull request feedback
  • Loading branch information
LarryOsterman authored Jun 3, 2022
1 parent 78095ce commit bea1479
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ int main()

// create client
std::string endpoint(GetEnvHelper::GetEnv("ATTESTATION_AAD_URL"));
AttestationClient attestationClient(AttestationClient::Create(endpoint));
std::shared_ptr<AttestationClient> attestationClient(
std::make_shared<AttestationClient>(AttestationClient::Create(endpoint)));

std::vector<uint8_t> const sgxEnclaveQuote = AttestationCollateral::SgxQuote();

Expand All @@ -56,7 +57,7 @@ int main()
= AttestationData{AttestationCollateral::RunTimeData(), AttestationDataType::Binary};

Azure::Response<AttestationToken<AttestationResult>> const sgxResult
= attestationClient.AttestSgxEnclave(sgxEnclaveQuote, attestOptions);
= attestationClient->AttestSgxEnclave(sgxEnclaveQuote, attestOptions);

std::cout << "SGX Quote MRSIGNER is: "
<< Convert::Base64Encode(*sgxResult.Value.Body.SgxMrSigner) << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ int main()
GetEnvHelper::GetEnv("AZURE_TENANT_ID"),
GetEnvHelper::GetEnv("AZURE_CLIENT_ID"),
GetEnvHelper::GetEnv("AZURE_CLIENT_SECRET"));

AttestationAdministrationClient adminClient(AttestationAdministrationClient::Create(
GetEnvHelper::GetEnv("ATTESTATION_AAD_URL"), credential));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,17 @@ issuancerules {
auto const client = AttestationClient::Create(this->m_endpoint, options);
EXPECT_EQ(m_endpoint, client.Endpoint());
}

{
std::unique_ptr<AttestationClient> client = std::make_unique<AttestationClient>(
AttestationClient::Create(this->m_endpoint, options));
EXPECT_EQ(m_endpoint, client->Endpoint());
}
{
std::unique_ptr<AttestationClient const> client = std::make_unique<AttestationClient>(
AttestationClient::Create(this->m_endpoint, options));
EXPECT_EQ(m_endpoint, client->Endpoint());
}
}

namespace {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,28 @@ namespace Azure { namespace Security { namespace Attestation { namespace Test {
private:
protected:
std::shared_ptr<Azure::Core::Credentials::TokenCredential> m_credential;

std::unique_ptr<AttestationAdministrationClient> m_adminClient;
// Create
virtual void SetUp() override
{
Azure::Core::Test::TestBase::SetUpTestBase(AZURE_TEST_RECORDING_DIR);
{
// TPM attestation requires a policy document be set. For simplicity, we only run the
// test against an AAD attestation service instance.
auto adminClient = CreateAdminClient(InstanceType::AAD);
m_adminClient = std::make_unique<AttestationAdministrationClient>(
CreateAdminClient(InstanceType::AAD));

// Set a minimal policy, which will make the TPM attestation code happy.
adminClient.SetAttestationPolicy(
m_adminClient->SetAttestationPolicy(
AttestationType::Tpm,
"version=1.0; authorizationrules{=> permit();}; issuancerules{};");
}
}

virtual void TearDown() override
{
{
auto adminClient = CreateAdminClient(InstanceType::AAD);
// Reset the attestation policy for this instance back to the default.
adminClient.ResetAttestationPolicy(AttestationType::Tpm);
}
// Reset the attestation policy for this instance back to the default.
m_adminClient->ResetAttestationPolicy(AttestationType::Tpm);

// Make sure you call the base classes TearDown method to ensure recordings are made.
TestBase::TearDown();
Expand Down

0 comments on commit bea1479

Please sign in to comment.