All checks were successful
check / check (push) Successful in 2m58s
static/js/alpine.min.js was a committed minified bundle, which REPO_POLICIES forbids, referenced by no content hash at all. A minified blob is unreviewable, which is the shape a supply-chain compromise takes. script/fetch-assets now downloads Alpine 3.14.9 from the npm registry and verifies sha256 on both the tarball and the extracted file, and static/vendor_test.go re-hashes the bytes go:embed actually placed in the binary. The shipped bytes are byte-identical to the blob that was committed, so the served asset does not change. Independently reviewed. Five negative controls reproduced by the reviewer: flipped expected hash, repointed URL, post-fetch tampering, asset absent, and manifest inconsistencies — each fails closed with static/js/ left clean. Registry hashes confirmed against the pins, and the runtime image was built, run and curled to confirm the asset is still served and the login page still loads it. Known gap, filed separately: static/static.go embeds the js directory rather than named files, so a missing fetched asset is not a compile error on ungated local build paths. Every gated path fails loudly, so the release artifact is unaffected.
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package server_test
|
|
|
|
import (
|
|
"net/http"
|
|
"regexp"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"sneak.berlin/go/webhooker/templates"
|
|
)
|
|
|
|
// TestBaseTemplateScriptsAreServed walks every /s/ script the base
|
|
// template loads on each page and fetches it through the real router.
|
|
// Alpine.js is fetched at build time rather than committed, so nothing
|
|
// in the repo guarantees it is present: this is the check that the page
|
|
// still gets the JavaScript it asks for.
|
|
func TestBaseTemplateScriptsAreServed(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// scriptSrc matches the src of every <script> tag pointing at the
|
|
// /s/ static mount.
|
|
scriptSrc := regexp.MustCompile(`<script[^>]+src="(/s/[^"]+)"`)
|
|
|
|
base, err := templates.Templates.ReadFile("base.html")
|
|
require.NoError(t, err)
|
|
|
|
matches := scriptSrc.FindAllStringSubmatch(string(base), -1)
|
|
require.NotEmpty(t, matches, "base.html should load scripts from /s/")
|
|
|
|
env := newTestEnv(t)
|
|
|
|
for _, m := range matches {
|
|
src := m[1]
|
|
t.Run(src, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
w := env.get(src, nil)
|
|
|
|
require.Equalf(
|
|
t, http.StatusOK, w.Code,
|
|
"base.html loads %s but the server does not serve it", src,
|
|
)
|
|
assert.NotEmptyf(
|
|
t, w.Body.Bytes(), "%s is served but empty", src,
|
|
)
|
|
})
|
|
}
|
|
}
|