diff --git a/.circleci/config.yml b/.circleci/config.yml index b0873d162..9a0e64179 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -137,7 +137,7 @@ jobs: - run: name: Maven Build/Test command: | - mvn clean install dependency:go-offline -T 2.0C -B + mvn clean install -Dtest=!LarkyQuickTests -DfailIfNoTests=false dependency:go-offline -T 2.0C -B - <<: *save-maven-cache - run: find . -type f -regex ".*/target/surefire-reports/.*xml" -exec cp {} $TEST_RESULTS_PATH/junit/ \; - run: find . -type f -regex ".*/target/surefire-reports/.*-output.txt" -exec cp {} $TEST_RESULTS_PATH/junit/ \; @@ -147,6 +147,26 @@ jobs: - store_test_results: path: *test_results_directory + larky-case-tests: + <<: *job-defaults + machine: + image: ubuntu-1604:202007-01 + steps: + - checkout + - <<: *install-java + - <<: *restore-maven-cache + - run: mkdir -p $TEST_RESULTS_PATH/junit/ + - run: mkdir -p $TEST_RESULTS_PATH/coverage/ + - run: + name: Maven Build/Test + command: | + mvn clean install -pl larky -Dtest=LarkyQuickTests dependency:go-offline -T 2.0C -B + - <<: *save-maven-cache + - run: find . -type f -regex ".*/target/surefire-reports/.*xml" -exec cp {} $TEST_RESULTS_PATH/junit/ \; + - run: find . -type f -regex ".*/target/surefire-reports/.*-output.txt" -exec cp {} $TEST_RESULTS_PATH/junit/ \; + - run: find . -type f -regex ".*/target/site/.*" -exec cp --parents {} $TEST_RESULTS_PATH/coverage/ \; + + build-and-test-docker: <<: *job-defaults machine: true @@ -280,6 +300,7 @@ workflows: build_and_tests: jobs: - build-and-test + - larky-case-tests - build-and-test-docker - build-dist-linux: requires: diff --git a/examples/test_aws_v4_sign.star b/examples/test_aws_v4_sign.star new file mode 100644 index 000000000..f9ff1cca6 --- /dev/null +++ b/examples/test_aws_v4_sign.star @@ -0,0 +1,32 @@ +load("@stdlib//builtins", builtins="builtins") +load("@vendor//Crypto/Hash/HMAC", HMAC="HMAC") +load("@vendor//Crypto/Hash/SHA256", SHA256="SHA256") + +load("@stdlib//unittest", "unittest") +load("@vendor//asserts", "asserts") + + +def b(s): + return builtins.bytes(s, encoding="UTF8") + + +def test_aws_v4_sign(): + expected_signature = "20a7ab2bfce9848a117546ad4f701270683e0f86e72703872841f7343a1a1a7e" + key = "this-is-a-key" + date = "1959-02-03" + region = "us-west-2" + service_name = "some-service" + kDate = HMAC.new(b("AWS4" + key), b(date), digestmod=SHA256).digest() + kRegion = HMAC.new(kDate, b(region), digestmod=SHA256).digest() + kService = HMAC.new(kRegion, b(service_name), digestmod=SHA256).digest() + kSigning = HMAC.new(kService, b("aws4_request"), digestmod=SHA256).hexdigest() + asserts.assert_that(kSigning).is_equal_to(expected_signature) + +def _testsuite(): + _suite = unittest.TestSuite() + _suite.addTest(unittest.FunctionTestCase(test_aws_v4_sign)) + return _suite + + +_runner = unittest.TextTestRunner() +_runner.run(_testsuite()) diff --git a/larky/src/test/resources/quick_tests/test_base64_AES.star b/examples/test_base64_AES.star similarity index 100% rename from larky/src/test/resources/quick_tests/test_base64_AES.star rename to examples/test_base64_AES.star diff --git a/larky/src/test/resources/quick_tests/test_export_public.star b/examples/test_export_public.star similarity index 100% rename from larky/src/test/resources/quick_tests/test_export_public.star rename to examples/test_export_public.star diff --git a/larky/src/test/resources/quick_tests/test_fd_hmac_sha256_signature.star b/examples/test_fd_hmac_sha256_signature.star similarity index 100% rename from larky/src/test/resources/quick_tests/test_fd_hmac_sha256_signature.star rename to examples/test_fd_hmac_sha256_signature.star diff --git a/larky/src/test/resources/quick_tests/test_opensslx509.star b/examples/test_opensslx509.star similarity index 100% rename from larky/src/test/resources/quick_tests/test_opensslx509.star rename to examples/test_opensslx509.star diff --git a/larky/src/test/java/com/verygood/security/larky/LarkyQuickTests.java b/larky/src/test/java/com/verygood/security/larky/LarkyQuickTests.java index 00f009d95..623df29ad 100644 --- a/larky/src/test/java/com/verygood/security/larky/LarkyQuickTests.java +++ b/larky/src/test/java/com/verygood/security/larky/LarkyQuickTests.java @@ -1,7 +1,5 @@ package com.verygood.security.larky; -import static com.verygood.security.larky.ModuleSupplier.CORE_MODULES; - import com.google.common.base.Strings; import com.google.common.collect.ImmutableSet; @@ -30,11 +28,15 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import static com.verygood.security.larky.ModuleSupplier.CORE_MODULES; + public class LarkyQuickTests { + private static final String PROPERTY_NAME = "larky.quick_test"; private static final Path QUICK_TEST_DIR = Paths.get( - "src","test", "resources", "quick_tests" +// "src", "test", "resources", "quick_tests" + "..", "examples" ); private static final TestingConsole console = new TestingConsole(); @@ -64,7 +66,7 @@ private List enumerateTests() { .filter(f -> { String fileName = f.getFileName().toString(); - if(!Strings.isNullOrEmpty(singleTestDesired)) { + if (!Strings.isNullOrEmpty(singleTestDesired)) { return fileName.equals(singleTestDesired); }