mirror of
https://github.com/certd/certd.git
synced 2025-11-25 09:10:11 +08:00
fix(cert): 修正证书过期时间计算逻辑
This commit is contained in:
@@ -145,7 +145,8 @@ export abstract class CertApplyBasePlugin extends CertApplyBaseConvertPlugin {
|
||||
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 {
|
||||
isWillExpire: leftDays <= maxDays,
|
||||
leftDays,
|
||||
|
||||
27
packages/plugins/plugin-cert/test/cert-plugin.test.mjs
Normal file
27
packages/plugins/plugin-cert/test/cert-plugin.test.mjs
Normal file
@@ -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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user