@@ -21,6 +21,24 @@ swap_source_url() {
2121 mv " ${TEST_TMPDIR} /tmp" " ${SRC} "
2222}
2323
24+ swap_attestation_url () {
25+ local SRC=$1
26+ local FIELD=$2
27+ local URL=$3
28+
29+ cat " ${SRC} " | jq " .attestations[\" ${FIELD} \" ].url = \" ${URL} \" " > " ${TEST_TMPDIR} /tmp"
30+ mv " ${TEST_TMPDIR} /tmp" " ${SRC} "
31+ }
32+
33+ mock_attestation () {
34+ local NAME=$1
35+
36+ FILE=" $( mktemp -p " ${TEST_TMPDIR} " --directory) /${NAME} "
37+ jq --null-input " {foobar:\" ${NAME} \" }" > " ${FILE} "
38+
39+ echo -n " ${FILE} "
40+ }
41+
2442@test ' no_args_shows_help' {
2543 run " ${NODE_BIN} " " ${CLI_BIN} "
2644
@@ -82,6 +100,31 @@ swap_source_url() {
82100 assert_file_exists " ${ENTRY_PATH} /1.0.0/presubmit.yml"
83101}
84102
103+ @test ' create entry with attestations' {
104+ FIXTURE=" e2e/fixtures/attestations"
105+ cp -R " ${FIXTURE} " " ${TEST_TMPDIR} /"
106+ FIXTURE=" ${TEST_TMPDIR} /$( basename " ${FIXTURE} " ) "
107+ TEMPLATES_DIR=" ${FIXTURE} /.bcr"
108+ RELEASE_ARCHIVE=" e2e/fixtures/attestations-attestations-1.0.0.tar"
109+
110+ SOURCE_ATTESTATION=$( mock_attestation " source.json.intoto.jsonl" )
111+ MODULE_ATTESTATION=$( mock_attestation " MODULE.bazel.intoto.jsonl" )
112+ ARCHIVE_ATTESTATION=$( mock_attestation " attestations-v1.0.0.tar.gz.intoto.jsonl" )
113+
114+ swap_source_url " ${TEMPLATES_DIR} /source.template.json" " file://$( realpath " ${RELEASE_ARCHIVE} " ) "
115+ swap_attestation_url " ${TEMPLATES_DIR} /attestations.template.json" " source.json" " file://$( realpath " ${SOURCE_ATTESTATION} " ) "
116+ swap_attestation_url " ${TEMPLATES_DIR} /attestations.template.json" " MODULE.bazel" " file://$( realpath " ${MODULE_ATTESTATION} " ) "
117+ swap_attestation_url " ${TEMPLATES_DIR} /attestations.template.json" " {REPO}-{TAG}.tar.gz.intoto.jsonl" " file://$( realpath " ${ARCHIVE_ATTESTATION} " ) "
118+
119+ run " ${NODE_BIN} " " ${CLI_BIN} " create-entry --local-registry " ${REGISTRY_PATH} " --templates-dir " ${TEMPLATES_DIR} " --module-version 1.0.0 --github-repository owner/attestations --tag v1.0.0
120+
121+ assert_success
122+
123+ ENTRY_PATH=" ${REGISTRY_PATH} /modules/attestations"
124+
125+ assert_file_exists " ${ENTRY_PATH} /1.0.0/attestations.json"
126+ }
127+
85128@test ' missing OWNER/REPO vars' {
86129 FIXTURE=" e2e/fixtures/versioned"
87130 cp -R " ${FIXTURE} " " ${TEST_TMPDIR} /"
0 commit comments