Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/actions/sandbox/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ inputs:
- html
- headless
- empty
- chaos
edition:
description: Edition
required: true
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ jobs:
edition: ${{ matrix.edition.name }}
port: 8000

- name: Sandbox (chaos)
uses: ./.github/actions/sandbox
with:
configuration: chaos
edition: ${{ matrix.edition.name }}
port: 8000

# Public instance
- run: docker build . --file public/Dockerfile --progress plain
if: matrix.edition.name == 'enterprise'
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ test:
.PHONY: test-e2e
HURL_TESTS += test/e2e/$(SANDBOX_CONFIGURATION)/*.hurl
ifneq ($(SANDBOX_CONFIGURATION),empty)
ifneq ($(SANDBOX_CONFIGURATION),chaos)
HURL_TESTS += test/e2e/populated/schemas/*.hurl
HURL_TESTS += test/e2e/populated/api/common/*.hurl
ifeq ($(ENTERPRISE),ON)
HURL_TESTS += test/e2e/populated/api/enterprise/*.hurl
endif
endif
endif
test-e2e:
$(HURL) --test \
--variable base=$(SANDBOX_URL) \
Expand All @@ -93,6 +95,7 @@ sandbox-index: compile
$(PREFIX)/bin/sourcemeta-one-index \
$(SANDBOX)/one-$(SANDBOX_CONFIGURATION)-$(EDITION).json \
$(OUTPUT)/sandbox --url $(SANDBOX_URL) --profile
./test/sandbox/postindex.sh $(SANDBOX_CONFIGURATION) $(EDITION) $(OUTPUT)/sandbox

.PHONY: sandbox
sandbox: sandbox-index
Expand Down
51 changes: 51 additions & 0 deletions test/e2e/chaos/corruptions.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# The server MUST NOT crash on corrupted indexed data

# Corrupted routes.bin node indices
GET {{base}}/self/v1/api/list
[Options]
retry: 3
retry-interval: 1000
HTTP *

GET {{base}}/
[Options]
retry: 3
retry-interval: 1000
HTTP *

GET {{base}}/self/v1/api/schemas/metadata/test/schemas/string
[Options]
retry: 3
retry-interval: 1000
HTTP *

GET {{base}}/does-not-exist/at/all
[Options]
retry: 3
retry-interval: 1000
HTTP *

# Corrupted directory.metapack metadata with wrong types
GET {{base}}/self/v1/api/list
[Options]
retry: 3
retry-interval: 1000
HTTP *

# Deleted search.metapack
GET {{base}}/self/v1/api/schemas/search?q=test
[Options]
retry: 3
retry-interval: 1000
HTTP *

# Corrupted locations.metapack with empty object
POST {{base}}/self/v1/api/schemas/trace/test/schemas/string
Content-Type: application/json
[Options]
retry: 3
retry-interval: 1000
```
"hello"
```
HTTP *
14 changes: 12 additions & 2 deletions test/sandbox/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ COPY one-headless-community.json .
COPY one-headless-enterprise.json .
COPY one-empty-community.json .
COPY one-empty-enterprise.json .
COPY one-chaos-community.json .
COPY one-chaos-enterprise.json .

# As the `sourcemeta` command wipes the working directory
COPY postindex.sh /usr/local/bin/sourcemeta-one-postindex

COPY schemas schemas
COPY rules rules
Expand All @@ -16,8 +21,13 @@ RUN sourcemeta \
one-${SOURCEMETA_ONE_SANDBOX_CONFIGURATION}-${SOURCEMETA_ONE_SANDBOX_EDITION}.json \
--profile

RUN sourcemeta-one-postindex \
"${SOURCEMETA_ONE_SANDBOX_CONFIGURATION}" \
"${SOURCEMETA_ONE_SANDBOX_EDITION}" \
"${SOURCEMETA_ONE_OUTPUT}"

# Check that by the end of the indexing, the workdir directory is empty
RUN test -d "$SOURCEMETA_ONE_WORKDIR" -a \
"$(find "$SOURCEMETA_ONE_WORKDIR" -mindepth 1 -maxdepth 1 | wc -l)" -eq 0
RUN set -e && test -d "$SOURCEMETA_ONE_WORKDIR" && \
test -z "$(ls -A "$SOURCEMETA_ONE_WORKDIR")"

RUN rm -rf "$SOURCEMETA_ONE_WORKDIR"
3 changes: 3 additions & 0 deletions test/sandbox/one-chaos-community.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": [ "./one-html-community.json" ]
}
3 changes: 3 additions & 0 deletions test/sandbox/one-chaos-enterprise.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": [ "./one-html-enterprise.json" ]
}
50 changes: 50 additions & 0 deletions test/sandbox/postindex.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/sh

set -o errexit
set -o nounset

if [ "$#" -ne 3 ]
then
echo "Usage: $0 <configuration> <edition> <output>" 1>&2
exit 1
fi

CONFIGURATION="$1"
EDITION="$2"
OUTPUT="$3"

echo "Running prepare hook..." 1>&2
echo " CONFIGURATION: $CONFIGURATION" 1>&2
echo " EDITION: $EDITION" 1>&2
echo " OUTPUT: $OUTPUT" 1>&2

if [ "$CONFIGURATION" != "chaos" ]
then
exit 0
fi

# To test how the server deals with corrupted data
echo "Applying chaos corruptions..." 1>&2

echo " Corrupting root node first_literal_child to an out-of-bounds index..." 1>&2
test -f "$OUTPUT/routes.bin"
printf '\x00\x00\x10\x00' | \
dd of="$OUTPUT/routes.bin" bs=1 seek=24 conv=notrunc 2>/dev/null

echo " Corrupting second node string_offset to point past the file end..." 1>&2
printf '\x00\x00\x00\x7f' | \
dd of="$OUTPUT/routes.bin" bs=1 seek=40 conv=notrunc 2>/dev/null

echo " Replacing directory.metapack metadata with wrong types..." 1>&2
test -f "$OUTPUT/explorer/%/directory.metapack"
printf '{"version":1,"checksum":99999,"lastModified":0,"mime":false,"bytes":1,"duration":1,"encoding":"identity"}' \
> "$OUTPUT/explorer/%/directory.metapack"

echo " Deleting search.metapack to trigger missing file assert..." 1>&2
test -f "$OUTPUT/explorer/%/search.metapack"
rm -f "$OUTPUT/explorer/%/search.metapack"

echo " Replacing locations.metapack with empty object for test/schemas/string..." 1>&2
test -f "$OUTPUT/schemas/test/schemas/string/%/locations.metapack"
printf '{"version":1,"checksum":"x","lastModified":"Thu, 01 Jan 2025 00:00:00 GMT","mime":"application/json","bytes":2,"duration":1,"encoding":"identity"}{}' \
> "$OUTPUT/schemas/test/schemas/string/%/locations.metapack"