v0.25.0 2e6c485

download_handler_test.go RawHistoryFolder

1package webkit
2
3import (
4	"testing"
5
6	"github.com/stretchr/testify/assert"
7)
8
9func TestSanitizeFilename(t *testing.T) {
10	tests := []struct {
11		name     string
12		input    string
13		expected string
14	}{
15		{
16			name:     "normal filename",
17			input:    "document.pdf",
18			expected: "document.pdf",
19		},
20		{
21			name:     "filename with spaces",
22			input:    "my document.pdf",
23			expected: "my document.pdf",
24		},
25		{
26			name:     "path traversal with parent dirs",
27			input:    "../../../etc/passwd",
28			expected: "passwd",
29		},
30		{
31			name:     "path traversal hidden file",
32			input:    "../.ssh/id_rsa",
33			expected: "id_rsa",
34		},
35		{
36			name:     "nested path",
37			input:    "foo/bar/baz.txt",
38			expected: "baz.txt",
39		},
40		{
41			name:     "absolute path",
42			input:    "/etc/passwd",
43			expected: "passwd",
44		},
45		{
46			name:     "dot only",
47			input:    ".",
48			expected: "download",
49		},
50		{
51			name:     "double dot only",
52			input:    "..",
53			expected: "download",
54		},
55		{
56			name:     "empty string",
57			input:    "",
58			expected: "download",
59		},
60		{
61			name:     "hidden file",
62			input:    ".bashrc",
63			expected: ".bashrc",
64		},
65		{
66			name:     "windows style path",
67			input:    "..\\..\\Windows\\System32\\config",
68			expected: "config",
69		},
70	}
71
72	for _, tt := range tests {
73		t.Run(tt.name, func(t *testing.T) {
74			result := sanitizeFilename(tt.input)
75			assert.Equal(t, tt.expected, result)
76		})
77	}
78}
79
80func TestExtractFilename(t *testing.T) {
81	tests := []struct {
82		name     string
83		input    string
84		expected string
85	}{
86		{
87			name:     "file URI with path",
88			input:    "file:///home/user/Downloads/document.pdf",
89			expected: "document.pdf",
90		},
91		{
92			name:     "file URI root",
93			input:    "file:///document.pdf",
94			expected: "document.pdf",
95		},
96		{
97			name:     "plain path",
98			input:    "/home/user/Downloads/image.png",
99			expected: "image.png",
100		},
101		{
102			name:     "filename only",
103			input:    "video.mp4",
104			expected: "video.mp4",
105		},
106		{
107			name:     "empty string",
108			input:    "",
109			expected: "download",
110		},
111		{
112			name:     "file URI with spaces",
113			input:    "file:///home/user/My Documents/file.txt",
114			expected: "file.txt",
115		},
116	}
117
118	for _, tt := range tests {
119		t.Run(tt.name, func(t *testing.T) {
120			result := extractFilename(tt.input)
121			assert.Equal(t, tt.expected, result)
122		})
123	}
124}
125
126func TestNewDownloadHandler(t *testing.T) {
127	t.Run("creates handler with path and nil event handler", func(t *testing.T) {
128		handler := NewDownloadHandler("/tmp/downloads", nil)
129
130		assert.NotNil(t, handler)
131		assert.Equal(t, "/tmp/downloads", handler.downloadPath)
132		assert.Nil(t, handler.eventHandler)
133	})
134
135	t.Run("creates handler with custom path", func(t *testing.T) {
136		handler := NewDownloadHandler("/custom/path", nil)
137
138		assert.Equal(t, "/custom/path", handler.downloadPath)
139	})
140}
141
142func TestDownloadHandler_SetDownloadPath(t *testing.T) {
143	handler := NewDownloadHandler("/initial/path", nil)
144
145	handler.SetDownloadPath("/new/path")
146
147	assert.Equal(t, "/new/path", handler.downloadPath)
148}

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 8

Tags 42

↑↓ moveenter openesc close