v0.4.1 122e784

idtoken_test.go RawHistoryFolder

1// SPDX-License-Identifier: MIT
2
3package host
4
5import (
6	"testing"
7
8	ermite "bnema.dev/ermite-api/gen/ermite"
9
10	"bnema.dev/ermite-runner/internal/execstream"
11	"bnema.dev/ermite-runner/internal/execstream/execpb"
12)
13
14const (
15	oidcPublicURL = "https://ermite.bnema.dev/-/oidc/token?api-version=2.0"
16	oidcToken     = "ermiteoidc_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
17)
18
19// The executor gets Job.id_token_url, its origin rewritten to the guest forge
20// like github.server_url (path and query kept), and the token, only when the
21// server sent both.
22func TestIDTokenRequestReachesTheExecutor(t *testing.T) {
23	for _, tc := range []struct {
24		name, url, token, guest string
25		wantURL, wantToken      string
26	}{
27		{"guest forge", oidcPublicURL, oidcToken, "http://ermite.bnema.dev:8088", "http://ermite.bnema.dev:8088/-/oidc/token?api-version=2.0", oidcToken},
28		{"no guest forge", oidcPublicURL, oidcToken, "", oidcPublicURL, oidcToken},
29		{"other origin", "https://other.example/-/oidc/token?api-version=2.0", oidcToken, "http://ermite.bnema.dev:8088", "https://other.example/-/oidc/token?api-version=2.0", oidcToken},
30		{"url only", oidcPublicURL, "", "http://ermite.bnema.dev:8088", "", ""},
31		{"token only", "", oidcToken, "http://ermite.bnema.dev:8088", "", ""},
32		{"none", "", "", "", "", ""},
33	} {
34		t.Run(tc.name, func(t *testing.T) {
35			h := newHarness(t, simpleScript("x"))
36			job := testJob("j1")
37			job.Contexts = publicContexts
38			job.IdTokenUrl, job.IdTokenRequestToken = tc.url, tc.token
39			h.srv.jobs = []*ermite.Job{job}
40			h.runner.Cfg.GuestForgeOrigin = tc.guest
41			var spec *execpb.JobSpec
42			inner := h.driver.script
43			h.driver.script = func(t *testing.T, c *execstream.Conn, run *execpb.Run, cn <-chan *execpb.Cancel) {
44				spec = run.Job
45				inner(t, c, run, cn)
46			}
47			h.run(t)
48			eventually(t, "CompleteJob", func() bool { return h.srv.completeCount() == 1 })
49			if spec == nil {
50				t.Fatal("no Run")
51			}
52			if spec.GetIdTokenUrl() != tc.wantURL || spec.GetIdTokenRequestToken() != tc.wantToken {
53				t.Errorf("got %q %q, want %q %q", spec.GetIdTokenUrl(), spec.GetIdTokenRequestToken(), tc.wantURL, tc.wantToken)
54			}
55		})
56	}
57}
58
59func TestRewriteOrigin(t *testing.T) {
60	for _, tc := range []struct{ in, want string }{
61		{"https://ermite.bnema.dev/-/oidc/token?api-version=2.0", "http://g:8088/-/oidc/token?api-version=2.0"},
62		{"https://ermite.bnema.dev:443?a=b", "http://g:8088?a=b"},
63		{"https://ermite.bnema.dev", "http://g:8088"},
64		{"https://other.example/x", "https://other.example/x"},
65		{"https://u@ermite.bnema.dev/x", "https://u@ermite.bnema.dev/x"},
66	} {
67		if got, _ := rewriteOrigin(tc.in, "https://ermite.bnema.dev", "http://g:8088"); got != tc.want {
68			t.Errorf("rewriteOrigin(%q) = %q, want %q", tc.in, got, tc.want)
69		}
70	}
71}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 4

Tags 11

↑↓ moveenter openesc close