feature/8-secure-without-content #10

Merged
william merged 7 commits from feature/8-secure-without-content into develop 2021-08-06 08:38:07 -04:00
4 changed files with 65 additions and 15 deletions
Showing only changes of commit a07c72b901 - Show all commits

View File

@ -81,9 +81,14 @@ fun configuration(
configuration(type = key.toConfigurationType(), content = content)
}
fun secureConfiguration(
type: ConfigurationType,
lastUpdated: LocalDateTime? = null
) = SecureConfiguration(type, lastUpdated ?: LocalDateTime.now())
fun secureConfiguration(
configuration: Configuration
) = SecureConfiguration(configuration.type, configuration.lastUpdated)
) = secureConfiguration(configuration.type, configuration.lastUpdated)
enum class ConfigurationType(
val key: String,

View File

@ -10,6 +10,7 @@ import io.mockk.*
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import kotlin.UnsupportedOperationException
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue
@ -165,7 +166,47 @@ class ConfigurationServiceTest {
}
@Test
fun `get(type) decrypts configuration content when the given ConfigurationType is secure`() {
fun `get(type) returns a SecureConfiguration when the given ConfigurationType is secure`() {
val type = ConfigurationType.DATABASE_PASSWORD
val configuration = configuration(
type = type,
content = "securepassword".encrypt(type.key, securityProperties.configSalt!!)
)
every { configurationSource.get(type) } returns configuration
val found = service.get(type)
assertTrue { found is SecureConfiguration }
}
@Test
fun `getContent(type) returns configuration content`() {
val type = ConfigurationType.INSTANCE_NAME
val configuration = configuration(
type = type,
content = "content"
)
every { service.get(type) } returns configuration
val found = service.getContent(type)
assertEquals(configuration.content, found)
}
@Test
fun `getContent(type) throws UnsupportedOperationException when configuration is secure`() {
val type = ConfigurationType.DATABASE_PASSWORD
val configuration = secureConfiguration(type)
every { service.get(type) } returns configuration
assertThrows<UnsupportedOperationException> { service.getContent(type) }
}
@Test
fun `getSecure(type) returns decrypted configuration content`() {
val type = ConfigurationType.DATABASE_PASSWORD
val content = "securepassword"
val configuration = configuration(
@ -175,9 +216,16 @@ class ConfigurationServiceTest {
every { configurationSource.get(type) } returns configuration
val found = service.get(type)
val found = service.getSecure(type)
assertEquals(content, found.content)
assertEquals(content, found)
}
@Test
fun `getSecure(type) throws UnsupportedOperationException when configuration is not secure`() {
val type = ConfigurationType.INSTANCE_NAME
assertThrows<UnsupportedOperationException> { service.getSecure(type) }
}
@Test
@ -197,7 +245,7 @@ class ConfigurationServiceTest {
fun `set(configuration) encrypts secure configurations`() {
val type = ConfigurationType.DATABASE_PASSWORD
val content = "securepassword"
val encryptedContent =content.encrypt(type.key, securityProperties.configSalt!!)
val encryptedContent = content.encrypt(type.key, securityProperties.configSalt!!)
val configuration = configuration(type = type, content = content)
mockkStatic(String::encrypt)

View File

@ -80,9 +80,9 @@ class RecipeServiceTest :
@Test
fun `isApprobationExpired() returns false when the approbation date of the given recipe is within the configured period`() {
val period = Period.ofMonths(4)
val config = configuration(type = ConfigurationType.RECIPE_APPROBATION_EXPIRATION, content = period.toString())
val recipe = recipe(approbationDate = LocalDate.now())
whenever(configService.get(ConfigurationType.RECIPE_APPROBATION_EXPIRATION)).doReturn(config)
whenever(configService.getContent(ConfigurationType.RECIPE_APPROBATION_EXPIRATION)).doReturn(period.toString())
val approbationExpired = service.isApprobationExpired(recipe)
@ -93,9 +93,9 @@ class RecipeServiceTest :
@Test
fun `isApprobationExpired() returns true when the approbation date of the given recipe is outside the configured period`() {
val period = Period.ofMonths(4)
val config = configuration(type = ConfigurationType.RECIPE_APPROBATION_EXPIRATION, content = period.toString())
val recipe = recipe(approbationDate = LocalDate.now().minus(period).minusMonths(1))
whenever(configService.get(ConfigurationType.RECIPE_APPROBATION_EXPIRATION)).doReturn(config)
whenever(configService.getContent(ConfigurationType.RECIPE_APPROBATION_EXPIRATION)).doReturn(period.toString())
val approbationExpired = service.isApprobationExpired(recipe)
@ -106,9 +106,9 @@ class RecipeServiceTest :
@Test
fun `isApprobationExpired() returns null when the given recipe as no approbation date`() {
val period = Period.ofMonths(4)
val config = configuration(type = ConfigurationType.RECIPE_APPROBATION_EXPIRATION, content = period.toString())
val recipe = recipe(approbationDate = null)
whenever(configService.get(ConfigurationType.RECIPE_APPROBATION_EXPIRATION)).doReturn(config)
whenever(configService.getContent(ConfigurationType.RECIPE_APPROBATION_EXPIRATION)).doReturn(period.toString())
val approbationExpired = service.isApprobationExpired(recipe)

View File

@ -131,10 +131,7 @@ class TouchUpKitServiceTest {
this.setCachePdf(false)
private fun TouchUpKitServiceTestContext.setCachePdf(enabled: Boolean) {
every { configService.get(ConfigurationType.TOUCH_UP_KIT_CACHE_PDF) } returns configuration(
type = ConfigurationType.TOUCH_UP_KIT_CACHE_PDF,
enabled.toString()
)
every { configService.getContent(ConfigurationType.TOUCH_UP_KIT_CACHE_PDF) } returns enabled.toString()
}
private fun test(test: TouchUpKitServiceTestContext.() -> Unit) {