小优化
This commit is contained in:
parent
82dd3cc300
commit
e953d55bc7
@ -19,10 +19,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
maxRegionBlockKeywords = 200
|
||||
maxRegionBlockKeywordLength = 128
|
||||
maxIPWhitelistItems = 500
|
||||
maxUserWhitelistItems = 500
|
||||
maxRegionBlockKeywords = 200
|
||||
maxRegionBlockKeywordLength = 128
|
||||
maxIPWhitelistItems = 500
|
||||
maxUserWhitelistItems = 500
|
||||
maxUserWhitelistLookupLength = 64
|
||||
)
|
||||
|
||||
@ -282,7 +282,10 @@ func (s *Service) normalizeUserIDWhitelist(ctx context.Context, requestID string
|
||||
return nil, errInvalidPayload
|
||||
}
|
||||
userID, err := s.resolveWhitelistUserID(ctx, requestID, value)
|
||||
if err != nil || userID <= 0 {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if userID <= 0 {
|
||||
return nil, errInvalidPayload
|
||||
}
|
||||
if _, ok := seen[userID]; ok {
|
||||
|
||||
@ -17,6 +17,7 @@ type fakeWhitelistCacheUserClient struct {
|
||||
|
||||
called bool
|
||||
err error
|
||||
resolveErr error
|
||||
users map[int64]*userclient.User
|
||||
identities map[string]*userclient.UserIdentity
|
||||
}
|
||||
@ -36,6 +37,9 @@ func (f *fakeWhitelistCacheUserClient) ResolveDisplayUserID(_ context.Context, r
|
||||
if req.RequestID != "req-refresh" || req.Caller != "admin-server" {
|
||||
return nil, errors.New("unexpected resolve request")
|
||||
}
|
||||
if f.resolveErr != nil {
|
||||
return nil, f.resolveErr
|
||||
}
|
||||
if identity := f.identities[req.DisplayUserID]; identity != nil {
|
||||
return identity, nil
|
||||
}
|
||||
@ -81,6 +85,18 @@ func TestNormalizeUserIDWhitelistRejectsInvalidID(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeUserIDWhitelistKeepsUserServiceError(t *testing.T) {
|
||||
upstreamErr := status.Error(codes.Unavailable, "user-service unavailable")
|
||||
service := NewService(nil, &fakeWhitelistCacheUserClient{resolveErr: upstreamErr})
|
||||
_, err := service.normalizeUserIDWhitelist(context.Background(), "req-refresh", []string{"VIP2026"})
|
||||
if !errors.Is(err, upstreamErr) {
|
||||
t.Fatalf("normalize error = %v, want upstream error", err)
|
||||
}
|
||||
if errors.Is(err, errInvalidPayload) {
|
||||
t.Fatalf("normalize error = %v, should not be mapped to invalid payload", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRefreshWhitelistCacheMapsUserServiceError(t *testing.T) {
|
||||
client := &fakeWhitelistCacheUserClient{err: errors.New("rpc down")}
|
||||
service := NewService(nil, client)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user