diff --git a/.vscode/cspell.json b/.vscode/cspell.json index 5cb0e9a7d..1a2fc8328 100644 --- a/.vscode/cspell.json +++ b/.vscode/cspell.json @@ -16,10 +16,7 @@ "json.hpp", "*nlohmann-json*", "eng/docs/api/assets/**/*", - "sdk/keyvault/azure-security-keyvault-keys/test/ut/recordings/*.json", - "sdk/keyvault/azure-security-keyvault-certificates/test/ut/recordings/*.json", - "sdk/keyvault/azure-security-keyvault-certificates/inc/azure/keyvault/certificates/certificate_client_models.hpp", - "sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_import_test_live.cpp" + "**/test/ut/recordings/*.json" ], // * Unless configured otherwise, these words are not case sensitive // * Alphabetize the list when making changes so the list is easier for future diff --git a/eng/pipelines/templates/jobs/ci.tests.yml b/eng/pipelines/templates/jobs/ci.tests.yml index a59c6e6a0..dbdaccfb1 100644 --- a/eng/pipelines/templates/jobs/ci.tests.yml +++ b/eng/pipelines/templates/jobs/ci.tests.yml @@ -73,8 +73,9 @@ jobs: value: "https://non-real-account.vault.azure.net" - name: AZURE_KEYVAULT_HSM_URL value: "https://non-real-account.vault.azure.net" +# Tenant ID should use the uniqueID format for playback recordings - name: AZURE_TENANT_ID - value: "non-real-tenant" + value: "33333333-3333-3333-3333-333333333333" - name: AZURE_CLIENT_ID value: "non-real-client" - name: AZURE_CLIENT_SECRET diff --git a/sdk/core/azure-core-test/inc/azure/core/test/test_base.hpp b/sdk/core/azure-core-test/inc/azure/core/test/test_base.hpp index c21d4cc47..5df9d37a1 100644 --- a/sdk/core/azure-core-test/inc/azure/core/test/test_base.hpp +++ b/sdk/core/azure-core-test/inc/azure/core/test/test_base.hpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -30,6 +31,19 @@ namespace Azure { namespace Core { namespace Test { class TestBase : public ::testing::Test { private: + void PrepareOptions(Azure::Core::_internal::ClientOptions& options) + { + // Set up client options depending on the test-mode + if (m_testContext.IsPlaybackMode()) + { + options.Transport.Transport = m_interceptor->GetPlaybackTransport(); + } + else if (!m_testContext.IsLiveMode()) + { + options.PerRetryPolicies.push_back(m_interceptor->GetRecordPolicy()); + } + } + // Call this method to update client options with the required configuration to // support Record & Playback. // If Playback or Record is not set, no changes will be done to the clientOptions or credential. @@ -84,6 +98,16 @@ namespace Azure { namespace Core { namespace Test { return testName; } + // Creates the sdk client for testing. + // The client will be set for record and playback before it is created. + Azure::Core::Credentials::TokenCredentialOptions GetTokenCredentialOptions() + { + // Run instrumentation before creating the client + Azure::Core::Credentials::TokenCredentialOptions options; + PrepareOptions(options); + return options; + } + // Creates the sdk client for testing. // The client will be set for record and playback before it is created. template diff --git a/sdk/core/azure-core-test/src/interceptor_manager.cpp b/sdk/core/azure-core-test/src/interceptor_manager.cpp index 1fdbb55d1..c29296fda 100644 --- a/sdk/core/azure-core-test/src/interceptor_manager.cpp +++ b/sdk/core/azure-core-test/src/interceptor_manager.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -62,7 +63,13 @@ Url InterceptorManager::RedactUrl(Url const& url) auto host = url.GetHost(); auto hostWithNoAccount = std::find(host.begin(), host.end(), '.'); redactedUrl.SetHost("REDACTED" + std::string(hostWithNoAccount, host.end())); - redactedUrl.SetPath(url.GetPath()); + // replace any uniqueID from the path for a hardcoded id + // For the regex, we should not assume anything about the version of UUID format being used. So, + // using the most general regex to get any uuid version. + redactedUrl.SetPath(std::regex_replace( + url.GetPath(), + std::regex("[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"), + "33333333-3333-3333-3333-333333333333")); // Query parameters for (auto const& qp : url.GetQueryParameters()) { diff --git a/sdk/core/ci.yml b/sdk/core/ci.yml index 83a04e314..261bfcda8 100644 --- a/sdk/core/ci.yml +++ b/sdk/core/ci.yml @@ -39,8 +39,7 @@ stages: # libraries to check for potential regressions everywhere. CtestRegex: .* # Storage tests have no recordings - # Identity live tests are pending to be recorded - CtestExcludeRegex: azure-storage|azure-identity-livetest + CtestExcludeRegex: azure-storage LiveTestCtestRegex: '"azure-core.|json-test"' LiveTestTimeoutInMinutes: 90 # default is 60 min. We need a little longer on worst case for Win+jsonTests LineCoverageTarget: 93 diff --git a/sdk/identity/azure-identity/CMakeLists.txt b/sdk/identity/azure-identity/CMakeLists.txt index b80aef8b7..ac58eb7e7 100644 --- a/sdk/identity/azure-identity/CMakeLists.txt +++ b/sdk/identity/azure-identity/CMakeLists.txt @@ -90,7 +90,6 @@ if(BUILD_TESTING) endif() add_subdirectory(test/e2e) - add_subdirectory(test/live) add_subdirectory(test/ut) endif() diff --git a/sdk/identity/azure-identity/test/live/CMakeLists.txt b/sdk/identity/azure-identity/test/live/CMakeLists.txt deleted file mode 100644 index 86a0d6ddf..000000000 --- a/sdk/identity/azure-identity/test/live/CMakeLists.txt +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# SPDX-License-Identifier: MIT - -cmake_minimum_required (VERSION 3.13) - -project (azure-identity-livetest LANGUAGES CXX) -set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_STANDARD_REQUIRED True) - -include(GoogleTest) - -add_executable ( - azure-identity-livetest - azure_identity_live_test.cpp - client_secret_credential_test.cpp - environment_credential_test.cpp - getenv.hpp -) - -if (MSVC) - # Disable warnings: - # - C26495: Variable - # - 'testing::internal::Mutex::critical_section_' - # - 'testing::internal::Mutex::critical_section_init_phase_' - # - 'testing::internal::Mutex::owner_thread_id_' - # - 'testing::internal::Mutex::type_' - # is uninitialized. Always initialize member variables (type.6). - # - C26812: The enum type - # - 'testing::internal::Mutex::StaticConstructorSelector' - # - 'testing::TestPartResult::Type' - # is unscoped. Prefer 'enum class' over 'enum' (Enum.3) - target_compile_options(azure-identity-livetest PUBLIC /wd6326 /wd26495 /wd26812) -endif() - -target_link_libraries(azure-identity-livetest PRIVATE azure-identity gtest gmock) - -# gtest_discover_tests will scan the test from azure-core-test and call add_test -# for each test to ctest. This enables `ctest -r` to run specific tests directly. -gtest_discover_tests(azure-identity-livetest - TEST_PREFIX azure-identity-livetest. - NO_PRETTY_TYPES - NO_PRETTY_VALUES -) diff --git a/sdk/identity/azure-identity/test/live/azure_identity_live_test.cpp b/sdk/identity/azure-identity/test/live/azure_identity_live_test.cpp deleted file mode 100644 index 471d6e961..000000000 --- a/sdk/identity/azure-identity/test/live/azure_identity_live_test.cpp +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// SPDX-License-Identifier: MIT - -#include - -int main(int argc, char** argv) -{ - testing::InitGoogleTest(&argc, argv); - auto r = RUN_ALL_TESTS(); - return r; -} diff --git a/sdk/identity/azure-identity/test/live/client_secret_credential_test.cpp b/sdk/identity/azure-identity/test/live/client_secret_credential_test.cpp deleted file mode 100644 index c0ee268db..000000000 --- a/sdk/identity/azure-identity/test/live/client_secret_credential_test.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// SPDX-License-Identifier: MIT - -#include - -#include - -#include - -#include "getenv.hpp" - -TEST(ClientSecretCredential, Basic) -{ - Azure::Identity::ClientSecretCredential const credential( - GetEnv("AZURE_TENANT_ID"), GetEnv("AZURE_CLIENT_ID"), GetEnv("AZURE_CLIENT_SECRET")); - - auto const token = credential.GetToken( - {{"https://vault.azure.net/.default"}}, Azure::Core::Context::ApplicationContext); - - EXPECT_FALSE(token.Token.empty()); - EXPECT_GE(token.ExpiresOn, std::chrono::system_clock::now()); -} diff --git a/sdk/identity/azure-identity/test/live/environment_credential_test.cpp b/sdk/identity/azure-identity/test/live/environment_credential_test.cpp deleted file mode 100644 index 3793b24b3..000000000 --- a/sdk/identity/azure-identity/test/live/environment_credential_test.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// SPDX-License-Identifier: MIT - -#include - -#include - -#include - -#include "getenv.hpp" - -TEST(EnvironmentCredential, ClientSecret) -{ - // See EnvironmentCredential's documentation - these below are the environment variables it reads - // from. - EXPECT_FALSE(GetEnv("AZURE_TENANT_ID").empty()); - EXPECT_FALSE(GetEnv("AZURE_CLIENT_ID").empty()); - EXPECT_FALSE(GetEnv("AZURE_CLIENT_SECRET").empty()); - - Azure::Identity::EnvironmentCredential const credential; - - auto const token = credential.GetToken( - {{"https://vault.azure.net/.default"}}, Azure::Core::Context::ApplicationContext); - - EXPECT_FALSE(token.Token.empty()); - EXPECT_GE(token.ExpiresOn, std::chrono::system_clock::now()); -} diff --git a/sdk/identity/azure-identity/test/live/getenv.hpp b/sdk/identity/azure-identity/test/live/getenv.hpp deleted file mode 100644 index 4c1257833..000000000 --- a/sdk/identity/azure-identity/test/live/getenv.hpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// SPDX-License-Identifier: MIT - -#include - -inline std::string GetEnv(std::string const& name) -{ -#if defined(_MSC_VER) -#pragma warning(push) -// warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s -// instead. -#pragma warning(disable : 4996) -#endif - auto const result = std::getenv(name.c_str()); - return result != nullptr ? result : ""; -#if defined(_MSC_VER) -#pragma warning(pop) -#endif -} diff --git a/sdk/identity/azure-identity/test/ut/CMakeLists.txt b/sdk/identity/azure-identity/test/ut/CMakeLists.txt index f8453a4f7..2a6f70d42 100644 --- a/sdk/identity/azure-identity/test/ut/CMakeLists.txt +++ b/sdk/identity/azure-identity/test/ut/CMakeLists.txt @@ -11,9 +11,11 @@ set(CMAKE_CXX_STANDARD_REQUIRED True) include(GoogleTest) +# Export the test folder for recordings access. +add_compile_definitions(AZURE_TEST_RECORDING_DIR="${CMAKE_CURRENT_LIST_DIR}") + add_executable ( azure-identity-test - azure_identity_test.cpp client_secret_credential_test.cpp credential_test_helper.cpp credential_test_helper.hpp @@ -21,7 +23,9 @@ add_executable ( macro_guard_test.cpp managed_identity_credential_test.cpp simplified_header_test.cpp - token_credential_impl_test.cpp) + token_credential_impl_test.cpp + token_credential_test.cpp + ) if (MSVC) # Disable warnings: @@ -41,11 +45,11 @@ endif() # Adding private headers from identity to the tests so we can test the private APIs with no relative paths include. target_include_directories (azure-identity-test PRIVATE $) -target_link_libraries(azure-identity-test PRIVATE azure-identity gtest gmock) +target_link_libraries(azure-identity-test PRIVATE azure-identity azure-core-test-fw gtest gtest_main gmock) # gtest_discover_tests will scan the test from azure-identity-test and call add_test # for each test to ctest. This enables `ctest -r` to run specific tests directly. gtest_discover_tests(azure-identity-test - TEST_PREFIX azure-identity-unittest. + TEST_PREFIX azure-identity. NO_PRETTY_TYPES NO_PRETTY_VALUES) diff --git a/sdk/identity/azure-identity/test/ut/azure_identity_test.cpp b/sdk/identity/azure-identity/test/ut/azure_identity_test.cpp deleted file mode 100644 index 471d6e961..000000000 --- a/sdk/identity/azure-identity/test/ut/azure_identity_test.cpp +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// SPDX-License-Identifier: MIT - -#include - -int main(int argc, char** argv) -{ - testing::InitGoogleTest(&argc, argv); - auto r = RUN_ALL_TESTS(); - return r; -} diff --git a/sdk/identity/azure-identity/test/ut/recordings/TokenCredentialTest.ClientSecret.json b/sdk/identity/azure-identity/test/ut/recordings/TokenCredentialTest.ClientSecret.json new file mode 100644 index 000000000..bf1e2715b --- /dev/null +++ b/sdk/identity/azure-identity/test/ut/recordings/TokenCredentialTest.ClientSecret.json @@ -0,0 +1,29 @@ +{ + "networkCallRecords": [ + { + "Headers": { + "content-type": "application/x-www-form-urlencoded", + "user-agent": "azsdk-cpp-identity/1.2.0-beta.1 (Linux 5.4.0-1063-azure x86_64 #66~18.04.1-Ubuntu SMP Thu Oct 21 09:59:28 UTC 2021)", + "x-ms-client-request-id": "c187c183-9e54-4f1b-6aa0-93eec70c4975" + }, + "Method": "POST", + "Response": { + "BODY": "{\"token_type\":\"Bearer\",\"expires_in\":86399,\"ext_expires_in\":86399,\"access_token\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Imw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5Dehd-MNn1u4WQWseG508oCVej1u-jNHlkfe7FrXRNTGO2XKVJnMZy-M7fC1E55iFZLBr0eHbdF_2qQdDpTp40Se4ps9zg8CNbRmZyEl8N8cSsblkVm3i6DPQWk6GU6b_xtG3fBoizzA\"}", + "STATUS_CODE": "200", + "cache-control": "no-store, no-cache", + "content-length": "1315", + "content-type": "application/json; charset=utf-8", + "date": "Tue, 07 Dec 2021 18:26:58 GMT", + "expires": "-1", + "p3p": "CP=\"DSP CUR OTPi IND OTRi ONL FIN\"", + "pragma": "no-cache", + "set-cookie": "stsservicecookie=estsfd; path=/; secure; samesite=none; httponly", + "strict-transport-security": "max-age=31536000; includeSubDomains", + "x-content-type-options": "nosniff", + "x-ms-ests-server": "2.1.12249.17 - EUS ProdSlices", + "x-ms-request-id": "1c3b55a6-4381-4065-91ae-a8b0bb2c2f00" + }, + "Url": "https://REDACTED.microsoftonline.com/33333333-3333-3333-3333-333333333333/oauth2/v2.0/token" + } + ] +} diff --git a/sdk/identity/azure-identity/test/ut/recordings/TokenCredentialTest.EnvironmentCredential.json b/sdk/identity/azure-identity/test/ut/recordings/TokenCredentialTest.EnvironmentCredential.json new file mode 100644 index 000000000..54f18b92d --- /dev/null +++ b/sdk/identity/azure-identity/test/ut/recordings/TokenCredentialTest.EnvironmentCredential.json @@ -0,0 +1,29 @@ +{ + "networkCallRecords": [ + { + "Headers": { + "content-type": "application/x-www-form-urlencoded", + "user-agent": "azsdk-cpp-identity/1.2.0-beta.1 (Linux 5.4.0-1063-azure x86_64 #66~18.04.1-Ubuntu SMP Thu Oct 21 09:59:28 UTC 2021)", + "x-ms-client-request-id": "249e2bf4-bc08-4dcf-477e-37ca159e120d" + }, + "Method": "POST", + "Response": { + "BODY": "{\"token_type\":\"Bearer\",\"expires_in\":86399,\"ext_expires_in\":86399,\"access_token\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Imwzc1EtNTBjQ0g0eEJWWkxIVEd3blNSNzY4MCI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NTnJJ5OGe9OxfH1oJA_TRDr2wk_CrTOyzH0ikKgAyrlTPKDk_SL7pjXhNKd61UIBP4vOzGA8YD_yorjrLVyag4s0OiS8JIg\"}", + "STATUS_CODE": "200", + "cache-control": "no-store, no-cache", + "content-length": "1315", + "content-type": "application/json; charset=utf-8", + "date": "Tue, 07 Dec 2021 18:26:58 GMT", + "expires": "-1", + "p3p": "CP=\"DSP CUR OTPi IND OTRi ONL FIN\"", + "pragma": "no-cache", + "set-cookie": "stsservicecookie=estsfd; path=/; secure; samesite=none; httponly", + "strict-transport-security": "max-age=31536000; includeSubDomains", + "x-content-type-options": "nosniff", + "x-ms-ests-server": "2.1.12249.17 - SCUS ProdSlices", + "x-ms-request-id": "3bf0a201-67a3-444f-90d8-a0c1d7b52f00" + }, + "Url": "https://REDACTED.microsoftonline.com/33333333-3333-3333-3333-333333333333/oauth2/v2.0/token" + } + ] +} diff --git a/sdk/identity/azure-identity/test/ut/token_credential_test.cpp b/sdk/identity/azure-identity/test/ut/token_credential_test.cpp new file mode 100644 index 000000000..1ad894727 --- /dev/null +++ b/sdk/identity/azure-identity/test/ut/token_credential_test.cpp @@ -0,0 +1,78 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +#include + +#include +#include +#include + +#include +#include + +namespace Azure { namespace Identity { namespace Test { + class TokenCredentialTest : public Azure::Core::Test::TestBase { + + protected: + // Required to rename the test properly once the test is started. + // We can only know the test instance name until the test instance is run. + std::unique_ptr GetClientSecretCredential( + std::string const& testName) + { + // set the interceptor for the current test + m_testContext.RenameTest(testName); + + Azure::Core::Credentials::TokenCredentialOptions options = GetTokenCredentialOptions(); + return std::make_unique( + GetEnv("AZURE_TENANT_ID"), + GetEnv("AZURE_CLIENT_ID"), + GetEnv("AZURE_CLIENT_SECRET"), + options); + } + + // Required to rename the test properly once the test is started. + // We can only know the test instance name until the test instance is run. + std::unique_ptr GetEnvironmentCredential( + std::string const& testName) + { + // set the interceptor for the current test + m_testContext.RenameTest(testName); + + Azure::Core::Credentials::TokenCredentialOptions options = GetTokenCredentialOptions(); + return std::make_unique(options); + } + + // Runs before every test. + virtual void SetUp() override + { + Azure::Core::Test::TestBase::SetUpTestBase(AZURE_TEST_RECORDING_DIR); + } + }; +}}} // namespace Azure::Identity::Test + +using namespace Azure::Identity::Test; +using namespace Azure::Identity; + +TEST_F(TokenCredentialTest, ClientSecret) +{ + std::string const testName(GetTestName()); + auto const clientSecretCredential = GetClientSecretCredential(testName); + + auto const token = clientSecretCredential->GetToken( + {{"https://vault.azure.net/.default"}}, Azure::Core::Context::ApplicationContext); + + EXPECT_FALSE(token.Token.empty()); + EXPECT_GE(token.ExpiresOn, std::chrono::system_clock::now()); +} + +TEST_F(TokenCredentialTest, EnvironmentCredential) +{ + std::string const testName(GetTestName()); + auto const clientSecretCredential = GetEnvironmentCredential(testName); + + auto const token = clientSecretCredential->GetToken( + {{"https://vault.azure.net/.default"}}, Azure::Core::Context::ApplicationContext); + + EXPECT_FALSE(token.Token.empty()); + EXPECT_GE(token.ExpiresOn, std::chrono::system_clock::now()); +} diff --git a/sdk/identity/ci.yml b/sdk/identity/ci.yml index c19d2f921..d791b0d05 100644 --- a/sdk/identity/ci.yml +++ b/sdk/identity/ci.yml @@ -26,8 +26,8 @@ stages: - template: ../../eng/pipelines/templates/stages/archetype-sdk-client.yml parameters: ServiceDirectory: identity - CtestRegex: azure-identity-unittest. - LiveTestCtestRegex: azure-identity-livetest. + CtestRegex: azure-identity. + LiveTestCtestRegex: azure-identity. LineCoverageTarget: 99 BranchCoverageTarget: 62 Artifacts: