将密码找回指引切换为本机管理命令
This commit is contained in:
1 parent
a0ed64d0b0
commit
6af7c5ab3b
7 files changed
+180
-6
No files matched your search
@@ -0,0 +1,63 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import test from "node:test";
|
||||
import { baseParse } from "@vue/compiler-dom";
|
||||
import { parse } from "@vue/compiler-sfc";
|
||||
import { usePasswordReset } from "./PasswordReset.js";
|
||||
import { mountComposable } from "../../test-support/mount.js";
|
||||
|
||||
function template(path) {
|
||||
const source = readFileSync(new URL(path, import.meta.url), "utf8");
|
||||
return baseParse(parse(source).descriptor.template.content);
|
||||
}
|
||||
|
||||
function elements(node, predicate, matches = []) {
|
||||
if (predicate(node)) matches.push(node);
|
||||
for (const child of node.children || []) elements(child, predicate, matches);
|
||||
return matches;
|
||||
}
|
||||
|
||||
test("超级管理员查询保留本机处理标识,不生成网页重置链接", async (t) => {
|
||||
const payload = {
|
||||
account_type: "super_admin",
|
||||
action: "local_admin_command",
|
||||
title: "超级管理员密码重置",
|
||||
description: "请在部署主机操作。",
|
||||
};
|
||||
const { state } = await mountComposable(t, usePasswordReset, async (url, options) => {
|
||||
assert.equal(url, "/api/v1/password-reset/resolve");
|
||||
assert.equal(options.credentials, "same-origin");
|
||||
assert.deepEqual(JSON.parse(options.body), { identifier: "owner" });
|
||||
return Response.json(payload);
|
||||
});
|
||||
state.identifier.value = " owner ";
|
||||
await state.submit();
|
||||
assert.equal(state.resolution.value.action, "local_admin_command");
|
||||
assert.equal("reset_path" in state.resolution.value, false);
|
||||
assert.equal(state.error.value, "");
|
||||
assert.equal(state.submitting.value, false);
|
||||
state.reset();
|
||||
assert.equal(state.resolution.value, null);
|
||||
});
|
||||
|
||||
test("本机命令指引仅对接口明确标记的处理方式显示", () => {
|
||||
const root = template("./PasswordReset.vue");
|
||||
const guides = elements(root, (node) => node.tag === "LocalResetGuide");
|
||||
assert.equal(guides.length, 1);
|
||||
assert.equal(guides[0].props.find((prop) => prop.name === "if").exp.content,
|
||||
"resolution.action === 'local_admin_command'");
|
||||
const message = elements(root, (node) => node.tag === "p"
|
||||
&& node.props.some((prop) => prop.name === "if"
|
||||
&& prop.exp?.content === "message && !resolution"));
|
||||
assert.equal(message.length, 1);
|
||||
});
|
||||
|
||||
test("本机指引只显示固定命令,解释放入悬浮提示", () => {
|
||||
const root = template("../components/LocalResetGuide/LocalResetGuide.vue");
|
||||
assert.equal(elements(root, (node) => ["a", "input", "form"].includes(node.tag)).length, 0);
|
||||
assert.equal(elements(root, (node) => node.tag === "HelpTip").length, 1);
|
||||
const commands = elements(root, (node) => node.tag === "code")
|
||||
.map((node) => node.children.filter((child) => child.type === 2)
|
||||
.map((child) => child.content).join(""));
|
||||
assert.deepEqual(commands, ["systemctl start Scert-admin", ".\\scert-admin.exe"]);
|
||||
});
|
||||
@@ -1,5 +1,6 @@
|
||||
<script setup>
|
||||
import AccessShell from "../components/AccessShell/AccessShell.vue";
|
||||
import LocalResetGuide from "../components/LocalResetGuide/LocalResetGuide.vue";
|
||||
import { usePasswordReset } from "./PasswordReset.js";
|
||||
|
||||
const {
|
||||
@@ -47,13 +48,14 @@ const {
|
||||
/>
|
||||
</label>
|
||||
|
||||
<p v-if="message" class="access-message">{{ message }}</p>
|
||||
<p v-if="message && !resolution" class="access-message">{{ message }}</p>
|
||||
<p v-if="error" class="access-error">{{ error }}</p>
|
||||
|
||||
<div v-if="resolution" class="reset-resolution" aria-live="polite">
|
||||
<span class="reset-resolution-label">处理方式</span>
|
||||
<strong>{{ resolution.title }}</strong>
|
||||
<p>{{ resolution.description }}</p>
|
||||
<LocalResetGuide v-if="resolution.action === 'local_admin_command'" />
|
||||
<a
|
||||
v-if="resolution.reset_path"
|
||||
class="access-submit reset-entry-link"
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
.local-reset-guide {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.local-reset-guide__heading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.local-reset-guide__commands {
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
margin: 0;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.local-reset-guide__commands > div {
|
||||
display: grid;
|
||||
grid-template-columns: 58px minmax(0, 1fr);
|
||||
align-items: baseline;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.local-reset-guide__commands dt,
|
||||
.local-reset-guide__commands dd {
|
||||
min-width: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.local-reset-guide__commands code {
|
||||
overflow-wrap: anywhere;
|
||||
font-family: Consolas, monospace;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<script setup>
|
||||
import HelpTip from "../HelpTip/HelpTip.vue";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="local-reset-guide">
|
||||
<div class="local-reset-guide__heading">
|
||||
<span>本机管理命令</span>
|
||||
<HelpTip>
|
||||
请由部署管理员在 Scert 所在主机执行命令。Linux 使用 root 终端;
|
||||
Windows 使用提升权限的控制台,在安装目录运行。
|
||||
验证码和新密码仅在本机终端输入,本页面不会开启重置会话。
|
||||
</HelpTip>
|
||||
</div>
|
||||
<dl class="local-reset-guide__commands">
|
||||
<div>
|
||||
<dt>Linux</dt>
|
||||
<dd><code>systemctl start Scert-admin</code></dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Windows</dt>
|
||||
<dd><code>.\scert-admin.exe</code></dd>
|
||||
</div>
|
||||
</dl>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped src="./LocalResetGuide.css"></style>
|
||||
Reference in new issue
Block a user