diff options
author | Tor Brede Vekterli <vekterli@yahooinc.com> | 2022-11-08 17:06:15 +0100 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@yahooinc.com> | 2022-11-08 17:12:54 +0100 |
commit | 29993d7fa6af8edbc51dcd903a1e27d3f62b4e82 (patch) | |
tree | 19e211cf4be60d056dd4834b532e5027df279260 /vespaclient-java/src/test/java | |
parent | f268379cb63e70cefaea18999767244a7d8bfc7f (diff) |
Add a simple base conversion tool
Currently supports converting from and to any combination of
base {16, 58, 62, 64}. Input is read from STDIN and is intentionally
limited in length due to the algorithmic complexity of base
conversions that are not a power of two. Converted value is
written to STDOUT.
Diffstat (limited to 'vespaclient-java/src/test/java')
-rw-r--r-- | vespaclient-java/src/test/java/com/yahoo/vespa/security/tool/CryptoToolsTest.java | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/vespaclient-java/src/test/java/com/yahoo/vespa/security/tool/CryptoToolsTest.java b/vespaclient-java/src/test/java/com/yahoo/vespa/security/tool/CryptoToolsTest.java index 8ba24d2cccc..f529ed828ea 100644 --- a/vespaclient-java/src/test/java/com/yahoo/vespa/security/tool/CryptoToolsTest.java +++ b/vespaclient-java/src/test/java/com/yahoo/vespa/security/tool/CryptoToolsTest.java @@ -40,6 +40,12 @@ public class CryptoToolsTest { assertEquals(readTestResource(expectedFile), procOut.stdOut()); } + private void verifyStdoutEquals(List<String> args, String stdIn, String expectedMessage) throws IOException { + var procOut = runMain(args, toUtf8Bytes(stdIn), Map.of()); + assertEquals(0, procOut.exitCode()); + assertEquals(expectedMessage, procOut.stdOut()); + } + private void verifyStderrEquals(List<String> args, String expectedMessage) throws IOException { var procOut = runMain(args, EMPTY_BYTES, Map.of()); assertEquals(1, procOut.exitCode()); // Assume checking stderr is because of a failure. @@ -77,6 +83,11 @@ public class CryptoToolsTest { } @Test + void convert_base_help_printed_if_help_option_given_to_subtool() throws IOException { + verifyStdoutMatchesFile(List.of("convert-base", "--help"), "expected-convert-base-help-output.txt"); + } + + @Test void missing_required_parameter_prints_error_message() throws IOException { // We don't test all possible input arguments to all tools, since it'd be too closely // bound to the order in which the implementation checks for argument presence. @@ -240,6 +251,26 @@ public class CryptoToolsTest { } @Test + void convert_base_reads_stdin_and_prints_conversion_on_stdout() throws IOException { + // Check all possible output encodings + verifyStdoutEquals(List.of("convert-base", "--from", "16", "--to", "16"), "0000287fb4cd", "0000287fb4cd\n"); + verifyStdoutEquals(List.of("convert-base", "--from", "16", "--to", "58"), "0000287fb4cd", "11233QC4\n"); + verifyStdoutEquals(List.of("convert-base", "--from", "16", "--to", "62"), "0000287fb4cd", "00jyw3x\n"); + verifyStdoutEquals(List.of("convert-base", "--from", "16", "--to", "64"), "0000287fb4cd", "AAAof7TN\n"); + + // Check a single output encoding for each input encoding, making the simplifying assumption that + // decoding and encoding is independent. Base 16 already covered above. + verifyStdoutEquals(List.of("convert-base", "--from", "58", "--to", "16"), "11233QC4", "0000287fb4cd\n"); + verifyStdoutEquals(List.of("convert-base", "--from", "62", "--to", "16"), "00jyw3x", "0000287fb4cd\n"); + verifyStdoutEquals(List.of("convert-base", "--from", "64", "--to", "16"), "AAAof7TN", "0000287fb4cd\n"); + } + + @Test + void convert_base_tool_ignores_whitespace_on_stdin() throws IOException { + verifyStdoutEquals(List.of("convert-base", "--from", "16", "--to", "58"), " 0000287fb4cd\n", "11233QC4\n"); + } + + @Test void can_end_to_end_keygen_encrypt_and_decrypt_via_files() throws IOException { String greatSecret = "Dogs can't look up"; |