Skip to content

Commit e5b8782

Browse files
committed
[ETCM-52] Fix KeyStore tests to pass on Windows
1 parent 8204d79 commit e5b8782

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ scalacOptions in (Compile, console) ~= (_.filterNot(
121121
"-Xfatal-warnings"
122122
)
123123
))
124+
Global / onChangedBuildSource := ReloadOnSourceChanges
124125

125126
Test / parallelExecution := false
126127

src/test/scala/io/iohk/ethereum/keystore/KeyStoreImplSpec.scala

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
package io.iohk.ethereum.keystore
22

33
import java.io.File
4+
import java.nio.file.{FileSystemException, FileSystems, Files, Path}
45

56
import akka.util.ByteString
67
import io.iohk.ethereum.domain.Address
78
import io.iohk.ethereum.keystore.KeyStore.{DecryptionFailed, IOError, KeyNotFound, PassPhraseTooShort}
89
import io.iohk.ethereum.nodebuilder.SecureRandomBuilder
910
import io.iohk.ethereum.utils.{Config, KeyStoreConfig}
10-
import org.scalatest.{BeforeAndAfter, FlatSpec, Matchers}
11-
import org.bouncycastle.util.encoders.Hex
1211
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
1316

1417
class KeyStoreImplSpec extends FlatSpec with Matchers with BeforeAndAfter with SecureRandomBuilder {
1518

@@ -86,7 +89,7 @@ class KeyStoreImplSpec extends FlatSpec with Matchers with BeforeAndAfter with S
8689
}
8790

8891
it should "return an error when the keystore dir cannot be initialized" in new TestSetup {
89-
intercept[IllegalArgumentException] {
92+
assertThrows[FileSystemException] {
9093
new KeyStoreImpl(testFailingPathConfig, secureRandom)
9194
}
9295
}
@@ -172,8 +175,15 @@ class KeyStoreImplSpec extends FlatSpec with Matchers with BeforeAndAfter with S
172175
val keyStoreConfig = KeyStoreConfig(Config.config)
173176

174177
object testFailingPathConfig extends KeyStoreConfig {
178+
175179
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+
}
177187
override val minimalPassphraseLength: Int = keyStoreConfig.minimalPassphraseLength
178188
}
179189
object noEmptyAllowedConfig extends KeyStoreConfig {

0 commit comments

Comments
 (0)