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
2 changes: 2 additions & 0 deletions e2e/scripts/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ ARG COMPOSER_VERSION
FROM docker.io/library/golang:1.26.2-alpine3.23@sha256:f85330846cde1e57ca9ec309382da3b8e6ae3ab943d2739500e08c86393a21b1 AS build
WORKDIR /app

ENV GOEXPERIMENT=jsonv2

COPY go.mod go.sum ./
RUN go mod download && go mod verify

Expand Down
32 changes: 30 additions & 2 deletions e2e/scripts/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package main

import (
"encoding/json/v2"
"fmt"
"os"
"strings"
Expand All @@ -17,7 +18,34 @@ func TestScripts(t *testing.T) {
if srvURL == "" {
t.Fatal("WPSECADV_SERVER_URL environment variable is not set")
}
t.Logf("server URL: %s", srvURL)
t.Logf("server URL: %q", srvURL)

caFile := os.Getenv("TESTSCRIPT_COMPOSER_CAFILE")
t.Logf("ca file: %q", caFile)

type repo struct {
Type string `json:"type"`
URL string `json:"url"`
Options struct {
SSL struct {
CAFile string `json:"cafile,omitzero"`
} `json:"ssl,omitzero"`
} `json:"options,omitzero"`
}

r := repo{
Type: "composer",
URL: srvURL,
}
if caFile != "" {
r.Options.SSL.CAFile = caFile
}

rb, err := json.Marshal(r)
if err != nil {
t.Fatalf("json.Marshal error: %v", err)
}
t.Logf("repo: %s", rb)

testscript.Run(t, testscript.Params{
Dir: "testdata",
Expand All @@ -27,7 +55,7 @@ func TestScripts(t *testing.T) {
"COMPOSER_NO_AUDIT=true",
"COMPOSER_NO_SECURITY_BLOCKING=true",
"COMPOSER_ROOT_VERSION=0.0.1",
"WPSECADV_SERVER_URL="+srvURL,
"REPO="+string(rb),
)

dir := os.Getenv("TESTSCRIPT_COMPOSER_CACHE_DIR")
Expand Down
2 changes: 1 addition & 1 deletion e2e/scripts/testdata/any_vendor_twentyfifteen.txtar
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exec composer config --quiet repositories.wpsecadv composer $WPSECADV_SERVER_URL
exec composer config --quiet repositories.wpsecadv ${REPO}
exec composer update --quiet
! exec composer audit --format=json
stdout CVE-2015-3429
Expand Down
2 changes: 1 addition & 1 deletion e2e/scripts/testdata/any_vendor_woocommerce.txtar
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exec composer config --quiet repositories.wpsecadv composer $WPSECADV_SERVER_URL
exec composer config --quiet repositories.wpsecadv ${REPO}
exec composer update --quiet
! exec composer audit --format=json
stdout CVE-2025-15033
Expand Down
2 changes: 1 addition & 1 deletion e2e/scripts/testdata/bedrock_append.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exec composer create-project --quiet --no-install roots/bedrock bedrock
cd bedrock

exec composer config --quiet secure-http false
exec composer repo --append add wpsecadv composer $WPSECADV_SERVER_URL
exec composer repo --append add wpsecadv $REPO

exec composer require --quiet --no-install wp-plugin/woocommerce:10.0.0

Expand Down
4 changes: 2 additions & 2 deletions e2e/scripts/testdata/bedrock_prepend.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ exec composer create-project --quiet --no-install roots/bedrock bedrock
cd bedrock

exec composer config --quiet secure-http false
[composer:2.9] exec composer repo add wpsecadv composer $WPSECADV_SERVER_URL
[!composer:2.9] exec composer config --quiet repositories.wpsecadv composer $WPSECADV_SERVER_URL
[composer:2.9] exec composer repo add wpsecadv ${REPO}
[!composer:2.9] exec composer config --quiet repositories.wpsecadv ${REPO}

exec composer require --quiet --no-install wp-plugin/woocommerce:10.0.0

Expand Down
2 changes: 1 addition & 1 deletion e2e/scripts/testdata/johnpbloch_wordpress_core.txtar
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exec composer config --quiet repositories.wpsecadv composer $WPSECADV_SERVER_URL
exec composer config --quiet repositories.wpsecadv ${REPO}
exec composer update --quiet
! exec composer audit --format=json
stdout CVE-2017-14990
Expand Down
2 changes: 1 addition & 1 deletion e2e/scripts/testdata/multiple_core.txtar
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exec composer config --quiet repositories.wpsecadv composer $WPSECADV_SERVER_URL
exec composer config --quiet repositories.wpsecadv ${REPO}
exec composer update --quiet
! exec composer audit --format=json
stdout -count=2 '"cve": "CVE-2025-58674"'
Expand Down
2 changes: 1 addition & 1 deletion e2e/scripts/testdata/notexist_cases.txtar
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exec composer config --quiet repositories.wpsecadv composer $WPSECADV_SERVER_URL
exec composer config --quiet repositories.wpsecadv ${REPO}
exec composer update --quiet
exec composer audit --format=json
cmp stdout stdout.golden
Expand Down
2 changes: 1 addition & 1 deletion e2e/scripts/testdata/roots_wordpress_full.txtar
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exec composer config --quiet repositories.wpsecadv composer $WPSECADV_SERVER_URL
exec composer config --quiet repositories.wpsecadv ${REPO}
exec composer update --quiet
! exec composer audit --format=json
stdout CVE-2017-14990
Expand Down
2 changes: 1 addition & 1 deletion e2e/scripts/testdata/roots_wordpress_no_content.txtar
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exec composer config --quiet repositories.wpsecadv composer $WPSECADV_SERVER_URL
exec composer config --quiet repositories.wpsecadv ${REPO}
exec composer update --quiet
! exec composer audit --format=json
stdout CVE-2017-14990
Expand Down
2 changes: 1 addition & 1 deletion e2e/scripts/testdata/wp_core_wordpress.txtar
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exec composer config --quiet repositories.wpsecadv composer $WPSECADV_SERVER_URL
exec composer config --quiet repositories.wpsecadv ${REPO}
exec composer update --quiet
! exec composer audit --format=json
stdout CVE-2017-14990
Expand Down
2 changes: 1 addition & 1 deletion e2e/scripts/testdata/wp_core_wordpress_no_content.txtar
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exec composer config --quiet repositories.wpsecadv composer $WPSECADV_SERVER_URL
exec composer config --quiet repositories.wpsecadv ${REPO}
exec composer update --quiet
! exec composer audit --format=json
stdout CVE-2017-14990
Expand Down
2 changes: 1 addition & 1 deletion e2e/scripts/testdata/wpackagist_plugin_woocommerce.txtar
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exec composer config --quiet repositories.wpsecadv composer $WPSECADV_SERVER_URL
exec composer config --quiet repositories.wpsecadv ${REPO}
exec composer update --quiet
! exec composer audit --format=json
stdout CVE-2025-15033
Expand Down
2 changes: 1 addition & 1 deletion e2e/scripts/testdata/wpackagist_theme_twentyfifteen.txtar
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exec composer config --quiet repositories.wpsecadv composer $WPSECADV_SERVER_URL
exec composer config --quiet repositories.wpsecadv ${REPO}
exec composer update --quiet
! exec composer audit --format=json
stdout CVE-2015-3429
Expand Down
152 changes: 59 additions & 93 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
[tools]
golangci-lint = "2.12" # Must be kept in sync with .github/workflows/lint.yml
"npm:portless" = "latest"
"npm:serve" = "latest"

[env]
GOEXPERIMENT = "jsonv2"
DOCKER = "docker"

[tools]
# Must be kept in sync with .github/workflows/lint.yml
golangci-lint = "2.12"

[tasks.upgrade]
run = [
'mise upgrade --bump --local',
'go get -u -t -tags e2econtainer,e2escripts ./...',
'go mod tidy',
'mise upgrade --bump --local',
'go get -u -t -tags e2econtainer,e2escripts ./...',
'go mod tidy',
]

[tasks.serve]
env.PORT = { value="{{ get_env(name='PORT', default='8080') }}" }
depends = [{ task = "port:check", args = ["{{ get_env(name='PORT', default='8080') }}"] }]
run = 'go run ./cmd/serve'
run = 'portless run -- go run ./cmd/serve'

[tasks.image]
env.PORT = { value="{{ get_env(name='PORT', default='8080') }}" }
depends = [
{ task = "port:check", args = ["{{ get_env(name='PORT', default='8080') }}"] },
{ task = "image:build" },
]
run = '${DOCKER} run --rm -p {{ env.PORT }}:8080 wpsecadv-dev'
depends = [{ task = "image:build" }]
run = '''
#!/usr/bin/env bash
set -e
app_port=($RANDOM + 65535 - 32767)

portless run --app-port "${app_port}" -- "${DOCKER}" run --rm -p "${app_port}:8080" wpsecadv-dev
'''

[tasks."image:build"]
run = '''
Expand Down Expand Up @@ -65,34 +66,43 @@ go test -tags=e2econtainer -count=1 -shuffle=on ./e2e/container/... $@
'''

[tasks."test:e2e:local"]
env.PORT = { value="{{ get_env(name='E2E_PORT', default='8081') }}" }
depends = [{ task = "port:check", args = ["{{ get_env(name='E2E_PORT', default='8081') }}"] }]
depends_post = [{ task = "port:terminate", args = ["{{ get_env(name='E2E_PORT', default='8081') }}"] }]
run = '''
#!/usr/bin/env bash
set -e

export TESTSCRIPT_COMPOSER_CACHE_DIR="$(composer global config cache-dir --absolute --quiet)"
export WPSECADV_SERVER_URL="http://localhost:${PORT}"
export TESTSCRIPT_COMPOSER_CAFILE="$HOME/.portless/ca.pem"

name="wpsecadv-e2e-local"

echo "==> Starting server on '"${WPSECADV_SERVER_URL}"' in the background..."
go run ./cmd/serve > /dev/null 2>&1 &
echo "==> Starting server in the background..."
portless run --name "${name}" -- go run ./cmd/serve > /dev/null 2>&1 &
pid=$!

echo "==> Waiting for server ready..."
curl --silent --out-null -X GET --retry 10 --retry-connrefused --retry-delay 1 "${WPSECADV_SERVER_URL}"
cleanup () {
echo "==> Cleaning up..."
echo "Terminating the server (pid: '"${pid}"')..."
kill -9 "${pid}" || true
}
trap 'cleanup' EXIT

export WPSECADV_SERVER_URL=$(portless get "${name}")

echo "==> Waiting for server '"${WPSECADV_SERVER_URL}/packages.json"' ready..."
curl --silent --out-null -X GET --fail --retry 10 --retry-all-errors --retry-connrefused --retry-delay 1 "${WPSECADV_SERVER_URL}/packages.json"

echo "==> Running e2e tests with system composer. This could take a while..."
go test -tags=e2escripts -count=1 -shuffle=on ./e2e/scripts/... $@
'''

[tasks."test:e2e:prod"]
env.WPSECADV_SERVER_URL = { value="{{ get_env(name='WPSECADV_SERVER_URL', default='https://repo-wpsecadv.typist.tech') }}" }
env.WPSECADV_SERVER_URL = { value = "{{ get_env(name='WPSECADV_SERVER_URL', default='https://repo-wpsecadv.typist.tech') }}" }
run = '''
#!/usr/bin/env bash
set -e

echo "==> Waiting for server '"${WPSECADV_SERVER_URL}"' ready..."
curl --silent --out-null -X GET --retry 10 --retry-connrefused --retry-delay 1 "${WPSECADV_SERVER_URL}"
echo "==> Waiting for server '"${WPSECADV_SERVER_URL}/packages.json"' ready..."
curl --silent --out-null -X GET --fail --retry 10 --retry-all-errors --retry-connrefused --retry-delay 1 "${WPSECADV_SERVER_URL}/packages.json"

echo "==> Running e2e tests with system composer. This could take a while..."
go test -tags=e2escripts -count=1 -shuffle=on ./e2e/scripts/... $@
Expand All @@ -105,7 +115,10 @@ go test -tags=e2escripts -count=1 -shuffle=on ./e2e/scripts/... $@
####################################

[tasks.lint]
run = 'golangci-lint run'
run = [
'go mod tidy -diff',
'golangci-lint run',
]

[tasks.fmt]
run = 'golangci-lint fmt'
Expand All @@ -122,23 +135,31 @@ run = 'go generate ./...'

[tasks."gen:data:fixture"]
env.FEED_FIXTURE = { required = true }
env.PORT = { value="{{ get_env(name='FIXTURE_PORT', default='8082') }}" }
depends = [{ task = "port:check", args = ["{{ get_env(name='FIXTURE_PORT', default='8082') }}"] }]
depends_post = [{ task = "port:terminate", args = ["{{ get_env(name='FIXTURE_PORT', default='8082') }}"] }]
run = '''
#!/usr/bin/env bash
set -e

export WORDFENCE_INTELLIGENCE_API_KEY="dummy"
export FEED_FIXTURE_DIR=$(dirname "${FEED_FIXTURE}")
export FEED_FIXTURE_BASENAME=$(basename "${FEED_FIXTURE}")
export WORDFENCE_FEED_URL="http://localhost:${PORT}/${FEED_FIXTURE_BASENAME}"

echo "==> Starting fixture server for '${FEED_FIXTURE}' on port ${PORT}..."
npx --yes serve "${FEED_FIXTURE_DIR}" -p "${PORT}" > /dev/null 2>&1 &
name="wpsecadv-gen-data-fixture"

echo "==> Starting server in the background..."
portless run --name "${name}" -- serve "${FEED_FIXTURE_DIR}" > /dev/null 2>&1 &
pid=$!

cleanup () {
echo "==> Cleaning up..."
echo "Terminating the server (pid: '"${pid}"')..."
kill -9 "${pid}" || true
}
trap 'cleanup' EXIT

export WORDFENCE_FEED_URL="$(portless get "${name}")/${FEED_FIXTURE_BASENAME}"

echo "==> Waiting for server '"${WORDFENCE_FEED_URL}"' ready..."
curl --silent --out-null -X GET --retry 10 --retry-connrefused --retry-delay 1 "${WORDFENCE_FEED_URL}"
curl --silent --out-null -X GET --fail --retry 10 --retry-all-errors --retry-connrefused --retry-delay 1 "${WORDFENCE_FEED_URL}"

echo "==> Generating data from fixture..."
go generate ./internal/data $@
Expand All @@ -152,68 +173,13 @@ depends = ["clean:*"]

[tasks."clean:data"]
run = [
'rm -rf internal/data/assets',
'rm -rf internal/data/assets_gen.go',
'rm -rf internal/data/assets_gen_test.go',
'rm -rf internal/data/assets',
'rm -rf internal/data/assets_gen.go',
'rm -rf internal/data/assets_gen_test.go',
]

[tasks."clean:packagist"]
run = 'rm -rf internal/packagist/core_gen.go'

[tasks."clean:test"]
run = 'rm -rf _artifacts'

####################################
#
# Utility
#
####################################

[tasks."port:check"]
hide = true
usage = '''
arg "<port>"
'''
run = '''
#!/usr/bin/env bash
set -e

echo "==> Checking whether port '{{ usage.port }}' is being used..."
pid=$(lsof -t -i ":{{ usage.port }}") || true

if [[ ! -z "${pid}" ]]; then
echo "Process '"${pid}"' is using port '{{ usage.port }}'"
echo "To terminate that process, run:"
echo ""
echo " mise run port:terminate {{ usage.port }}"
echo ""
echo "To forcefully kill that process, run:"
echo ""
echo " kill -9 "${pid}""
echo ""
exit 1
fi

echo "No process is using port '{{ usage.port }}'."
'''

[tasks."port:terminate"]
hide = true
usage = '''
arg "<port>"
'''
run = '''
#!/usr/bin/env bash
set -e

echo "==> Checking whether port '{{ usage.port }}' is being used..."
pid=$(lsof -t -i ":{{ usage.port }}") || true

if [[ -z "${pid}" ]]; then
echo "No process is using port '{{ usage.port }}'."
exit 0
fi

echo "==> Terminating the server (pid: '"${pid}"') using port '{{ usage.port }}'..."
kill -15 "${pid}"
'''
Loading