From e1c7f1b2ff9cd406b7734d49787b3ce81312a1ca Mon Sep 17 00:00:00 2001 From: bryan newbold Date: Tue, 28 Nov 2023 23:53:02 -0800 Subject: [PATCH 1/2] identity: normalize handle before resolving (esp for caching) --- atproto/identity/base_directory.go | 1 + atproto/identity/cache_directory.go | 2 ++ atproto/identity/mock_directory.go | 1 + 3 files changed, 4 insertions(+) diff --git a/atproto/identity/base_directory.go b/atproto/identity/base_directory.go index 6b8c8325f..6e395d397 100644 --- a/atproto/identity/base_directory.go +++ b/atproto/identity/base_directory.go @@ -33,6 +33,7 @@ type BaseDirectory struct { var _ Directory = (*BaseDirectory)(nil) func (d *BaseDirectory) LookupHandle(ctx context.Context, h syntax.Handle) (*Identity, error) { + h = h.Normalize() did, err := d.ResolveHandle(ctx, h) if err != nil { return nil, err diff --git a/atproto/identity/cache_directory.go b/atproto/identity/cache_directory.go index 15e83cb1f..9ec659a6c 100644 --- a/atproto/identity/cache_directory.go +++ b/atproto/identity/cache_directory.go @@ -226,6 +226,7 @@ func (d *CacheDirectory) LookupDID(ctx context.Context, did syntax.DID) (*Identi } func (d *CacheDirectory) LookupHandle(ctx context.Context, h syntax.Handle) (*Identity, error) { + h = h.Normalize() did, err := d.ResolveHandle(ctx, h) if err != nil { return nil, err @@ -260,6 +261,7 @@ func (d *CacheDirectory) Lookup(ctx context.Context, a syntax.AtIdentifier) (*Id func (d *CacheDirectory) Purge(ctx context.Context, a syntax.AtIdentifier) error { handle, err := a.AsHandle() if nil == err { // if not an error, is a handle + handle = handle.Normalize() d.handleCache.Remove(handle) return nil } diff --git a/atproto/identity/mock_directory.go b/atproto/identity/mock_directory.go index 69c8fa03a..b69fc0cba 100644 --- a/atproto/identity/mock_directory.go +++ b/atproto/identity/mock_directory.go @@ -30,6 +30,7 @@ func (d *MockDirectory) Insert(ident Identity) { } func (d *MockDirectory) LookupHandle(ctx context.Context, h syntax.Handle) (*Identity, error) { + h = h.Normalize() did, ok := d.Handles[h] if !ok { return nil, ErrHandleNotFound From 218e5253ffa927aff256e68cedeb0573e74196db Mon Sep 17 00:00:00 2001 From: bryan newbold Date: Tue, 28 Nov 2023 23:55:48 -0800 Subject: [PATCH 2/2] identity: return cache directory error correctly --- atproto/identity/cache_directory.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atproto/identity/cache_directory.go b/atproto/identity/cache_directory.go index 9ec659a6c..df67b4e5a 100644 --- a/atproto/identity/cache_directory.go +++ b/atproto/identity/cache_directory.go @@ -181,7 +181,7 @@ func (d *CacheDirectory) updateDID(ctx context.Context, did syntax.DID) (*Identi if he != nil { d.handleCache.Add(ident.Handle, *he) } - return &entry, nil + return &entry, err } func (d *CacheDirectory) LookupDID(ctx context.Context, did syntax.DID) (*Identity, error) {