AGENTS.md + code cleanup
This commit is contained in:
parent
21b4169130
commit
9df61e0cd3
20 changed files with 365 additions and 910 deletions
|
|
@ -5,12 +5,7 @@ import ai.nomyo.util.Pass2Key;
|
|||
import org.junit.jupiter.api.*;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
|
@ -51,7 +46,7 @@ class SecureCompletionClientTest {
|
|||
|
||||
assertNotNull(privateKey, "Private key should not be null");
|
||||
assertNotNull(publicPemKey, "Public PEM key should not be null");
|
||||
assertTrue(privateKey.getAlgorithm().equals("RSA"), "Key algorithm should be RSA");
|
||||
assertEquals("RSA", privateKey.getAlgorithm(), "Key algorithm should be RSA");
|
||||
assertTrue(publicPemKey.contains("BEGIN PUBLIC KEY"), "Public key should be valid PEM");
|
||||
}
|
||||
|
||||
|
|
@ -81,8 +76,8 @@ class SecureCompletionClientTest {
|
|||
client2.generateKeys(false);
|
||||
PrivateKey secondKey = client2.getPrivateKey();
|
||||
|
||||
assertNotEquals(firstKey.getEncoded().length, secondKey.getEncoded().length,
|
||||
"Different keys should have different encoded lengths");
|
||||
assertNotEquals(java.util.Arrays.hashCode(firstKey.getEncoded()), java.util.Arrays.hashCode(secondKey.getEncoded()),
|
||||
"Different keys should have different encoded content");
|
||||
}
|
||||
|
||||
// ── Key Generation with File Save Tests ───────────────────────────
|
||||
|
|
@ -90,7 +85,7 @@ class SecureCompletionClientTest {
|
|||
@Test
|
||||
@Order(4)
|
||||
@DisplayName("generateKeys with saveToFile=true should create key files")
|
||||
void generateKeys_withSaveToFile_shouldCreateKeyFiles(@TempDir Path tempDir) throws Exception {
|
||||
void generateKeys_withSaveToFile_shouldCreateKeyFiles(@TempDir Path tempDir) {
|
||||
File keyDir = tempDir.toFile();
|
||||
|
||||
client.generateKeys(true, keyDir.getAbsolutePath(), null);
|
||||
|
|
@ -124,7 +119,7 @@ class SecureCompletionClientTest {
|
|||
@Test
|
||||
@Order(6)
|
||||
@DisplayName("generateKeys should not overwrite existing key files")
|
||||
void generateKeys_shouldNotOverwriteExistingKeys(@TempDir Path tempDir) throws Exception {
|
||||
void generateKeys_shouldNotOverwriteExistingKeys(@TempDir Path tempDir) {
|
||||
File keyDir = tempDir.toFile();
|
||||
|
||||
client.generateKeys(true, keyDir.getAbsolutePath(), null);
|
||||
|
|
@ -143,7 +138,7 @@ class SecureCompletionClientTest {
|
|||
@Test
|
||||
@Order(7)
|
||||
@DisplayName("loadKeys should load plaintext private key from file")
|
||||
void loadKeys_plaintext_shouldLoadPrivateKey(@TempDir Path tempDir) throws Exception {
|
||||
void loadKeys_plaintext_shouldLoadPrivateKey(@TempDir Path tempDir) {
|
||||
File keyDir = tempDir.toFile();
|
||||
client.generateKeys(true, keyDir.getAbsolutePath(), null);
|
||||
|
||||
|
|
@ -164,7 +159,7 @@ class SecureCompletionClientTest {
|
|||
@Test
|
||||
@Order(8)
|
||||
@DisplayName("loadKeys should load encrypted private key with correct password")
|
||||
void loadKeys_encrypted_correctPassword_shouldLoadPrivateKey(@TempDir Path tempDir) throws Exception {
|
||||
void loadKeys_encrypted_correctPassword_shouldLoadPrivateKey(@TempDir Path tempDir) {
|
||||
File keyDir = tempDir.toFile();
|
||||
client.generateKeys(true, keyDir.getAbsolutePath(), TEST_PASSWORD);
|
||||
|
||||
|
|
@ -186,7 +181,7 @@ class SecureCompletionClientTest {
|
|||
@Test
|
||||
@Order(9)
|
||||
@DisplayName("loadKeys should handle wrong password gracefully")
|
||||
void loadKeys_encrypted_wrongPassword_shouldHandleGracefully(@TempDir Path tempDir) throws Exception {
|
||||
void loadKeys_encrypted_wrongPassword_shouldHandleGracefully(@TempDir Path tempDir) {
|
||||
File keyDir = tempDir.toFile();
|
||||
client.generateKeys(true, keyDir.getAbsolutePath(), TEST_PASSWORD);
|
||||
|
||||
|
|
@ -220,7 +215,7 @@ class SecureCompletionClientTest {
|
|||
@Test
|
||||
@Order(11)
|
||||
@DisplayName("validateRsaKey should accept valid 4096-bit key")
|
||||
void validateRsaKey_validKey_shouldPass() throws Exception {
|
||||
void validateRsaKey_validKey_shouldPass() {
|
||||
client.generateKeys(false);
|
||||
PrivateKey key = client.getPrivateKey();
|
||||
|
||||
|
|
@ -231,7 +226,7 @@ class SecureCompletionClientTest {
|
|||
@Test
|
||||
@Order(12)
|
||||
@DisplayName("validateRsaKey should reject null key")
|
||||
void validateRsaKey_nullKey_shouldThrowSecurityError() throws Exception {
|
||||
void validateRsaKey_nullKey_shouldThrowSecurityError() {
|
||||
SecurityError error = assertThrows(SecurityError.class, () ->
|
||||
client.validateRsaKey(null));
|
||||
|
||||
|
|
@ -273,7 +268,7 @@ class SecureCompletionClientTest {
|
|||
@Test
|
||||
@Order(15)
|
||||
@DisplayName("Full roundtrip: generate, save, load should produce same key")
|
||||
void roundtrip_generateSaveLoad_shouldProduceSameKey(@TempDir Path tempDir) throws Exception {
|
||||
void roundtrip_generateSaveLoad_shouldProduceSameKey(@TempDir Path tempDir) {
|
||||
File keyDir = tempDir.toFile();
|
||||
|
||||
// Generate and save
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue