From 176fdf8b565a0128de804b1a28ab7b2f06c69e27 Mon Sep 17 00:00:00 2001 From: Jaz Volpert Date: Fri, 29 Sep 2023 22:29:15 +0000 Subject: [PATCH] Fix domain ban test --- bgs/handlers.go | 4 ++-- testing/integ_test.go | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/bgs/handlers.go b/bgs/handlers.go index c29201880..a278e93fb 100644 --- a/bgs/handlers.go +++ b/bgs/handlers.go @@ -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") @@ -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 diff --git a/testing/integ_test.go b/testing/integ_test.go index b285f8762..67b946336 100644 --- a/testing/integ_test.go +++ b/testing/integ_test.go @@ -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") } - }