feat: license校验方式增加

This commit is contained in:
2026-05-18 10:03:19 +08:00
parent b7f3ae2854
commit 6c3d98eaac
4 changed files with 262 additions and 29 deletions

View File

@@ -2,9 +2,12 @@ package tech.easyflow.autoconfig.license;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.core.io.DefaultResourceLoader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@@ -59,6 +62,35 @@ public class MachineIdentityCollectorTest {
Assert.assertEquals("AA-BB-CC-DD-EE-FF", identity.macAddresses());
}
/**
* 已配置的覆盖文件应优先于系统命令。
*
* @throws Exception 创建临时文件失败
*/
@Test
public void shouldPreferConfiguredIdentityFiles() throws Exception {
Path tempDir = Files.createTempDirectory("machine-identity-collector");
Path machineIdFile = tempDir.resolve("machine-id.txt");
Path productUuidFile = tempDir.resolve("product-uuid.txt");
Path macAddressFile = tempDir.resolve("mac-address.txt");
Files.writeString(machineIdFile, "mounted-machine\n", StandardCharsets.UTF_8);
Files.writeString(productUuidFile, "mounted-product\n", StandardCharsets.UTF_8);
Files.writeString(macAddressFile, "02:42:ac:20:00:11\n", StandardCharsets.UTF_8);
TestMachineIdentityCollector collector = new TestMachineIdentityCollector(
"Linux",
new DefaultResourceLoader(),
machineIdFile.toUri().toString(),
productUuidFile.toUri().toString(),
macAddressFile.toUri().toString()
);
MachineIdentity identity = collector.collect();
Assert.assertEquals("mounted-machine", identity.machineId());
Assert.assertEquals("mounted-product", identity.productUuid());
Assert.assertEquals("02:42:ac:20:00:11", identity.macAddresses());
}
/**
* 空输出应被识别为采集失败。
*/
@@ -85,6 +117,15 @@ public class MachineIdentityCollectorTest {
private final Map<String, String> powerShellOutputs = new HashMap<>();
private TestMachineIdentityCollector(String osName) {
this(osName, new DefaultResourceLoader(), null, null, null);
}
private TestMachineIdentityCollector(String osName,
DefaultResourceLoader resourceLoader,
String machineIdFile,
String productUuidFile,
String macAddressFile) {
super(resourceLoader, machineIdFile, productUuidFile, macAddressFile);
this.osName = osName;
}