aboutsummaryrefslogtreecommitdiffstats
path: root/syz-hub/hub_test.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-03-05 14:06:46 +0100
committerDmitry Vyukov <dvyukov@google.com>2018-03-05 14:07:02 +0100
commitaef0b7921ba0a2770c978d2ccd4babb4c5ac998e (patch)
treebe2d6a2d339699eb84ed6fa4fed946ea4b49392a /syz-hub/hub_test.go
parentbbd5104f064535a3da6bb3c21b826d645620db19 (diff)
syz-hub: fix auth logic
Fix a bug and add a test.
Diffstat (limited to 'syz-hub/hub_test.go')
-rw-r--r--syz-hub/hub_test.go103
1 files changed, 103 insertions, 0 deletions
diff --git a/syz-hub/hub_test.go b/syz-hub/hub_test.go
new file mode 100644
index 000000000..ec9350798
--- /dev/null
+++ b/syz-hub/hub_test.go
@@ -0,0 +1,103 @@
+// Copyright 2018 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 (
+ "fmt"
+ "testing"
+)
+
+func TestAuth(t *testing.T) {
+ hub := &Hub{
+ keys: map[string]string{
+ "foo": "1234",
+ "bar": "abcd",
+ },
+ }
+ tests := []struct {
+ client string
+ key string
+ manager string
+ result string
+ ok bool
+ }{
+ {
+ client: "",
+ key: "",
+ manager: "",
+ result: "",
+ ok: false,
+ },
+ {
+ client: "",
+ key: "1234",
+ manager: "manager",
+ result: "",
+ ok: false,
+ },
+ {
+ client: "foo",
+ key: "",
+ manager: "foo",
+ result: "",
+ ok: false,
+ },
+ {
+ client: "foo",
+ key: "123",
+ manager: "foo",
+ result: "",
+ ok: false,
+ },
+ {
+ client: "foo",
+ key: "abcd",
+ manager: "foo",
+ result: "",
+ ok: false,
+ },
+ {
+ client: "foo",
+ key: "1234",
+ manager: "foo",
+ result: "foo",
+ ok: true,
+ },
+ {
+ client: "foo",
+ key: "1234",
+ manager: "foo-suffix",
+ result: "foo-suffix",
+ ok: true,
+ },
+ {
+ client: "foo",
+ key: "1234",
+ manager: "",
+ result: "foo",
+ ok: true,
+ },
+ {
+ client: "foo",
+ key: "1234",
+ manager: "bar",
+ result: "",
+ ok: false,
+ },
+ }
+ for _, test := range tests {
+ t.Run(fmt.Sprintf("%q/%q/%q", test.client, test.key, test.manager), func(t *testing.T) {
+ manager, err := hub.auth(test.client, test.key, test.manager)
+ if !test.ok && err == nil {
+ t.Fatalf("auth is expected to fail, but it did not")
+ }
+ if test.ok && err != nil {
+ t.Fatalf("auth is not expected to fail, but it did: %v", err)
+ }
+ if manager != test.result {
+ t.Fatalf("got bad manager %q, want %q", manager, test.result)
+ }
+ })
+ }
+}