mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-11-03 06:43:09 +00:00
store: test the registration route at boot
This commit is contained in:
1 parent
7786b4c6e4
commit
caa4a7f7fd
1 file changed
+6
-2
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user