36 lines
1.1 KiB
Java
36 lines
1.1 KiB
Java
package tech.easyflow.manuagent;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import tech.easyflow.manuagent.config.AppProperties;
|
|
import tech.easyflow.manuagent.model.KeyCipher;
|
|
import java.nio.file.Path;
|
|
import java.time.Duration;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
/**
|
|
* 验证模型密钥保护。
|
|
*/
|
|
class KeyCipherAndShellTest {
|
|
|
|
/**
|
|
* 验证密钥可恢复且相同明文每次产生不同密文。
|
|
*/
|
|
@Test
|
|
void shouldEncryptModelKeyWithRandomIv() {
|
|
KeyCipher cipher = new KeyCipher(properties());
|
|
byte[] first = cipher.encrypt("local-test-key");
|
|
byte[] second = cipher.encrypt("local-test-key");
|
|
|
|
assertThat(first).isNotEqualTo(second);
|
|
assertThat(cipher.decrypt(first)).isEqualTo("local-test-key");
|
|
}
|
|
|
|
private AppProperties properties() {
|
|
return new AppProperties(
|
|
Path.of("data"), Path.of("dashscope"),
|
|
"unit-test-master", "admin", "admin123",
|
|
"smart-factory-agent-runtime:test", "bridge", Duration.ofMinutes(1));
|
|
}
|
|
}
|