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
|
_G.spy = spy
|
||||||
local mock_env = require("spec.env_mock")
|
local mock_env = require("spec.env_mock")
|
||||||
|
local rng = require("spec.fuzzgen")
|
||||||
|
|
||||||
describe("smr login",function()
|
describe("smr login",function()
|
||||||
setup(mock_env.setup)
|
setup(mock_env.setup)
|
||||||
|
@ -52,15 +53,14 @@ describe("smr login",function()
|
||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
it("should give a session cookie when logging in with a user",function()
|
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 claim_post = require("endpoints.claim_post")
|
||||||
local login_post = require("endpoints.login_post")
|
local login_post = require("endpoints.login_post")
|
||||||
local config = require("config")
|
local config = require("config")
|
||||||
local db = require("db")
|
local db = require("db")
|
||||||
|
local session = require("session")
|
||||||
configure()
|
configure()
|
||||||
|
|
||||||
local username = "nuser"
|
local username = rng.subdomain()
|
||||||
local claim_req = {
|
local claim_req = {
|
||||||
method = "POST",
|
method = "POST",
|
||||||
host = "test.host",
|
host = "test.host",
|
||||||
|
@ -81,7 +81,9 @@ describe("smr login",function()
|
||||||
pass = claim_req.response
|
pass = claim_req.response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sessionspy = spy.on(session,"start")
|
||||||
login_post(login_req)
|
login_post(login_req)
|
||||||
|
assert.spy(sessionspy).was.called()
|
||||||
local code = login_req.responsecode
|
local code = login_req.responsecode
|
||||||
assert(
|
assert(
|
||||||
code >= 300 and code <= 400,
|
code >= 300 and code <= 400,
|
||||||
|
@ -123,8 +125,6 @@ describe("smr login",function()
|
||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
it("should allow logged in users the option of posting under their username",function()
|
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 claim_post = require("endpoints.claim_post")
|
||||||
local login_post = require("endpoints.login_post")
|
local login_post = require("endpoints.login_post")
|
||||||
local paste_get = require("endpoints.paste_get")
|
local paste_get = require("endpoints.paste_get")
|
||||||
|
@ -134,12 +134,13 @@ describe("smr login",function()
|
||||||
local config = require("config")
|
local config = require("config")
|
||||||
config.domain = "test.host"
|
config.domain = "test.host"
|
||||||
configure()
|
configure()
|
||||||
|
local username = rng.subdomain()
|
||||||
local claim_req = {
|
local claim_req = {
|
||||||
method = "POST",
|
method = "POST",
|
||||||
host = "test.host",
|
host = "test.host",
|
||||||
path = "/_claim",
|
path = "/_claim",
|
||||||
args = {
|
args = {
|
||||||
user = "user"
|
user = username
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
claim_post(claim_req)
|
claim_post(claim_req)
|
||||||
|
@ -148,7 +149,7 @@ describe("smr login",function()
|
||||||
host = "test.host",
|
host = "test.host",
|
||||||
path = "/_login",
|
path = "/_login",
|
||||||
args = {
|
args = {
|
||||||
user = "user"
|
user = username
|
||||||
},
|
},
|
||||||
file = {
|
file = {
|
||||||
pass = claim_req.response
|
pass = claim_req.response
|
||||||
|
@ -159,14 +160,14 @@ describe("smr login",function()
|
||||||
local sessionid = cookie:match("session=([^;]+)")
|
local sessionid = cookie:match("session=([^;]+)")
|
||||||
local paste_req_get = {
|
local paste_req_get = {
|
||||||
method = "GET",
|
method = "GET",
|
||||||
host = "user.test.host",
|
host = username .. ".test.host",
|
||||||
path = "/_paste",
|
path = "/_paste",
|
||||||
cookies = {
|
cookies = {
|
||||||
session = sessionid
|
session = sessionid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
paste_get(paste_req_get)
|
paste_get(paste_req_get)
|
||||||
local option = '<option value="user">user</option>'
|
local option = '<option value="' .. username .. '">' .. username .. '</option>'
|
||||||
assert(
|
assert(
|
||||||
paste_req_get.response:find(option),
|
paste_req_get.response:find(option),
|
||||||
"After logging in the user should have an option to "..
|
"After logging in the user should have an option to "..
|
||||||
|
@ -175,7 +176,7 @@ describe("smr login",function()
|
||||||
)
|
)
|
||||||
local paste_req_post = {
|
local paste_req_post = {
|
||||||
method = "POST",
|
method = "POST",
|
||||||
host = "user.test.host",
|
host = username .. ".test.host",
|
||||||
path = "/_paste",
|
path = "/_paste",
|
||||||
cookies = {
|
cookies = {
|
||||||
session = sessionid
|
session = sessionid
|
||||||
|
@ -198,7 +199,7 @@ describe("smr login",function()
|
||||||
local redirect = paste_req_post.response_headers.Location:match("(/[^/]*)$")
|
local redirect = paste_req_post.response_headers.Location:match("(/[^/]*)$")
|
||||||
local read_req_get = {
|
local read_req_get = {
|
||||||
method = "GET",
|
method = "GET",
|
||||||
host = "user.test.host",
|
host = username .. ".test.host",
|
||||||
path = redirect,
|
path = redirect,
|
||||||
cookies = {
|
cookies = {
|
||||||
session = sessionid
|
session = sessionid
|
||||||
|
@ -212,7 +213,7 @@ describe("smr login",function()
|
||||||
"Failed to find post title in response."
|
"Failed to find post title in response."
|
||||||
)
|
)
|
||||||
assert(
|
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."
|
"Failed to find the author name after a paste."
|
||||||
)
|
)
|
||||||
assert(
|
assert(
|
||||||
|
|
Loading…
Reference in New Issue