safedb 디버깅

This commit is contained in:
Rinjae
2025-09-25 17:33:26 +09:00
parent dc5f9e6835
commit f0b126d736
2 changed files with 70 additions and 20 deletions
@@ -1,15 +1,23 @@
package com.eactive.ext.kjb.safedb.test;
import com.eactive.ext.kjb.safedb.SafeDBWrapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
@Slf4j
public class SafeDbWrapperTest {
@Test
public void faceSafeDBTest() {
log("FakeSafeDBWrapper Length Validation Start");
public void fakeSafeDBTest() {
log.info("FakeSafeDBWrapper Length Validation Start");
if ("true".equalsIgnoreCase(System.getenv("safedb"))) {
log.info("실제 Safedb 테스트를 위해 테스트 종료 처리");
assertTrue("true".equalsIgnoreCase(System.getenv("safedb")));
return;
}
SafeDBWrapper wrapper;
try {
@@ -20,13 +28,13 @@ public class SafeDbWrapperTest {
throw new RuntimeException("SafeDBWrapper classloader error: " + e.getMessage(), e);
} else {
// initialization 에러(로컬에서는 동작하지 않는다 = 정상 처리)
log("SafeDBWrapper initialization error (expected in local environment): " + e.getMessage());
log.info("SafeDBWrapper initialization error (expected in local environment): " + e.getMessage());
return;
}
}
if (wrapper.isRealSafeDB()) {
log("This test is for FakeSafeDBWrapper only. Skipping test.");
log.info("This test is for FakeSafeDBWrapper only. Skipping test.");
return;
}
@@ -45,7 +53,7 @@ public class SafeDbWrapperTest {
assertEquals(originalData, decryptedData, "Decrypted data does not match original at plain length=" + len);
// 로그 출력
log(String.format("Plain=%3d, Encrypted=%3d, Expected=%3d %s",
log.info(String.format("Plain=%3d, Encrypted=%3d, Expected=%3d %s",
len, encryptedData.length(), expectedLen,
(encryptedData.length() == expectedLen ? "" : "")));
@@ -55,7 +63,7 @@ public class SafeDbWrapperTest {
// 암복호화 로그 출력
log(String.format("Original: %s", originalData) +
log.info(String.format("Original: %s", originalData) +
String.format("\nEncrypted: %s", encryptedData) +
String.format("\nDecrypted: %s", decryptedData) + "\n");
@@ -66,6 +74,42 @@ public class SafeDbWrapperTest {
}
}
@Test
public void safeDBTest() {
// safedb 프러퍼티가 활성화 일때만 동작
if (!"true".equalsIgnoreCase(System.getProperty("safedb"))) {
log.info("gradle : -Psafedb 일때만 동작");
return;
}
SafeDBWrapper wrapper;
try {
wrapper = SafeDBWrapper.getInstance();
} catch (Exception e) {
log.error("SafeDBWrapper 활성화 실패");
fail();
return;
}
if (!wrapper.isRealSafeDB()) {
log.error("실제 Safedb 로 동작하지 않음");
fail();
return;
}
String value = "test";
log.info("Original : {}", value);
String encryptValue = wrapper.encryptNotRnnoString(value);
log.info("Encrypted : {}", encryptValue);
String decryptedValue = wrapper.decryptNotRnno(encryptValue);
log.info("Decrypted : {}", decryptedValue);
assertEquals(value, decryptedValue);
assertTrue(true);
}
/**
* 암호문 예상 길이 계산 (AES/SEED/ARIA CBC 기준, PKCS5Padding)
*/
@@ -90,8 +134,4 @@ public class SafeDbWrapperTest {
}
return sb.toString();
}
private void log(String message) {
System.out.println(message);
}
}