Skip to content

Commit

Permalink
test: #8 SecretKeyManagerService - 기밀 데이터 조회 기능 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
woody35545 committed Apr 15, 2024
1 parent 376d63d commit c4e2158
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package com.t3t.authenticationapi.keymanager;

import com.t3t.authenticationapi.keymanager.properties.SecretKeyProperties;
import com.t3t.authenticationapi.keymanager.service.SecretKeyManagerService;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;

/**
* Secret Key Manager API 를 통해 기밀 데이터를 정상적으로 가져오는지에 대한 통합 테스트한다.<br>
* 해당 테스트는 가져온 기밀데이터가 실제값과 동일한지 확인하는 테스트가 아니라,<br>
* Secret Key Manager API 를 통해 값이 조회되는지에 대한 테스트이다.<br>
* Secret Key Manager 빈을 위한 실행 환경 변수를 설정하고, application.yml 파일을 통해 테스트에 사용할 key id 를 정의하여 테스트한다.<br>
* @apiNote 확인이 필요한 경우에만 실행하도록 설정하기 위해 테스트를 하고자하는 항목을 제외하고는 @Disabled 어노테이션을 선언하여 테스트를 비활성화한다.<br>
* @see SecretKeyManagerService
* @see SecretKeyProperties
* @author woody35545(구건모)
*/
@SpringBootTest
@TestPropertySource(locations = "classpath:application.yml")
@Slf4j
class SecretKeyManagerTest {

@Autowired
private SecretKeyProperties secretKeyProperties;

@Autowired
private SecretKeyManagerService secretKeyManagerService;


/**
* Secret Key Manager API를 통해 databaseIpAddress 값이 정상적으로 로드되는지 테스트
* @author woody35545(구건모)
*/
@Test
@Disabled
void databaseIpAddressLoadTest () {

// when & then
Assertions.assertDoesNotThrow(()-> secretKeyManagerService.getSecretValue(secretKeyProperties.getDatabaseIpAddressKeyId()));
String value = secretKeyManagerService.getSecretValue(secretKeyProperties.getDatabaseIpAddressKeyId());
Assertions.assertNotNull(value);

log.info("databaseIpAddress => {}", value);
}

/**
* Secret Key Manager API를 통해 databasePort 값이 정상적으로 로드되는지 테스트
* @author woody35545(구건모)
*/
@Test
@Disabled
void databasePortLoadTest () {

// when & then
Assertions.assertDoesNotThrow(() -> secretKeyManagerService.getSecretValue(secretKeyProperties.getDatabasePortKeyId()));
String value = secretKeyManagerService.getSecretValue(secretKeyProperties.getDatabasePortKeyId());
Assertions.assertNotNull(value);

log.info("databasePort => {}", value);
}

/**
* Secret Key Manager API를 통해 databaseName 값이 정상적으로 로드되는지 테스트
* @author woody35545(구건모)
*/
@Test
@Disabled
void databaseNameLoadTest () {

// when & then
Assertions.assertDoesNotThrow(() -> secretKeyManagerService.getSecretValue(secretKeyProperties.getDatabaseNameKeyId()));
String value = secretKeyManagerService.getSecretValue(secretKeyProperties.getDatabaseNameKeyId());
Assertions.assertNotNull(value);

log.info("databaseName => {}", value);
}

/**
* Secret Key Manager API를 통해 databaseUsername 값이 정상적으로 로드되는지 테스트
* @author woody35545(구건모)
*/
@Test
@Disabled
void databaseUsernameLoadTest () {

// when & then
Assertions.assertDoesNotThrow(() -> secretKeyManagerService.getSecretValue(secretKeyProperties.getDatabaseUsernameKeyId()));
String value = secretKeyManagerService.getSecretValue(secretKeyProperties.getDatabaseUsernameKeyId());
Assertions.assertNotNull(value);

log.info("databaseUsername => {}", value);
}


/**
* Secret Key Manager API를 통해 databasePassword 값이 정상적으로 로드되는지 테스트
* @author woody35545(구건모)
*/
@Test
@Disabled
void databasePasswordLoadTest () {
Assertions.assertDoesNotThrow(() -> secretKeyManagerService.getSecretValue(secretKeyProperties.getDatabasePasswordKeyId()));
String value = secretKeyManagerService.getSecretValue(secretKeyProperties.getDatabasePasswordKeyId());

Assertions.assertNotNull(value);
}


/**
* Secret Key Manager API를 통해 jwtSecretKey 값이 정상적으로 로드되는지 테스트
* @author woody35545(구건모)
*/
@Test
@Disabled
void jwtSecretKeyLoadTest () {
Assertions.assertDoesNotThrow(() -> secretKeyManagerService.getSecretValue(secretKeyProperties.getJwtSecretKeyId()));
String value = secretKeyManagerService.getSecretValue(secretKeyProperties.getJwtSecretKeyId());

Assertions.assertNotNull(value);
}

/**
* Secret Key Manager API 를 통해 redisIpAddress 값이 정상적으로 로드되는지 테스트
* @author woody35545(구건모)
*/
@Test
@Disabled
void redisIpAddressLoadTest() {
Assertions.assertDoesNotThrow(() -> secretKeyManagerService.getSecretValue(secretKeyProperties.getRedisIpAddressKeyId()));

String value = secretKeyManagerService.getSecretValue(secretKeyProperties.getRedisIpAddressKeyId());
Assertions.assertNotNull(value);

log.info("redisIpAddress => {}", value);
}

/**
* Secret Key Manager API 를 통해 redisPort 값이 정상적으로 로드되는지 테스트
* @author woody35545(구건모)
*/
@Test
@Disabled
void redisPortLoadTest() {
Assertions.assertDoesNotThrow(() -> secretKeyManagerService.getSecretValue(secretKeyProperties.getRedisPortKeyId()));

String value = secretKeyManagerService.getSecretValue(secretKeyProperties.getRedisPortKeyId());
Assertions.assertNotNull(value);

log.info("redisPort => {}", value);
}

/**
* Secret Key Manager API 를 통해 redisPassword 값이 정상적으로 로드되는지 테스트
* @author woody35545(구건모)
*/
@Test
@Disabled
void redisPasswordLoadTest() {
Assertions.assertDoesNotThrow(() -> secretKeyManagerService.getSecretValue(secretKeyProperties.getRedisPasswordKeyId()));

String value = secretKeyManagerService.getSecretValue(secretKeyProperties.getRedisPasswordKeyId());
Assertions.assertNotNull(value);
}
}
27 changes: 27 additions & 0 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,30 @@ eureka:
service-url:
defaultZone : http://127.0.0.1:8761/eureka


t3t:
secretKeyManager:
certKeyPath: ${secretKeyManagerCertKeyPath}
certKeyType: ${secretKeyManagerCertKeyType}
appKey: ${secretKeyManagerAppKey}
password: ${secretKeyManagerPassword}

secrets:
databaseName:
keyId: "e3203972cbf04433b90c752f695d5736"
databaseServerIpAddress:
keyId: "62911d2c30064812b2b2c97a8dd90782"
databaseServerPort:
keyId: "48e191996aa748938a1edb62652336f4"
databaseServerUsername:
keyId: "f008c1d3f87f4f88ae57bd03871eb10d"
databaseServerPassword:
keyId: "8a65684780224384a681c3e9035ca7d6"
jwtSecretKey:
keyId: "e4f4d4a87ccd49e594f03dffee9fa58d"
redisServerIpAddress:
keyId: "10ee8b6140cc49ffa9e7a7c8a2924a3e"
redisServerPort:
keyId: "0582f8b117604b7d86e9f3ff26931cde"
redisServerPassword:
keyId: "ec1eb8e0706e402cbec8487cbcb86564"

0 comments on commit c4e2158

Please sign in to comment.