Wallet configuration rejection
This complete test checks deployment maturity, unsafe paths and invalid/conflicting encryption keys before accepting configuration. It demonstrates rejected configurations, not a production endorsement of the file wallet. Run :wallet:plugins:file:test --tests "*FileWalletFactoryTest".
The source block is an exact copy of a compiled SDK file. Documentation CI checks synchronization, and required test gates check execution.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package org.trustweave.wallet.file
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.io.TempDir
import org.trustweave.wallet.exception.WalletException
import org.trustweave.wallet.services.WalletCreationOptions
import org.trustweave.wallet.services.WalletDeploymentPolicy
import java.nio.file.Files
import java.nio.file.Path
import kotlin.test.Test
import kotlin.test.assertFailsWith
import kotlin.test.assertFalse
import kotlin.test.assertTrue
class FileWalletFactoryTest {
@TempDir
lateinit var directory: Path
@Test
fun `production policy rejects before storage creation`() =
runBlocking {
val path = directory.resolve("not-created")
val error =
assertFailsWith<IllegalArgumentException> {
FileWalletFactory().create(
"file",
holderDid = "did:key:holder",
options =
WalletCreationOptions(
storagePath = path.toString(),
deploymentPolicy = WalletDeploymentPolicy.SUPPORTED_ONLY,
),
)
}
assertTrue(error.message!!.contains("deployment maturity policy"))
assertFalse(Files.exists(path))
}
@Test
fun `unsafe wallet ids cannot escape or reuse the storage root`() =
runBlocking {
for (id in listOf("..", ".", "../outside", "a/b", "a\\b", "C:\\outside", "")) {
assertFailsWith<IllegalArgumentException> {
FileWalletFactory().create(
"file",
walletId = id,
holderDid = "did:key:holder",
options = WalletCreationOptions(storagePath = directory.resolve("root").toString()),
)
}
}
assertFalse(Files.exists(directory.resolve("root")))
}
@Test
fun `typed encryption key is validated rather than silently ignored`(): Unit =
runBlocking {
assertFailsWith<WalletException.WalletCreationFailed> {
FileWalletFactory().create(
"file",
holderDid = "did:key:holder",
options =
WalletCreationOptions(
storagePath = directory.toString(),
encryptionKey = "invalid-key",
),
)
}
assertFailsWith<IllegalArgumentException> {
FileWalletFactory().create(
"file",
holderDid = "did:key:holder",
options =
WalletCreationOptions(
storagePath = directory.toString(),
encryptionKey = "one",
additionalProperties = mapOf("encryptionKey" to "two"),
),
)
}
}
}