grpc: support expire/delete API keys by ID
Update ExpireApiKey and DeleteApiKey handlers to accept either ID or prefix for identifying the API key. Returns InvalidArgument error if neither or both are provided. Add tests for: - Expire by ID - Expire by prefix (backwards compatibility) - Delete by ID - Delete by prefix (backwards compatibility) - Error when neither ID nor prefix provided - Error when both ID and prefix provided Updates #2986
This commit is contained in:
parent
8776745428
commit
a194712c34
3 changed files with 239 additions and 10 deletions
|
|
@ -246,3 +246,30 @@ func TestAPIKeyWithPrefix(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAPIKeyByID(t *testing.T) {
|
||||
db, err := newSQLiteTestDB()
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create an API key
|
||||
_, apiKey, err := db.CreateAPIKey(nil)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, apiKey)
|
||||
|
||||
// Retrieve by ID
|
||||
retrievedKey, err := db.GetAPIKeyByID(apiKey.ID)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, retrievedKey)
|
||||
assert.Equal(t, apiKey.ID, retrievedKey.ID)
|
||||
assert.Equal(t, apiKey.Prefix, retrievedKey.Prefix)
|
||||
}
|
||||
|
||||
func TestGetAPIKeyByIDNotFound(t *testing.T) {
|
||||
db, err := newSQLiteTestDB()
|
||||
require.NoError(t, err)
|
||||
|
||||
// Try to get a non-existent key by ID
|
||||
key, err := db.GetAPIKeyByID(99999)
|
||||
require.Error(t, err)
|
||||
assert.Nil(t, key)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue