When key not found during deletion, return 404 and not 500.

This commit is contained in:
Kishore Nallan 2021-05-20 14:49:57 +05:30
parent 16d91aec6f
commit e6340dd645
2 changed files with 9 additions and 1 deletions

View File

@ -117,7 +117,7 @@ Option<api_key_t> AuthManager::remove_key(uint32_t id) {
Option<api_key_t> key_op = get_key(id, false);
if(!key_op.ok()) {
return Option<api_key_t>(500, key_op.error());
return Option<api_key_t>(key_op.code(), key_op.error());
}
std::string api_key_store_key = std::string(API_KEYS_PREFIX) + "_" + std::to_string(id);

View File

@ -88,6 +88,14 @@ TEST_F(AuthManagerTest, CreateListDeleteAPIKeys) {
ASSERT_EQ("abcd", list_op.get()[0].value);
ASSERT_EQ("test key 2", list_op.get()[1].description);
ASSERT_EQ("abcd", list_op.get()[1].value);
// delete key
auto del_op = auth_manager.remove_key(1);
ASSERT_TRUE(del_op.ok());
del_op = auth_manager.remove_key(1000);
ASSERT_FALSE(del_op.ok());
ASSERT_EQ(404, del_op.code());
}
TEST_F(AuthManagerTest, CheckRestoreOfAPIKeys) {