mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-11-14 06:47:19 +00:00
fix(auth): 停用/删除分组后阻断 API Key
This commit is contained in:
1 parent
7ec61eb2f5
commit
22ff1acde3
7 files changed
+169
-18
No files matched your search
@@ -244,6 +244,21 @@ func (s *groupRepoStub) UpdateSortOrders(ctx context.Context, updates []GroupSor
|
||||
return nil
|
||||
}
|
||||
|
||||
type deleteGroupAPIKeyRepoStub struct {
|
||||
apiKeyRepoStubForGroupUpdate
|
||||
keys []string
|
||||
listErr error
|
||||
listGroupIDs []int64
|
||||
}
|
||||
|
||||
func (s *deleteGroupAPIKeyRepoStub) ListKeysByGroupID(ctx context.Context, groupID int64) ([]string, error) {
|
||||
s.listGroupIDs = append(s.listGroupIDs, groupID)
|
||||
if s.listErr != nil {
|
||||
return nil, s.listErr
|
||||
}
|
||||
return s.keys, nil
|
||||
}
|
||||
|
||||
type proxyRepoStub struct {
|
||||
deleteErr error
|
||||
countErr error
|
||||
@@ -500,6 +515,23 @@ func TestAdminService_DeleteGroup_Success_WithCacheInvalidation(t *testing.T) {
|
||||
}, calls)
|
||||
}
|
||||
|
||||
func TestAdminService_DeleteGroup_InvalidatesAuthCacheForBoundKeys(t *testing.T) {
|
||||
repo := &groupRepoStub{}
|
||||
apiKeyRepo := &deleteGroupAPIKeyRepoStub{keys: []string{"k1", "k2"}}
|
||||
invalidator := &authCacheInvalidatorStub{}
|
||||
svc := &adminServiceImpl{
|
||||
groupRepo: repo,
|
||||
apiKeyRepo: apiKeyRepo,
|
||||
authCacheInvalidator: invalidator,
|
||||
}
|
||||
|
||||
err := svc.DeleteGroup(context.Background(), 5)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []int64{5}, repo.deleteCalls)
|
||||
require.Equal(t, []int64{5}, apiKeyRepo.listGroupIDs)
|
||||
require.Equal(t, []string{"k1", "k2"}, invalidator.keys)
|
||||
}
|
||||
|
||||
func TestAdminService_DeleteGroup_NotFound(t *testing.T) {
|
||||
repo := &groupRepoStub{deleteErr: ErrGroupNotFound}
|
||||
svc := &adminServiceImpl{groupRepo: repo}
|
||||
|
||||
Reference in new issue
Block a user