mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-12-17 19:54:39 -05:00
[test] reset-password
This commit is contained in:
parent
7276f34d90
commit
4d26825cbe
@ -12,50 +12,60 @@ const rl = readline.createInterface({
|
|||||||
output: process.stdout
|
output: process.stdout
|
||||||
});
|
});
|
||||||
|
|
||||||
(async () => {
|
const main = async () => {
|
||||||
Database.init(args);
|
Database.init(args);
|
||||||
await Database.connect();
|
await Database.connect();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const user = await R.findOne("user");
|
const user = await R.findOne("user");
|
||||||
|
|
||||||
if (! user) {
|
// No need to actually reset the password for testing, just make sure no connection problem. It is ok for now.
|
||||||
throw new Error("user not found, have you installed?");
|
if (!process.env.TEST_BACKEND) {
|
||||||
}
|
if (! user) {
|
||||||
|
throw new Error("user not found, have you installed?");
|
||||||
console.log("Found user: " + user.username);
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
let password = await question("New Password: ");
|
|
||||||
let confirmPassword = await question("Confirm New Password: ");
|
|
||||||
|
|
||||||
if (password === confirmPassword) {
|
|
||||||
await user.resetPassword(password);
|
|
||||||
|
|
||||||
// Reset all sessions by reset jwt secret
|
|
||||||
await initJWTSecret();
|
|
||||||
|
|
||||||
rl.close();
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
console.log("Passwords do not match, please try again.");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
console.log("Password reset successfully.");
|
console.log("Found user: " + user.username);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
let password = await question("New Password: ");
|
||||||
|
let confirmPassword = await question("Confirm New Password: ");
|
||||||
|
|
||||||
|
if (password === confirmPassword) {
|
||||||
|
await user.resetPassword(password);
|
||||||
|
|
||||||
|
// Reset all sessions by reset jwt secret
|
||||||
|
await initJWTSecret();
|
||||||
|
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
console.log("Passwords do not match, please try again.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log("Password reset successfully.");
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Error: " + e.message);
|
console.error("Error: " + e.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
await Database.close();
|
await Database.close();
|
||||||
|
rl.close();
|
||||||
|
|
||||||
console.log("Finished. You should restart the Uptime Kuma server.")
|
console.log("Finished.");
|
||||||
})();
|
};
|
||||||
|
|
||||||
function question(question) {
|
function question(question) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
rl.question(question, (answer) => {
|
rl.question(question, (answer) => {
|
||||||
resolve(answer);
|
resolve(answer);
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!process.env.TEST_BACKEND) {
|
||||||
|
main();
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
main,
|
||||||
|
};
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
const { genSecret } = require("../src/util");
|
const { genSecret, sleep } = require("../src/util");
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("Test genSecret", () => {
|
describe("Test genSecret", () => {
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
it("should be correct length", () => {
|
it("should be correct length", () => {
|
||||||
let secret = genSecret(-1);
|
let secret = genSecret(-1);
|
||||||
expect(secret).toEqual("");
|
expect(secret).toEqual("");
|
||||||
@ -34,4 +34,11 @@ describe("Test genSecret", () => {
|
|||||||
expect(secret).toContain("A");
|
expect(secret).toContain("A");
|
||||||
expect(secret).toContain("9");
|
expect(secret).toContain("9");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Test reset-password", () => {
|
||||||
|
it("should able to run", async () => {
|
||||||
|
await require("../extra/reset-password").main();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user