Skip to content

Commit

Permalink
Exclude no password tests for native, add warning
Browse files Browse the repository at this point in the history
  • Loading branch information
MaciejG604 committed Mar 8, 2023
1 parent c1b85d4 commit 6050d29
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 70 deletions.
Expand Up @@ -865,6 +865,9 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
}
}

if (secretKeyPasswordOpt.isEmpty)
logger.diagnostic("PGP signing with no password is not recommended since it's not stable")

if (forceSigningBinary)
(new scala.cli.internal.BouncycastleSignerMakerSubst).get(
secretKeyPasswordOpt.fold(null)(_.toCliSigning),
Expand Down
Expand Up @@ -274,90 +274,91 @@ abstract class PublishTestDefinitions(val scalaVersionOpt: Option[String])
}
}

test("missing secret key password") {
// format: off
val signingOptions = Seq(
"--secret-key", s"file:key.skr",
"--signer", "bc"
)
// format: on
if (!TestUtil.isNativeCli)
test("missing secret key password") {
// format: off
val signingOptions = Seq(
"--secret-key", s"file:key.skr",
"--signer", "bc"
)
// format: on

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

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

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

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

os.proc(
TestUtil.cli,
"--power",
"pgp",
"create",
"--email",
"some_email",
"--password",
"value:"
).call(cwd = root, env = extraEnv)
os.proc(
TestUtil.cli,
"--power",
"pgp",
"create",
"--email",
"some_email",
"--password",
"value:"
).call(cwd = root, env = extraEnv)

val publicKey = os.Path("key.pub", root)
val publicKey = os.Path("key.pub", root)

os.proc(
TestUtil.cli,
"--power",
"publish",
extraOptions,
signingOptions,
"project",
"-R",
"test-repo"
).call(cwd = root, env = extraEnv)
os.proc(
TestUtil.cli,
"--power",
"publish",
extraOptions,
signingOptions,
"project",
"-R",
"test-repo"
).call(cwd = root, 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 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 files0 = files.map(_.relativeTo(TestCase.expectedArtifactsDir)).toSet

expect((files0 -- expectedArtifacts).isEmpty)
expect((expectedArtifacts -- files0).isEmpty)
expect(files0 == expectedArtifacts) // just in case…
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 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 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 signatures = expectedArtifacts.filter(_.last.endsWith(".asc"))
assert(signatures.nonEmpty)
os.proc(
TestUtil.cli,
"--power",
"pgp",
"verify",
"--key",
publicKey,
signatures.map(os.rel / "test-repo" / TestCase.expectedArtifactsDir / _)
).call(cwd = root, env = extraEnv)
val signatures = expectedArtifacts.filter(_.last.endsWith(".asc"))
assert(signatures.nonEmpty)
os.proc(
TestUtil.cli,
"--power",
"pgp",
"verify",
"--key",
publicKey,
signatures.map(os.rel / "test-repo" / TestCase.expectedArtifactsDir / _)
).call(cwd = root, env = extraEnv)
}
}
}

test("secret keys in config") {

Expand Down

0 comments on commit 6050d29

Please sign in to comment.