v0.3.2 a514042

wire_test.go RawHistoryFolder

1package visualproc
2
3import (
4	"bytes"
5	"encoding/binary"
6	"reflect"
7	"testing"
8	"time"
9
10	"github.com/bnema/neferafk/internal/ports"
11)
12
13func TestCommandRoundTrip(t *testing.T) {
14	var b bytes.Buffer
15	lock := ports.VisualLock{Generation: 4, Auth: ports.AuthBootstrap{Generation: 4, PINSource: ports.PINSourceEnv, PINReference: "r", EnvPIN: []byte("123456")}}
16	for _, c := range []ports.VisualCommand{ports.VisualFade{Black: true, Duration: 2 * time.Second}, ports.VisualFade{}, lock} {
17		if err := WriteCommand(&b, c); err != nil {
18			t.Fatal(err)
19		}
20	}
21	if c, err := ReadCommand(&b); err != nil || !reflect.DeepEqual(c, ports.VisualFade{Black: true, Duration: 2 * time.Second}) {
22		t.Fatalf("%#v %v", c, err)
23	}
24	if c, err := ReadCommand(&b); err != nil || !reflect.DeepEqual(c, ports.VisualFade{}) {
25		t.Fatalf("%#v %v", c, err)
26	}
27	c, err := ReadCommand(&b)
28	got, ok := c.(ports.VisualLock)
29	if err != nil || !ok || got.Generation != 4 || got.Auth.Generation != 4 || got.Auth.PINSource != ports.PINSourceEnv || got.Auth.PINReference != "r" || string(got.Auth.EnvPIN) != "123456" {
30		t.Fatalf("%#v %v", c, err)
31	}
32}
33
34func TestCommandRejectsMismatchedGenerationAndGarbage(t *testing.T) {
35	var b bytes.Buffer
36	if err := WriteCommand(&b, ports.VisualLock{Generation: 1, Auth: ports.AuthBootstrap{Generation: 2}}); err == nil {
37		t.Fatal("mismatched generations encoded")
38	}
39	if err := WriteCommand(&b, ports.VisualLock{}); err == nil {
40		t.Fatal("zero generation encoded")
41	}
42	for _, in := range []string{"", "NAV1", "XXXX\x01\x00\x00\x00\x00", "NAV1\x09\x00\x00\x00\x00", "NAV1\x01\xff\xff\xff\xff", "NAV1\x01\x00\x00\x00\x02ab"} {
43		if _, err := ReadCommand(bytes.NewReader([]byte(in))); err == nil {
44			t.Fatalf("%q accepted", in)
45		}
46		if _, err := ReadEvent(bytes.NewReader([]byte(in))); err == nil {
47			t.Fatalf("%q accepted as event", in)
48		}
49	}
50}
51
52func TestEventRoundTripAndNoUnlockRequestExists(t *testing.T) {
53	var b bytes.Buffer
54	for _, e := range []ports.VisualEvent{ports.LockConfirmed{Generation: 2}, ports.LockReleased{Generation: 2}} {
55		if err := WriteEvent(&b, e); err != nil {
56			t.Fatal(err)
57		}
58	}
59	if e, err := ReadEvent(&b); err != nil || e != (ports.LockConfirmed{Generation: 2}) {
60		t.Fatalf("%#v %v", e, err)
61	}
62	if e, err := ReadEvent(&b); err != nil || e != (ports.LockReleased{Generation: 2}) {
63		t.Fatalf("%#v %v", e, err)
64	}
65	if err := WriteEvent(&b, ports.VisualExited{}); err == nil {
66		t.Fatal("process exit must not be a wire event")
67	}
68	// A daemon->visual frame kind is not accepted in the event direction, and
69	// there is no command kind other than fade and lock.
70	var c bytes.Buffer
71	WriteCommand(&c, ports.VisualFade{})
72	if _, err := ReadEvent(&c); err == nil {
73		t.Fatal("command parsed as event")
74	}
75	if _, err := ReadCommand(bytes.NewReader([]byte("NAV1\x04\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x01"))); err == nil {
76		t.Fatal("event parsed as command")
77	}
78}
79
80func TestReadCommandBoundsPINSource(t *testing.T) {
81	// Hand-build a lock frame whose PINSource is 17 bytes: the writer refuses
82	// it, so craft the payload directly.
83	p := binary.BigEndian.AppendUint64(nil, 1)
84	for _, f := range [][]byte{bytes.Repeat([]byte("x"), 17), nil, nil} {
85		p = binary.BigEndian.AppendUint32(p, uint32(len(f)))
86		p = append(p, f...)
87	}
88	var b bytes.Buffer
89	if err := writeFrame(&b, kindLock, p); err != nil {
90		t.Fatal(err)
91	}
92	if _, err := ReadCommand(&b); err == nil {
93		t.Fatal("oversize PINSource accepted")
94	}
95}

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 2

Tags 9

↑↓ moveenter openesc close