Set secret (#2663)
* Progress stream reader * format * Update sdk/core/azure-core/src/io/body_stream.cpp Co-authored-by: JinmingHu <jinmhu@microsoft.com> * PR comments * remove * one more comment * replaced if null with azure_assert * moved from pointer to reference * first pass * src builds * new line * huzaaaaa * readme * strating point * get progress, need to deserialize now * serializer * some more * tests * more tests * some refactor * start * comment and formatting * set secret serializer * added serializer ut * add headers * working again * add cmake * cleanup relative paths * couple of updates * clang * working as expected * remove pedantic ; * include * pr comments * clang format * trigger * trigger 2 * PR comments * name value swap * updates from merge * pre PR * format * remove hpp from list * remove unused #include * put back hpp file * put the methods in a namespace * PR comments * some more comments * fixes Co-authored-by: JinmingHu <jinmhu@microsoft.com>
This commit is contained in:
parent
65d560dc11
commit
72b9cf9487
@ -29,8 +29,9 @@ endif()
|
||||
set(
|
||||
AZURE_SECURITY_KEYVAULT_SECRETS_HEADER
|
||||
inc/azure/keyvault/secrets/dll_import_export.hpp
|
||||
inc/azure/keyvault/secrets/secret_client.hpp
|
||||
inc/azure/keyvault/secrets/keyvault_secret.hpp
|
||||
inc/azure/keyvault/secrets/keyvault_secret_properties.hpp
|
||||
inc/azure/keyvault/secrets/secret_client.hpp
|
||||
inc/azure/keyvault/keyvault_secrets.hpp
|
||||
inc/azure/keyvault/secrets/keyvault_deleted_secret.hpp
|
||||
)
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <azure/keyvault/secrets/keyvault_secret_properties.hpp>
|
||||
#include "azure/keyvault/secrets/keyvault_secret_properties.hpp"
|
||||
|
||||
namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
|
||||
struct KeyVaultSecret
|
||||
@ -48,8 +48,8 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
|
||||
* @param name The name of the secret.
|
||||
* @param value The name of the secret.
|
||||
*/
|
||||
KeyVaultSecret(std::string name, std::string value)
|
||||
: Name(std::move(name)), Value(std::move(value))
|
||||
KeyVaultSecret(std::string const& name, std::string const& value)
|
||||
: Name(name), Value(value), Properties(name)
|
||||
{
|
||||
if (Name.empty())
|
||||
{
|
||||
|
||||
@ -123,5 +123,17 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
|
||||
*
|
||||
*/
|
||||
KeyvaultSecretProperties() = default;
|
||||
|
||||
/**
|
||||
* @brief Construct a new secret Properties object.
|
||||
*
|
||||
*/
|
||||
KeyvaultSecretProperties(std::string const& name) : Name(name)
|
||||
{
|
||||
if (Name.empty())
|
||||
{
|
||||
throw std::invalid_argument("Name cannot be empty");
|
||||
}
|
||||
};
|
||||
};
|
||||
}}}} // namespace Azure::Security::KeyVault::Secrets
|
||||
|
||||
@ -155,6 +155,34 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
|
||||
Azure::Response<KeyVaultDeletedSecret> GetDeletedSecret(
|
||||
std::string const& name,
|
||||
Azure::Core::Context const& context = Azure::Core::Context()) const;
|
||||
|
||||
/**
|
||||
* @brief Set a secret in a specified key vault.
|
||||
*
|
||||
* @param name The name of the secret<span class="x x-first x-last">.</span>
|
||||
* @param value The value of the secret<span class="x x-first x-last">.</span>
|
||||
*
|
||||
* @param context The context for the operation can be used for request cancellation.
|
||||
* @return The Secret wrapped in the Response.
|
||||
*/
|
||||
Azure::Response<KeyVaultSecret> SetSecret(
|
||||
std::string const& name,
|
||||
std::string const& value,
|
||||
Azure::Core::Context const& context = Azure::Core::Context()) const;
|
||||
|
||||
/**
|
||||
* @brief Set a secret in a specified key vault.
|
||||
*
|
||||
* @param name The name of the secret<span class="x x-first x-last">.</span>
|
||||
* @param secret The secret definition <span class="x x-first x-last">.</span>
|
||||
*
|
||||
* @param context The context for the operation can be used for request cancellation.
|
||||
* @return The Secret wrapped in the Response.
|
||||
*/
|
||||
Azure::Response<KeyVaultSecret> SetSecret(
|
||||
std::string const& name,
|
||||
KeyVaultSecret const& secret,
|
||||
Azure::Core::Context const& context = Azure::Core::Context()) const;
|
||||
};
|
||||
|
||||
}}}} // namespace Azure::Security::KeyVault::Secrets
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Serializers/sdeserializers for the KeyVault Secret client.
|
||||
* @brief Serializers/deserializers for the KeyVault Secret client.
|
||||
*
|
||||
*/
|
||||
|
||||
@ -32,7 +32,10 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
|
||||
KeyVaultSecret& key,
|
||||
Azure::Core::Http::RawResponse const& rawResponse);
|
||||
|
||||
// extract the host out of the URL (with port if available)
|
||||
// Serializes a key vault secret for set action
|
||||
static std::string KeyVaultSecretSerialize(KeyVaultSecret const& parameters);
|
||||
|
||||
// Extract the host out of the URL (with port if available)
|
||||
static std::string GetUrlAuthorityWithScheme(Azure::Core::Url const& url)
|
||||
{
|
||||
std::string urlString;
|
||||
|
||||
@ -78,4 +78,28 @@ Azure::Response<KeyVaultDeletedSecret> SecretClient::GetDeletedSecret(
|
||||
{_detail::DeletedSecretPath, name});
|
||||
}
|
||||
|
||||
Azure::Response<KeyVaultSecret> SecretClient::SetSecret(
|
||||
std::string const& name,
|
||||
std::string const& value,
|
||||
Azure::Core::Context const& context) const
|
||||
{
|
||||
KeyVaultSecret setParameters(name, value);
|
||||
return SetSecret(name, setParameters, context);
|
||||
}
|
||||
|
||||
Azure::Response<KeyVaultSecret> SecretClient::SetSecret(
|
||||
std::string const& name,
|
||||
KeyVaultSecret const& secret,
|
||||
Azure::Core::Context const& context) const
|
||||
{
|
||||
return m_protocolClient->SendRequest<KeyVaultSecret>(
|
||||
context,
|
||||
Azure::Core::Http::HttpMethod::Put,
|
||||
[&secret]() { return _detail::KeyVaultSecretSerializer::KeyVaultSecretSerialize(secret); },
|
||||
[&name](Azure::Core::Http::RawResponse const& rawResponse) {
|
||||
return _detail::KeyVaultSecretSerializer::KeyVaultSecretDeserialize(name, rawResponse);
|
||||
},
|
||||
{_detail::SecretPath, name});
|
||||
}
|
||||
|
||||
const ServiceVersion ServiceVersion::V7_2("7.2");
|
||||
|
||||
@ -152,3 +152,52 @@ void KeyVaultDeletedSecretSerializer::KeyVaultDeletedSecretDeserialize(
|
||||
secret.DeletedDate
|
||||
= PosixTimeConverter::PosixTimeToDateTime(jsonParser[_detail::DeletedDatePropertyName]);
|
||||
}
|
||||
|
||||
// serializes a set secret parameters object
|
||||
std::string KeyVaultSecretSerializer::KeyVaultSecretSerialize(KeyVaultSecret const& parameters)
|
||||
{
|
||||
Azure::Core::Json::_internal::json payload;
|
||||
using namespace Azure::Security::KeyVault::Secrets::_detail;
|
||||
|
||||
// value is required
|
||||
payload[ValuePropertyName] = parameters.Value;
|
||||
|
||||
// all else is optional
|
||||
JsonOptional::SetFromNullable(
|
||||
parameters.Properties.ContentType, payload, ContentTypePropertyName);
|
||||
|
||||
Azure::Core::Json::_internal::json attributes;
|
||||
|
||||
JsonOptional::SetFromNullable<Azure::DateTime, int64_t>(
|
||||
parameters.Properties.CreatedOn,
|
||||
attributes,
|
||||
CreatedPropertyName,
|
||||
PosixTimeConverter::DateTimeToPosixTime);
|
||||
JsonOptional::SetFromNullable(parameters.Properties.Enabled, attributes, EnabledPropertyName);
|
||||
JsonOptional::SetFromNullable<Azure::DateTime, int64_t>(
|
||||
parameters.Properties.ExpiresOn,
|
||||
attributes,
|
||||
ExpPropertyName,
|
||||
PosixTimeConverter::DateTimeToPosixTime);
|
||||
JsonOptional::SetFromNullable<Azure::DateTime, int64_t>(
|
||||
parameters.Properties.NotBefore,
|
||||
attributes,
|
||||
NbfPropertyName,
|
||||
PosixTimeConverter::DateTimeToPosixTime);
|
||||
JsonOptional::SetFromNullable(
|
||||
parameters.Properties.RecoverableDays, attributes, RecoverableDaysPropertyName);
|
||||
JsonOptional::SetFromNullable(
|
||||
parameters.Properties.RecoveryLevel, attributes, RecoveryLevelPropertyName);
|
||||
JsonOptional::SetFromNullable<Azure::DateTime, int64_t>(
|
||||
parameters.Properties.UpdatedOn,
|
||||
attributes,
|
||||
UpdatedPropertyName,
|
||||
PosixTimeConverter::DateTimeToPosixTime);
|
||||
|
||||
// optional tags
|
||||
attributes[TagsPropertyName] = Azure::Core::Json::_internal::json(parameters.Properties.Tags);
|
||||
|
||||
payload[AttributesPropertyName] = attributes;
|
||||
|
||||
return payload.dump();
|
||||
}
|
||||
|
||||
@ -19,10 +19,12 @@ int main()
|
||||
= std::make_shared<Azure::Identity::ClientSecretCredential>(tenantId, clientId, clientSecret);
|
||||
|
||||
SecretClient secretClient(std::getenv("AZURE_KEYVAULT_URL"), credential);
|
||||
// just a response, with a secret
|
||||
auto response = secretClient.GetSecret("testSecret");
|
||||
|
||||
auto response = secretClient.SetSecret("someSecret3", "someData");
|
||||
|
||||
auto response2 = secretClient.GetSecret("someSecret3");
|
||||
|
||||
// just a response, with a secret
|
||||
auto response2 = secretClient.GetDeletedSecret("someSecret");
|
||||
auto response3 = secretClient.GetDeletedSecret("someSecret");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -11,12 +11,12 @@ include(GoogleTest)
|
||||
|
||||
add_executable (
|
||||
azure-security-keyvault-secrets-test
|
||||
|
||||
macro_guard.cpp
|
||||
secret_client_test.cpp
|
||||
secret_get_client_deserialize_test.hpp
|
||||
secret_get_client_deserialize_test.cpp
|
||||
)
|
||||
secret_set_parameters_serializer_test.cpp
|
||||
)
|
||||
|
||||
if (MSVC)
|
||||
target_compile_options(azure-security-keyvault-secrets-test PUBLIC /wd6326 /wd26495 /wd26812)
|
||||
|
||||
@ -7,94 +7,95 @@
|
||||
#include "azure/keyvault/secrets/secret_client.hpp"
|
||||
|
||||
using namespace Azure::Security::KeyVault::Secrets;
|
||||
using namespace Azure::Security::KeyVault::Secrets::_test;
|
||||
using namespace Azure::Security::KeyVault::Secrets::_detail;
|
||||
|
||||
TEST(KeyVaultSecretSerializer, GetClientDeserializePartial1)
|
||||
{
|
||||
auto response = getPartialResponse();
|
||||
auto response = Helpers::GetPartialResponse();
|
||||
|
||||
KeyVaultSecret secret = _detail::KeyVaultSecretSerializer::KeyVaultSecretDeserialize(response);
|
||||
runPartialExpect(secret);
|
||||
Helpers::RunPartialExpect(secret);
|
||||
}
|
||||
|
||||
TEST(KeyVaultSecretSerializer, GetClientDeserializePartial2)
|
||||
{
|
||||
auto response = getPartialResponse();
|
||||
auto response = Helpers::GetPartialResponse();
|
||||
|
||||
KeyVaultSecret secret
|
||||
= _detail::KeyVaultSecretSerializer::KeyVaultSecretDeserialize("name1", response);
|
||||
|
||||
runPartialExpect(secret);
|
||||
Helpers::RunPartialExpect(secret);
|
||||
}
|
||||
|
||||
TEST(KeyVaultSecretSerializer, GetClientDeserializePartial3)
|
||||
{
|
||||
auto response = getPartialResponse();
|
||||
auto response = Helpers::GetPartialResponse();
|
||||
|
||||
KeyVaultSecret secret = KeyVaultSecret("name2", "a");
|
||||
_detail::KeyVaultSecretSerializer::KeyVaultSecretDeserialize(secret, response);
|
||||
|
||||
runPartialExpect(secret);
|
||||
Helpers::RunPartialExpect(secret);
|
||||
}
|
||||
|
||||
TEST(KeyVaultSecretSerializer, GetClientdeserializeFull1)
|
||||
{
|
||||
auto response = getFullResponse();
|
||||
auto response = Helpers::GetFullResponse();
|
||||
|
||||
KeyVaultSecret secret = _detail::KeyVaultSecretSerializer::KeyVaultSecretDeserialize(response);
|
||||
runFullExpect(secret);
|
||||
Helpers::RunFullExpect(secret);
|
||||
}
|
||||
|
||||
TEST(KeyVaultSecretSerializer, GetClientdeserializeFull2)
|
||||
{
|
||||
auto response = getFullResponse();
|
||||
auto response = Helpers::GetFullResponse();
|
||||
|
||||
KeyVaultSecret secret
|
||||
= _detail::KeyVaultSecretSerializer::KeyVaultSecretDeserialize("name1", response);
|
||||
|
||||
runFullExpect(secret);
|
||||
Helpers::RunFullExpect(secret);
|
||||
}
|
||||
|
||||
TEST(KeyVaultSecretSerializer, GetClientdeserializeFull3)
|
||||
{
|
||||
auto response = getFullResponse();
|
||||
auto response = Helpers::GetFullResponse();
|
||||
|
||||
KeyVaultSecret secret = KeyVaultSecret("name2", "a");
|
||||
_detail::KeyVaultSecretSerializer::KeyVaultSecretDeserialize(secret, response);
|
||||
|
||||
runFullExpect(secret);
|
||||
Helpers::RunFullExpect(secret);
|
||||
}
|
||||
|
||||
TEST(KeyVaultDeletedSecretSerializer, GetDeletedClientDeserializeFull1)
|
||||
{
|
||||
auto response = getDeletedFullResponse();
|
||||
auto response = Helpers::GetDeletedFullResponse();
|
||||
|
||||
KeyVaultDeletedSecret secret
|
||||
= _detail::KeyVaultDeletedSecretSerializer::KeyVaultDeletedSecretDeserialize(response);
|
||||
|
||||
runFullExpect(secret, false);
|
||||
runDeletedExtras(secret);
|
||||
Helpers::RunFullExpect(secret, false);
|
||||
Helpers::RunDeletedExtras(secret);
|
||||
}
|
||||
|
||||
TEST(KeyVaultDeletedSecretSerializer, GetDeletedClientDeserializeFull2)
|
||||
{
|
||||
auto response = getDeletedFullResponse();
|
||||
auto response = Helpers::GetDeletedFullResponse();
|
||||
|
||||
KeyVaultDeletedSecret secret
|
||||
= _detail::KeyVaultDeletedSecretSerializer::KeyVaultDeletedSecretDeserialize(
|
||||
"name1", response);
|
||||
|
||||
runFullExpect(secret, false);
|
||||
runDeletedExtras(secret);
|
||||
Helpers::RunFullExpect(secret, false);
|
||||
Helpers::RunDeletedExtras(secret);
|
||||
}
|
||||
|
||||
TEST(KeyVaultDeletedSecretSerializer, GetDeletedClientDeserializeFull3)
|
||||
{
|
||||
auto response = getDeletedFullResponse();
|
||||
auto response = Helpers::GetDeletedFullResponse();
|
||||
|
||||
KeyVaultDeletedSecret secret = KeyVaultDeletedSecret("name2");
|
||||
_detail::KeyVaultDeletedSecretSerializer::KeyVaultDeletedSecretDeserialize(secret, response);
|
||||
|
||||
runFullExpect(secret, false);
|
||||
runDeletedExtras(secret);
|
||||
Helpers::RunFullExpect(secret, false);
|
||||
Helpers::RunDeletedExtras(secret);
|
||||
}
|
||||
|
||||
@ -11,12 +11,16 @@
|
||||
using namespace Azure::Security::KeyVault::Secrets;
|
||||
using namespace Azure::Core::Http::_internal;
|
||||
|
||||
namespace {
|
||||
Azure::Core::Http::RawResponse getPartialResponse()
|
||||
{
|
||||
auto response = Azure::Core::Http::RawResponse(1, 1, Azure::Core::Http::HttpStatusCode::Ok, "OK");
|
||||
namespace Azure { namespace Security { namespace KeyVault { namespace Secrets { namespace _test {
|
||||
struct Helpers
|
||||
{
|
||||
|
||||
constexpr static const uint8_t responseBody[] = R"json({
|
||||
static Azure::Core::Http::RawResponse GetPartialResponse()
|
||||
{
|
||||
auto response
|
||||
= Azure::Core::Http::RawResponse(1, 1, Azure::Core::Http::HttpStatusCode::Ok, "OK");
|
||||
|
||||
constexpr static const uint8_t responseBody[] = R"json({
|
||||
"value": "mysecretvalue",
|
||||
"id": "https://myvault.vault.azure.net/secrets/mysecretname/4387e9f3d6e14c459867679a90fd0f79",
|
||||
"attributes": {
|
||||
@ -28,22 +32,23 @@ Azure::Core::Http::RawResponse getPartialResponse()
|
||||
}
|
||||
)json";
|
||||
|
||||
response.SetHeader(HttpShared::ContentType, "application/json");
|
||||
response.SetHeader(HttpShared::MsRequestId, "1");
|
||||
response.SetHeader(HttpShared::MsClientRequestId, "2");
|
||||
response.SetBody(std::vector<uint8_t>(responseBody, responseBody + sizeof(responseBody)));
|
||||
response.SetBodyStream(
|
||||
std::make_unique<Azure::Core::IO::MemoryBodyStream>(responseBody, sizeof(responseBody) - 1));
|
||||
response.SetHeader(HttpShared::ContentType, "application/json");
|
||||
response.SetHeader(HttpShared::MsRequestId, "1");
|
||||
response.SetHeader(HttpShared::MsClientRequestId, "2");
|
||||
response.SetBody(std::vector<uint8_t>(responseBody, responseBody + sizeof(responseBody)));
|
||||
response.SetBodyStream(std::make_unique<Azure::Core::IO::MemoryBodyStream>(
|
||||
responseBody, sizeof(responseBody) - 1));
|
||||
|
||||
return response;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
Azure::Core::Http::RawResponse getFullResponse()
|
||||
static Azure::Core::Http::RawResponse GetFullResponse()
|
||||
|
||||
{
|
||||
auto response = Azure::Core::Http::RawResponse(1, 1, Azure::Core::Http::HttpStatusCode::Ok, "OK");
|
||||
{
|
||||
auto response
|
||||
= Azure::Core::Http::RawResponse(1, 1, Azure::Core::Http::HttpStatusCode::Ok, "OK");
|
||||
|
||||
constexpr static const uint8_t responseBody[] = R"json({
|
||||
constexpr static const uint8_t responseBody[] = R"json({
|
||||
"value": "mysecretvalue",
|
||||
"id": "https://myvault.vault.azure.net/secrets/mysecretname/4387e9f3d6e14c459867679a90fd0f79",
|
||||
"contentType" : "ct",
|
||||
@ -58,22 +63,23 @@ Azure::Core::Http::RawResponse getFullResponse()
|
||||
}
|
||||
)json";
|
||||
|
||||
response.SetHeader(HttpShared::ContentType, "application/json");
|
||||
response.SetHeader(HttpShared::MsRequestId, "1");
|
||||
response.SetHeader(HttpShared::MsClientRequestId, "2");
|
||||
response.SetBody(std::vector<uint8_t>(responseBody, responseBody + sizeof(responseBody)));
|
||||
response.SetBodyStream(
|
||||
std::make_unique<Azure::Core::IO::MemoryBodyStream>(responseBody, sizeof(responseBody) - 1));
|
||||
response.SetHeader(HttpShared::ContentType, "application/json");
|
||||
response.SetHeader(HttpShared::MsRequestId, "1");
|
||||
response.SetHeader(HttpShared::MsClientRequestId, "2");
|
||||
response.SetBody(std::vector<uint8_t>(responseBody, responseBody + sizeof(responseBody)));
|
||||
response.SetBodyStream(std::make_unique<Azure::Core::IO::MemoryBodyStream>(
|
||||
responseBody, sizeof(responseBody) - 1));
|
||||
|
||||
return response;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
Azure::Core::Http::RawResponse getDeletedFullResponse()
|
||||
static Azure::Core::Http::RawResponse GetDeletedFullResponse()
|
||||
|
||||
{
|
||||
auto response = Azure::Core::Http::RawResponse(1, 1, Azure::Core::Http::HttpStatusCode::Ok, "OK");
|
||||
{
|
||||
auto response
|
||||
= Azure::Core::Http::RawResponse(1, 1, Azure::Core::Http::HttpStatusCode::Ok, "OK");
|
||||
|
||||
constexpr static const uint8_t responseBody[] = R"json({
|
||||
constexpr static const uint8_t responseBody[] = R"json({
|
||||
"recoveryId": "https://myvault.vault.azure.net/deletedsecrets/GetDeletedSecretTest",
|
||||
"deletedDate": 1493938433,
|
||||
"scheduledPurgeDate": 1501714433,
|
||||
@ -87,63 +93,66 @@ Azure::Core::Http::RawResponse getDeletedFullResponse()
|
||||
}
|
||||
})json";
|
||||
|
||||
response.SetHeader(HttpShared::ContentType, "application/json");
|
||||
response.SetHeader(HttpShared::MsRequestId, "1");
|
||||
response.SetHeader(HttpShared::MsClientRequestId, "2");
|
||||
response.SetBody(std::vector<uint8_t>(responseBody, responseBody + sizeof(responseBody)));
|
||||
response.SetBodyStream(
|
||||
std::make_unique<Azure::Core::IO::MemoryBodyStream>(responseBody, sizeof(responseBody) - 1));
|
||||
response.SetHeader(HttpShared::ContentType, "application/json");
|
||||
response.SetHeader(HttpShared::MsRequestId, "1");
|
||||
response.SetHeader(HttpShared::MsClientRequestId, "2");
|
||||
response.SetBody(std::vector<uint8_t>(responseBody, responseBody + sizeof(responseBody)));
|
||||
response.SetBodyStream(std::make_unique<Azure::Core::IO::MemoryBodyStream>(
|
||||
responseBody, sizeof(responseBody) - 1));
|
||||
|
||||
return response;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
void runPartialExpect(KeyVaultSecret& secret, bool expectValue = true)
|
||||
{
|
||||
if (expectValue)
|
||||
{
|
||||
EXPECT_EQ(secret.Value, "mysecretvalue");
|
||||
}
|
||||
static void RunPartialExpect(KeyVaultSecret& secret, bool expectValue = true)
|
||||
{
|
||||
if (expectValue)
|
||||
{
|
||||
EXPECT_EQ(secret.Value, "mysecretvalue");
|
||||
}
|
||||
|
||||
EXPECT_EQ(secret.Name, "mysecretname");
|
||||
EXPECT_EQ(secret.Properties.VaultUrl, "https://myvault.vault.azure.net");
|
||||
EXPECT_EQ(secret.Properties.Version, "4387e9f3d6e14c459867679a90fd0f79");
|
||||
EXPECT_EQ(secret.Properties.Id, secret.Id);
|
||||
EXPECT_EQ(
|
||||
secret.Id,
|
||||
"https://myvault.vault.azure.net/secrets/mysecretname/4387e9f3d6e14c459867679a90fd0f79");
|
||||
EXPECT_EQ(secret.Properties.KeyId.HasValue(), false);
|
||||
EXPECT_EQ(secret.Properties.Managed, false);
|
||||
EXPECT_EQ(secret.Properties.UpdatedOn.HasValue(), true);
|
||||
EXPECT_EQ(secret.Properties.CreatedOn.HasValue(), true);
|
||||
}
|
||||
EXPECT_EQ(secret.Name, "mysecretname");
|
||||
EXPECT_EQ(secret.Properties.VaultUrl, "https://myvault.vault.azure.net");
|
||||
EXPECT_EQ(secret.Properties.Version, "4387e9f3d6e14c459867679a90fd0f79");
|
||||
EXPECT_EQ(secret.Properties.Id, secret.Id);
|
||||
EXPECT_EQ(
|
||||
secret.Id,
|
||||
"https://myvault.vault.azure.net/secrets/mysecretname/"
|
||||
"4387e9f3d6e14c459867679a90fd0f79");
|
||||
EXPECT_EQ(secret.Properties.KeyId.HasValue(), false);
|
||||
EXPECT_EQ(secret.Properties.Managed, false);
|
||||
EXPECT_EQ(secret.Properties.UpdatedOn.HasValue(), true);
|
||||
EXPECT_EQ(secret.Properties.CreatedOn.HasValue(), true);
|
||||
}
|
||||
|
||||
void runFullExpect(KeyVaultSecret& secret, bool expectValue = true)
|
||||
{
|
||||
if (expectValue)
|
||||
{
|
||||
EXPECT_EQ(secret.Value, "mysecretvalue");
|
||||
EXPECT_EQ(secret.Properties.ContentType.Value(), "ct");
|
||||
EXPECT_EQ(secret.Properties.KeyId.Value(), "kid");
|
||||
}
|
||||
static void RunFullExpect(KeyVaultSecret& secret, bool expectValue = true)
|
||||
{
|
||||
if (expectValue)
|
||||
{
|
||||
EXPECT_EQ(secret.Value, "mysecretvalue");
|
||||
EXPECT_EQ(secret.Properties.ContentType.Value(), "ct");
|
||||
EXPECT_EQ(secret.Properties.KeyId.Value(), "kid");
|
||||
}
|
||||
|
||||
EXPECT_EQ(secret.Name, "mysecretname");
|
||||
EXPECT_EQ(secret.Properties.VaultUrl, "https://myvault.vault.azure.net");
|
||||
EXPECT_EQ(secret.Properties.Version, "4387e9f3d6e14c459867679a90fd0f79");
|
||||
EXPECT_EQ(secret.Properties.Id, secret.Id);
|
||||
EXPECT_EQ(
|
||||
secret.Id,
|
||||
"https://myvault.vault.azure.net/secrets/mysecretname/4387e9f3d6e14c459867679a90fd0f79");
|
||||
EXPECT_EQ(secret.Properties.Enabled.Value(), true);
|
||||
EXPECT_EQ(secret.Properties.Managed, true);
|
||||
EXPECT_EQ(secret.Properties.UpdatedOn.HasValue(), true);
|
||||
EXPECT_EQ(secret.Properties.CreatedOn.HasValue(), true);
|
||||
}
|
||||
EXPECT_EQ(secret.Name, "mysecretname");
|
||||
EXPECT_EQ(secret.Properties.VaultUrl, "https://myvault.vault.azure.net");
|
||||
EXPECT_EQ(secret.Properties.Version, "4387e9f3d6e14c459867679a90fd0f79");
|
||||
EXPECT_EQ(secret.Properties.Id, secret.Id);
|
||||
EXPECT_EQ(
|
||||
secret.Id,
|
||||
"https://myvault.vault.azure.net/secrets/mysecretname/"
|
||||
"4387e9f3d6e14c459867679a90fd0f79");
|
||||
EXPECT_EQ(secret.Properties.Enabled.Value(), true);
|
||||
EXPECT_EQ(secret.Properties.Managed, true);
|
||||
EXPECT_EQ(secret.Properties.UpdatedOn.HasValue(), true);
|
||||
EXPECT_EQ(secret.Properties.CreatedOn.HasValue(), true);
|
||||
}
|
||||
|
||||
void runDeletedExtras(KeyVaultDeletedSecret& secret)
|
||||
{
|
||||
EXPECT_EQ(
|
||||
secret.RecoveryId, "https://myvault.vault.azure.net/deletedsecrets/GetDeletedSecretTest");
|
||||
EXPECT_EQ(secret.ScheduledPurgeDate.ToString(), "2017-08-02T22:53:53Z");
|
||||
EXPECT_EQ(secret.DeletedDate.ToString(), "2017-05-04T22:53:53Z");
|
||||
}
|
||||
} // namespace
|
||||
static void RunDeletedExtras(KeyVaultDeletedSecret& secret)
|
||||
{
|
||||
EXPECT_EQ(
|
||||
secret.RecoveryId, "https://myvault.vault.azure.net/deletedsecrets/GetDeletedSecretTest");
|
||||
EXPECT_EQ(secret.ScheduledPurgeDate.ToString(), "2017-08-02T22:53:53Z");
|
||||
EXPECT_EQ(secret.DeletedDate.ToString(), "2017-05-04T22:53:53Z");
|
||||
}
|
||||
};
|
||||
}}}}} // namespace Azure::Security::KeyVault::Secrets::_test
|
||||
|
||||
@ -0,0 +1,61 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "private/secret_constants.hpp"
|
||||
#include "private/secret_serializers.hpp"
|
||||
|
||||
#include "../src/private/secret_serializers.hpp"
|
||||
#include "azure/core/internal/json/json.hpp"
|
||||
#include "azure/core/internal/json/json_optional.hpp"
|
||||
#include "azure/core/internal/json/json_serializable.hpp"
|
||||
#include "azure/keyvault/secrets/secret_client.hpp"
|
||||
#include "secret_get_client_deserialize_test.hpp"
|
||||
|
||||
using namespace Azure::Security::KeyVault::Secrets;
|
||||
using namespace Azure::Security::KeyVault::Secrets::_detail;
|
||||
using namespace Azure::Core::Json::_internal;
|
||||
|
||||
TEST(KeyvaultSecretSetParametersSerializer, SetValue)
|
||||
{
|
||||
KeyVaultSecret params("name", "value");
|
||||
|
||||
std::string result = KeyVaultSecretSerializer::KeyVaultSecretSerialize(params);
|
||||
|
||||
auto jsonParser = json::parse(result);
|
||||
|
||||
EXPECT_EQ(jsonParser[ValuePropertyName], params.Value);
|
||||
EXPECT_EQ(jsonParser[IdPropertyName], nullptr);
|
||||
EXPECT_EQ(jsonParser[ContentTypePropertyName], nullptr);
|
||||
}
|
||||
|
||||
TEST(KeyvaultSecretSetParametersSerializer, SetValueCT)
|
||||
{
|
||||
KeyVaultSecret params("name", "value");
|
||||
|
||||
params.Properties.ContentType = "ct";
|
||||
|
||||
std::string result = KeyVaultSecretSerializer::KeyVaultSecretSerialize(params);
|
||||
|
||||
auto jsonParser = json::parse(result);
|
||||
|
||||
EXPECT_EQ(jsonParser[ValuePropertyName], params.Value);
|
||||
EXPECT_EQ(jsonParser[ContentTypePropertyName], params.Properties.ContentType.Value());
|
||||
}
|
||||
|
||||
TEST(KeyvaultSecretSetParametersSerializer, SetValueCTAttrTag)
|
||||
{
|
||||
KeyVaultSecret params("name", "value");
|
||||
|
||||
params.Properties.ContentType = "ct";
|
||||
params.Properties.Enabled = true;
|
||||
params.Properties.Tags = std::unordered_map<std::string, std::string>{{"a", "b"}};
|
||||
|
||||
std::string result = KeyVaultSecretSerializer::KeyVaultSecretSerialize(params);
|
||||
|
||||
auto jsonParser = json::parse(result);
|
||||
|
||||
EXPECT_EQ(jsonParser[ValuePropertyName], params.Value);
|
||||
EXPECT_EQ(jsonParser[AttributesPropertyName][TagsPropertyName]["a"], "b");
|
||||
EXPECT_EQ(jsonParser[AttributesPropertyName][EnabledPropertyName], true);
|
||||
EXPECT_EQ(jsonParser[ContentTypePropertyName], params.Properties.ContentType.Value());
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user