-
Notifications
You must be signed in to change notification settings - Fork 164
/
Copy pathprompts_test.go
98 lines (82 loc) · 2.46 KB
/
prompts_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
package uaa_test
import (
"net/http"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/ghttp"
. "github.com/cloudfoundry/bosh-cli/v7/uaa"
)
var _ = Describe("UAA", func() {
var (
uaa UAA
server *ghttp.Server
)
BeforeEach(func() {
uaa, server = BuildServer()
})
AfterEach(func() {
server.Close()
})
Describe("Prompts", func() {
It("returns list of prompts sorted with passwords showing up last", func() {
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/login"),
ghttp.VerifyBasicAuth("client", "client-secret"),
ghttp.VerifyHeader(http.Header{
"Accept": []string{"application/json"},
}),
ghttp.RespondWith(http.StatusOK, `{
"prompts": {
"key1": ["password", "lbl"],
"key2": ["text", "lbl2"],
"key3": ["password", "lbl"]
}
}`),
),
)
prompts, err := uaa.Prompts()
Expect(err).ToNot(HaveOccurred())
types := []string{prompts[0].Type, prompts[1].Type, prompts[2].Type}
Expect(types).To(Equal([]string{"text", "password", "password"}))
Expect(prompts).To(ConsistOf(
Prompt{Key: "key1", Type: "password", Label: "lbl"},
Prompt{Key: "key2", Type: "text", Label: "lbl2"},
Prompt{Key: "key3", Type: "password", Label: "lbl"},
))
})
It("returns error if prompts response in non-200", func() {
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/login"),
ghttp.RespondWith(http.StatusBadRequest, ``),
),
)
_, err := uaa.Prompts()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("UAA responded with non-successful status code"))
})
It("returns error if prompts cannot be unmarshalled", func() {
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/login"),
ghttp.RespondWith(http.StatusOK, ``),
),
)
_, err := uaa.Prompts()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Unmarshaling UAA response"))
})
})
})
var _ = Describe("Prompt", func() {
Describe("IsPassword", func() {
It("returns true if type is 'password'", func() {
Expect(Prompt{Type: "password"}.IsPassword()).To(BeTrue())
})
It("returns false if type is not 'password'", func() {
Expect(Prompt{}.IsPassword()).To(BeFalse())
Expect(Prompt{Type: "passwordz"}.IsPassword()).To(BeFalse())
})
})
})