-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests for account creation and currency exchange: val…
…idate UUID security
- Loading branch information
kamil.jedrzejuk
committed
Oct 11, 2024
1 parent
d76ff65
commit 14160dd
Showing
16 changed files
with
107 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/camilyed/github/io/currencyexchangeapi/api/XRequestId.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package camilyed.github.io.currencyexchangeapi.api | ||
|
||
import camilyed.github.io.currencyexchangeapi.domain.OperationId | ||
import camilyed.github.io.currencyexchangeapi.infrastructure.InvalidHeaderException | ||
import java.util.UUID | ||
|
||
typealias XRequestId = String? | ||
|
||
fun XRequestId.toOperationId() = | ||
try { | ||
OperationId(UUID.fromString(this)) | ||
} catch (_: IllegalArgumentException) { | ||
throw InvalidHeaderException("X-Request-Id is required and must be a valid UUID") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/main/kotlin/camilyed/github/io/currencyexchangeapi/application/CreateAccountCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
package camilyed.github.io.currencyexchangeapi.application | ||
|
||
import camilyed.github.io.currencyexchangeapi.domain.OperationId | ||
import java.math.BigDecimal | ||
import java.util.UUID | ||
|
||
data class CreateAccountCommand( | ||
val owner: String, | ||
val initialBalance: BigDecimal, | ||
val commandId: UUID, | ||
val operationId: OperationId, | ||
) |
3 changes: 2 additions & 1 deletion
3
...main/kotlin/camilyed/github/io/currencyexchangeapi/application/ExchangePlnToUsdCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
package camilyed.github.io.currencyexchangeapi.application | ||
|
||
import camilyed.github.io.currencyexchangeapi.domain.OperationId | ||
import java.math.BigDecimal | ||
import java.util.UUID | ||
|
||
data class ExchangePlnToUsdCommand( | ||
val accountId: UUID, | ||
val amount: BigDecimal, | ||
val commandId: UUID, | ||
val operationId: OperationId, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 9 additions & 1 deletion
10
src/main/kotlin/camilyed/github/io/currencyexchangeapi/domain/OperationId.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
package camilyed.github.io.currencyexchangeapi.domain | ||
|
||
import camilyed.github.io.security.UUIDSecureValidator | ||
import java.util.UUID | ||
|
||
@JvmInline | ||
value class OperationId(val value: UUID) | ||
value class OperationId(val value: UUID) { | ||
|
||
init { | ||
require(UUIDSecureValidator.default().isSecure(value)) { | ||
throw InsecureOperationException("Insecure operation: UUID $value does not meet security requirements.") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters