Identity perf tests (#5329)

* mroe quotes

* dssf

* azure identity tests

* comments

* comments
This commit is contained in:
George Arama 2024-02-21 12:05:43 -08:00 committed by GitHub
parent 8ef815dc6a
commit 1bb65192d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 262 additions and 0 deletions

View File

@ -8,6 +8,10 @@
{
"file": [ "sdk/attestation/azure-security-attestation/test/ut/crypto_test_collateral.cpp" ],
"_justification": "File contains a PEM encoded RSA private key used by test code."
},
{
"file": [ "sdk/identity/azure-identity/test/perf/inc/azure/identity/test/externals/perf.combo.pem" ],
"_justification": "File contains a PEM encoded RSA private key used by perf test code."
}
]
}

View File

@ -9,6 +9,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
set(
AZURE_IDENTITY_PERF_TEST_HEADER
inc/azure/identity/test/client_certificate_credential_test.hpp
inc/azure/identity/test/environment_credential_test.hpp
inc/azure/identity/test/secret_credential_test.hpp
)

View File

@ -0,0 +1,105 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* @file
* @brief Test the overhead of authenticating with client certificate credential.
*
*/
#pragma once
#include <azure/identity.hpp>
#include <azure/perf.hpp>
#include <memory>
#include <string>
#include <vector>
namespace Azure { namespace Identity { namespace Test {
/**
* @brief A test to measure the authentication token performance.
*
*/
class ClientCertificateCredentialTest : public Azure::Perf::PerfTest {
private:
std::string m_tenantId;
std::string m_clientId;
std::string m_certPath;
Core::Credentials::TokenRequestContext m_tokenRequestContext;
std::unique_ptr<Azure::Core::Credentials::TokenCredential> m_credential;
public:
/**
* @brief Setup the test.
*
*/
void Setup() override
{
m_tenantId = m_options.GetMandatoryOption<std::string>("TenantId");
m_clientId = m_options.GetMandatoryOption<std::string>("ClientId");
m_certPath = m_options.GetMandatoryOption<std::string>("CertPath");
m_tokenRequestContext.Scopes.push_back(m_options.GetMandatoryOption<std::string>("Scope"));
if (!m_options.GetOptionOrDefault<bool>("Cache", false))
{
// having this set ignores the credentials cache and forces a new token to be requested
m_tokenRequestContext.MinimumExpiration = std::chrono::hours(1000000);
}
m_credential = std::make_unique<Azure::Identity::ClientCertificateCredential>(
m_tenantId,
m_clientId,
m_certPath,
InitClientOptions<Azure::Core::Credentials::TokenCredentialOptions>());
}
/**
* @brief Construct a new ClientCertificateCredentialTest test.
*
* @param options The test options.
*/
ClientCertificateCredentialTest(Azure::Perf::TestOptions options) : PerfTest(options) {}
/**
* @brief Define the test
*
* @param context The cancellation token.
*/
void Run(Azure::Core::Context const& context) override
{
auto t = m_credential->GetToken(m_tokenRequestContext, context);
}
/**
* @brief Define the test options for the test.
*
* @return The list of test options.
*/
std::vector<Azure::Perf::TestOption> GetTestOptions() override
{
return {
{"Cache", {"--cache"}, "Use credential cache.", 1, false},
{"CertPath", {"--certpath"}, "The certificate path for authentication.", 1, true, true},
{"ClientId", {"--clientId"}, "The client Id for the authentication.", 1, true},
{"Scope", {"--scope"}, "One scope to request access to.", 1, true},
{"TenantId", {"--tenantId"}, "The tenant Id for the authentication.", 1, true}};
}
/**
* @brief Get the static Test Metadata for the test.
*
* @return Azure::Perf::TestMetadata describing the test.
*/
static Azure::Perf::TestMetadata GetTestMetadata()
{
return {
"ClientCertificateCredential",
"Get a token using a client certificate credential.",
[](Azure::Perf::TestOptions options) {
return std::make_unique<Azure::Identity::Test::ClientCertificateCredentialTest>(
options);
}};
}
};
}}} // namespace Azure::Identity::Test

View File

@ -0,0 +1,93 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* @file
* @brief Test the overhead of authenticating with secret credential.
*
*/
#pragma once
#include <azure/identity.hpp>
#include <azure/perf.hpp>
#include <memory>
#include <string>
#include <vector>
namespace Azure { namespace Identity { namespace Test {
/**
* @brief A test to measure the authentication token performance.
*
*/
class EnvironmentCredentialTest : public Azure::Perf::PerfTest {
private:
Core::Credentials::TokenRequestContext m_tokenRequestContext;
std::unique_ptr<Azure::Core::Credentials::TokenCredential> m_credential;
public:
/**
* @brief Setup the test
*
*/
void Setup() override
{
m_tokenRequestContext.Scopes.push_back(m_options.GetMandatoryOption<std::string>("Scope"));
if (!m_options.GetOptionOrDefault<bool>("Cache", false))
{
// having this set ignores the credentials cache and forces a new token to be requested
m_tokenRequestContext.MinimumExpiration = std::chrono::hours(1000000);
}
m_credential = std::make_unique<Azure::Identity::EnvironmentCredential>(
InitClientOptions<Azure::Core::Credentials::TokenCredentialOptions>());
}
/**
* @brief Construct a new EnvironmentCredentialTest test.
*
* @param options The test options.
*/
EnvironmentCredentialTest(Azure::Perf::TestOptions options) : PerfTest(options) {}
/**
* @brief Define the test
*
* @param context The cancellation token.
*/
void Run(Azure::Core::Context const& context) override
{
auto t = m_credential->GetToken(m_tokenRequestContext, context);
}
/**
* @brief Define the test options for the test.
*
* @return The list of test options.
*/
std::vector<Azure::Perf::TestOption> GetTestOptions() override
{
return {
{"Cache", {"--cache"}, "Use credential cache.", 1, false},
{"Scope", {"--scope"}, "One scope to request access to.", 1, true},
};
}
/**
* @brief Get the static Test Metadata for the test.
*
* @return Azure::Perf::TestMetadata describing the test.
*/
static Azure::Perf::TestMetadata GetTestMetadata()
{
return {
"EnvironmentCredential",
"Get a token using a secret client token credential.",
[](Azure::Perf::TestOptions options) {
return std::make_unique<Azure::Identity::Test::EnvironmentCredentialTest>(options);
}};
}
};
}}} // namespace Azure::Identity::Test

View File

@ -0,0 +1,53 @@
Bag Attributes
localKeyID: 01 00 00 00
1.3.6.1.4.1.311.17.3.71: 44 00 45 00 53 00 4B 00 54 00 4F 00 50 00 2D 00 48 00 33 00 35 00 4B 00 51 00 51 00 42 00 00 00
subject=CN = perfCert
issuer=CN = perfCert
-----BEGIN CERTIFICATE-----
MIIDADCCAeigAwIBAgIQIugayGqZbqRIT+zbzllIFzANBgkqhkiG9w0BAQsFADAT
MREwDwYDVQQDDAhwZXJmQ2VydDAeFw0yNDAyMDYyMDI5NThaFw0yNTAyMDYyMDQ5
NThaMBMxETAPBgNVBAMMCHBlcmZDZXJ0MIIBIjANBgkqhkiG9w0BAQEF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iVTDNQuxWUCgYAFsWaEXm+xEbuR1EgwlRhMXVTCbbYQvYzDxpvE
NvQ6JPJhDKw28oGx6nEFUgVhGUuIPPGgggJ26XXtnbyiCzzV+pEgQ6aE00mnBwqA
N6YPvZYvBQWZZd0Chi+g09zWI6QK8mLZpCKjhUe5vJ4RgmnMeqzeQvIB/y2DNCnT
Ns3XFQKBgHSBQhloKjqDJ9hsLpvaVd7hNvYkuZXFj6C1xj1tWeAoNv5hPJQMQgzw
XMCIIwynr8FkL42HSwYG42LZ7d7powGhPf8k7gAyniVcgQelomUE799/OhUEQ0RX
9E7TF4ErVzijnvxYwI+2ed+54JB3XJnphDn99GrOJSi3c4qlEFvx
-----END RSA PRIVATE KEY-----

View File

@ -43,6 +43,7 @@ namespace Azure { namespace Identity { namespace Test {
m_tokenRequestContext.Scopes.push_back(m_options.GetMandatoryOption<std::string>("Scope"));
if (!m_options.GetOptionOrDefault<bool>("Cache", false))
{
// having this set ignores the credentials cache and forces a new token to be requested
m_tokenRequestContext.MinimumExpiration = std::chrono::hours(1000000);
}
m_credential = std::make_unique<Azure::Identity::ClientSecretCredential>(

View File

@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "azure/identity/test/client_certificate_credential_test.hpp"
#include "azure/identity/test/environment_credential_test.hpp"
#include "azure/identity/test/secret_credential_test.hpp"
#include <azure/perf.hpp>
@ -10,6 +12,8 @@ int main(int argc, char** argv)
// Create the test list
std::vector<Azure::Perf::TestMetadata> tests{
Azure::Identity::Test::ClientCertificateCredentialTest::GetTestMetadata(),
Azure::Identity::Test::EnvironmentCredentialTest::GetTestMetadata(),
Azure::Identity::Test::SecretCredentialTest::GetTestMetadata()};
Azure::Perf::Program::Run(Azure::Core::Context::ApplicationContext, tests, argc, argv);