6 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
7 . "github.com/onsi/ginkgo"
8 . "github.com/onsi/ginkgo/extensions/table"
9 . "github.com/onsi/gomega"
12var _ = Describe("Headers", func() {
13 type validateHeaderTableInput struct {
14 headers []options.Header
18 validHeader1 := options.Header{
20 Values: []options.HeaderValue{
22 ClaimSource: &options.ClaimSource{
29 validHeader2 := options.Header{
30 Name: "X-Forwarded-Auth",
31 Values: []options.HeaderValue{
33 SecretSource: &options.SecretSource{
34 Value: []byte(base64.StdEncoding.EncodeToString([]byte("secret"))),
40 validHeader3 := options.Header{
41 Name: "Authorization",
42 Values: []options.HeaderValue{
44 ClaimSource: &options.ClaimSource{
46 BasicAuthPassword: &options.SecretSource{
47 Value: []byte(base64.StdEncoding.EncodeToString([]byte("secret"))),
54 DescribeTable("validateHeaders",
55 func(in validateHeaderTableInput) {
56 Expect(validateHeaders(in.headers)).To(ConsistOf(in.expectedMsgs))
58 Entry("with no headers", validateHeaderTableInput{
59 headers: []options.Header{},
60 expectedMsgs: []string{},
62 Entry("with valid headers", validateHeaderTableInput{
63 headers: []options.Header{
68 expectedMsgs: []string{},
70 Entry("with multiple headers with the same name", validateHeaderTableInput{
71 headers: []options.Header{
77 expectedMsgs: []string{
78 "multiple headers found with name \"X-Email\": header names must be unique",
79 "multiple headers found with name \"X-Forwarded-Auth\": header names must be unique",
82 Entry("with an unamed header", validateHeaderTableInput{
83 headers: []options.Header{
87 expectedMsgs: []string{
88 "header has empty name: names are required for all headers",
91 Entry("with a header which has a claim and secret source", validateHeaderTableInput{
92 headers: []options.Header{
94 Name: "With-Claim-And-Secret",
95 Values: []options.HeaderValue{
97 ClaimSource: &options.ClaimSource{},
98 SecretSource: &options.SecretSource{},
104 expectedMsgs: []string{
105 "invalid header \"With-Claim-And-Secret\": invalid values: header value has multiple entries: only one entry per value is allowed",
108 Entry("with a header which has a claim without a claim", validateHeaderTableInput{
109 headers: []options.Header{
111 Name: "Without-Claim",
112 Values: []options.HeaderValue{
114 ClaimSource: &options.ClaimSource{
122 expectedMsgs: []string{
123 "invalid header \"Without-Claim\": invalid values: claim should not be empty",
126 Entry("with a header with invalid secret source", validateHeaderTableInput{
127 headers: []options.Header{
129 Name: "With-Invalid-Secret",
130 Values: []options.HeaderValue{
132 SecretSource: &options.SecretSource{},
138 expectedMsgs: []string{
139 "invalid header \"With-Invalid-Secret\": invalid values: multiple values specified for secret source: specify either value, fromEnv of fromFile",
142 Entry("with a header with invalid basicAuthPassword source", validateHeaderTableInput{
143 headers: []options.Header{
145 Name: "With-Invalid-Basic-Auth",
146 Values: []options.HeaderValue{
148 ClaimSource: &options.ClaimSource{
150 BasicAuthPassword: &options.SecretSource{
151 FromEnv: "UNKNOWN_ENV",
159 expectedMsgs: []string{
160 "invalid header \"With-Invalid-Basic-Auth\": invalid values: invalid basicAuthPassword: error loading secret from environent: no value for for key \"UNKNOWN_ENV\"",
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