Skip to content

Commit

Permalink
Fix domain ban test
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvolp12 committed Sep 29, 2023
1 parent 9955111 commit 176fdf8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions bgs/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (s *BGS) handleComAtprotoSyncRequestCrawl(ctx context.Context, body *comatp

banned, err := s.domainIsBanned(ctx, host)
if banned {
return echo.NewHTTPError(http.StatusForbidden, "domain is banned")
return echo.NewHTTPError(http.StatusUnauthorized, "domain is banned")
}

log.Warnf("TODO: better host validation for crawl requests")
Expand All @@ -117,7 +117,7 @@ func (s *BGS) handleComAtprotoSyncRequestCrawl(ctx context.Context, body *comatp

desc, err := atproto.ServerDescribeServer(ctx, c)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "requested host failed to respond to describe request")
return echo.NewHTTPError(http.StatusBadRequest, "requested host failed to respond to describe request")
}

// Maybe we could do something with this response later
Expand Down
14 changes: 9 additions & 5 deletions testing/integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,18 +380,22 @@ func TestDomainBans(t *testing.T) {
t.Fatal("domain should be banned")
}

if err := atproto.SyncRequestCrawl(context.TODO(), c, &atproto.SyncRequestCrawl_Input{Hostname: "app.pds.foo.com"}); err == nil {
err := atproto.SyncRequestCrawl(context.TODO(), c, &atproto.SyncRequestCrawl_Input{Hostname: "app.pds.foo.com"})
if err == nil {
t.Fatal("domain should be banned")
}

if !strings.Contains(err.Error(), "XRPC ERROR 401") {
t.Fatal("should have failed with a 401")
}

// should not be banned
err := atproto.SyncRequestCrawl(context.TODO(), c, &atproto.SyncRequestCrawl_Input{Hostname: "foo.bar.com"})
err = atproto.SyncRequestCrawl(context.TODO(), c, &atproto.SyncRequestCrawl_Input{Hostname: "foo.bar.com"})
if err == nil {
t.Fatal("should still fail")
}

if !strings.Contains(err.Error(), "XRPC ERROR 401") {
t.Fatal("should have failed with a 401")
if !strings.Contains(err.Error(), "XRPC ERROR 400") {
t.Fatal("should have failed with a 400")
}

}

0 comments on commit 176fdf8

Please sign in to comment.