forked from micro/micro
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmultitenancy_test.go
executable file
·108 lines (94 loc) · 2.62 KB
/
multitenancy_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//go:build integration
// +build integration
package test
import (
"errors"
"fmt"
"strings"
"testing"
"time"
)
// Test for making sure config and store values across namespaces
// are correctly isolated
func TestNamespaceConfigIsolation(t *testing.T) {
TrySuite(t, testNamespaceConfigIsolation, retryCount)
}
func testNamespaceConfigIsolation(t *T) {
t.Parallel()
serv := NewServer(t, WithLogin())
defer serv.Close()
if err := serv.Run(); err != nil {
return
}
testNamespaceConfigIsolationSuite(serv, t)
}
func testNamespaceConfigIsolationSuite(serv Server, t *T) {
cmd := serv.Command()
if err := Try("Calling micro config set", t, func() ([]byte, error) {
outp, err := cmd.Exec("config", "set", "somekey", "val1")
if err != nil {
return outp, err
}
if string(outp) != "" {
return outp, fmt.Errorf("Expected no output, got: %v", string(outp))
}
return outp, err
}, 5*time.Second); err != nil {
return
}
if err := Try("micro config get somekey", t, func() ([]byte, error) {
outp, err := cmd.Exec("config", "get", "somekey")
if err != nil {
return outp, err
}
if string(outp) != "val1\n" {
return outp, errors.New("Expected 'val1\n'")
}
return outp, err
}, 8*time.Second); err != nil {
return
}
outp, err := cmd.Exec("auth", "create", "account", "--secret", "micro", "--scopes", "admin", "--namespace", "random", "admin")
if err != nil {
t.Fatal(string(outp), err)
return
}
currNamespace, _ := cmd.Exec("user", "namespace")
if err := ChangeNamespace(cmd, serv.Env(), "random"); err != nil {
t.Fatalf("Error changing namespace %s", err)
}
if err := Login(serv, t, "admin", "micro"); err != nil {
return
}
if err := Try("reading 'somekey' should not be found with this account", t, func() ([]byte, error) {
outp, err := cmd.Exec("config", "get", "somekey")
if err == nil {
return outp, errors.New("getting somekey should fail")
}
if !strings.Contains(string(outp), "Not found") {
return outp, errors.New("Expected 'Not found\n'")
}
return outp, nil
}, 8*time.Second); err != nil {
return
}
// Log back to original namespace and see if value is already there
if err := ChangeNamespace(cmd, serv.Env(), string(currNamespace)); err != nil {
t.Fatalf("Error changing namespace %s", err)
}
if err := Login(serv, t, "admin", "micro"); err != nil {
return
}
if err := Try("micro config get somekey", t, func() ([]byte, error) {
outp, err := cmd.Exec("config", "get", "somekey")
if err != nil {
return outp, err
}
if string(outp) != "val1\n" {
return outp, errors.New("Expected 'val1\n'")
}
return outp, err
}, 8*time.Second); err != nil {
return
}
}