Use random usernames to unittest
Don't replace the database with a unittest database, just use the usual database and user randomly generated usernames so we don't have collisions.
This commit is contained in:
parent
d5a3197262
commit
37a9bbd63d
|
@ -1,6 +1,7 @@
|
|||
|
||||
_G.spy = spy
|
||||
local mock_env = require("spec.env_mock")
|
||||
local rng = require("spec.fuzzgen")
|
||||
|
||||
describe("smr login",function()
|
||||
setup(mock_env.setup)
|
||||
|
@ -52,15 +53,14 @@ describe("smr login",function()
|
|||
)
|
||||
end)
|
||||
it("should give a session cookie when logging in with a user",function()
|
||||
pending("Look at cleaning mock env")
|
||||
mock_env.mockdb()
|
||||
local claim_post = require("endpoints.claim_post")
|
||||
local login_post = require("endpoints.login_post")
|
||||
local config = require("config")
|
||||
local db = require("db")
|
||||
local session = require("session")
|
||||
configure()
|
||||
|
||||
local username = "nuser"
|
||||
local username = rng.subdomain()
|
||||
local claim_req = {
|
||||
method = "POST",
|
||||
host = "test.host",
|
||||
|
@ -81,7 +81,9 @@ describe("smr login",function()
|
|||
pass = claim_req.response
|
||||
}
|
||||
}
|
||||
sessionspy = spy.on(session,"start")
|
||||
login_post(login_req)
|
||||
assert.spy(sessionspy).was.called()
|
||||
local code = login_req.responsecode
|
||||
assert(
|
||||
code >= 300 and code <= 400,
|
||||
|
@ -123,8 +125,6 @@ describe("smr login",function()
|
|||
)
|
||||
end)
|
||||
it("should allow logged in users the option of posting under their username",function()
|
||||
pending("Fix up cleaning db for unit tests")
|
||||
mock_env.mockdb()
|
||||
local claim_post = require("endpoints.claim_post")
|
||||
local login_post = require("endpoints.login_post")
|
||||
local paste_get = require("endpoints.paste_get")
|
||||
|
@ -134,12 +134,13 @@ describe("smr login",function()
|
|||
local config = require("config")
|
||||
config.domain = "test.host"
|
||||
configure()
|
||||
local username = rng.subdomain()
|
||||
local claim_req = {
|
||||
method = "POST",
|
||||
host = "test.host",
|
||||
path = "/_claim",
|
||||
args = {
|
||||
user = "user"
|
||||
user = username
|
||||
}
|
||||
}
|
||||
claim_post(claim_req)
|
||||
|
@ -148,7 +149,7 @@ describe("smr login",function()
|
|||
host = "test.host",
|
||||
path = "/_login",
|
||||
args = {
|
||||
user = "user"
|
||||
user = username
|
||||
},
|
||||
file = {
|
||||
pass = claim_req.response
|
||||
|
@ -159,14 +160,14 @@ describe("smr login",function()
|
|||
local sessionid = cookie:match("session=([^;]+)")
|
||||
local paste_req_get = {
|
||||
method = "GET",
|
||||
host = "user.test.host",
|
||||
host = username .. ".test.host",
|
||||
path = "/_paste",
|
||||
cookies = {
|
||||
session = sessionid
|
||||
}
|
||||
}
|
||||
paste_get(paste_req_get)
|
||||
local option = '<option value="user">user</option>'
|
||||
local option = '<option value="' .. username .. '">' .. username .. '</option>'
|
||||
assert(
|
||||
paste_req_get.response:find(option),
|
||||
"After logging in the user should have an option to "..
|
||||
|
@ -175,7 +176,7 @@ describe("smr login",function()
|
|||
)
|
||||
local paste_req_post = {
|
||||
method = "POST",
|
||||
host = "user.test.host",
|
||||
host = username .. ".test.host",
|
||||
path = "/_paste",
|
||||
cookies = {
|
||||
session = sessionid
|
||||
|
@ -198,7 +199,7 @@ describe("smr login",function()
|
|||
local redirect = paste_req_post.response_headers.Location:match("(/[^/]*)$")
|
||||
local read_req_get = {
|
||||
method = "GET",
|
||||
host = "user.test.host",
|
||||
host = username .. ".test.host",
|
||||
path = redirect,
|
||||
cookies = {
|
||||
session = sessionid
|
||||
|
@ -212,7 +213,7 @@ describe("smr login",function()
|
|||
"Failed to find post title in response."
|
||||
)
|
||||
assert(
|
||||
response:find([[By <a href="https://user.test.host">user</a>]]),
|
||||
response:find('By <a href="https://' .. username .. '.test.host">' .. username .. '</a>'),
|
||||
"Failed to find the author name after a paste."
|
||||
)
|
||||
assert(
|
||||
|
|
Loading…
Reference in New Issue