mirror of
https://github.com/certd/certd.git
synced 2026-04-24 12:27:25 +08:00
fix(cert): 修正证书过期时间计算逻辑
This commit is contained in:
@@ -145,7 +145,8 @@ export abstract class CertApplyBasePlugin extends CertApplyBaseConvertPlugin {
|
|||||||
throw new Error("过期时间不能为空");
|
throw new Error("过期时间不能为空");
|
||||||
}
|
}
|
||||||
// 检查有效期
|
// 检查有效期
|
||||||
const leftDays = dayjs(expires).diff(dayjs(), "day");
|
const leftDays = Math.floor((expires - dayjs().valueOf()) / (1000 * 60 * 60 * 24));
|
||||||
|
this.logger.info(`证书剩余天数:${leftDays}`);
|
||||||
return {
|
return {
|
||||||
isWillExpire: leftDays <= maxDays,
|
isWillExpire: leftDays <= maxDays,
|
||||||
leftDays,
|
leftDays,
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import { expect } from "chai";
|
||||||
|
import { CertApplyPlugin } from "../dist/index.js";
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
import { logger } from "@certd/basic";
|
||||||
|
|
||||||
|
describe("test/cert-plugin.ts", () => {
|
||||||
|
const certApplyPlugin = new CertApplyPlugin();
|
||||||
|
certApplyPlugin.logger = logger;
|
||||||
|
it("should throw error when expires is null or undefined", () => {
|
||||||
|
expect(() => {
|
||||||
|
// @ts-ignore
|
||||||
|
certApplyPlugin.isWillExpire(undefined);
|
||||||
|
}).throw("过期时间不能为空");
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
// @ts-ignore
|
||||||
|
certApplyPlugin.isWillExpire(null);
|
||||||
|
}).throw("过期时间不能为空");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("isWillExpire", () => {
|
||||||
|
const now = dayjs().add(36, "day") - 10000;
|
||||||
|
const res = certApplyPlugin.isWillExpire(now.valueOf(), 35);
|
||||||
|
console.log(res);
|
||||||
|
expect(res.isWillExpire).eq(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -65,4 +65,10 @@ footer{
|
|||||||
.ant-select-multiple .ant-select-selection-item-remove{
|
.ant-select-multiple .ant-select-selection-item-remove{
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.ant-progress.ant-progress-show-info .ant-progress-outer {
|
||||||
|
margin-inline-end: calc(-3em - 8px);
|
||||||
|
padding-inline-end: calc(3em + 8px);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user