From 14f590a6a765d9fbe53e2f7bacb5d9f6d7cb9063 Mon Sep 17 00:00:00 2001 From: Greg Steuck Date: Wed, 28 Jul 2021 10:44:02 -0700 Subject: dashboard/app: chop off auth so it can be reused in syz-hub --- dashboard/app/api_test.go | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 dashboard/app/api_test.go (limited to 'dashboard/app/api_test.go') 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) + } +} -- cgit mrf-deployment