For new surface area, classes marked as final should not have virtual methods. (#5331)

* Classes marked as final should not have virtual methods.

(cherry picked from commit 7413384c111b73be448f78527a08a544fd1f6ec6)

* Update changelog.

* Address PR feedback and use named-macro.

* Only use the macro for testing_build final classes.

* Add a new compile definition _azure_TESTING_BUILD.

* Add test as a friend class and put the test in a Identity specific test
namespace.

* Remove the macro for final expansion since doxygen struggles with it.

* Address PR feedback, add ifdef guard around _azure_VIRTUAL_FOR_TESTS.
This commit is contained in:
Ahson Khan 2024-02-09 17:46:04 -08:00 committed by GitHub
parent 78a3239006
commit ddd0f4bd07
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 667 additions and 639 deletions

View File

@ -127,6 +127,7 @@ az_rtti_setup(
if(BUILD_TESTING)
# define a symbol that enables some test hooks in code
add_compile_definitions(TESTING_BUILD)
add_compile_definitions(_azure_TESTING_BUILD)
# tests
if (NOT AZ_ALL_LIBRARIES OR FETCH_SOURCE_DEPS)

View File

@ -9,6 +9,7 @@
#pragma once
#include "azure/identity/detail/token_cache.hpp"
#include "azure/identity/dll_import_export.hpp"
#include <azure/core/credentials/credentials.hpp>
#include <azure/core/credentials/token_credential_options.hpp>
@ -18,6 +19,12 @@
#include <string>
#include <vector>
#if defined(_azure_TESTING_BUILD)
namespace Azure { namespace Identity { namespace Test {
class AzureCliTestCredential;
}}} // namespace Azure::Identity::Test
#endif
namespace Azure { namespace Identity {
/**
* @brief Options for configuring the #Azure::Identity::AzureCliCredential.
@ -50,10 +57,15 @@ namespace Azure { namespace Identity {
* token.
*/
class AzureCliCredential
#if !defined(TESTING_BUILD)
#if !defined(_azure_TESTING_BUILD)
final
#endif
: public Core::Credentials::TokenCredential {
#if defined(_azure_TESTING_BUILD)
friend class Azure::Identity::Test::AzureCliTestCredential;
#endif
protected:
/** @brief The cache for the access token. */
_detail::TokenCache m_tokenCache;
@ -106,13 +118,12 @@ namespace Azure { namespace Identity {
Core::Credentials::TokenRequestContext const& tokenRequestContext,
Core::Context const& context) const override;
#if !defined(TESTING_BUILD)
private:
#else
protected:
#endif
virtual std::string GetAzCommand(std::string const& scopes, std::string const& tenantId) const;
virtual int GetLocalTimeToUtcDiffSeconds() const;
_azure_VIRTUAL_FOR_TESTS std::string GetAzCommand(
std::string const& scopes,
std::string const& tenantId) const;
_azure_VIRTUAL_FOR_TESTS int GetLocalTimeToUtcDiffSeconds() const;
};
}} // namespace Azure::Identity

View File

@ -38,6 +38,16 @@
#undef AZ_IDENTITY_BUILT_AS_DLL
#if defined(_azure_TESTING_BUILD)
#if !defined(_azure_VIRTUAL_FOR_TESTS)
#define _azure_VIRTUAL_FOR_TESTS virtual
#endif
#else
#if !defined(_azure_VIRTUAL_FOR_TESTS)
#define _azure_VIRTUAL_FOR_TESTS
#endif
#endif
/**
* @brief Azure SDK abstractions.
*