Skip to content

Commit

Permalink
sonar hints
Browse files Browse the repository at this point in the history
  • Loading branch information
mrFlick72 committed Oct 24, 2024
1 parent 910ca00 commit 3d25157
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.vauthenticator.server.keys.domain

interface KeyDecrypter {
fun interface KeyDecrypter {
fun decryptKey(encrypted: String): String
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import com.vauthenticator.server.account.Account
import com.vauthenticator.server.account.AccountMandatoryAction.RESET_PASSWORD
import com.vauthenticator.server.role.domain.Role
import com.vauthenticator.server.role.domain.RoleRepository
import com.vauthenticator.server.support.AccountTestFixture.anAccount
import com.vauthenticator.server.support.defaultRole
import com.vauthenticator.server.support.protectedRoleName
import com.vauthenticator.server.support.AccountTestFixture.anAccount
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertThrows
import org.junit.jupiter.api.BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package com.vauthenticator.server.account.repository.dynamodb

import com.vauthenticator.server.account.repository.AbstractAccountRepositoryTest
import com.vauthenticator.server.account.repository.AccountRepository
import com.vauthenticator.server.role.domain.RoleRepository
import com.vauthenticator.server.support.protectedRoleNames
import com.vauthenticator.server.role.adapter.dynamodb.DynamoDbRoleRepository
import com.vauthenticator.server.role.domain.RoleRepository
import com.vauthenticator.server.support.DynamoDbUtils.dynamoAccountTableName
import com.vauthenticator.server.support.DynamoDbUtils.dynamoDbClient
import com.vauthenticator.server.support.DynamoDbUtils.dynamoRoleTableName
import com.vauthenticator.server.support.DynamoDbUtils.resetDynamoDb
import com.vauthenticator.server.support.protectedRoleNames


internal class DynamoDbAbstractAccountRepositoryTest : AbstractAccountRepositoryTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package com.vauthenticator.server.account.repository.jdbc

import com.vauthenticator.server.account.repository.AbstractAccountRepositoryTest
import com.vauthenticator.server.account.repository.AccountRepository
import com.vauthenticator.server.role.domain.RoleRepository
import com.vauthenticator.server.support.protectedRoleNames
import com.vauthenticator.server.role.adapter.jdbc.JdbcRoleRepository
import com.vauthenticator.server.role.domain.RoleRepository
import com.vauthenticator.server.support.JdbcUtils.jdbcTemplate
import com.vauthenticator.server.support.JdbcUtils.resetDb
import com.vauthenticator.server.support.protectedRoleNames

class JdbcAccountRepositoryTest : AbstractAccountRepositoryTest() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.vauthenticator.server.support.AccountTestFixture.anAccount
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

private const val NEW_ACCOUNT_EMAIL_EMAIL_COM = "[email protected]"

internal class SimpleEMailMessageFactoryTest {

private val underTest = SimpleEMailMessageFactory("from", "subject", EMailType.WELCOME)
Expand Down Expand Up @@ -34,15 +36,15 @@ internal class SimpleEMailMessageFactoryTest {
@Test
internal fun `make a new mail message when the sender mail has changed`() {
val account = anAccount()
val actual = underTest.makeMailMessageFor(account, mapOf("key" to "value", "email" to "[email protected]"))
val actual = underTest.makeMailMessageFor(account, mapOf("key" to "value", "email" to NEW_ACCOUNT_EMAIL_EMAIL_COM))

val expected = EMailMessage(
"[email protected]", "from", "subject", EMailType.WELCOME,
NEW_ACCOUNT_EMAIL_EMAIL_COM, "from", "subject", EMailType.WELCOME,
mapOf(
"enabled" to account.enabled,
"username" to account.username,
"authorities" to account.authorities,
"email" to "[email protected]",
"email" to NEW_ACCOUNT_EMAIL_EMAIL_COM,
"firstName" to account.firstName,
"lastName" to account.lastName,
"birthDate" to "",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.vauthenticator.server.events

import com.vauthenticator.server.events.EventFixture.vauthenticatorAuthEvent
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.boot.test.system.CapturedOutput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import io.mockk.junit5.MockKExtension
import io.mockk.just
import io.mockk.runs
import io.mockk.verify
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.context.ApplicationEventPublisher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ import com.vauthenticator.server.support.DynamoDbUtils.dynamoDbClient
import com.vauthenticator.server.support.DynamoDbUtils.dynamoMfaKeysTableName
import com.vauthenticator.server.support.DynamoDbUtils.dynamoSignatureKeysTableName
import com.vauthenticator.server.support.DynamoDbUtils.resetDynamoDb
import software.amazon.awssdk.services.dynamodb.model.AttributeValue
import software.amazon.awssdk.services.dynamodb.model.GetItemRequest
import java.time.Clock
import java.time.Instant
import java.time.ZoneId
import kotlin.reflect.jvm.internal.impl.load.kotlin.JvmType

class DynamoDbKeyStorageTest : AbstractKeyStorageTest() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package com.vauthenticator.server.keys.api

import com.fasterxml.jackson.databind.ObjectMapper
import com.vauthenticator.server.keys.domain.*
import com.vauthenticator.server.support.KeysUtils
import com.vauthenticator.server.support.KeysUtils.aKid
import com.vauthenticator.server.support.KeysUtils.aMasterKey
import com.vauthenticator.server.support.KeysUtils.anotherKid
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.junit5.MockKExtension
Expand All @@ -20,6 +24,8 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetu
import java.security.KeyPairGenerator
import java.time.Duration

private const val API_PATH = "/api/keys"

@ExtendWith(MockKExtension::class)
internal class KeyEndPointTest {

Expand Down Expand Up @@ -50,8 +56,8 @@ internal class KeyEndPointTest {
listOf(
Key(
DataKey.from("", ""),
MasterKid("A_MASTER_KEY"),
Kid("A_KID"),
aMasterKey,
aKid,
true,
KeyType.ASYMMETRIC,
KeyPurpose.SIGNATURE,
Expand All @@ -60,26 +66,26 @@ internal class KeyEndPointTest {
)
)

mokMvc.perform(get("/api/keys"))
mokMvc.perform(get(API_PATH))
.andExpect(status().isOk)
.andExpect(content().json(mapper.writeValueAsString(listOf(payload))))
}

@Test
internal fun `when we are able to create a new key`() {
every { keyRepository.createKeyFrom(MasterKid("A_MASTER_KEY")) } returns Kid("123")
every { keyRepository.createKeyFrom(aMasterKey) } returns Kid("123")

mokMvc.perform(post("/api/keys"))
mokMvc.perform(post(API_PATH))
.andExpect(status().isCreated)

}

@Test
internal fun `when we are able to delete a new key`() {
every { keyRepository.deleteKeyFor(Kid("A_KID"), KeyPurpose.SIGNATURE) } just runs
every { keyRepository.deleteKeyFor(aKid, KeyPurpose.SIGNATURE) } just runs

mokMvc.perform(
delete("/api/keys")
delete(API_PATH)
.contentType(MediaType.APPLICATION_JSON)
.content(mapper.writeValueAsString(deletePayload))
)
Expand All @@ -88,10 +94,10 @@ internal class KeyEndPointTest {

@Test
internal fun `when we are not able to delete a new key`() {
every { keyRepository.deleteKeyFor(Kid("A_KID"), KeyPurpose.SIGNATURE) } throws KeyDeletionException("")
every { keyRepository.deleteKeyFor(aKid, KeyPurpose.SIGNATURE) } throws KeyDeletionException("")

mokMvc.perform(
delete("/api/keys")
delete(API_PATH)
.contentType(MediaType.APPLICATION_JSON)
.content(mapper.writeValueAsString(deletePayload))
)
Expand All @@ -100,12 +106,12 @@ internal class KeyEndPointTest {

@Test
internal fun `when we rotate a signature key`() {
val expectedKid = Kid("A_NEW_KID")
val expectedKid = anotherKid

every {
signatureKeyRotation.rotate(
MasterKid("A_MASTER_KEY"),
Kid("A_KID"),
aMasterKey,
aKid,
Duration.ofSeconds(100)
)
} returns expectedKid
Expand All @@ -119,8 +125,8 @@ internal class KeyEndPointTest {

verify {
signatureKeyRotation.rotate(
MasterKid("A_MASTER_KEY"),
Kid("A_KID"),
aMasterKey,
aKid,
Duration.ofSeconds(100)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import java.time.Clock
import java.time.Duration
import java.time.Instant
import java.time.ZoneId
import java.util.*

@ExtendWith(MockKExtension::class)
class KeyRepositoryTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.vauthenticator.server.mask
import com.vauthenticator.server.mfa.domain.MfaMethod
import io.mockk.impl.annotations.MockK
import io.mockk.junit5.MockKExtension
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.vauthenticator.server.mask

import com.vauthenticator.server.support.AccountTestFixture.anAccountWithPhoneNumber
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class SensitivePhoneMaskerTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.vauthenticator.server.role.adapter.dynamodb

import com.vauthenticator.server.role.domain.RoleRepository
import com.vauthenticator.server.support.protectedRoleNames
import com.vauthenticator.server.role.adapter.AbstractRoleRepositoryTest
import com.vauthenticator.server.role.domain.RoleRepository
import com.vauthenticator.server.support.DynamoDbUtils.dynamoDbClient
import com.vauthenticator.server.support.DynamoDbUtils.dynamoRoleTableName
import com.vauthenticator.server.support.DynamoDbUtils.initRoleTestsInDynamo
import com.vauthenticator.server.support.DynamoDbUtils.resetDynamoDb
import com.vauthenticator.server.support.protectedRoleNames

class DynamoDbRoleRepositoryTest : AbstractRoleRepositoryTest() {
override fun initRoleRepository(): RoleRepository =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.vauthenticator.server.role.adapter.jdbc

import com.vauthenticator.server.role.domain.RoleRepository
import com.vauthenticator.server.support.protectedRoleNames
import com.vauthenticator.server.role.adapter.AbstractRoleRepositoryTest
import com.vauthenticator.server.role.domain.RoleRepository
import com.vauthenticator.server.support.JdbcUtils.initRoleTestsInDB
import com.vauthenticator.server.support.JdbcUtils.jdbcTemplate
import com.vauthenticator.server.support.JdbcUtils.resetDb
import com.vauthenticator.server.support.protectedRoleNames

class JdbcRoleRepositoryTest : AbstractRoleRepositoryTest() {
override fun initRoleRepository(): RoleRepository =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
import org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup

private const val A_ROLE_DESCRIPTION = "A Role description"

@ExtendWith(MockKExtension::class)
internal class RoleEndPointTest {

Expand All @@ -37,9 +39,9 @@ internal class RoleEndPointTest {
@Test
internal fun `find al roles`() {
val roles = listOf(
Role("a_role1", "A Role description"),
Role("a_role2", "A Role description"),
Role("a_role3", "A Role description")
Role("a_role1", A_ROLE_DESCRIPTION),
Role("a_role2", A_ROLE_DESCRIPTION),
Role("a_role3", A_ROLE_DESCRIPTION)
)

every { roleRepository.findAll() } returns roles
Expand All @@ -55,7 +57,7 @@ internal class RoleEndPointTest {

@Test
internal fun `save a new role`() {
val role = Role("a_role", "A Role description")
val role = Role("a_role", A_ROLE_DESCRIPTION)
every { roleRepository.save(role) } just runs

mokMvc.perform(
Expand Down

0 comments on commit 3d25157

Please sign in to comment.