internal/control/status_test.go
26 lines · 933 bytes
1package control
2
3import (
4 "strings"
5 "testing"
6
7 "gitbay.org/gitbay/internal/protocol"
8 "gitbay.org/gitbay/internal/store"
9)
10
11// ci/<job> statuses are the build subsystem's. A writer who could post
12// one could mark ci/test green on their own head before, or instead of,
13// the build (#258).
14func TestStatusSetRefusesReservedContext(t *testing.T) {
15 st, repo, uid := newQueueTestRepo(t)
16 for _, ctx := range []string{"ci/test", "CI/test", "ci/"} {
17 c, errOut := pruneCtx(st, t.TempDir(), store.User{ID: uid, Username: "alice"})
18 code := Dispatch(c, []string{"status", "set", repo.Path(), "abc1234", "--context", ctx, "--state", "success"})
19 if code != protocol.ExitDenied || !strings.Contains(errOut.String(), "reserved") {
20 t.Errorf("--context %s: exit %d, %s", ctx, code, errOut.String())
21 }
22 }
23 if has, err := st.RepoHasStatuses(repo.ID); err != nil || has {
24 t.Fatalf("a refused status was stored: %v %v", has, err)
25 }
26}