mirror of https://github.com/certd/certd
fix: 允许七牛云cdn插件输入.号开头的通配符域名
parent
2b89fba7eb
commit
18ee87daff
|
@ -0,0 +1,44 @@
|
||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { isDomain } from "/@/plugin/validator";
|
||||||
|
|
||||||
|
describe("domain_validator", () => {
|
||||||
|
it("ok", () => {
|
||||||
|
const value = ["a.cc.com", "*.zz.com", "a.cc.com"];
|
||||||
|
const v = isDomain({}, value);
|
||||||
|
expect(v).to.be.true;
|
||||||
|
});
|
||||||
|
|
||||||
|
it("allowDotStart", () => {
|
||||||
|
let value = ["&.cc.com"];
|
||||||
|
function test() {
|
||||||
|
return isDomain({ allowDotStart: true }, value);
|
||||||
|
}
|
||||||
|
expect(test).to.throw(Error, "域名有误:&.cc.com,请输入正确的域名");
|
||||||
|
|
||||||
|
value = ["a,cc.com"];
|
||||||
|
expect(test).to.throw(Error, "域名有误:a,cc.com,请输入正确的域名");
|
||||||
|
|
||||||
|
value = ["&cc.com"];
|
||||||
|
expect(test).to.throw(Error, "域名有误:&cc.com,请输入正确的域名");
|
||||||
|
|
||||||
|
value = [".cc.com"];
|
||||||
|
expect(test()).to.be.true;
|
||||||
|
});
|
||||||
|
|
||||||
|
it("default", () => {
|
||||||
|
let value = ["&.cc.com"];
|
||||||
|
function test() {
|
||||||
|
return isDomain({ allowDotStart: false }, value);
|
||||||
|
}
|
||||||
|
expect(test).to.throw(Error, "域名有误:&.cc.com,请输入正确的域名");
|
||||||
|
|
||||||
|
value = ["&cc.com"];
|
||||||
|
expect(test).to.throw(Error, "域名有误:&cc.com,请输入正确的域名");
|
||||||
|
|
||||||
|
value = ["a,cc.com"];
|
||||||
|
expect(test).to.throw(Error, "域名有误:a,cc.com,请输入正确的域名");
|
||||||
|
|
||||||
|
value = [".cc.com"];
|
||||||
|
expect(test).to.throw(Error, "域名有误:.cc.com,请输入正确的域名");
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,6 +1,6 @@
|
||||||
import Validator from "async-validator";
|
import Validator from "async-validator";
|
||||||
// 自定义验证器函数
|
// 自定义验证器函数
|
||||||
function isDomain(rule, value) {
|
export function isDomain(rule: any, value: any) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,14 @@ function isDomain(rule, value) {
|
||||||
if (typeof value === "string") {
|
if (typeof value === "string") {
|
||||||
domains = value.split(",");
|
domains = value.split(",");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const allowDotStart = rule.allowDotStart ? "\\.|" : "";
|
||||||
|
const exp = `^(?:${allowDotStart}\\*\\.|[0-9a-zA-Z\u4e00-\u9fa5-]+\\.)+[0-9a-zA-Z\u4e00-\u9fa5-]+$`;
|
||||||
|
const compiled = new RegExp(exp);
|
||||||
for (const domain of domains) {
|
for (const domain of domains) {
|
||||||
//域名可以是泛域名,中文域名,数字域名,英文域名,域名中可以包含-和. ,可以_开头
|
//域名可以是泛域名,中文域名,数字域名,英文域名,域名中可以包含-和. ,可以_开头
|
||||||
if (!/^(?:\*\.|[0-9a-zA-Z\u4e00-\u9fa5-]+\.)+[0-9a-zA-Z\u4e00-\u9fa5-]+$/.test(domain)) {
|
|
||||||
|
if (!compiled.test(domain)) {
|
||||||
throw new Error(`域名有误:${domain},请输入正确的域名`);
|
throw new Error(`域名有误:${domain},请输入正确的域名`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { CertInfo } from '@certd/plugin-cert';
|
||||||
title: '部署证书至七牛CDN',
|
title: '部署证书至七牛CDN',
|
||||||
icon: 'svg:icon-qiniuyun',
|
icon: 'svg:icon-qiniuyun',
|
||||||
group: pluginGroups.cdn.key,
|
group: pluginGroups.cdn.key,
|
||||||
desc: '自动部署域名证书至七牛云CDN,七牛云OSS',
|
desc: '自动部署域名证书至七牛云CDN',
|
||||||
default: {
|
default: {
|
||||||
strategy: {
|
strategy: {
|
||||||
runStrategy: RunStrategy.SkipWhenSucceed,
|
runStrategy: RunStrategy.SkipWhenSucceed,
|
||||||
|
@ -25,7 +25,7 @@ export class QiniuDeployCertToCDN extends AbstractTaskPlugin {
|
||||||
open: false,
|
open: false,
|
||||||
tokenSeparators: [',', ' ', ',', '、', '|'],
|
tokenSeparators: [',', ' ', ',', '、', '|'],
|
||||||
},
|
},
|
||||||
rules: [{ type: 'domains' }],
|
rules: [{ type: 'domains', allowDotStart: true }],
|
||||||
required: true,
|
required: true,
|
||||||
})
|
})
|
||||||
domainName!: string | string[];
|
domainName!: string | string[];
|
||||||
|
|
Loading…
Reference in New Issue