mirror of
https://github.com/certd/certd.git
synced 2026-07-05 19:37:34 +08:00
chore: 清理无用测试文件并更新配置与文档
This commit is contained in:
@@ -52,7 +52,7 @@ describe("RuntimeDepsService", () => {
|
||||
} as any;
|
||||
|
||||
const plugins: RuntimeDependencyPluginDefine[] = [{ name: "a", dependPackages: { foo: "^1.0.0" } }];
|
||||
const result = await service.ensureInstalled(plugins);
|
||||
const result = await service.ensureInstalled({ plugins });
|
||||
|
||||
assert.equal(result.registryUrl, "https://registry.npmmirror.com");
|
||||
assert.ok(fs.existsSync(path.join(rootDir, "package.json")));
|
||||
@@ -78,7 +78,7 @@ describe("RuntimeDepsService", () => {
|
||||
},
|
||||
} as any;
|
||||
|
||||
await service.ensureDependencies({ directPkg: "^1.0.0" });
|
||||
await service.ensureDependencies({ dependencies: { directPkg: "^1.0.0" } });
|
||||
|
||||
const manifest = JSON.parse(fs.readFileSync(path.join(rootDir, "package.json"), "utf8"));
|
||||
assert.deepEqual(manifest.dependencies, { directPkg: "^1.0.0" });
|
||||
@@ -238,8 +238,8 @@ describe("RuntimeDepsService", () => {
|
||||
},
|
||||
} as any;
|
||||
|
||||
await service.ensureInstalled([{ name: "a", pluginType: "deploy", dependPackages: { foo: "^1.0.0" } }]);
|
||||
await service.ensureInstalled([{ name: "b", pluginType: "deploy", dependPackages: { bar: "^2.0.0" } }]);
|
||||
await service.ensureInstalled({ plugins: [{ name: "a", pluginType: "deploy", dependPackages: { foo: "^1.0.0" } }] });
|
||||
await service.ensureInstalled({ plugins: [{ name: "b", pluginType: "deploy", dependPackages: { bar: "^2.0.0" } }] });
|
||||
|
||||
const manifest = JSON.parse(fs.readFileSync(path.join(rootDir, "package.json"), "utf8"));
|
||||
assert.deepEqual(manifest.dependencies, {
|
||||
@@ -399,7 +399,7 @@ describe("RuntimeDepsService", () => {
|
||||
},
|
||||
} as any;
|
||||
|
||||
await service.ensureInstalled([{ name: "a", dependPackages: { foo: "^1.0.0" } }]);
|
||||
await service.ensureInstalled({ plugins: [{ name: "a", dependPackages: { foo: "^1.0.0" } }] });
|
||||
|
||||
const state = JSON.parse(fs.readFileSync(path.join(rootDir, "install-state.json"), "utf8"));
|
||||
assert.equal(state.nodeVersion, process.version);
|
||||
@@ -436,7 +436,7 @@ describe("RuntimeDepsService", () => {
|
||||
serviceA.commandRunner = commandRunner as any;
|
||||
serviceB.commandRunner = commandRunner as any;
|
||||
|
||||
await Promise.all([serviceA.ensureInstalled([{ name: "a", dependPackages: { foo: "^1.0.0" } }]), serviceB.ensureInstalled([{ name: "a", dependPackages: { foo: "^1.0.0" } }])]);
|
||||
await Promise.all([serviceA.ensureInstalled({ plugins: [{ name: "a", dependPackages: { foo: "^1.0.0" } }] }), serviceB.ensureInstalled({ plugins: [{ name: "a", dependPackages: { foo: "^1.0.0" } }] })]);
|
||||
|
||||
assert.equal(installCount, 1);
|
||||
});
|
||||
@@ -468,7 +468,7 @@ describe("RuntimeDepsService", () => {
|
||||
},
|
||||
} as any;
|
||||
|
||||
await service.ensureInstalled([{ name: "a", dependPackages: { foo: "^1.0.0" } }]);
|
||||
await service.ensureInstalled({ plugins: [{ name: "a", dependPackages: { foo: "^1.0.0" } }] });
|
||||
} finally {
|
||||
if (oldNodeOptions == null) {
|
||||
delete process.env.NODE_OPTIONS;
|
||||
|
||||
+7
-5
@@ -1,9 +1,10 @@
|
||||
import { HttpClient } from "@certd/basic";
|
||||
import { AbstractTaskPlugin, CertTargetItem, IsTaskPlugin, PageSearch, pluginGroups, RunStrategy, TaskInput, TaskOutput } from "@certd/pipeline";
|
||||
import { CertTargetItem, IsTaskPlugin, PageSearch, pluginGroups, RunStrategy, TaskInput, TaskOutput } from "@certd/pipeline";
|
||||
import { CertApplyPluginNames, CertInfo } from "@certd/plugin-cert";
|
||||
import { createCertDomainGetterInputDefine } from "@certd/plugin-lib";
|
||||
import { BaotaClient } from "../lib/client.js";
|
||||
import { AbstractPlusTaskPlugin } from "@certd/plugin-plus";
|
||||
import { BaotaAccess } from "../access.js";
|
||||
import { BaotaClient } from "../lib/client.js";
|
||||
|
||||
/**
|
||||
* 宝塔-全自动部署插件
|
||||
@@ -17,8 +18,9 @@ import { BaotaAccess } from "../access.js";
|
||||
group: pluginGroups.panel.key,
|
||||
desc: "根据证书域名自动匹配宝塔站点,全自动部署SSL证书。新增加速域名自动感知,自动新增部署",
|
||||
runStrategy: RunStrategy.AlwaysRun,
|
||||
needPlus: true,
|
||||
})
|
||||
export class BaotaAutoDeploySiteCert extends AbstractTaskPlugin {
|
||||
export class BaotaAutoDeploySiteCert extends AbstractPlusTaskPlugin {
|
||||
/** 域名证书 */
|
||||
@TaskInput({
|
||||
title: "域名证书",
|
||||
@@ -37,7 +39,7 @@ export class BaotaAutoDeploySiteCert extends AbstractTaskPlugin {
|
||||
/** 宝塔授权 */
|
||||
@TaskInput({
|
||||
title: "宝塔授权",
|
||||
helper: "baota的接口密钥",
|
||||
helper: "将自动查找证书匹配的站点,检查证书即将过期的站点并更新",
|
||||
component: {
|
||||
name: "access-selector",
|
||||
type: "baota",
|
||||
@@ -55,7 +57,7 @@ export class BaotaAutoDeploySiteCert extends AbstractTaskPlugin {
|
||||
async onInstance() {}
|
||||
|
||||
async execute(): Promise<any> {
|
||||
this.logger.info("开始宝塔全自动部署证书");
|
||||
this.logger.info(`开始宝塔全自动部署证书: ${this.certDomains.join(",")}`);
|
||||
const access = await this.getAccess<BaotaAccess>(this.accessId);
|
||||
const http: HttpClient = this.ctx.http;
|
||||
const client = new BaotaClient(access, http);
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import { createHttpRequest } from "@midwayjs/mock";
|
||||
import { Application } from "@midwayjs/koa";
|
||||
import assert from "assert";
|
||||
import { getApp } from "../setup.js";
|
||||
|
||||
describe("test/controller/home.test.ts", () => {
|
||||
it("should POST /api/get_user", async function (this: any) {
|
||||
const app: Application = getApp();
|
||||
// make request
|
||||
const result = await createHttpRequest(app).get("/api/get_user").query({ uid: 123 });
|
||||
|
||||
// use expect by jest
|
||||
assert(result.status === 200);
|
||||
assert(result.body.message === "OK");
|
||||
});
|
||||
});
|
||||
@@ -1,16 +0,0 @@
|
||||
import { createHttpRequest } from "@midwayjs/mock";
|
||||
import { Application } from "@midwayjs/koa";
|
||||
import assert from "assert";
|
||||
import { getApp } from "../setup.js";
|
||||
|
||||
describe("test/controller/home.test.ts", () => {
|
||||
it("should GET /", async () => {
|
||||
const app: Application = getApp();
|
||||
// make request
|
||||
const result = await createHttpRequest(app).get("/");
|
||||
|
||||
// use expect by jest
|
||||
assert(result.status === 200);
|
||||
assert(result.text === "Hello Midwayjs!");
|
||||
});
|
||||
});
|
||||
@@ -1,136 +0,0 @@
|
||||
import CryptoJS from 'crypto-js'
|
||||
|
||||
function aes(val) {
|
||||
var k = CryptoJS.enc.Utf8.parse('1234567890abcDEF');
|
||||
var iv = CryptoJS.enc.Utf8.parse('1234567890abcDEF');
|
||||
const enc = CryptoJS.AES.encrypt(val, k, {
|
||||
iv: iv,
|
||||
mode: CryptoJS.mode.CBC,
|
||||
padding: CryptoJS.pad.ZeroPadding
|
||||
}).toString();
|
||||
return enc;
|
||||
}
|
||||
|
||||
|
||||
import axios from 'axios'
|
||||
|
||||
const instance = axios.create({
|
||||
baseURL: 'https://www.51dns.com',
|
||||
timeout: 5000,
|
||||
withCredentials: true,
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
}
|
||||
})
|
||||
|
||||
async function login() {
|
||||
|
||||
const res = await instance.request({
|
||||
url: 'https://www.51dns.com/login.html',
|
||||
method: 'get',
|
||||
headers: {
|
||||
// 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.95 Safari/537.36',
|
||||
'Origin': 'https://www.51dns.com',
|
||||
'Referer': 'https://www.51dns.com',
|
||||
}
|
||||
})
|
||||
|
||||
//提取 var csrfToken = "ieOfM21eDd9nWJv3OZtMJF6ogDsnPKQHJ17dlMck";
|
||||
const _token = res.data.match(/var csrfToken = "(.*?)"/)[1]
|
||||
console.log(_token)
|
||||
console.log(res.headers)
|
||||
|
||||
|
||||
const setCookie = res.headers['set-cookie']
|
||||
const cookie = setCookie.map(item => {
|
||||
return item.split(';')[0]
|
||||
}).join(';')
|
||||
|
||||
|
||||
var obj = {
|
||||
'email_or_phone': aes(""),
|
||||
'password': aes(""),
|
||||
'type': aes('account'),
|
||||
'redirectTo': 'https://www.51dns.com/domain',
|
||||
'_token': _token
|
||||
}
|
||||
// console.log(JSON.stringify(obj, null, 2)) // Avoid logging sensitive data
|
||||
const res2 = await instance.request({
|
||||
url: 'https://www.51dns.com/login',
|
||||
method: 'post',
|
||||
data: {
|
||||
...obj
|
||||
},
|
||||
headers: {
|
||||
/**
|
||||
* Origin:
|
||||
* https://www.51dns.com
|
||||
* Referer:
|
||||
* https://www.51dns.com/login.html
|
||||
* User-Agent:
|
||||
* Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.95 Safari/537.36
|
||||
// __root_domain_v=.51dns.com;
|
||||
*/
|
||||
|
||||
// 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.95 Safari/537.36',
|
||||
'Origin': 'https://www.51dns.com',
|
||||
'Referer': 'https://www.51dns.com/login.html',
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Cookie': cookie,
|
||||
//X-Requested-With:
|
||||
// XMLHttpRequest
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
})
|
||||
|
||||
console.log(res2.headers)
|
||||
if (res2.data.code == 0) {
|
||||
console.log("登录成功")
|
||||
}
|
||||
|
||||
const setCookie2 = res2.headers['set-cookie']
|
||||
const cookie2 = setCookie2.map(item => {
|
||||
return item.split(';')[0]
|
||||
}).join(';')
|
||||
|
||||
//
|
||||
// // console.log(res2.data)
|
||||
// // 提取 <span class="user_email">182****43522</span><br>
|
||||
// console.log(res2.data.match(/<span class="user_email">(.*?)<\/span>/)[1])
|
||||
// const success1 = res2.data.includes('<span class="nav-title">DNS解析</span>')
|
||||
// console.log("success", success1)
|
||||
|
||||
|
||||
const res3 = await instance.request({
|
||||
url: 'https://www.51dns.com/domain',
|
||||
method: 'get',
|
||||
withCredentials: true,
|
||||
headers: {
|
||||
// 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.95 Safari/537.36',
|
||||
'Origin': 'https://www.51dns.com',
|
||||
'Referer': 'https://www.51dns.com/login.html',
|
||||
'Cookie': cookie2,
|
||||
}
|
||||
})
|
||||
|
||||
console.log(res3.statusText)
|
||||
console.log(res3.headers)
|
||||
const success2 = res3.data.includes('<span class="nav-title">DNS解析</span>')
|
||||
console.log("success", success2)
|
||||
|
||||
|
||||
/**
|
||||
* <a target="_blank" href="https://www.51dns.com/domain/record/193341603"
|
||||
* class="color47">certd.top</a>
|
||||
|
||||
*/
|
||||
//上面文本中间有换行,需要提取 193341603 部分,必须有certd.top,使用 new Regexp, .号要能匹配换行符,非贪婪模式
|
||||
const regExp = new RegExp('<a target="_blank" href="https://www.51dns.com/domain/record/(\\d+)"[^>]*>certd\\.top<\\/a>',"i");
|
||||
|
||||
const domainId = res3.data.match(regExp)[1]
|
||||
|
||||
|
||||
console.log("domainId", domainId)
|
||||
}
|
||||
|
||||
login()
|
||||
Reference in New Issue
Block a user