🗃️ Check loopback hostnames in memory client repository

This commit is contained in:
Maxim Lebedev 2022-07-29 01:24:15 +05:00
parent e61c79136b
commit 61f1324c27
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
1 changed files with 13 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package memory
import (
"context"
"fmt"
"net"
"path"
"sync"
@ -29,6 +30,18 @@ func (repo *memoryClientRepository) Create(ctx context.Context, client *domain.C
}
func (repo *memoryClientRepository) Get(ctx context.Context, id *domain.ClientID) (*domain.Client, error) {
// WARN(toby3d): more often than not, we will work from tests with
// non-existent clients, almost guaranteed to cause a resolution error.
ips, _ := net.LookupIP(id.URL().Hostname())
for _, ip := range ips {
if !ip.IsLoopback() {
continue
}
return nil, client.ErrNotExist
}
src, ok := repo.store.Load(path.Join(DefaultPathPrefix, id.String()))
if !ok {
return nil, fmt.Errorf("cannot find client in store: %w", client.ErrNotExist)