Skip to content

Commit

Permalink
add another subdomain resolver test
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkr committed Feb 10, 2024
1 parent 2b9b894 commit 4e5cab8
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions fed/resolve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,96 @@ func TestResolve_FederatedActorCachedActorHostSubdomain(t *testing.T) {
assert.Equal("https://0.0.0.0/inbox/dan", actor.Inbox)
}

func TestResolve_FederatedActorCachedActorHostSubdomainFetchedRecently(t *testing.T) {
assert := assert.New(t)

f, err := os.CreateTemp("", "tootik-*.sqlite3")
assert.NoError(err)
f.Close()

path := f.Name()
defer os.Remove(path)

db, err := sql.Open("sqlite3", path+"?_journal_mode=WAL")
assert.NoError(err)

blockList := BlockList{}

var cfg cfg.Config
cfg.FillDefaults()

client := testClient{
"https://0.0.0.0/.well-known/webfinger?resource=acct:dan@0.0.0.0": testResponse{
Response: &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewReader([]byte(
`{
"aliases": [
"https://0.0.0.0/user/dan"
],
"links": [
{
"href": "https://tootik.0.0.0.0/user/dan",
"rel": "self",
"type": "application/activity+json"
},
{
"href": "https://tootik.0.0.0.0/user/dan",
"rel": "self",
"type": "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
}
],
"subject": "acct:dan@0.0.0.0"
}`))),
},
},
"https://tootik.0.0.0.0/user/dan": testResponse{
Response: &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewReader([]byte(
`{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1"
],
"id": "https://tootik.0.0.0.0/user/dan",
"type": "Person",
"inbox": "https://0.0.0.0/inbox/dan",
"outbox": "https://0.0.0.0/outbox/dan",
"preferredUsername": "dan",
"followers": "https://0.0.0.0/followers/dan",
"endpoints": {
"sharedInbox": "https://0.0.0.0/inbox/nobody"
}
}`))),
},
},
}

assert.NoError(migrations.Run(context.Background(), slog.Default(), "localhost.localdomain", db))

nobody, err := user.CreateNobody(context.Background(), "localhost.localdomain", db)
assert.NoError(err)

resolver := NewResolver(&blockList, "localhost.localdomain", &cfg, &client)

actor, err := resolver.ResolveID(context.Background(), slog.Default(), db, nobody, "https://0.0.0.0/user/dan", false)
assert.NoError(err)
assert.Empty(client)

assert.Equal("https://tootik.0.0.0.0/user/dan", actor.ID)
assert.Equal("https://0.0.0.0/inbox/dan", actor.Inbox)

client = testClient{}

actor, err = resolver.ResolveID(context.Background(), slog.Default(), db, nobody, "https://tootik.0.0.0.0/user/dan", false)
assert.NoError(err)
assert.Empty(client)

assert.Equal("https://tootik.0.0.0.0/user/dan", actor.ID)
assert.Equal("https://0.0.0.0/inbox/dan", actor.Inbox)
}

func TestResolve_FederatedActorCachedActorIDChanged(t *testing.T) {
assert := assert.New(t)

Expand Down

0 comments on commit 4e5cab8

Please sign in to comment.