diff options
author | 2024-02-27 10:07:29 -0500 | |
---|---|---|
committer | 2024-02-27 16:07:29 +0100 | |
commit | 9bf448be7aa5e2468d5a6302d7c37ebad0f84176 (patch) | |
tree | c03e0079e84d8fd412cc23abc9ebb1b1118559e8 /internal/api/auth/callback_test.go | |
parent | [chore/docs] Various little docs updates (#2691) (diff) | |
download | gotosocial-9bf448be7aa5e2468d5a6302d7c37ebad0f84176.tar.xz |
[feature/oidc] Add support for very basic RBAC (#2642)
* Add support for very basic RBAC
* Add some small tests for allowedGroup and adminGroup
* Switch to table-driven tests
Diffstat (limited to 'internal/api/auth/callback_test.go')
-rw-r--r-- | internal/api/auth/callback_test.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/internal/api/auth/callback_test.go b/internal/api/auth/callback_test.go new file mode 100644 index 000000000..2624f3f3f --- /dev/null +++ b/internal/api/auth/callback_test.go @@ -0,0 +1,45 @@ +package auth + +import ( + "testing" + + "github.com/superseriousbusiness/gotosocial/testrig" +) + +func TestAdminGroup(t *testing.T) { + testrig.InitTestConfig() + for _, test := range []struct { + name string + groups []string + expected bool + }{ + {name: "not in admin group", groups: []string{"group1", "group2", "allowedRole"}, expected: false}, + {name: "in admin group", groups: []string{"group1", "group2", "adminRole"}, expected: true}, + } { + test := test // loopvar capture + t.Run(test.name, func(t *testing.T) { + if got := adminGroup(test.groups); got != test.expected { + t.Fatalf("got: %t, wanted: %t", got, test.expected) + } + }) + } +} + +func TestAllowedGroup(t *testing.T) { + testrig.InitTestConfig() + for _, test := range []struct { + name string + groups []string + expected bool + }{ + {name: "not in allowed group", groups: []string{"group1", "group2", "adminRole"}, expected: false}, + {name: "in allowed group", groups: []string{"group1", "group2", "allowedRole"}, expected: true}, + } { + test := test // loopvar capture + t.Run(test.name, func(t *testing.T) { + if got := allowedGroup(test.groups); got != test.expected { + t.Fatalf("got: %t, wanted: %t", got, test.expected) + } + }) + } +} |