8 middlewareapi "github.com/oauth2-proxy/oauth2-proxy/pkg/apis/middleware"
9 . "github.com/onsi/ginkgo"
10 . "github.com/onsi/gomega"
13var _ = Describe("Scope Suite", func() {
14 Context("NewScope", func() {
15 var request, nextRequest *http.Request
16 var rw http.ResponseWriter
20 request, err = http.NewRequest("", "http://127.0.0.1/", nil)
21 Expect(err).ToNot(HaveOccurred())
23 rw = httptest.NewRecorder()
25 handler := NewScope()(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
29 handler.ServeHTTP(rw, request)
32 It("does not add a scope to the original request", func() {
33 Expect(request.Context().Value(requestScopeKey)).To(BeNil())
36 It("cannot load a scope from the original request using GetRequestScope", func() {
37 Expect(GetRequestScope(request)).To(BeNil())
40 It("adds a scope to the request for the next handler", func() {
41 Expect(nextRequest.Context().Value(requestScopeKey)).ToNot(BeNil())
44 It("can load a scope from the next handler's request using GetRequestScope", func() {
45 Expect(GetRequestScope(nextRequest)).ToNot(BeNil())
49 Context("GetRequestScope", func() {
50 var request *http.Request
54 request, err = http.NewRequest("", "http://127.0.0.1/", nil)
55 Expect(err).ToNot(HaveOccurred())
58 Context("with a scope", func() {
59 var scope *middlewareapi.RequestScope
62 scope = &middlewareapi.RequestScope{}
63 contextWithScope := context.WithValue(request.Context(), requestScopeKey, scope)
64 request = request.WithContext(contextWithScope)
67 It("returns the scope", func() {
68 s := GetRequestScope(request)
69 Expect(s).ToNot(BeNil())
70 Expect(s).To(Equal(scope))
73 Context("if the scope is then modified", func() {
75 Expect(scope.SaveSession).To(BeFalse())
76 scope.SaveSession = true
79 It("returns the updated session", func() {
80 s := GetRequestScope(request)
81 Expect(s).ToNot(BeNil())
82 Expect(s).To(Equal(scope))
83 Expect(s.SaveSession).To(BeTrue())
88 Context("without a scope", func() {
89 It("returns nil", func() {
90 Expect(GetRequestScope(request)).To(BeNil())
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list