Skip to content

Commit

Permalink
renaming
Browse files Browse the repository at this point in the history
unite test coverage
  • Loading branch information
mrFlick72 committed Nov 17, 2024
1 parent f85410e commit 2d55c12
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 50 deletions.
18 changes: 9 additions & 9 deletions src/main/kotlin/com/vauthenticator/server/keys/KeyConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.vauthenticator.server.keys.adapter.dynamo.DynamoDbKeyStorage
import com.vauthenticator.server.keys.adapter.jdbc.JdbcKeyStorage
import com.vauthenticator.server.keys.adapter.kms.KmsKeyDecrypter
import com.vauthenticator.server.keys.adapter.kms.KmsKeyGenerator
import com.vauthenticator.server.keys.adapter.local.*
import com.vauthenticator.server.keys.adapter.java.*
import com.vauthenticator.server.keys.domain.*
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
Expand All @@ -25,12 +25,12 @@ class KeyConfig {

@Profile("!kms")
@Bean("keyGenerator")
fun bouncyCastleKeyGenerator(
fun JavaSecurityKeyGenerator(
kmsClient: KmsClient,
storage: BouncyCastleKeyGeneratorMasterKeyStorage
): KeyGenerator = BouncyCastleKeyGenerator(
storage: KeyGeneratorMasterKeyStorage
): KeyGenerator = JavaSecurityKeyGenerator(
KeyCryptographicOperations(
BouncyCastleKeyGeneratorMasterKeyRepository(storage)
KeyGeneratorMasterKeyRepository(storage)
)
)

Expand All @@ -40,13 +40,13 @@ class KeyConfig {

@Profile("!kms")
@Bean("keyDecrypter")
fun bouncyCastleKeyDecrypter(
fun JavaSecurityKeyDecrypter(
@Value("\${key.master-key}") maserKid: String,
storage: BouncyCastleKeyGeneratorMasterKeyStorage
): KeyDecrypter = BouncyCastleKeyDecrypter(
storage: KeyGeneratorMasterKeyStorage
): KeyDecrypter = JavaSecurityKeyDecrypter(
maserKid,
KeyCryptographicOperations(
BouncyCastleKeyGeneratorMasterKeyRepository(storage)
KeyGeneratorMasterKeyRepository(storage)
)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.vauthenticator.server.keys.adapter.local
package com.vauthenticator.server.keys.adapter.java

import com.vauthenticator.server.extentions.encoder
import com.vauthenticator.server.keys.domain.KeyDecrypter
import com.vauthenticator.server.keys.domain.MasterKid
import org.springframework.beans.factory.annotation.Value

class BouncyCastleKeyDecrypter(
class JavaSecurityKeyDecrypter(
private val maserKid: String,
private val keyCryptographicOperations: KeyCryptographicOperations
) : KeyDecrypter {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.vauthenticator.server.keys.adapter.local
package com.vauthenticator.server.keys.adapter.java

import com.vauthenticator.server.keys.domain.DataKey
import com.vauthenticator.server.keys.domain.KeyGenerator
import com.vauthenticator.server.keys.domain.MasterKid
import java.util.*


class BouncyCastleKeyGenerator(
class JavaSecurityKeyGenerator(
private val keyCryptographicOperations: KeyCryptographicOperations
) : KeyGenerator {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.vauthenticator.server.keys.adapter.local
package com.vauthenticator.server.keys.adapter.java

import com.vauthenticator.server.extentions.decoder
import com.vauthenticator.server.keys.domain.MasterKid
Expand All @@ -12,11 +12,11 @@ import javax.crypto.spec.SecretKeySpec


class KeyCryptographicOperations(
private val repository: BouncyCastleKeyGeneratorMasterKeyRepository,
private val repository: KeyGeneratorMasterKeyRepository
) {
companion object {
init {
Security.addProvider(BouncyCastleProvider());
Security.addProvider(BouncyCastleProvider())
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.vauthenticator.server.keys.adapter.local
package com.vauthenticator.server.keys.adapter.java

import com.vauthenticator.server.keys.domain.MasterKid
import org.springframework.boot.context.properties.ConfigurationProperties
Expand All @@ -7,8 +7,8 @@ import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Profile


class BouncyCastleKeyGeneratorMasterKeyRepository(
val storage: BouncyCastleKeyGeneratorMasterKeyStorage
class KeyGeneratorMasterKeyRepository(
val storage: KeyGeneratorMasterKeyStorage
) {

fun maskerKeyFor(masterKeyId: MasterKid): String {
Expand All @@ -19,12 +19,12 @@ class BouncyCastleKeyGeneratorMasterKeyRepository(

@Profile("!kms")
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(BouncyCastleKeyGeneratorMasterKeyStorage::class)
class BouncyCastleKeyGeneratorMasterKeyRepositoryConfig {
@EnableConfigurationProperties(KeyGeneratorMasterKeyStorage::class)
class KeyGeneratorMasterKeyRepositoryConfig {

}

@ConfigurationProperties(prefix = "key.master-key.storage")
data class BouncyCastleKeyGeneratorMasterKeyStorage(val content: Map<String, String>) {
data class KeyGeneratorMasterKeyStorage(val content: Map<String, String>) {

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.vauthenticator.server.keys.adapter.local
package com.vauthenticator.server.keys.adapter.java

import com.vauthenticator.server.keys.domain.*
import org.springframework.beans.factory.annotation.Value
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.vauthenticator.server.keys.adapter.java

import com.vauthenticator.server.extentions.encoder
import com.vauthenticator.server.keys.domain.MasterKid
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.junit5.MockKExtension
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith

@ExtendWith(MockKExtension::class)
class JavaSecurityKeyDecrypterTest {

@MockK
lateinit var keyCryptographicOperations: KeyCryptographicOperations

@Test
fun `happy path`() {
val encrypted = "AN_ENCRYPTED_VALUE"
val decrypted = "AN_UNENCRYPTED_VALUE".toByteArray()
val maserKid = "A_MASTER_KEY"

val uut = JavaSecurityKeyDecrypter(maserKid, keyCryptographicOperations)

every { keyCryptographicOperations.decryptKeyWith(MasterKid(maserKid), encrypted.toByteArray()) } returns decrypted

val actual = uut.decryptKey(encrypted)
val expected = encoder.encode(decrypted).decodeToString()

Assertions.assertEquals(expected, actual)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.vauthenticator.server.keys.adapter.java

//todo
class JavaSecurityKeyGeneratorTest
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.vauthenticator.server.keys.adapter.java

//todo
class KeyCryptographicOperationsTest
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.vauthenticator.server.keys.adapter.java

//todo
class KeyGeneratorMasterKeyRepositoryTest

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 2d55c12

Please sign in to comment.