|
@@ -5,12 +5,15 @@ import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
-import cn.hutool.core.date.DateUnit;
|
|
|
|
|
|
|
+import cn.hutool.core.date.DatePattern;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.junit.jupiter.api.Assertions;
|
|
import org.junit.jupiter.api.Assertions;
|
|
|
|
|
+import org.junit.jupiter.api.Disabled;
|
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
+import org.junit.jupiter.params.ParameterizedTest;
|
|
|
|
|
+import org.junit.jupiter.params.provider.CsvSource;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
import oshi.SystemInfo;
|
|
import oshi.SystemInfo;
|
|
@@ -38,7 +41,7 @@ import oshi.util.Util;
|
|
|
import org.junit.jupiter.api.DisplayName;
|
|
import org.junit.jupiter.api.DisplayName;
|
|
|
import top.haijunit.common.domain.ResultData;
|
|
import top.haijunit.common.domain.ResultData;
|
|
|
import top.haijunit.train.TrainServerMain;
|
|
import top.haijunit.train.TrainServerMain;
|
|
|
-import top.haijunit.train.service.LicenseService;
|
|
|
|
|
|
|
+import top.haijunit.train.service.LicenseServiceImpl;
|
|
|
import top.haijunit.train.utils.LicenseUtil;
|
|
import top.haijunit.train.utils.LicenseUtil;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -52,41 +55,44 @@ import top.haijunit.train.utils.LicenseUtil;
|
|
|
public class LicenseTest {
|
|
public class LicenseTest {
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private LicenseService licenseService;
|
|
|
|
|
|
|
+ private LicenseServiceImpl licenseService;
|
|
|
|
|
|
|
|
- @DisplayName("授权+验证")
|
|
|
|
|
|
|
+ @DisplayName("获取本机的机器码")
|
|
|
@Test
|
|
@Test
|
|
|
- void licenseValid() {
|
|
|
|
|
- String machineStr = licenseService.getMachineStr();
|
|
|
|
|
- String dateStr = "2024-01-01";
|
|
|
|
|
- String licenseStr = getLicenseStr(machineStr, dateStr);
|
|
|
|
|
- log.info(">>>>>>授权码: 【{}】", licenseStr);
|
|
|
|
|
- ResultData<String> result = licenseService.licenseVerify(licenseStr, machineStr);
|
|
|
|
|
- log.info(">>>>>>验证结果: {}", result);
|
|
|
|
|
|
|
+ void getMachineStr() {
|
|
|
|
|
+ log.info(">>>>>>本机的机器码: {}", this.licenseService.getMachineStr());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private String getLicenseStr(String machineStr, String dateStr) {
|
|
|
|
|
|
|
+ @DisplayName("生成授权")
|
|
|
|
|
+ @ParameterizedTest
|
|
|
|
|
+ @CsvSource({"b6f35e941ae79841494fe2e3e7f961a9+876,2024-01-01", "b6f35e941ae79841494fe2e3e7f961a9+876,2024-12-31"})
|
|
|
|
|
+ void generateLicense(String machineStr, String dateStr) {
|
|
|
if (machineStr.contains(LicenseUtil.MARK)) {
|
|
if (machineStr.contains(LicenseUtil.MARK)) {
|
|
|
String machineCode = StrUtil.subBefore(machineStr, LicenseUtil.MARK, false);
|
|
String machineCode = StrUtil.subBefore(machineStr, LicenseUtil.MARK, false);
|
|
|
String code = StrUtil.subAfter(machineStr, LicenseUtil.MARK, false);
|
|
String code = StrUtil.subAfter(machineStr, LicenseUtil.MARK, false);
|
|
|
Assertions.assertEquals(code, LicenseUtil.generateCheckKey(machineCode));
|
|
Assertions.assertEquals(code, LicenseUtil.generateCheckKey(machineCode));
|
|
|
machineStr = machineCode;
|
|
machineStr = machineCode;
|
|
|
}
|
|
}
|
|
|
- log.info(">>>>>>机器码: {}", machineStr);
|
|
|
|
|
- String string = machineStr + "," + DateUtil.parse(dateStr).getTime();
|
|
|
|
|
|
|
+ String string = machineStr + LicenseUtil.SEPARATOR + DateUtil.parse(dateStr).getTime();
|
|
|
String licenseStr = LicenseUtil.licenseEncrypt(string);
|
|
String licenseStr = LicenseUtil.licenseEncrypt(string);
|
|
|
log.info(">>>>>>授权码: {}", licenseStr);
|
|
log.info(">>>>>>授权码: {}", licenseStr);
|
|
|
- return licenseStr;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- void getMachineCode() {
|
|
|
|
|
- log.info("机器码: {}", LicenseUtil.getMachineCode());
|
|
|
|
|
- log.info("校验位: {}", LicenseUtil.generateCheckKey(LicenseUtil.getMachineCode()));
|
|
|
|
|
|
|
+ @DisplayName("更新授权")
|
|
|
|
|
+ @ParameterizedTest
|
|
|
|
|
+ @CsvSource({"51fb66146f102603cd8118bf4051f50e771d2f3b65fda1ed3010d54525461b3e0e4006842a410c965d19aa1711728695", "51fb66146f102603cd8118bf4051f50e771d2f3b65fda1ed3010d54525461b3edab16ab28983625a494b5831d8d135ec"})
|
|
|
|
|
+ void licenseValid(String licenseStr) {
|
|
|
|
|
+ String machineStr = licenseService.getMachineStr();
|
|
|
|
|
+ ResultData<String> result = licenseService.licenseVerify(licenseStr, machineStr);
|
|
|
|
|
+ if (result.codeSucceed()) {
|
|
|
|
|
+ log.info("授权更新成功,时间到:{}", DateUtil.format(new Date(this.licenseService.getLicenseItem().getTime()), DatePattern.UTC_SIMPLE_FORMAT));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.info("授权更新失败: {}", result.getMessage());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
|
|
+ @Disabled
|
|
|
void test() {
|
|
void test() {
|
|
|
System.out.println("Initializing System...");
|
|
System.out.println("Initializing System...");
|
|
|
SystemInfo si = new SystemInfo();
|
|
SystemInfo si = new SystemInfo();
|