aboutsummaryrefslogtreecommitdiffstats
path: root/dashboard/app/api_test.go
diff options
context:
space:
mode:
authorGreg Steuck <gnezdo@google.com>2021-07-28 10:44:02 -0700
committerDmitry Vyukov <dvyukov@google.com>2021-07-30 18:21:17 +0200
commit14f590a6a765d9fbe53e2f7bacb5d9f6d7cb9063 (patch)
tree49616fd39deeb248bb0ba440e2080144d5e4c15f /dashboard/app/api_test.go
parentc585c7b0ea16dc4326bf5e8f2f00cc6638e2feb1 (diff)
dashboard/app: chop off auth so it can be reused in syz-hub
Diffstat (limited to 'dashboard/app/api_test.go')
-rw-r--r--dashboard/app/api_test.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/dashboard/app/api_test.go b/dashboard/app/api_test.go
new file mode 100644
index 000000000..8d63ce7a7
--- /dev/null
+++ b/dashboard/app/api_test.go
@@ -0,0 +1,65 @@
+// Copyright 2017 syzkaller project authors. All rights reserved.
+// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+
+package main
+
+import (
+ "testing"
+)
+
+func TestClientSecretOK(t *testing.T) {
+ got, err := checkClient(&GlobalConfig{
+ Clients: map[string]string{
+ "user": "secr1t",
+ },
+ }, "user", "secr1t", "")
+ if err != nil || got != "" {
+ t.Errorf("Unexpected error %v %v", got, err)
+ }
+}
+
+func TestClientOauthOK(t *testing.T) {
+ got, err := checkClient(&GlobalConfig{
+ Clients: map[string]string{
+ "user": "OauthSubject:public",
+ },
+ }, "user", "", "OauthSubject:public")
+ if err != nil || got != "" {
+ t.Errorf("Unexpected error %v %v", got, err)
+ }
+}
+
+func TestClientSecretFail(t *testing.T) {
+ got, err := checkClient(&GlobalConfig{
+ Clients: map[string]string{
+ "user": "secr1t",
+ },
+ }, "user", "wrong", "")
+ if err != ErrAccess || got != "" {
+ t.Errorf("Unexpected error %v %v", got, err)
+ }
+}
+
+func TestClientSecretMissing(t *testing.T) {
+ got, err := checkClient(&GlobalConfig{
+ Clients: map[string]string{},
+ }, "user", "ignored", "")
+ if err != ErrAccess || got != "" {
+ t.Errorf("Unexpected error %v %v", got, err)
+ }
+}
+
+func TestClientNamespaceOK(t *testing.T) {
+ got, err := checkClient(&GlobalConfig{
+ Namespaces: map[string]*Config{
+ "ns1": {
+ Clients: map[string]string{
+ "user": "secr1t",
+ },
+ },
+ },
+ }, "user", "secr1t", "")
+ if err != nil || got != "ns1" {
+ t.Errorf("Unexpected error %v %v", got, err)
+ }
+}