From caa4a7f7fda87cd000deb94556d250f57f509922 Mon Sep 17 00:00:00 2001 From: shum Date: Thu, 22 Oct 2026 04:30:00 +0000 Subject: [PATCH] store: test the registration route at boot --- tests/Bots/StoreService/GroupIntegrationTests.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/Bots/StoreService/GroupIntegrationTests.hs b/tests/Bots/StoreService/GroupIntegrationTests.hs index d8e8198a35..42bc5bb133 100644 --- a/tests/Bots/StoreService/GroupIntegrationTests.hs +++ b/tests/Bots/StoreService/GroupIntegrationTests.hs @@ -46,7 +46,7 @@ import qualified Data.Text as T import Data.Text.Encoding (encodeUtf8) import Data.Time.Calendar (fromGregorian) import Data.Time.Clock (NominalDiffTime, UTCTime (..), addUTCTime, getCurrentTime) -import Network.HTTP.Client (RequestBody (..), defaultManagerSettings, httpLbs, method, newManager, parseRequest, requestBody, responseBody, responseStatus) +import Network.HTTP.Client (RequestBody (..), defaultManagerSettings, httpLbs, method, newManager, parseRequest, requestBody, responseBody, responseHeaders, responseStatus) import Network.HTTP.Types.Status (statusCode) import Network.Socket (Family (..), SockAddr (..), SocketType (..), close, connect, defaultProtocol, socket, tupleToHostAddress) import Network.Wai.Handler.Warp (openFreePort) @@ -134,7 +134,7 @@ badgeGroupIntegrationTests = do it "leaves a tracker it cannot edit alone rather than publishing the code again" testUneditableTrackerLeftAlone namesBootTests :: SpecWith TestParams -namesBootTests = it "boots with [names] and [chain], routing fixed /api/name paths ahead of a search, a path no route knows to 404, and code checks and orders under one limit" testNamesBoot +namesBootTests = it "boots with [names] and [chain], routing fixed /api/name paths ahead of a search, registrations to GET, a path no route knows to 404, and code checks and orders under one limit" testNamesBoot testNamesBoot :: HasCallStack => TestParams -> IO () testNamesBoot ps = do @@ -154,6 +154,10 @@ testNamesBoot ps = do answer register {method = "POST", requestBody = RequestBodyLBS "{}"} `shouldReturn` refused "bad_request" search <- request $ "/api/name/" <> T.unpack aliceHex <> "?length=5" answer search `shouldReturn` refused "invalid_name" + registration <- request "/api/registration/t2Jk8RmQ4vXw9NcP3yLb6g" + answer registration `shouldReturn` (404, Just $ J.object ["error" J..= ("not_found" :: Text)]) + posted <- httpLbs registration {method = "POST"} mgr + (statusCode $ responseStatus posted, lookup "Allow" $ responseHeaders posted) `shouldBe` (405, Just "GET") -- the register above took the first of this client's 10 code requests a minute, which the code check shares let codeRequest path = request path >>= \r -> statusCode . responseStatus <$> httpLbs r {method = "POST", requestBody = RequestBodyLBS "{}"} mgr forM_ (take 9 $ cycle ["/api/code/check", "/api/name/register"]) $ \path -> (path,) <$> codeRequest path `shouldReturn` (path, 400)