|
1 | 1 | package io.iohk.ethereum.keystore
|
2 | 2 |
|
3 | 3 | import java.io.File
|
| 4 | +import java.nio.file.{FileSystemException, FileSystems, Files, Path} |
4 | 5 |
|
5 | 6 | import akka.util.ByteString
|
6 | 7 | import io.iohk.ethereum.domain.Address
|
7 | 8 | import io.iohk.ethereum.keystore.KeyStore.{DecryptionFailed, IOError, KeyNotFound, PassPhraseTooShort}
|
8 | 9 | import io.iohk.ethereum.nodebuilder.SecureRandomBuilder
|
9 | 10 | import io.iohk.ethereum.utils.{Config, KeyStoreConfig}
|
10 |
| -import org.scalatest.{BeforeAndAfter, FlatSpec, Matchers} |
11 |
| -import org.bouncycastle.util.encoders.Hex |
12 | 11 | import org.apache.commons.io.FileUtils
|
| 12 | +import org.bouncycastle.util.encoders.Hex |
| 13 | +import org.scalatest.{BeforeAndAfter, FlatSpec, Matchers} |
| 14 | + |
| 15 | +import scala.util.Try |
13 | 16 |
|
14 | 17 | class KeyStoreImplSpec extends FlatSpec with Matchers with BeforeAndAfter with SecureRandomBuilder {
|
15 | 18 |
|
@@ -86,7 +89,7 @@ class KeyStoreImplSpec extends FlatSpec with Matchers with BeforeAndAfter with S
|
86 | 89 | }
|
87 | 90 |
|
88 | 91 | it should "return an error when the keystore dir cannot be initialized" in new TestSetup {
|
89 |
| - intercept[IllegalArgumentException] { |
| 92 | + assertThrows[FileSystemException] { |
90 | 93 | new KeyStoreImpl(testFailingPathConfig, secureRandom)
|
91 | 94 | }
|
92 | 95 | }
|
@@ -172,8 +175,15 @@ class KeyStoreImplSpec extends FlatSpec with Matchers with BeforeAndAfter with S
|
172 | 175 | val keyStoreConfig = KeyStoreConfig(Config.config)
|
173 | 176 |
|
174 | 177 | object testFailingPathConfig extends KeyStoreConfig {
|
| 178 | + |
175 | 179 | override val allowNoPassphrase: Boolean = keyStoreConfig.allowNoPassphrase
|
176 |
| - override val keyStoreDir: String = "/root/keystore" |
| 180 | + override val keyStoreDir: String = { |
| 181 | + val tmpDir: Path = Files.createTempDirectory("mentis-keystore") |
| 182 | + val principalLookupService = FileSystems.getDefault.getUserPrincipalLookupService |
| 183 | + val rootOrAdminPrincipal = Try { principalLookupService.lookupPrincipalByName("root") }.orElse(Try {principalLookupService.lookupPrincipalByName("Administrator")}) |
| 184 | + Files.setOwner(tmpDir, rootOrAdminPrincipal.get) |
| 185 | + tmpDir.toString |
| 186 | + } |
177 | 187 | override val minimalPassphraseLength: Int = keyStoreConfig.minimalPassphraseLength
|
178 | 188 | }
|
179 | 189 | object noEmptyAllowedConfig extends KeyStoreConfig {
|
|
0 commit comments