6133774bb9e83f21aeab02ba50e8e40cdd6d09f8
- Author
- Ayman Bagabas <ayman.bagabas@gmail.com>
- Committer
- Ayman Bagabas <ayman.bagabas@gmail.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/config/auth_test.go b/config/auth_test.go
2new file mode 100644
3index 0000000000000000000000000000000000000000..7e59b59b3be5d0618cf53ffb480ef7bda75a4a0e
4--- /dev/null
5+++ b/config/auth_test.go
6@@ -0,0 +1,610 @@
7+package config
8+
9+import (
10+ "testing"
11+
12+ "github.com/charmbracelet/wish/git"
13+ "github.com/gliderlabs/ssh"
14+ "github.com/matryer/is"
15+)
16+
17+func TestAuth(t *testing.T) {
18+ adminKey := "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINMwLvyV3ouVrTysUYGoJdl5Vgn5BACKov+n9PlzfPwH a@b"
19+ adminPk, _, _, _, _ := ssh.ParseAuthorizedKey([]byte(adminKey))
20+ dummyKey := "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFxIobhwtfdwN7m1TFt9wx3PsfvcAkISGPxmbmbauST8 a@b"
21+ dummyPk, _, _, _, _ := ssh.ParseAuthorizedKey([]byte(dummyKey))
22+ cases := []struct {
23+ name string
24+ cfg Config
25+ repo string
26+ key ssh.PublicKey
27+ access git.AccessLevel
28+ }{
29+ // Repo access
30+ {
31+ name: "anon access: no-access, anonymous user",
32+ access: git.NoAccess,
33+ repo: "foo",
34+ cfg: Config{
35+ AnonAccess: "no-access",
36+ Repos: []RepoConfig{
37+ {
38+ Repo: "foo",
39+ },
40+ },
41+ },
42+ },
43+ {
44+ name: "anon access: no-access, authd user",
45+ key: dummyPk,
46+ repo: "foo",
47+ access: git.ReadOnlyAccess,
48+ cfg: Config{
49+ AnonAccess: "no-access",
50+ Repos: []RepoConfig{
51+ {
52+ Repo: "foo",
53+ },
54+ },
55+ Users: []User{
56+ {
57+ PublicKeys: []string{
58+ dummyKey,
59+ },
60+ },
61+ },
62+ },
63+ },
64+ {
65+ name: "anon access: no-access, admin user",
66+ repo: "foo",
67+ key: adminPk,
68+ access: git.AdminAccess,
69+ cfg: Config{
70+ AnonAccess: "no-access",
71+ Repos: []RepoConfig{
72+ {
73+ Repo: "foo",
74+ },
75+ },
76+ Users: []User{
77+ {
78+ Admin: true,
79+ PublicKeys: []string{
80+ adminKey,
81+ },
82+ },
83+ },
84+ },
85+ },
86+ {
87+ name: "anon access: read-only, anonymous user",
88+ repo: "foo",
89+ access: git.ReadOnlyAccess,
90+ cfg: Config{
91+ AnonAccess: "read-only",
92+ Repos: []RepoConfig{
93+ {
94+ Repo: "foo",
95+ },
96+ },
97+ },
98+ },
99+ {
100+ name: "anon access: read-only, authd user",
101+ repo: "foo",
102+ key: dummyPk,
103+ access: git.ReadOnlyAccess,
104+ cfg: Config{
105+ AnonAccess: "read-only",