mirror of
https://github.com/zkldi/Tachi.git
synced 2026-09-30 10:58:07 +03:00
finish tests for login
This commit is contained in:
@@ -60,13 +60,93 @@ t.test("POST /api/v1/auth/login", (t) => {
|
||||
|
||||
const cookie = res.headers["set-cookie"];
|
||||
|
||||
const stat = await mockApi.post("/api/v1/auth/stat").set("Cookie", cookie);
|
||||
const stat = await mockApi.post("/api/v1/auth/status").set("Cookie", cookie);
|
||||
|
||||
t.equal(stat.status, 200);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test("Should return 409 if user already logged in", async (t) => {
|
||||
const res = await mockApi.post("/api/v1/auth/login").send({
|
||||
username: "test_zkldi",
|
||||
password: "password",
|
||||
captcha: "foo",
|
||||
});
|
||||
|
||||
const cookie = res.headers["set-cookie"];
|
||||
|
||||
const res2 = await mockApi
|
||||
.post("/api/v1/auth/login")
|
||||
.send({
|
||||
username: "test_zkldi",
|
||||
password: "password",
|
||||
captcha: "foo",
|
||||
})
|
||||
.set("Cookie", cookie);
|
||||
|
||||
t.equal(res2.status, 409);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test("Should return 401 if password invalid", async (t) => {
|
||||
const res = await mockApi.post("/api/v1/auth/login").send({
|
||||
username: "test_zkldi",
|
||||
password: "invalid_password",
|
||||
captcha: "foo",
|
||||
});
|
||||
|
||||
t.equal(res.status, 401);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test("Should return 404 if user invalid", async (t) => {
|
||||
const res = await mockApi.post("/api/v1/auth/login").send({
|
||||
username: "invalid_user",
|
||||
password: "password",
|
||||
captcha: "foo",
|
||||
});
|
||||
|
||||
t.equal(res.status, 404);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test("Should return 400 if no password", async (t) => {
|
||||
const res = await mockApi.post("/api/v1/auth/login").send({
|
||||
username: "invalid_user",
|
||||
captcha: "foo",
|
||||
});
|
||||
|
||||
t.equal(res.status, 400);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test("Should return 400 if no username", async (t) => {
|
||||
const res = await mockApi.post("/api/v1/auth/login").send({
|
||||
password: "password",
|
||||
captcha: "foo",
|
||||
});
|
||||
|
||||
t.equal(res.status, 400);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test("Should return 400 if no captcha", async (t) => {
|
||||
const res = await mockApi.post("/api/v1/auth/login").send({
|
||||
password: "password",
|
||||
username: "test_zkldi",
|
||||
});
|
||||
|
||||
t.equal(res.status, 400);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ router.post(
|
||||
|
||||
if (!requestedUser) {
|
||||
logger.verbose(`Invalid username for login ${req.body.username}.`);
|
||||
return res.status(400).json({
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
description: `This user does not exist.`,
|
||||
});
|
||||
@@ -101,7 +101,7 @@ router.post(
|
||||
|
||||
if (!passwordMatch) {
|
||||
logger.verbose("Invalid password provided.");
|
||||
return res.status(400).json({
|
||||
return res.status(401).json({
|
||||
success: false,
|
||||
description: `Invalid password.`,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user