Skip to content

Commit

Permalink
Merge pull request #43 from JohnLCaron/testdir
Browse files Browse the repository at this point in the history
Use Files.createTempDirectory for output so github testing works.
  • Loading branch information
JohnLCaron authored Apr 8, 2024
2 parents 01c08e9 + 71015ca commit eadc84e
Show file tree
Hide file tree
Showing 30 changed files with 120 additions and 117 deletions.
23 changes: 20 additions & 3 deletions src/test/kotlin/org/cryptobiotic/eg/cli/RunCreateConfigTest.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
package org.cryptobiotic.eg.cli

import org.cryptobiotic.util.testOut
import org.cryptobiotic.util.Testing
import java.nio.file.Files
import kotlin.test.Test

class RunCreateConfigTest {

@Test
fun showTestDirs() {
println("topdir = ${Testing.tmpdir}")
//println("testOut = $testOut")
//println("testOutMixnet = $testOutMixnet")
}

@Test
fun getTTT() {
val tmpdir = Files.createTempDirectory("tmpDirPrefix").toFile().absolutePath
val tmpDirsLocation = System.getProperty("java.io.tmpdir")
require(tmpdir.startsWith(tmpDirsLocation))
println("tmpdir = $tmpdir")
println("tmpDirsLocation = $tmpDirsLocation")
}

@Test
fun testCreateConfigJson() {
RunCreateElectionConfig.main(
Expand All @@ -14,7 +31,7 @@ class RunCreateConfigTest {
"-nguardians", "3",
"-quorum", "3",
"-out",
"$testOut/config/startConfigJson",
"${Testing.testOut}/config/startConfigJson",
"-device",
"device information",
)
Expand All @@ -31,7 +48,7 @@ class RunCreateConfigTest {
"-quorum", "3",
"-createdBy", "testCreateConfigDirectoryJson",
"-out",
"$testOut/config/testCreateConfigDirectoryJson",
"${Testing.testOut}/config/testCreateConfigDirectoryJson",
"-device",
"device information",
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.cryptobiotic.eg.cli

import org.cryptobiotic.util.testOut
import org.cryptobiotic.util.Testing
import kotlin.test.Test

class RunCreateInputBallotsTest {
Expand All @@ -9,7 +9,7 @@ class RunCreateInputBallotsTest {
RunCreateInputBallots.main(
arrayOf(
"-manifest", "src/test/data/startConfigEc",
"-out", "$testOut/generateInputBallots",
"-out", "${Testing.testOut}/generateInputBallots",
"-n", "42"
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package org.cryptobiotic.eg.cli

import kotlin.test.Test
import org.cryptobiotic.eg.cli.RunCreateTestManifest
import org.cryptobiotic.util.testOut
import org.cryptobiotic.util.Testing

class RunCreateTestManifestTest {

Expand All @@ -13,7 +12,7 @@ class RunCreateTestManifestTest {
"--nstyles", "5",
"-ncontests", "20",
"-nselections", "4",
"-out", "$testOut/manifest/runCreateTestManifest",
"-out", "${Testing.testOut}/manifest/runCreateTestManifest",
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.cryptobiotic.eg.publish.makePublisher
import org.cryptobiotic.eg.publish.readElectionRecord
import org.cryptobiotic.eg.verifier.VerifyEncryptedBallots
import org.cryptobiotic.util.ErrorMessages
import org.cryptobiotic.util.testOut
import org.cryptobiotic.util.Testing
import java.nio.file.Files
import java.nio.file.Path
import kotlin.random.Random
Expand All @@ -20,7 +20,7 @@ class RunEncryptBallotTest {
@Test
fun testRunEncryptOneBallotNoChaining() {
val inputDir = "src/test/data/encrypt/testBallotNoChain"
val outputDir = "$testOut/encrypt/testRunEncryptOneBallotNoChaining"
val outputDir = "${Testing.testOut}/encrypt/testRunEncryptOneBallotNoChaining"
val ballotId = "3842034"

val consumerIn = makeConsumer(inputDir)
Expand Down Expand Up @@ -52,7 +52,7 @@ class RunEncryptBallotTest {
@Test
fun testRunEncryptBallotsNoChaining() {
val inputDir = "src/test/data/encrypt/testBallotNoChain"
val outputDir = "$testOut/encrypt/testRunEncryptBallotsNoChaining"
val outputDir = "${Testing.testOut}/encrypt/testRunEncryptBallotsNoChaining"
val nballots = 10
val device = "device42"

Expand Down Expand Up @@ -98,7 +98,7 @@ class RunEncryptBallotTest {
fun testRunEncryptBallotsChaining() {
val inputDir = "src/test/data/encrypt/testBallotChain"
val device = "device42"
val outputDir = "$testOut/encrypt/testRunEncryptBallotsChaining"
val outputDir = "${Testing.testOut}/encrypt/testRunEncryptBallotsChaining"
val outputDeviceDir = "$outputDir/encrypted_ballots/$device"
val nballots = 10

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.cryptobiotic.eg.cli

import org.cryptobiotic.eg.core.removeAllFiles
import org.cryptobiotic.util.testOut
import org.cryptobiotic.util.Testing
import java.nio.file.Path
import kotlin.test.*

Expand All @@ -10,7 +10,7 @@ class RunExampleEncryptionTest {
@Test
fun testExampleEncryptionWithChaining() {
val inputDir = "src/test/data/encrypt/testBallotChain"
val outputDir = "$testOut/encrypt/testExampleEncryptionWithChaining"
val outputDir = "${Testing.testOut}/encrypt/testExampleEncryptionWithChaining"
val nballots = 33

removeAllFiles(Path.of("$outputDir/encrypted_ballots"))
Expand All @@ -33,7 +33,7 @@ class RunExampleEncryptionTest {
@Test
fun testExampleEncryptionWithNoChaining() {
val inputDir = "src/test/data/encrypt/testBallotNoChain"
val outputDir = "$testOut/encrypt/testExampleEncryptionNoChaining"
val outputDir = "${Testing.testOut}/encrypt/testExampleEncryptionNoChaining"
val nballots = 33

removeAllFiles(Path.of("$outputDir/encrypted_ballots"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.cryptobiotic.eg.cli

import org.cryptobiotic.util.testOut
import org.cryptobiotic.util.Testing
import kotlin.test.Test

class RunTrustedKeyCeremonyTest {
Expand All @@ -9,8 +9,8 @@ class RunTrustedKeyCeremonyTest {
RunTrustedKeyCeremony.main(
arrayOf(
"-in", "src/test/data/startConfigEc",
"-trustees", "$testOut/cliWorkflow/keyceremonyEc/trustees",
"-out", "$testOut/cliWorkflow/keyceremonyEc",
"-trustees", "${Testing.testOut}/cliWorkflow/keyceremonyEc/trustees",
"-out", "${Testing.testOut}/cliWorkflow/keyceremonyEc",
)
)
}
Expand Down
16 changes: 0 additions & 16 deletions src/test/kotlin/org/cryptobiotic/eg/cli/RunVerifierTest.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import org.cryptobiotic.eg.keyceremony.KeyCeremonyTrustee
import org.cryptobiotic.eg.publish.readElectionRecord
import org.cryptobiotic.util.ErrorMessages
import org.cryptobiotic.eg.verifier.VerifyDecryption
import org.cryptobiotic.util.testOut
import org.cryptobiotic.util.Testing
import kotlin.test.*

class EncryptDecrypt2Test {
val configDir = "src/test/data/startConfigEc"
val outputDir = "$testOut/RecoveredDecryptionTest"
val outputDir = "${Testing.testOut}/RecoveredDecryptionTest"
val trusteeDir = "$outputDir/private_data"

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import org.cryptobiotic.eg.publish.readElectionRecord
import org.cryptobiotic.util.ErrorMessages
import org.cryptobiotic.util.Stats
import org.cryptobiotic.eg.verifier.VerifyDecryption
import org.cryptobiotic.util.testOut
import org.cryptobiotic.util.Testing
import kotlin.math.roundToInt
import kotlin.test.*

class EncryptDecryptBallotTest {
val configDir = "src/test/data/startConfigEc"
val outputDir = "$testOut/RecoveredDecryptionTest"
val outputDir = "${Testing.testOut}/RecoveredDecryptionTest"
val trusteeDir = "$outputDir/private_data"

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.cryptobiotic.eg.decryptBallot
import org.cryptobiotic.eg.cli.RunTrustedBallotDecryption.Companion.runDecryptBallots
import org.cryptobiotic.eg.cli.RunTrustedTallyDecryption.Companion.readDecryptingTrustees
import org.cryptobiotic.eg.publish.makeConsumer
import org.cryptobiotic.util.testOut
import org.cryptobiotic.util.Testing

import kotlin.test.Test
import kotlin.test.assertEquals
Expand All @@ -22,7 +22,7 @@ class RunDecryptBallotsJsonTest {
fun testDecryptBallotsAll() {
val inputDir = "src/test/data/workflow/allAvailableEc"
val trusteeDir = "$inputDir/private_data/trustees"
val outputDir = "$testOut/decrypt/testDecryptBallotsAllJson"
val outputDir = "${Testing.testOut}/decrypt/testDecryptBallotsAllJson"
println("\ntestDecryptBallotsAll")
val n = runDecryptBallots(
inputDir,
Expand All @@ -38,7 +38,7 @@ class RunDecryptBallotsJsonTest {
fun testDecryptBallotsSome() {
val inputDir = "src/test/data/workflow/someAvailableEc"
val trusteeDir = "$inputDir/private_data/trustees"
val outputDir = "$testOut/decrypt/testDecryptBallotsSomeJson"
val outputDir = "${Testing.testOut}/decrypt/testDecryptBallotsSomeJson"
println("\ntestDecryptBallotsAll")
val n = runDecryptBallots(
inputDir,
Expand All @@ -54,7 +54,7 @@ class RunDecryptBallotsJsonTest {
fun testDecryptBallotsSomeFromList() {
val inputDir = "src/test/data/workflow/someAvailableEc"
val trusteeDir = "$inputDir/private_data/trustees"
val outputDir = "$testOut/decrypt/testDecryptBallotsSomeFromListJson"
val outputDir = "${Testing.testOut}/decrypt/testDecryptBallotsSomeFromListJson"
println("\ntestDecryptBallotsSomeFromList")
val n = runDecryptBallots(
inputDir, outputDir, readDecryptingTrustees(inputDir, trusteeDir, "5"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.cryptobiotic.eg.cli.RunTrustedBallotDecryption
import org.cryptobiotic.eg.cli.RunTrustedBallotDecryption.Companion.runDecryptBallots
import org.cryptobiotic.eg.cli.RunTrustedTallyDecryption.Companion.readDecryptingTrustees
import org.cryptobiotic.eg.publish.makeConsumer
import org.cryptobiotic.util.testOut
import org.cryptobiotic.util.Testing

import kotlin.test.Test
import kotlin.test.assertEquals
Expand All @@ -23,7 +23,7 @@ class RunDecryptBallotsTest {
fun testDecryptBallotsAll() {
val inputDir = "src/test/data/workflow/allAvailableEc"
val trusteeDir = "$inputDir/private_data/trustees"
val outputDir = "$testOut/decrypt/testDecryptBallotsAll"
val outputDir = "${Testing.testOut}/decrypt/testDecryptBallotsAll"
println("\ntestDecryptBallotsAll")
val n = runDecryptBallots(
inputDir,
Expand All @@ -39,7 +39,7 @@ class RunDecryptBallotsTest {
fun testDecryptBallotsSomeFromList() {
val inputDir = "src/test/data/workflow/someAvailableEc"
val trusteeDir = "$inputDir/private_data/trustees"
val outputDir = "$testOut/decrypt/testDecryptBallotsSomeFromList"
val outputDir = "${Testing.testOut}/decrypt/testDecryptBallotsSomeFromList"
println("\ntestDecryptBallotsSomeFromList")
val n = runDecryptBallots(
inputDir, outputDir, readDecryptingTrustees(inputDir, trusteeDir, "5"),
Expand All @@ -56,7 +56,7 @@ class RunDecryptBallotsTest {
val inputDir = "src/test/data/workflow/someAvailableEc"
val trusteeDir = "$inputDir/private_data/trustees"
val wantBallots = "$inputDir/private_data/wantedBallots.txt"
val outputDir = "$testOut/decrypt/testDecryptBallotsSomeFromFile"
val outputDir = "${Testing.testOut}/decrypt/testDecryptBallotsSomeFromFile"
println("\ntestDecryptBallotsSomeFromFile")
val n = runDecryptBallots(
inputDir, outputDir, readDecryptingTrustees(inputDir, trusteeDir, "4,5"),
Expand All @@ -77,7 +77,7 @@ class RunDecryptBallotsTest {
"-trustees",
"src/test/data/workflow/someAvailableEc/private_data/trustees",
"-out",
"$testOut/decrypt/testDecryptBallotsMainMultiThreaded",
"${Testing.testOut}/decrypt/testDecryptBallotsMainMultiThreaded",
"-challenged",
"all",
"-nthreads",
Expand All @@ -97,7 +97,7 @@ class RunDecryptBallotsTest {
"-trustees",
"src/test/data/workflow/someAvailableEc/private_data/trustees",
"-out",
"$testOut/decrypt/testDecryptBallotsMarkedChallenged",
"${Testing.testOut}/decrypt/testDecryptBallotsMarkedChallenged",
"-nthreads",
"1"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.cryptobiotic.eg.decrypt

import org.cryptobiotic.eg.cli.RunTrustedTallyDecryption
import org.cryptobiotic.util.testOut
import org.cryptobiotic.util.Testing

import kotlin.test.Test

Expand All @@ -17,7 +17,7 @@ class RunTrustedTallyDecryptionTest {
"-trustees",
"src/test/data/workflow/allAvailableEc/private_data/trustees",
"-out",
"$testOut/decrypt/testDecryptionJson",
"${Testing.testOut}/decrypt/testDecryptionJson",
"-createdBy",
"RunTrustedTallyDecryptionTest",
)
Expand All @@ -33,7 +33,7 @@ class RunTrustedTallyDecryptionTest {
"-trustees",
"src/test/data/workflow/someAvailableEc/private_data/trustees",
"-out",
"$testOut/decrypt/testDecryptionSome",
"${Testing.testOut}/decrypt/testDecryptionSome",
"-createdBy",
"RunTrustedTallyDecryptionTest",
"-missing",
Expand All @@ -49,7 +49,7 @@ class RunTrustedTallyDecryptionTest {
arrayOf(
"-in", "src/test/data/workflow/someAvailableEc",
"-trustees", "src/test/data/workflow/someAvailableEc/private_data/trustees",
"-out", "$testOut/decrypt/testDecryptionFromFile",
"-out", "${Testing.testOut}/decrypt/testDecryptionFromFile",
"--encryptedTallyFile", "src/test/data/workflow/someAvailableEc/encrypted_tally.json",
"-createdBy", "testDecryptionFromFile",
"-missing", "1,4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import org.cryptobiotic.eg.input.RandomBallotProvider
import org.cryptobiotic.eg.publish.makePublisher
import org.cryptobiotic.eg.publish.readElectionRecord
import org.cryptobiotic.util.ErrorMessages
import org.cryptobiotic.util.testOut
import org.cryptobiotic.util.Testing
import kotlin.test.*

// test what happens when AddEncryptedBallot is called after being closed
class AddBallotSyncTest {
val inputJson = "src/test/data/workflow/allAvailableEc"
val outputDirTop = "$testOut/encrypt/addEncryptedBallot/SyncTest"
val outputDirTop = "${Testing.testOut}/encrypt/addEncryptedBallot/SyncTest"
val nballots = 4

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import org.cryptobiotic.eg.publish.readElectionRecord
import org.cryptobiotic.eg.verifier.VerifyEncryptedBallots
import org.cryptobiotic.util.ErrorMessages
import org.cryptobiotic.util.Stats
import org.cryptobiotic.util.testOut
import org.cryptobiotic.util.Testing

class AddEncryptedBallotTest {
val input = "src/test/data/workflow/allAvailableEc"
val outputDir = "$testOut/encrypt/addEncryptedBallot/Plain"
val outputDir = "${Testing.testOut}/encrypt/addEncryptedBallot/Plain"
val nballots = 4

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ import org.cryptobiotic.eg.publish.makePublisher
import org.cryptobiotic.eg.publish.readElectionRecord

import org.cryptobiotic.util.ErrorMessages
import org.cryptobiotic.util.testOut
import kotlin.test.assertEquals
import org.cryptobiotic.util.Testing
import kotlin.test.assertTrue

// check AddEncryptedBallot doesnt depend on the order that ballots are submitted
class AddEncryptedChallengedTest {
val input = "src/test/data/workflow/allAvailableEc"
val outputDirTop = "$testOut/encrypt/addEncryptedBallot/ChallengedTest"
val outputDirTop = "${Testing.testOut}/encrypt/addEncryptedBallot/ChallengedTest"

val nballots = 30

Expand Down
Loading

0 comments on commit eadc84e

Please sign in to comment.