Skip to content

Commit 61b34c1

Browse files
committed
.github/workflows: improve test.yml
1 parent 242a202 commit 61b34c1

7 files changed

Lines changed: 69 additions & 28 deletions

File tree

.github/workflows/test.yml

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,58 @@
11
name: Go tests
2-
on: [push, pull_request]
2+
on:
3+
push:
4+
pull_request:
5+
schedule: # daily at 09:42 UTC
6+
- cron: '42 9 * * *'
7+
workflow_dispatch:
38
permissions:
49
contents: read
510
jobs:
611
test:
712
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
go:
17+
- { go-version: stable }
18+
- { go-version: oldstable }
19+
- { go-version-file: go.mod }
20+
deps:
21+
- locked
22+
- latest
823
steps:
9-
- name: Install hurl
24+
- name: Install hurl 4.1.0
1025
run: |
1126
curl --location --remote-name https://github.com/Orange-OpenSource/hurl/releases/download/4.1.0/hurl_4.1.0_amd64.deb
1227
sudo apt-get update && sudo apt-get install ./hurl_4.1.0_amd64.deb
13-
- name: Checkout repository
14-
uses: actions/checkout@v2
28+
- uses: actions/checkout@v5
1529
with:
16-
fetch-depth: 0
17-
- name: Install Go (from go.mod)
18-
uses: actions/setup-go@v4
30+
persist-credentials: false
31+
- uses: actions/setup-go@v6
1932
with:
20-
go-version-file: go.mod
21-
check-latest: true
22-
- name: Run tests
23-
run: go test ./...
24-
- name: Run tests (short + race)
25-
run: go test -short -race ./...
33+
go-version: ${{ matrix.go.go-version }}
34+
go-version-file: ${{ matrix.go.go-version-file }}
35+
- run: go get -u
36+
if: matrix.deps == 'latest'
37+
- run: go test ./...
38+
- run: go test -short -race ./...
39+
staticcheck:
40+
runs-on: ubuntu-latest
41+
steps:
42+
- uses: actions/checkout@v5
43+
with:
44+
persist-credentials: false
45+
- uses: actions/setup-go@v6
46+
with:
47+
go-version: stable
48+
- run: go run honnef.co/go/tools/cmd/staticcheck@latest ./...
49+
govulncheck:
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/checkout@v5
53+
with:
54+
persist-credentials: false
55+
- uses: actions/setup-go@v6
56+
with:
57+
go-version: stable
58+
- run: go run golang.org/x/vuln/cmd/govulncheck@latest ./...

bastion/bastion.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ func (kh keyHash) String() string {
5959
return hex.EncodeToString(kh[:])
6060
}
6161

