Skip to content

Commit d816e96

Browse files
ajewellamzlavaleri
andauthored
feat: run TestVectors tests in CI (#206)
* feat: run TestVectors tests in CI --------- Co-authored-by: Valerie Lambert <[email protected]>
1 parent cb4bc2b commit d816e96

File tree

7 files changed

+337
-41
lines changed

7 files changed

+337
-41
lines changed

.github/workflows/ci_test_java.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
strategy:
3131
matrix:
3232
library: [
33-
DynamoDbEncryption,
33+
DynamoDbEncryption
3434
]
3535
java-version: [ 8, 11, 16, 17 ]
3636
os: [
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# This workflow performs test vectors in Java.
2+
name: Library Java Test Vectors
3+
4+
on:
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
10+
jobs:
11+
testJava:
12+
strategy:
13+
matrix:
14+
java-version: [ 8, 11, 16, 17 ]
15+
os: [
16+
# Run on ubuntu image that comes pre-configured with docker
17+
ubuntu-latest
18+
]
19+
runs-on: ${{ matrix.os }}
20+
environment: "MPL CI"
21+
permissions:
22+
id-token: write
23+
contents: read
24+
steps:
25+
- name: Setup DynamoDB Local
26+
uses: rrainn/[email protected]
27+
with:
28+
port: 8000
29+
cors: '*'
30+
31+
- name: Configure AWS Credentials
32+
uses: aws-actions/configure-aws-credentials@v1
33+
with:
34+
aws-region: us-west-2
35+
role-to-assume: arn:aws:iam::370957321024:role/GitHub-CI-DDBEC-Dafny-Role-us-west-2
36+
role-session-name: DDBEC-Dafny-Java-Tests
37+
38+
- uses: actions/checkout@v3
39+
40+
- name: Init Submodules
41+
env:
42+
# This secret is in the configured environment,
43+
# and set to expire every 30 days
44+
MPL_PAT: ${{ secrets.MPL_PAT }}
45+
run: |
46+
AUTH="$(echo -n "pat:${MPL_PAT}" | base64 | tr -d '\n')"
47+
git config --global http.https://github.com/.extraheader "AUTHORIZATION: basic $AUTH"
48+
git config --global --add url.https://github.com/.insteadOf [email protected]:
49+
git submodule update --init --recursive submodules/MaterialProviders
50+
51+
- name: Setup Dafny
52+
uses: dafny-lang/[email protected]
53+
with:
54+
dafny-version: '4.1.0'
55+
56+
- name: Setup Java ${{ matrix.java-version }}
57+
uses: actions/setup-java@v3
58+
with:
59+
distribution: 'corretto'
60+
java-version: ${{ matrix.java-version }}
61+
62+
- name: Build TestVectors implementation
63+
shell: bash
64+
working-directory: ./TestVectors
65+
run: |
66+
# This works because `node` is installed by default on GHA runners
67+
CORES=$(node -e 'console.log(os.cpus().length)')
68+
make build_java CORES=$CORES
69+
70+
- name: Test TestVectors
71+
working-directory: ./TestVectors
72+
run: |
73+
make test_java

TestVectors/dafny/DDBEncryption/src/JsonItem.dfy

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,14 @@ module {:options "-functionSyntax:4"} DdbItemJson {
285285
:- Need(data.Array?, "Value for 'NS' must be a Array");
286286
var result : seq<string> := [];
287287
for i := 0 to |data.arr| {
288-
:- Need(data.arr[i].String?, "Values for 'NS' must be Strings");
289-
result := result + [data.arr[i].str];
288+
if data.arr[i].String? {
289+
result := result + [data.arr[i].str];
290+
} else if data.arr[i].Number? {
291+
var val :- DecimalToStr(data.arr[i].num);
292+
result := result + [val];
293+
} else {
294+
return Failure("Values for 'NS' must be Strings or Numbers");
295+
}
290296
}
291297
return Success(DDB.AttributeValue.NS(result));
292298
case "B" =>

TestVectors/dafny/DDBEncryption/src/TestVectors.dfy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,6 @@ module {:options "-functionSyntax:4"} DdbEncryptionTestVectors {
373373
{
374374
print "RunIoTests\n";
375375
for i := 0 to |ioTests| {
376-
print "RunIoTest ", i, "\n";
377376
BasicIoTestBatchWriteItem(ioTests[i].writeConfig, ioTests[i].readConfig, ioTests[i].records);
378377
BasicIoTestPutItem(ioTests[i].writeConfig, ioTests[i].readConfig, ioTests[i].records);
379378
BasicIoTestTransactWriteItems(ioTests[i].writeConfig, ioTests[i].readConfig, ioTests[i].records);

TestVectors/runtimes/java/build.gradle.kts

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import java.net.URI
22
import javax.annotation.Nullable
3+
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
4+
import org.gradle.api.tasks.testing.logging.TestLogEvent
35

46
tasks.wrapper {
57
gradleVersion = "7.6"
@@ -26,38 +28,26 @@ java {
2628
}
2729
}
2830

29-
var caUrl: URI? = null
30-
@Nullable
31-
val caUrlStr: String? = System.getenv("CODEARTIFACT_URL_JAVA_CONVERSION")
32-
if (!caUrlStr.isNullOrBlank()) {
33-
caUrl = URI.create(caUrlStr)
34-
}
35-
36-
var caPassword: String? = null
37-
@Nullable
38-
val caPasswordString: String? = System.getenv("CODEARTIFACT_AUTH_TOKEN")
39-
if (!caPasswordString.isNullOrBlank()) {
40-
caPassword = caPasswordString
31+
tasks.withType<JavaCompile>() {
32+
options.encoding = "UTF-8"
4133
}
4234

4335
repositories {
36+
maven {
37+
name = "DynamoDB Local Release Repository - US West (Oregon) Region"
38+
url = URI.create("https://s3-us-west-2.amazonaws.com/dynamodb-local/release")
39+
}
4440
mavenCentral()
4541
mavenLocal()
46-
if (caUrl != null && caPassword != null) {
47-
maven {
48-
name = "CodeArtifact"
49-
url = caUrl!!
50-
credentials {
51-
username = "aws"
52-
password = caPassword!!
53-
}
54-
}
55-
}
5642
}
5743

44+
// Configuration to hold SQLLite information.
45+
// DynamoDB-Local needs to have access to native sqllite4java.
46+
val dynamodb by configurations.creating
47+
5848
dependencies {
5949
implementation("org.dafny:DafnyRuntime:4.0.0")
60-
implementation("software.amazon.dafny:conversion:1.0-SNAPSHOT")
50+
implementation("software.amazon.smithy.dafny:conversion:0.1")
6151
implementation("software.amazon.cryptography:StandardLibrary:1.0-SNAPSHOT")
6252
implementation("software.amazon.cryptography:AwsCryptographyPrimitives:1.0-SNAPSHOT")
6353
implementation("software.amazon.cryptography:AwsCryptographicMaterialProviders:1.0-SNAPSHOT")
@@ -71,7 +61,16 @@ dependencies {
7161
implementation("software.amazon.awssdk:dynamodb-enhanced")
7262
implementation("software.amazon.awssdk:core:2.19.1")
7363
implementation("software.amazon.awssdk:kms")
74-
64+
testImplementation("com.amazonaws:DynamoDBLocal:1.+")
65+
// This is where we gather the SQLLite files to copy over
66+
dynamodb("com.amazonaws:DynamoDBLocal:1.+")
67+
// As of 1.21.0 DynamoDBLocal does not support Apple Silicon
68+
// This checks the dependencies and adds a native library
69+
// to support this architecture.
70+
if (org.apache.tools.ant.taskdefs.condition.Os.isArch("aarch64")) {
71+
testImplementation("io.github.ganadist.sqlite4java:libsqlite4java-osx-aarch64:1.0.392")
72+
dynamodb("io.github.ganadist.sqlite4java:libsqlite4java-osx-aarch64:1.0.392")
73+
}
7574
}
7675

7776
publishing {
@@ -83,17 +82,25 @@ publishing {
8382
repositories { mavenLocal() }
8483
}
8584

86-
tasks.withType<JavaCompile>() {
87-
options.encoding = "UTF-8"
85+
86+
tasks.register<Copy>("copyKeysJSON") {
87+
from(layout.projectDirectory.file("../../../submodules/MaterialProviders/TestVectorsAwsCryptographicMaterialProviders/dafny/TestVectorsAwsCryptographicMaterialProviders/test/keys.json"))
88+
into(layout.projectDirectory.dir("dafny/DDBEncryption/test"))
89+
}
90+
91+
tasks.register<Copy>("CopyDynamoDb") {
92+
from (dynamodb) {
93+
include("*.dll")
94+
include("*.dylib")
95+
include("*.so")
96+
}
97+
into("build/libs")
8898
}
8999

90100
tasks.register<JavaExec>("runTests") {
101+
dependsOn("CopyDynamoDb")
91102
dependsOn("copyKeysJSON")
103+
systemProperty("java.library.path", "build/libs")
92104
mainClass.set("TestsFromDafny")
93105
classpath = sourceSets["test"].runtimeClasspath
94106
}
95-
96-
tasks.register<Copy>("copyKeysJSON") {
97-
from(layout.projectDirectory.file("../../../submodules/MaterialProviders/TestVectorsAwsCryptographicMaterialProviders/dafny/TestVectorsAwsCryptographicMaterialProviders/test/keys.json"))
98-
into(layout.projectDirectory.dir("dafny/DDBEncryption/test"))
99-
}

0 commit comments

Comments
 (0)