Start adding actual HTTP tests.
This commit is contained in:
parent
b402a8eb6d
commit
d701460e91
@ -3,7 +3,7 @@
|
|||||||
"authSecret": "change me",
|
"authSecret": "change me",
|
||||||
"debug": true,
|
"debug": true,
|
||||||
"users": [
|
"users": [
|
||||||
{ "name": "bob@builder.com", "hashedPwd": "testvalue" },
|
{ "name": "bob@builder.com", "hashedPwd": "$2a$11$lVZ9U4optQMhzPh0E9A7Yu6XndXblUF3gCa.zmEvJy4F.4C4718b." },
|
||||||
{ "name": "sam@sousa.com", "hashedPwd": "testvalue" }
|
{ "name": "sam@sousa.com", "hashedPwd": "testvalue" }
|
||||||
],
|
],
|
||||||
"pwdCost": 11,
|
"pwdCost": 11,
|
||||||
|
@ -1,21 +1,35 @@
|
|||||||
import times, unittest
|
import asyncdispatch, httpclient, os, osproc, strutils, times, unittest
|
||||||
import ./testutil
|
import ./testutil
|
||||||
import ../../main/nim/strawbosspkg/configuration
|
import ../../main/nim/strawbosspkg/configuration
|
||||||
import ../../main/nim/strawbosspkg/server
|
import ../../main/nim/strawbosspkg/server
|
||||||
|
import ../../main/nim/strawbosspkg/private/util
|
||||||
|
|
||||||
let testuser = UserRef( # note: needs to correspond to an actual user
|
|
||||||
name: "bob@builder.com",
|
|
||||||
hashedPwd: "$2a$11$lVZ9U4optQMhzPh0E9A7Yu6XndXblUF3gCa.zmEvJy4F.4C4718b.")
|
|
||||||
|
|
||||||
let cfg = loadStrawBossConfig("src/test/json/strawboss.config.json")
|
|
||||||
|
|
||||||
## UNIT TESTS
|
|
||||||
suite "strawboss server":
|
suite "strawboss server":
|
||||||
|
|
||||||
|
# suite setup code
|
||||||
|
let cfgFilePath = "src/test/json/strawboss.config.json"
|
||||||
|
let cfg = loadStrawBossConfig(cfgFilePath)
|
||||||
|
|
||||||
|
discard startProcess("./strawboss", ".", @["serve", "-c", cfgFilePath], loadEnv(), {poUsePath})
|
||||||
|
|
||||||
|
let http = newHttpClient()
|
||||||
|
let apiBase = "http://localhost:8180/api"
|
||||||
|
|
||||||
|
let testuser = UserRef( # note: needs to correspond to an actual user
|
||||||
|
name: "bob@builder.com",
|
||||||
|
hashedPwd: "$2a$11$lVZ9U4optQMhzPh0E9A7Yu6XndXblUF3gCa.zmEvJy4F.4C4718b.")
|
||||||
|
|
||||||
|
# give the server time to spin up
|
||||||
|
sleep(100)
|
||||||
|
|
||||||
|
## UNIT TESTS
|
||||||
|
|
||||||
test "can validate hashed pwd":
|
test "can validate hashed pwd":
|
||||||
|
|
||||||
check validatePwd(testuser, "password")
|
check validatePwd(testuser, "password")
|
||||||
|
|
||||||
test "can detect invalid pwds":
|
test "can detect invalid pwds":
|
||||||
check (not validatePwd(testuser, "Password"))
|
check(not validatePwd(testuser, "Password"))
|
||||||
|
|
||||||
test "can make and extract a JWT token from a session":
|
test "can make and extract a JWT token from a session":
|
||||||
let session = newSession(testuser)
|
let session = newSession(testuser)
|
||||||
@ -23,3 +37,23 @@ suite "strawboss server":
|
|||||||
|
|
||||||
check:
|
check:
|
||||||
fromJWT(cfg, tok) == session
|
fromJWT(cfg, tok) == session
|
||||||
|
|
||||||
|
test "can ping":
|
||||||
|
let resp = http.get(apiBase & "/ping")
|
||||||
|
check:
|
||||||
|
resp.status.startsWith("200")
|
||||||
|
resp.body == "\"pong\""
|
||||||
|
|
||||||
|
test "can fail auth":
|
||||||
|
let resp = http.get(apiBase & "/auth-token?username=bob@builder.com&password=notpassword")
|
||||||
|
check:
|
||||||
|
resp.status.startsWith("401")
|
||||||
|
|
||||||
|
test "can auth":
|
||||||
|
let resp = http.get(apiBase & "/auth-token?username=bob@builder.com&password=password")
|
||||||
|
check:
|
||||||
|
resp.status.startsWith("200")
|
||||||
|
|
||||||
|
# suite tear-down
|
||||||
|
try: discard http.post(apiBase & "/service/debug/stop")
|
||||||
|
except: discard ""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user