Skip to content

Commit

Permalink
update:
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe committed Aug 15, 2024
1 parent 500b66d commit 83d4693
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
14 changes: 14 additions & 0 deletions impl/internal/did/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/anacrolix/dht/v2/bep44"
"github.com/goccy/go-json"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -42,6 +43,19 @@ func TestClient(t *testing.T) {
t.Logf("time to put and get: %s", since)
}

func TestGet(t *testing.T) {
client, err := NewGatewayClient("https://diddht.tbddev.org")
require.NoError(t, err)
require.NotNil(t, client)

doc, err := client.GetDIDDocument("did:dht:w57sq1urnd8d413sbhgqzr86x8cnmb9nx6utz7qszq1nxt3x1tpy")
require.NoError(t, err)
require.NotNil(t, doc)

b, _ := json.Marshal(doc)
println(string(b))
}

func TestClientInvalidGateway(t *testing.T) {
g, err := NewGatewayClient("\n")
assert.Error(t, err)
Expand Down
6 changes: 4 additions & 2 deletions impl/pkg/service/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ func (s *DHTService) GetDHT(ctx context.Context, id string) (*dht.BEP44Response,

// make sure the key is valid
if _, err := util.Z32Decode(id); err != nil {
return nil, ssiutil.LoggingCtxErrorMsgf(ctx, err, "failed to decode z-base-32 encoded ID: %s", id)
logrus.WithContext(ctx).WithField("record_id", id).Error("failed to decode z-base-32 encoded ID")
return nil, errors.Wrapf(err, "failed to decode z-base-32 encoded ID: %s", id)
}

// if the key is in the badGetCache, return an error
if _, err := s.badGetCache.Get(id); err == nil {
return nil, ssiutil.LoggingCtxErrorMsgf(ctx, err, "bad key [%s] rate limited to prevent spam", id)
logrus.WithContext(ctx).WithField("record_id", id).Error("bad key rate limited to prevent spam")
return nil, errors.Wrapf(err, "bad key [%s] rate limited to prevent spam", id)
}

// first do a cache lookup
Expand Down

0 comments on commit 83d4693

Please sign in to comment.