62+
type backendContextKey struct{}
63+
6264
// New returns a new Bastion.
6365
//
6466
// The Config must not be modified after the call to New.
@@ -74,7 +76,7 @@ func New(c *Config) (*Bastion, error) {
7476
b.proxy = &httputil.ReverseProxy{
7577
Rewrite: func(pr *httputil.ProxyRequest) {
7678
pr.Out.URL.Scheme = "https" // needed for the required :scheme header
77-
pr.Out.Host = pr.In.Context().Value("backend").(string)
79+
pr.Out.Host = pr.In.Context().Value(backendContextKey{}).(string)
7880
pr.SetXForwarded()
7981
// We don't interpret the query, so pass it on unmodified.
8082
pr.Out.URL.RawQuery = pr.In.URL.RawQuery
@@ -158,7 +160,7 @@ func (b *Bastion) ServeHTTP(w http.ResponseWriter, r *http.Request) {
158160
http.Error(w, "request must start with /KEY_HASH/", http.StatusNotFound)
159161
return
160162
}
161-
ctx := context.WithValue(r.Context(), "backend", kh)
163+
ctx := context.WithValue(r.Context(), backendContextKey{}, kh)
162164
r = r.Clone(ctx)
163165
r.URL.Path = "/" + path
164166
b.proxy.ServeHTTP(w, r)

cmd/litewitness/litewitness.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,14 @@ func indexHandler(w *witness.Witness) http.HandlerFunc {
233233
fmt.Fprintf(rw, "# litewitness %s\n\n", html.EscapeString(*nameFlag))
234234
fmt.Fprintf(rw, "%s\n\n", html.EscapeString(w.VerifierKey()))
235235
fmt.Fprintf(rw, "## Logs\n\n")
236-
sqlitex.Exec(db, "SELECT origin, tree_size, tree_hash FROM log",
237-
func(stmt *sqlite.Stmt) error {
236+
sqlitex.Execute(db, "SELECT origin, tree_size, tree_hash FROM log", &sqlitex.ExecOptions{
237+
ResultFunc: func(stmt *sqlite.Stmt) error {
238238
fmt.Fprintf(rw, "- %s\n (size %d, root %s)\n\n",
239239
html.EscapeString(stmt.ColumnText(0)),
240240
stmt.ColumnInt64(1), stmt.ColumnText(2))
241241
return nil
242242
},
243-
)
243+
})
244244
}
245245
}
246246

cmd/witnessctl/witnessctl.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func openDB(dbPath string) *sqlite.Conn {
8080

8181
func addLog(db *sqlite.Conn, origin string) {
8282
treeHash := merkle.HashEmptyTree()
83-
if err := sqlitex.Exec(db, "INSERT INTO log (origin, tree_size, tree_hash) VALUES (?, 0, ?)",
83+
if err := sqlitexExec(db, "INSERT INTO log (origin, tree_size, tree_hash) VALUES (?, 0, ?)",
8484
nil, origin, base64.StdEncoding.EncodeToString(treeHash[:])); err != nil {
8585
log.Fatalf("Error adding log: %v", err)
8686
}
@@ -95,15 +95,15 @@ func addKey(db *sqlite.Conn, origin string, vk string) {
9595
if v.Name() != origin {
9696
log.Printf("Warning: verifier key name %q does not match origin %q.", v.Name(), origin)
9797
}
98-
err = sqlitex.Exec(db, "INSERT INTO key (origin, key) VALUES (?, ?)", nil, origin, vk)
98+
err = sqlitexExec(db, "INSERT INTO key (origin, key) VALUES (?, ?)", nil, origin, vk)
9999
if err != nil {
100100
log.Fatalf("Error adding key: %v", err)
101101
}
102102
log.Printf("Added key %q.", vk)
103103
}
104104

105105
func delKey(db *sqlite.Conn, origin string, vk string) {
106-
err := sqlitex.Exec(db, "DELETE FROM key WHERE origin = ? AND key = ?", nil, origin, vk)
106+
err := sqlitexExec(db, "DELETE FROM key WHERE origin = ? AND key = ?", nil, origin, vk)
107107
if err != nil {
108108
log.Fatalf("Error deleting key: %v", err)
109109
}
@@ -132,7 +132,7 @@ func addSigsumLog(db *sqlite.Conn, keyFlag string) {
132132
}
133133

134134
func listLogs(db *sqlite.Conn) {
135-
if err := sqlitex.Exec(db, `
135+
if err := sqlitexExec(db, `
136136
SELECT json_object(
137137
'origin', log.origin,
138138
'size', log.tree_size,
@@ -152,3 +152,7 @@ func listLogs(db *sqlite.Conn) {
152152
log.Fatalf("Error listing logs: %v", err)
153153
}
154154
}
155+
156+
func sqlitexExec(conn *sqlite.Conn, query string, resultFn func(stmt *sqlite.Stmt) error, args ...any) error {
157+
return sqlitex.Execute(conn, query, &sqlitex.ExecOptions{ResultFunc: resultFn, Args: args})
158+
}

internal/witness/witness.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ func (w *Witness) getKeys(origin string) (note.Verifiers, error) {
303303
func (w *Witness) dbExec(query string, resultFn func(stmt *sqlite.Stmt) error, args ...interface{}) error {
304304
w.dmMu.Lock()
305305
defer w.dmMu.Unlock()
306-
err := sqlitex.Exec(w.db, query, resultFn, args...)
306+
err := sqlitexExec(w.db, query, resultFn, args...)
307307
if err != nil {
308308
w.log.Error("database error", "error", err)
309309
}
@@ -313,10 +313,14 @@ func (w *Witness) dbExec(query string, resultFn func(stmt *sqlite.Stmt) error, a
313313
func (w *Witness) dbExecWithChanges(query string, resultFn func(stmt *sqlite.Stmt) error, args ...interface{}) (int, error) {
314314
w.dmMu.Lock()
315315
defer w.dmMu.Unlock()
316-
err := sqlitex.Exec(w.db, query, resultFn, args...)
316+
err := sqlitexExec(w.db, query, resultFn, args...)
317317
if err != nil {
318318
w.log.Error("database error", "error", err)
319319
return 0, err
320320
}
321321
return w.db.Changes(), nil
322322
}
323+
324+
func sqlitexExec(conn *sqlite.Conn, query string, resultFn func(stmt *sqlite.Stmt) error, args ...any) error {
325+
return sqlitex.Execute(conn, query, &sqlitex.ExecOptions{ResultFunc: resultFn, Args: args})
326+
}

internal/witness/witness_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"golang.org/x/mod/sumdb/note"
1414
"golang.org/x/mod/sumdb/tlog"
1515
"sigsum.org/sigsum-go/pkg/merkle"
16-
"zombiezen.com/go/sqlite/sqlitex"
1716
)
1817

1918
func TestRace(t *testing.T) {
@@ -28,11 +27,11 @@ func TestRace(t *testing.T) {
2827
origin := "sigsum.org/v1/tree/4d6d8825a6bb689d459628312889dfbb0bcd41b5211d9e1ce768b0ff0309e562"
2928

3029
treeHash := merkle.HashEmptyTree()
31-
fatalIfErr(t, sqlitex.Exec(w.db, "INSERT INTO log (origin, tree_size, tree_hash) VALUES (?, 0, ?)",
30+
fatalIfErr(t, sqlitexExec(w.db, "INSERT INTO log (origin, tree_size, tree_hash) VALUES (?, 0, ?)",
3231
nil, origin, base64.StdEncoding.EncodeToString(treeHash[:])))
3332
k, err := note.NewEd25519VerifierKey(origin, pk[:])
3433
fatalIfErr(t, err)
35-
fatalIfErr(t, sqlitex.Exec(w.db, "INSERT INTO key (origin, key) VALUES (?, ?)", nil, origin, k))
34+
fatalIfErr(t, sqlitexExec(w.db, "INSERT INTO key (origin, key) VALUES (?, ?)", nil, origin, k))
3635

3736
_, err = w.processAddCheckpointRequest([]byte(`old 0
3837

note.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ type verifier struct {
5050
name string
5151
hash uint32
5252
verify func(msg, sig []byte) bool
53-
key ed25519.PublicKey
5453
}
5554

5655
func (v *verifier) Name() string { return v.name }

0 commit comments

Comments
 (0)