Skip to content

Commit

Permalink
Temporarily disable PublishTests.secret keys in config on Windows (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Gedochao authored Mar 21, 2023
1 parent 6710f91 commit fbcdca0
Showing 1 changed file with 87 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,99 +360,105 @@ abstract class PublishTestDefinitions(val scalaVersionOpt: Option[String])
}
}

test("secret keys in config") {

TestCase.testInputs.fromRoot { root =>
val confDir = root / "config"
val confFile = confDir / "test-config.json"

os.write(confFile, "{}", createFolders = true)

if (!Properties.isWin)
os.perms.set(confDir, "rwx------")

val extraEnv = Map("SCALA_CLI_CONFIG" -> confFile.toString)

os.proc(
TestUtil.cli,
"--power",
"config",
"--create-pgp-key",
"--email",
"some_email"
).call(cwd = root, env = extraEnv)
if (!Properties.isWin) // TODO: fix intermittent failures on Windows
test("secret keys in config") {

TestCase.testInputs.fromRoot { root =>
os.proc(
TestUtil.cli,
"--power",
"publish",
extraOptions,
"--signer",
"bc",
"project",
"-R",
"test-repo"
).call(
cwd = root,
stdin = os.Inherit,
stdout = os.Inherit,
env = extraEnv
)

val files = os.walk(root / "test-repo")
.filter(os.isFile(_))
.map(_.relativeTo(root / "test-repo"))
val notInDir = files.filter(!_.startsWith(TestCase.expectedArtifactsDir))
expect(notInDir.isEmpty)

val files0 = files.map(_.relativeTo(TestCase.expectedArtifactsDir)).toSet
val confDir = root / "config"
val confFile = confDir / "test-config.json"

expect((files0 -- expectedArtifacts).isEmpty)
expect((expectedArtifacts -- files0).isEmpty)
expect(files0 == expectedArtifacts) // just in case…
os.write(confFile, "{}", createFolders = true)

val repoArgs =
Seq[os.Shellable]("-r", "!central", "-r", (root / "test-repo").toNIO.toUri.toASCIIString)
val dep = s"org.virtuslab.scalacli.test:simple${TestCase.scalaSuffix}:0.2.0-SNAPSHOT"
val res = os.proc(TestUtil.cs, "launch", repoArgs, dep).call(cwd = root)
val output = res.out.trim()
expect(output == "Hello")
if (!Properties.isWin)
os.perms.set(confDir, "rwx------")

val sourceJarViaCsStr =
os.proc(TestUtil.cs, "fetch", repoArgs, "--sources", "--intransitive", dep)
.call(cwd = root)
.out.trim()
val sourceJarViaCs = os.Path(sourceJarViaCsStr, os.pwd)
val zf = new ZipFile(sourceJarViaCs.toIO)
val entries = zf.entries().asScala.toVector.map(_.getName).toSet
expect(entries == expectedSourceEntries)
val extraEnv = Map("SCALA_CLI_CONFIG" -> confFile.toString)

val publicKey = os.proc(
os.proc(
TestUtil.cli,
"--power",
"config",
"pgp.public-key"
"--create-pgp-key",
"--email",
"some_email"
).call(cwd = root, env = extraEnv)
.out.trim()
.stripPrefix("value:")

os.write(os.Path("key.pub", root), publicKey)

val signatures = expectedArtifacts.filter(_.last.endsWith(".asc"))
assert(signatures.nonEmpty)
os.proc(
TestUtil.cli,
"--power",
"pgp",
"verify",
"--key",
s"key.pub",
signatures.map(os.rel / "test-repo" / TestCase.expectedArtifactsDir / _)
)
.call(cwd = root, env = extraEnv)
TestCase.testInputs.fromRoot { root =>
os.proc(
TestUtil.cli,
"--power",
"publish",
extraOptions,
"--signer",
"bc",
"project",
"-R",
"test-repo"
).call(
cwd = root,
stdin = os.Inherit,
stdout = os.Inherit,
env = extraEnv
)

val files = os.walk(root / "test-repo")
.filter(os.isFile(_))
.map(_.relativeTo(root / "test-repo"))
val notInDir = files.filter(!_.startsWith(TestCase.expectedArtifactsDir))
expect(notInDir.isEmpty)

val files0 = files.map(_.relativeTo(TestCase.expectedArtifactsDir)).toSet

expect((files0 -- expectedArtifacts).isEmpty)
expect((expectedArtifacts -- files0).isEmpty)
expect(files0 == expectedArtifacts) // just in case…

val repoArgs =
Seq[os.Shellable](
"-r",
"!central",
"-r",
(root / "test-repo").toNIO.toUri.toASCIIString
)
val dep = s"org.virtuslab.scalacli.test:simple${TestCase.scalaSuffix}:0.2.0-SNAPSHOT"
val res = os.proc(TestUtil.cs, "launch", repoArgs, dep).call(cwd = root)
val output = res.out.trim()
expect(output == "Hello")

val sourceJarViaCsStr =
os.proc(TestUtil.cs, "fetch", repoArgs, "--sources", "--intransitive", dep)
.call(cwd = root)
.out.trim()
val sourceJarViaCs = os.Path(sourceJarViaCsStr, os.pwd)
val zf = new ZipFile(sourceJarViaCs.toIO)
val entries = zf.entries().asScala.toVector.map(_.getName).toSet
expect(entries == expectedSourceEntries)

val publicKey = os.proc(
TestUtil.cli,
"--power",
"config",
"pgp.public-key"
).call(cwd = root, env = extraEnv)
.out.trim()
.stripPrefix("value:")

os.write(os.Path("key.pub", root), publicKey)

val signatures = expectedArtifacts.filter(_.last.endsWith(".asc"))
assert(signatures.nonEmpty)
os.proc(
TestUtil.cli,
"--power",
"pgp",
"verify",
"--key",
s"key.pub",
signatures.map(os.rel / "test-repo" / TestCase.expectedArtifactsDir / _)
)
.call(cwd = root, env = extraEnv)
}
}
}
}

}

0 comments on commit fbcdca0

Please sign in to comment.