-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathuaa_transport_test.go
65 lines (56 loc) · 1.61 KB
/
uaa_transport_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
package uaa
import (
"net/http"
"testing"
. "github.com/onsi/gomega"
"github.com/sclevine/spec"
)
type fakeTransport struct {
roundtripper func(req *http.Request)
}
func (f *fakeTransport) RoundTrip(req *http.Request) (*http.Response, error) {
if f.roundtripper != nil {
f.roundtripper(req)
}
return nil, nil
}
func testUaaTransport(t *testing.T, when spec.G, it spec.S) {
var (
request *http.Request
transport *uaaTransport
)
it.Before(func() {
RegisterTestingT(t)
transport = &uaaTransport{
base: &fakeTransport{roundtripper: func(req *http.Request) {
request = req
}},
LoggingEnabled: false,
}
})
it("can identify a nil baseTransport", func() {
a := API{}
Expect(a.baseTransportIsNil()).To(BeTrue())
a.baseTransport = nil
Expect(a.baseTransportIsNil()).To(BeTrue())
})
it("can identify a non-nil baseTransport", func() {
a := API{baseTransport: &fakeTransport{}}
Expect(a.baseTransportIsNil()).To(BeFalse())
})
it("adds X-CF-ENCODED-CREDENTIALS header when using basic auth", func() {
req, _ := http.NewRequest("", "", nil)
req.Header.Add("Authorization", "Basic ENCODEDCREDENTIALS")
_, err := transport.RoundTrip(req)
Expect(err).NotTo(HaveOccurred())
Expect(request).NotTo(BeNil())
Expect(request.Header.Get("X-CF-ENCODED-CREDENTIALS")).To(Equal("true"))
})
it("does not add X-CF-ENCODED-CREDENTIALS header when not using basic auth", func() {
req, _ := http.NewRequest("", "", nil)
_, err := transport.RoundTrip(req)
Expect(err).NotTo(HaveOccurred())
Expect(request).NotTo(BeNil())
Expect(request.Header.Get("X-CF-ENCODED-CREDENTIALS")).To(BeEmpty())
})
}