update polling timeout to 5 min (#2641)
* update polling timeout to 5 min * update all polling intervals * disable purge testing until it is again supported by service * update live tests * update test to avoid checking number of keys * fix test - look keys in deleted keys * max timeout
This commit is contained in:
parent
c4b88f933e
commit
82ca4cfc83
@ -54,7 +54,8 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
|
||||
std::unique_ptr<Azure::Core::Http::RawResponse> rawResponse,
|
||||
std::shared_ptr<KeyClient> keyClient,
|
||||
std::string const& keyName = std::string())
|
||||
: m_keyName(keyName), m_keyClient(keyClient), Items(std::move(keyProperties.Items))
|
||||
: PagedResponse(std::move(keyProperties)), m_keyName(keyName), m_keyClient(keyClient),
|
||||
Items(std::move(keyProperties.Items))
|
||||
{
|
||||
RawResponse = std::move(rawResponse);
|
||||
}
|
||||
@ -101,7 +102,8 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
|
||||
DeletedKeyPagedResponse&& deletedKeyProperties,
|
||||
std::unique_ptr<Azure::Core::Http::RawResponse> rawResponse,
|
||||
std::shared_ptr<KeyClient> keyClient)
|
||||
: m_keyClient(keyClient), Items(std::move(deletedKeyProperties.Items))
|
||||
: PagedResponse(std::move(deletedKeyProperties)), m_keyClient(keyClient),
|
||||
Items(std::move(deletedKeyProperties.Items))
|
||||
{
|
||||
RawResponse = std::move(rawResponse);
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ TEST_F(KeyVaultClientTest, BackupKey)
|
||||
// Delete
|
||||
std::cout << std::endl << "- Delete key";
|
||||
auto response = keyClient.StartDeleteKey(keyName);
|
||||
response.PollUntilDone(std::chrono::milliseconds(1000));
|
||||
response.PollUntilDone(m_testPollingIntervalMinutes);
|
||||
}
|
||||
{
|
||||
// Purge
|
||||
@ -53,7 +53,7 @@ TEST_F(KeyVaultClientTest, BackupKey)
|
||||
auto response = keyClient.PurgeDeletedKey(keyName);
|
||||
CheckValidResponse(response, Azure::Core::Http::HttpStatusCode::NoContent);
|
||||
// Purge can take up to 2 min
|
||||
std::this_thread::sleep_for(std::chrono::minutes(2));
|
||||
std::this_thread::sleep_for(std::chrono::minutes(4));
|
||||
}
|
||||
{ // Check key is gone
|
||||
EXPECT_THROW(keyClient.GetKey(keyName), Azure::Core::RequestFailedException);
|
||||
@ -70,15 +70,4 @@ TEST_F(KeyVaultClientTest, BackupKey)
|
||||
CheckValidResponse(response);
|
||||
EXPECT_EQ(keyName, response.Value.Name());
|
||||
}
|
||||
{
|
||||
// Delete
|
||||
std::cout << std::endl << "- Clean";
|
||||
auto response = keyClient.StartDeleteKey(keyName);
|
||||
response.PollUntilDone(std::chrono::milliseconds(1000));
|
||||
}
|
||||
{
|
||||
// Purge
|
||||
auto response = keyClient.PurgeDeletedKey(keyName);
|
||||
CheckValidResponse(response, Azure::Core::Http::HttpStatusCode::NoContent);
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,10 @@
|
||||
namespace Azure { namespace Security { namespace KeyVault { namespace Keys { namespace Test {
|
||||
|
||||
class KeyVaultClientTest : public ::testing::TestWithParam<int> {
|
||||
protected:
|
||||
int m_testPollingTimeOutMinutes = 20;
|
||||
std::chrono::minutes m_testPollingIntervalMinutes = std::chrono::minutes(1);
|
||||
|
||||
private:
|
||||
std::string GetEnv(const std::string& name, std::string const& defaultValue = std::string())
|
||||
{
|
||||
@ -127,7 +131,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { nam
|
||||
<< " Will be deleted and purged now...";
|
||||
for (auto& deletedKey : deletedKeys)
|
||||
{
|
||||
auto readyToPurgeKey = deletedKey.PollUntilDone(std::chrono::milliseconds(1000));
|
||||
auto readyToPurgeKey = deletedKey.PollUntilDone(std::chrono::minutes(1));
|
||||
keyClient.PurgeDeletedKey(readyToPurgeKey.Value.Name());
|
||||
std::cout << std::endl << "Deleted and purged key: " + readyToPurgeKey.Value.Name();
|
||||
}
|
||||
|
||||
@ -191,14 +191,6 @@ TEST_F(KeyVaultClientTest, CreateEcHsmKey)
|
||||
auto keyVaultKey = keyResponse.Value;
|
||||
EXPECT_EQ(keyVaultKey.Name(), keyName);
|
||||
}
|
||||
{
|
||||
// Delete key
|
||||
auto keyResponseOperation = keyClient.StartDeleteKey(keyName);
|
||||
auto keyResponse = keyResponseOperation.PollUntilDone(std::chrono::milliseconds(1000));
|
||||
CheckValidResponse(keyResponse);
|
||||
auto keyVaultKey = keyResponse.Value;
|
||||
EXPECT_EQ(keyVaultKey.Name(), keyName);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(KeyVaultClientTest, CreateRsaHsmKey)
|
||||
@ -220,12 +212,4 @@ TEST_F(KeyVaultClientTest, CreateRsaHsmKey)
|
||||
auto keyVaultKey = keyResponse.Value;
|
||||
EXPECT_EQ(keyVaultKey.Name(), keyName);
|
||||
}
|
||||
{
|
||||
// Delete key
|
||||
auto keyResponseOperation = keyClient.StartDeleteKey(keyName);
|
||||
auto keyResponse = keyResponseOperation.PollUntilDone(std::chrono::milliseconds(1000));
|
||||
CheckValidResponse(keyResponse);
|
||||
auto keyVaultKey = keyResponse.Value;
|
||||
EXPECT_EQ(keyVaultKey.Name(), keyName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
#include <string>
|
||||
|
||||
namespace {
|
||||
|
||||
std::string GetNotFoundErrorMsg(std::string const& keyName)
|
||||
{
|
||||
return "A key with (name/id) " + keyName
|
||||
@ -58,7 +59,8 @@ TEST_F(KeyVaultClientTest, DeleteKey)
|
||||
// The polling operation would usually complete in ~20 seconds.
|
||||
// Setting 3 min as timeout just because I like number 3. We just want to prevent test running
|
||||
// for so long if something happens and no exception is thrown (paranoid scenario)
|
||||
auto duration = std::chrono::system_clock::now() + std::chrono::minutes(3);
|
||||
auto duration
|
||||
= std::chrono::system_clock::now() + std::chrono::minutes(m_testPollingTimeOutMinutes);
|
||||
auto cancelToken = Azure::Core::Context::ApplicationContext.WithDeadline(duration);
|
||||
|
||||
auto keyResponseLRO = keyClient.StartDeleteKey(keyName);
|
||||
@ -66,21 +68,16 @@ TEST_F(KeyVaultClientTest, DeleteKey)
|
||||
EXPECT_EQ(keyResponseLRO.GetResumeToken(), expectedStatusToken);
|
||||
// poll each second until key is soft-deleted
|
||||
// Will throw and fail test if test takes more than 3 minutes (token cancelled)
|
||||
auto keyResponse = keyResponseLRO.PollUntilDone(std::chrono::milliseconds(1000), cancelToken);
|
||||
auto keyResponse = keyResponseLRO.PollUntilDone(m_testPollingIntervalMinutes, cancelToken);
|
||||
}
|
||||
{
|
||||
// recover
|
||||
auto recoverOperation = keyClient.StartRecoverDeletedKey(keyName);
|
||||
auto keyResponse = recoverOperation.PollUntilDone(std::chrono::milliseconds(500));
|
||||
auto keyResponse = recoverOperation.PollUntilDone(m_testPollingIntervalMinutes);
|
||||
auto key = keyResponse.Value;
|
||||
// Delete again for purging
|
||||
auto deleteOp = keyClient.StartDeleteKey(key.Name());
|
||||
deleteOp.PollUntilDone(std::chrono::milliseconds(200));
|
||||
}
|
||||
{
|
||||
// Purge
|
||||
auto response = keyClient.PurgeDeletedKey(keyName);
|
||||
CheckValidResponse(response, Azure::Core::Http::HttpStatusCode::NoContent);
|
||||
deleteOp.PollUntilDone(m_testPollingIntervalMinutes);
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,10 +142,11 @@ TEST_F(KeyVaultClientTest, DoubleDelete)
|
||||
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::KeyVaultKeyType::Ec);
|
||||
}
|
||||
{
|
||||
auto duration = std::chrono::system_clock::now() + std::chrono::minutes(3);
|
||||
auto duration
|
||||
= std::chrono::system_clock::now() + std::chrono::minutes(m_testPollingTimeOutMinutes);
|
||||
auto cancelToken = Azure::Core::Context::ApplicationContext.WithDeadline(duration);
|
||||
auto keyResponseLRO = keyClient.StartDeleteKey(keyName);
|
||||
auto keyResponse = keyResponseLRO.PollUntilDone(std::chrono::milliseconds(1000), cancelToken);
|
||||
auto keyResponse = keyResponseLRO.PollUntilDone(m_testPollingIntervalMinutes, cancelToken);
|
||||
}
|
||||
// delete same key again
|
||||
auto wasThrown = false;
|
||||
@ -219,10 +217,11 @@ TEST_F(KeyVaultClientTest, CreateDeletedKey)
|
||||
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::KeyVaultKeyType::Ec);
|
||||
}
|
||||
{
|
||||
auto duration = std::chrono::system_clock::now() + std::chrono::minutes(3);
|
||||
auto duration
|
||||
= std::chrono::system_clock::now() + std::chrono::minutes(m_testPollingTimeOutMinutes);
|
||||
auto cancelToken = Azure::Core::Context::ApplicationContext.WithDeadline(duration);
|
||||
auto keyResponseLRO = keyClient.StartDeleteKey(keyName);
|
||||
auto keyResponse = keyResponseLRO.PollUntilDone(std::chrono::milliseconds(1000), cancelToken);
|
||||
auto keyResponse = keyResponseLRO.PollUntilDone(m_testPollingIntervalMinutes, cancelToken);
|
||||
}
|
||||
// Create a key with same name
|
||||
auto wasThrown = false;
|
||||
@ -300,13 +299,14 @@ TEST_F(KeyVaultClientTest, GetDeletedKey)
|
||||
}
|
||||
{
|
||||
// Wait until key is deleted
|
||||
auto duration = std::chrono::system_clock::now() + std::chrono::minutes(3);
|
||||
auto duration
|
||||
= std::chrono::system_clock::now() + std::chrono::minutes(m_testPollingTimeOutMinutes);
|
||||
auto cancelToken = Azure::Core::Context::ApplicationContext.WithDeadline(duration);
|
||||
|
||||
auto keyResponseLRO = keyClient.StartDeleteKey(keyName);
|
||||
auto expectedStatusToken = m_keyVaultUrl
|
||||
+ std::string(Azure::Security::KeyVault::Keys::_detail::DeletedKeysPath) + "/" + keyName;
|
||||
auto keyResponse = keyResponseLRO.PollUntilDone(std::chrono::milliseconds(1000), cancelToken);
|
||||
auto keyResponse = keyResponseLRO.PollUntilDone(m_testPollingIntervalMinutes, cancelToken);
|
||||
}
|
||||
{
|
||||
// Get the deleted key
|
||||
@ -340,21 +340,7 @@ TEST_F(KeyVaultClientTest, DeleteOperationResumeToken)
|
||||
auto resumeOperation
|
||||
= Azure::Security::KeyVault::Keys::DeleteKeyOperation::CreateFromResumeToken(
|
||||
resumeToken, keyClient);
|
||||
resumeOperation.PollUntilDone(std::chrono::milliseconds(500));
|
||||
}
|
||||
{
|
||||
// recover
|
||||
auto recoverOperation = keyClient.StartRecoverDeletedKey(keyName);
|
||||
auto keyResponse = recoverOperation.PollUntilDone(std::chrono::milliseconds(500));
|
||||
auto key = keyResponse.Value;
|
||||
// Delete again for purging
|
||||
auto deleteOp = keyClient.StartDeleteKey(key.Name());
|
||||
deleteOp.PollUntilDone(std::chrono::milliseconds(200));
|
||||
}
|
||||
{
|
||||
// Purge
|
||||
auto response = keyClient.PurgeDeletedKey(keyName);
|
||||
CheckValidResponse(response, Azure::Core::Http::HttpStatusCode::NoContent);
|
||||
resumeOperation.PollUntilDone(m_testPollingIntervalMinutes);
|
||||
}
|
||||
}
|
||||
|
||||
@ -380,7 +366,7 @@ TEST_F(KeyVaultClientTest, RecoverOperationResumeToken)
|
||||
auto resumeOperation
|
||||
= Azure::Security::KeyVault::Keys::DeleteKeyOperation::CreateFromResumeToken(
|
||||
resumeToken, keyClient);
|
||||
resumeOperation.PollUntilDone(std::chrono::milliseconds(500));
|
||||
resumeOperation.PollUntilDone(m_testPollingIntervalMinutes);
|
||||
}
|
||||
{
|
||||
// recover
|
||||
@ -392,15 +378,7 @@ TEST_F(KeyVaultClientTest, RecoverOperationResumeToken)
|
||||
auto resumeRecoveryOp
|
||||
= Azure::Security::KeyVault::Keys::RecoverDeletedKeyOperation::CreateFromResumeToken(
|
||||
resumeToken, keyClient);
|
||||
auto keyResponse = resumeRecoveryOp.PollUntilDone(std::chrono::milliseconds(500));
|
||||
auto keyResponse = resumeRecoveryOp.PollUntilDone(m_testPollingIntervalMinutes);
|
||||
auto key = keyResponse.Value;
|
||||
// Delete again for purging
|
||||
auto deleteOp = keyClient.StartDeleteKey(key.Name());
|
||||
deleteOp.PollUntilDone(std::chrono::milliseconds(200));
|
||||
}
|
||||
{
|
||||
// Purge
|
||||
auto response = keyClient.PurgeDeletedKey(keyName);
|
||||
CheckValidResponse(response, Azure::Core::Http::HttpStatusCode::NoContent);
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,7 +20,6 @@ using namespace Azure::Security::KeyVault::Keys;
|
||||
TEST_F(KeyVaultClientTest, GetSingleKey)
|
||||
{
|
||||
KeyClient keyClient(m_keyVaultUrl, m_credential);
|
||||
// Assuming and RS Key exists in the KeyVault Account.
|
||||
std::string keyName(GetUniqueName());
|
||||
|
||||
auto createKeyResponse = keyClient.CreateEcKey(CreateEcKeyOptions(keyName));
|
||||
@ -69,9 +68,6 @@ TEST_F(KeyVaultClientTest, GetPropertiesOfKeysOnePage)
|
||||
auto findKeyName = std::find(keyNames.begin(), keyNames.end(), keyProperties.Name);
|
||||
EXPECT_NE(findKeyName, keyNames.end());
|
||||
}
|
||||
|
||||
// Clean vault
|
||||
RemoveAllKeysFromVault(keyClient, false);
|
||||
}
|
||||
|
||||
TEST_F(KeyVaultClientTest, GetKeysVersionsOnePage)
|
||||
@ -104,18 +100,12 @@ TEST_F(KeyVaultClientTest, GetKeysVersionsOnePage)
|
||||
{
|
||||
EXPECT_EQ(keyName, keyProperties.Name);
|
||||
}
|
||||
|
||||
// Clean vault
|
||||
RemoveAllKeysFromVault(keyClient, false);
|
||||
}
|
||||
|
||||
TEST_F(KeyVaultClientTest, GetDeletedKeysOnePage)
|
||||
{
|
||||
KeyClient keyClient(m_keyVaultUrl, m_credential);
|
||||
|
||||
// Delete and purge anything before starting the test to ensure test will work
|
||||
CleanUpKeyVault(keyClient);
|
||||
|
||||
// Create 5 keys
|
||||
std::vector<std::string> keyNames;
|
||||
for (int counter = 0; counter < 5; counter++)
|
||||
@ -135,31 +125,25 @@ TEST_F(KeyVaultClientTest, GetDeletedKeysOnePage)
|
||||
// wait for all of the delete operations to complete
|
||||
for (auto& operation : operations)
|
||||
{
|
||||
operation.PollUntilDone(std::chrono::milliseconds(1000));
|
||||
operation.PollUntilDone(m_testPollingIntervalMinutes);
|
||||
}
|
||||
|
||||
// Get all deleted Keys
|
||||
std::vector<DeletedKey> deletedKeys;
|
||||
std::vector<std::string> deletedKeys;
|
||||
for (auto keyResponse = keyClient.GetDeletedKeys(); keyResponse.HasPage();
|
||||
keyResponse.MoveToNextPage())
|
||||
{
|
||||
for (auto& key : keyResponse.Items)
|
||||
{
|
||||
deletedKeys.emplace_back(key);
|
||||
deletedKeys.emplace_back(key.Name());
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_EQ(keyNames.size(), deletedKeys.size());
|
||||
for (auto const& deletedKey : deletedKeys)
|
||||
// Check all keys are in the deleted key list
|
||||
for (auto const& key : keyNames)
|
||||
{
|
||||
// Check names are in the keyNames list
|
||||
auto findKeyName = std::find(keyNames.begin(), keyNames.end(), deletedKey.Name());
|
||||
EXPECT_NE(findKeyName, keyNames.end());
|
||||
}
|
||||
|
||||
// Purge
|
||||
for (auto const& keyName : keyNames)
|
||||
{
|
||||
keyClient.PurgeDeletedKey(keyName);
|
||||
auto findKeyName = std::find(deletedKeys.begin(), deletedKeys.end(), key);
|
||||
EXPECT_NE(findKeyName, deletedKeys.end());
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,11 +69,4 @@ TEST_F(KeyVaultClientTest, ImportKey)
|
||||
EXPECT_EQ(key.CurveName.Value().ToString(), returnedkey.Key.CurveName.Value().ToString());
|
||||
EXPECT_EQ(returnedkey.KeyOperations().size(), 1);
|
||||
EXPECT_EQ(returnedkey.KeyOperations()[0].ToString(), KeyOperation::Sign.ToString());
|
||||
|
||||
{
|
||||
// delete + purge
|
||||
auto op = keyClient.StartDeleteKey(keyName);
|
||||
op.PollUntilDone(std::chrono::milliseconds(1000));
|
||||
keyClient.PurgeDeletedKey(keyName);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user