-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenqueue_test.go
More file actions
64 lines (55 loc) · 1.94 KB
/
Copy pathenqueue_test.go
File metadata and controls
64 lines (55 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"io"
"strconv"
"strings"
"testing"
)
// The ticket the board mints must be byte-identical to what holodex's
// parseTicketHeader expects — same canonical, same field order. This pins the
// board side; holodex's jobs_test pins the server side.
func TestBuildTicketCanonicalMatchesHolodex(t *testing.T) {
secret := "build-secret"
job, repo, max, exp := "wj-abc", "Velaoc/app", 6, int64(1_800_000_000)
got := signBuildTicket(secret, job, repo, max, exp)
// Recompute the way holodex does.
canonical := strings.Join([]string{
"holodex-ticket-v1", job, repo, strconv.Itoa(max), strconv.FormatInt(exp, 10), "",
}, "\n")
mac := hmac.New(sha256.New, []byte(secret))
_, _ = io.WriteString(mac, canonical)
want := hex.EncodeToString(mac.Sum(nil))
if got != want {
t.Fatalf("ticket signature drift:\n%s\nwant\n%s", got, want)
}
}
func TestEnqueueBuildRequiresWorkerConfig(t *testing.T) {
cfg := testCfg(t)
cfg.Coders = map[string]bool{"coder": true}
// No worker configured.
tc := &ToolCtx{cfg: cfg, authorID: "coder"}
out := tc.enqueueBuild(toolArgs{Repo: "Velaoc/app", Name: "app"})
if !strings.Contains(out, "worker isn't configured") {
t.Fatalf("expected a not-configured message, got: %s", out)
}
}
func TestEnqueueBuildValidatesArgs(t *testing.T) {
cfg := testCfg(t)
cfg.Coders = map[string]bool{"coder": true}
cfg.WorkerURL = "https://worker.example"
cfg.WorkerToken = "wt"
cfg.SandboxSecret = "s"
cfg.GitHubToken = "gh"
tc := &ToolCtx{cfg: cfg, authorID: "coder"}
if out := tc.enqueueBuild(toolArgs{Name: "app"}); !strings.Contains(out, "needs the repo") {
t.Fatalf("missing-repo not caught: %s", out)
}
// A non-coder is refused before any network work.
nc := &ToolCtx{cfg: cfg, authorID: "stranger"}
if out := nc.enqueueBuild(toolArgs{Repo: "Velaoc/app", Name: "app"}); !strings.Contains(out, "REFUSED") {
t.Fatalf("non-coder enqueue not refused: %s", out)
}
}