-
Notifications
You must be signed in to change notification settings - Fork 11
/
logout_test.go
102 lines (91 loc) · 2.77 KB
/
logout_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
package test
import (
"fmt"
"os"
"github.com/confluentinc/cli/v4/pkg/auth"
"github.com/confluentinc/cli/v4/pkg/config"
"github.com/confluentinc/cli/v4/pkg/utils"
)
func (s *CLITestSuite) TestLogout_RemoveUsernamePassword() {
type saveTest struct {
isCloud bool
loginURL string
bin string
}
cloudUrl := s.TestBackend.GetCloudUrl()
mdsUrl := s.TestBackend.GetMdsUrl()
tests := []saveTest{
{
true,
cloudUrl,
testBin,
},
{
false,
mdsUrl,
testBin,
},
}
for _, test := range tests {
var env []string
if test.isCloud {
env = []string{fmt.Sprintf("%[email protected]", auth.ConfluentCloudEmail), fmt.Sprintf("%s=pass1", auth.ConfluentCloudPassword)}
} else {
env = []string{fmt.Sprintf("%[email protected]", auth.ConfluentPlatformUsername), fmt.Sprintf("%s=pass1", auth.ConfluentPlatformPassword)}
}
// run login to provide context, then logout command and check output
output := runCommand(s.T(), test.bin, env, "login -vvvv --save --url "+test.loginURL, 0, "")
if test.isCloud {
s.Contains(output, loggedInAsWithOrgOutput)
} else {
s.Contains(output, loggedInAsOutput)
}
got, err := os.ReadFile(config.GetDefaultFilename())
s.NoError(err)
s.Require().Contains(utils.NormalizeNewLines(string(got)), "saved_credentials")
output = runCommand(s.T(), test.bin, env, "logout -vvvv", 0, "")
s.Contains(output, "You are now logged out.")
got, err = os.ReadFile(config.GetDefaultFilename())
s.NoError(err)
s.Require().NotContains(utils.NormalizeNewLines(string(got)), "saved_credentials")
}
}
func (s *CLITestSuite) TestLogout_RemoveUsernamePasswordFail() {
type saveTest struct {
isCloud bool
loginURL string
bin string
}
cloudUrl := s.TestBackend.GetCloudUrl()
mdsUrl := s.TestBackend.GetMdsUrl()
tests := []saveTest{
{
true,
cloudUrl,
testBin,
},
{
false,
mdsUrl,
testBin,
},
}
for _, test := range tests {
var env []string
if test.isCloud {
env = []string{fmt.Sprintf("%[email protected]", auth.ConfluentCloudEmail), fmt.Sprintf("%s=pass1", auth.ConfluentCloudPassword)}
} else {
env = []string{fmt.Sprintf("%[email protected]", auth.ConfluentPlatformUsername), fmt.Sprintf("%s=pass1", auth.ConfluentPlatformPassword)}
}
got, err := os.ReadFile(config.GetDefaultFilename())
s.NoError(err)
s.Require().NotContains(utils.NormalizeNewLines(string(got)), "saved_credentials")
// run login to provide context, then logout command and check output
runCommand(s.T(), test.bin, env, "login --url "+test.loginURL, 0, "")
output := runCommand(s.T(), test.bin, env, "logout", 0, "")
s.Contains(output, "You are now logged out.")
got, err = os.ReadFile(config.GetDefaultFilename())
s.NoError(err)
s.Require().NotContains(utils.NormalizeNewLines(string(got)), "saved_credentials")
}
}