From 3a20c44ea46bc930d549abaeda9985b404e445a8 Mon Sep 17 00:00:00 2001 From: Wout Slakhorst Date: Mon, 16 Sep 2024 16:37:11 +0200 Subject: [PATCH] fix ordering of DID document context (#3375) * fix ordering of DID document context * add e2e-test to check all generated DID documents have the correct 0-th context --------- Co-authored-by: Gerard Snaauw --- .../ops/create-subject/docker-compose.yml | 11 ++++++ e2e-tests/ops/create-subject/run-test.sh | 39 +++++++++++++++++++ e2e-tests/ops/run-tests.sh | 7 ++++ storage/orm/did_document.go | 3 +- vdr/didnuts/manager.go | 2 +- 5 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 e2e-tests/ops/create-subject/docker-compose.yml create mode 100755 e2e-tests/ops/create-subject/run-test.sh diff --git a/e2e-tests/ops/create-subject/docker-compose.yml b/e2e-tests/ops/create-subject/docker-compose.yml new file mode 100644 index 0000000000..28d1a2ee4f --- /dev/null +++ b/e2e-tests/ops/create-subject/docker-compose.yml @@ -0,0 +1,11 @@ +services: + nodeA: + image: "${IMAGE_NODE_A:-nutsfoundation/nuts-node:master}" + ports: + - "18081:8081" + environment: + NUTS_CONFIGFILE: /opt/nuts/nuts.yaml + volumes: + - "./nuts.yaml:/opt/nuts/nuts.yaml:ro" + healthcheck: + interval: 1s # Make test run quicker by checking health status more often \ No newline at end of file diff --git a/e2e-tests/ops/create-subject/run-test.sh b/e2e-tests/ops/create-subject/run-test.sh new file mode 100755 index 0000000000..a2ee38a098 --- /dev/null +++ b/e2e-tests/ops/create-subject/run-test.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +source ../../util.sh + +echo "------------------------------------" +echo "Cleaning up running Docker containers and volumes, and key material..." +echo "------------------------------------" +docker compose down +docker compose rm -f -v + +echo "------------------------------------" +echo "Starting Docker containers..." +echo "------------------------------------" +docker compose up -d --remove-orphans +docker compose up --wait nodeA + +echo "------------------------------------" +echo "Registering vendors..." +echo "------------------------------------" + +# Create Subject +DID_DOCS=$(curl -s -X POST http://localhost:18081/internal/vdr/v2/subject) +# Get @context at index 0 from all DID Documents +FIRST_CONTEXT=$(echo ${DID_DOCS} | jq -r '.documents[]["@context"][0]') +COUNTER=0 +for row in ${FIRST_CONTEXT}; do + if [ "$row" != "https://www.w3.org/ns/did/v1" ]; then + FAILING_DID=$(echo ${DID_DOCS} | jq -r ".documents[${COUNTER}].id") + echo "First Context in DID Document '${FAILING_DID}' ($row) is not equal to https://www.w3.org/ns/did/v1" + echo ${DID_DOCS} | jq -r .documents[${COUNTER}] + docker compose stop + exit 1 + fi + COUNTER=$((COUNTER + 1)) +done + +echo "------------------------------------" +echo "Stopping Docker containers..." +echo "------------------------------------" +docker compose stop diff --git a/e2e-tests/ops/run-tests.sh b/e2e-tests/ops/run-tests.sh index 32400b532b..8aff604cc5 100755 --- a/e2e-tests/ops/run-tests.sh +++ b/e2e-tests/ops/run-tests.sh @@ -8,3 +8,10 @@ echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" #pushd key-rotation #./run-test.sh #popd + +echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" +echo "!! Running test: Create Subject !!" +echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" +pushd create-subject +./run-test.sh +popd \ No newline at end of file diff --git a/storage/orm/did_document.go b/storage/orm/did_document.go index b5da3fc19a..a0c3137150 100644 --- a/storage/orm/did_document.go +++ b/storage/orm/did_document.go @@ -75,7 +75,8 @@ func (sqlDoc DidDocument) GenerateDIDDocument() (did.Document, error) { document := did.Document{ AlsoKnownAs: others, Context: []interface{}{ - jsonld.JWS2020ContextV1URI(), did.DIDContextV1URI(), + did.DIDContextV1URI(), + jsonld.JWS2020ContextV1URI(), }, ID: *id, } diff --git a/vdr/didnuts/manager.go b/vdr/didnuts/manager.go index f5cae0639b..a2341a4d91 100644 --- a/vdr/didnuts/manager.go +++ b/vdr/didnuts/manager.go @@ -75,7 +75,7 @@ const MethodName = "nuts" // CreateDocument creates an empty DID document with baseline properties set. func CreateDocument() did.Document { return did.Document{ - Context: []interface{}{jsonld.JWS2020ContextV1URI(), did.DIDContextV1URI()}, + Context: []interface{}{did.DIDContextV1URI(), jsonld.JWS2020ContextV1URI()}, } }