fork of indigo with slightly nicer lexgen

identity: ensure handles are normalized in more places

+1
atproto/identity/apidir/apidir.go
··· 153 153 } 154 154 155 155 func (dir *APIDirectory) ResolveHandle(ctx context.Context, handle syntax.Handle) (syntax.DID, error) { 156 + handle = handle.Normalize() 156 157 var body handleBody 157 158 u := dir.Host + "/xrpc/com.atproto.identity.resolveHandle?handle=" + handle.String() 158 159
+1
atproto/identity/base_directory.go
··· 55 55 if err != nil { 56 56 return nil, fmt.Errorf("could not verify handle/DID match: %w", err) 57 57 } 58 + // NOTE: DeclaredHandle() returns a normalized handle, and we already normalized 'h' above 58 59 if declared != h { 59 60 return nil, fmt.Errorf("%w: %s != %s", ErrHandleMismatch, declared, h) 60 61 }
+2
atproto/identity/cache_directory.go
··· 93 93 } 94 94 95 95 func (d *CacheDirectory) ResolveHandle(ctx context.Context, h syntax.Handle) (syntax.DID, error) { 96 + h = h.Normalize() 96 97 if h.IsInvalidHandle() { 97 98 return "", fmt.Errorf("can not resolve handle: %w", ErrInvalidHandle) 98 99 } ··· 251 252 if err != nil { 252 253 return nil, hit, fmt.Errorf("could not verify handle/DID mapping: %w", err) 253 254 } 255 + // NOTE: DeclaredHandle() returns a normalized handle, and we already normalized 'h' above 254 256 if declared != h { 255 257 return nil, hit, fmt.Errorf("%w: %s != %s", ErrHandleMismatch, declared, h) 256 258 }
+2
atproto/identity/handle.go
··· 177 177 var dnsErr error 178 178 var did syntax.DID 179 179 180 + handle = handle.Normalize() 181 + 180 182 if handle.IsInvalidHandle() { 181 183 return "", fmt.Errorf("can not resolve handle: %w", ErrInvalidHandle) 182 184 }
+1 -1
atproto/identity/mock_directory.go
··· 26 26 27 27 func (d *MockDirectory) Insert(ident Identity) { 28 28 if !ident.Handle.IsInvalidHandle() { 29 - d.Handles[ident.Handle] = ident.DID 29 + d.Handles[ident.Handle.Normalize()] = ident.DID 30 30 } 31 31 d.Identities[ident.DID] = ident 32 32 }
+5
atproto/identity/mock_directory_test.go
··· 65 65 66 66 _, err = c.ResolveDID(ctx, syntax.DID("did:plc:abc999")) 67 67 assert.ErrorIs(err, ErrDIDNotFound) 68 + 69 + // handle lookups should be case-insensitive 70 + _, err = c.ResolveHandle(ctx, syntax.Handle("handle.EXAMPLE.com")) 71 + assert.NoError(err) 72 + assert.Equal(id1.DID, did) 68 73 }
+2
atproto/identity/redisdir/redis_directory.go
··· 156 156 157 157 func (d *RedisDirectory) ResolveHandle(ctx context.Context, h syntax.Handle) (syntax.DID, error) { 158 158 start := time.Now() 159 + h = h.Normalize() 159 160 if h.IsInvalidHandle() { 160 161 return "", fmt.Errorf("can not resolve handle: %w", identity.ErrInvalidHandle) 161 162 } ··· 359 360 if err != nil { 360 361 return nil, hit, err 361 362 } 363 + // NOTE: DeclaredHandle() returns a normalized handle, and we already normalized 'h' above 362 364 if declared != h { 363 365 return nil, hit, identity.ErrHandleMismatch 364 366 }