6 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
7 . "github.com/onsi/ginkgo/v2"
8 . "github.com/onsi/gomega"
11var _ = Describe("Headers", func() {
12 type validateHeaderTableInput struct {
13 headers []options.Header
17 validHeader1 := options.Header{
19 Values: []options.HeaderValue{
21 ClaimSource: &options.ClaimSource{
28 validHeader2 := options.Header{
29 Name: "X-Forwarded-Auth",
30 Values: []options.HeaderValue{
32 SecretSource: &options.SecretSource{
33 Value: []byte(base64.StdEncoding.EncodeToString([]byte("secret"))),
39 validHeader3 := options.Header{
40 Name: "Authorization",
41 Values: []options.HeaderValue{
43 ClaimSource: &options.ClaimSource{
45 BasicAuthPassword: &options.SecretSource{
46 Value: []byte(base64.StdEncoding.EncodeToString([]byte("secret"))),
53 DescribeTable("validateHeaders",
54 func(in validateHeaderTableInput) {
55 Expect(validateHeaders(in.headers)).To(ConsistOf(in.expectedMsgs))
57 Entry("with no headers", validateHeaderTableInput{
58 headers: []options.Header{},
59 expectedMsgs: []string{},
61 Entry("with valid headers", validateHeaderTableInput{
62 headers: []options.Header{
67 expectedMsgs: []string{},
69 Entry("with multiple headers with the same name", validateHeaderTableInput{
70 headers: []options.Header{
76 expectedMsgs: []string{
77 "multiple headers found with name \"X-Email\": header names must be unique",
78 "multiple headers found with name \"X-Forwarded-Auth\": header names must be unique",
81 Entry("with an unamed header", validateHeaderTableInput{
82 headers: []options.Header{
86 expectedMsgs: []string{
87 "header has empty name: names are required for all headers",
90 Entry("with a header which has a claim and secret source", validateHeaderTableInput{
91 headers: []options.Header{
93 Name: "With-Claim-And-Secret",
94 Values: []options.HeaderValue{
96 ClaimSource: &options.ClaimSource{},
97 SecretSource: &options.SecretSource{},
103 expectedMsgs: []string{
104 "invalid header \"With-Claim-And-Secret\": invalid values: header value has multiple entries: only one entry per value is allowed",
107 Entry("with a header which has a claim without a claim", validateHeaderTableInput{
108 headers: []options.Header{
110 Name: "Without-Claim",
111 Values: []options.HeaderValue{
113 ClaimSource: &options.ClaimSource{
121 expectedMsgs: []string{
122 "invalid header \"Without-Claim\": invalid values: claim should not be empty",
125 Entry("with a header with invalid secret source", validateHeaderTableInput{
126 headers: []options.Header{
128 Name: "With-Invalid-Secret",
129 Values: []options.HeaderValue{
131 SecretSource: &options.SecretSource{},
137 expectedMsgs: []string{
138 "invalid header \"With-Invalid-Secret\": invalid values: multiple values specified for secret source: specify either value, fromEnv of fromFile",
141 Entry("with a header with invalid basicAuthPassword source", validateHeaderTableInput{
142 headers: []options.Header{
144 Name: "With-Invalid-Basic-Auth",
145 Values: []options.HeaderValue{
147 ClaimSource: &options.ClaimSource{
149 BasicAuthPassword: &options.SecretSource{
150 FromEnv: "UNKNOWN_ENV",
158 expectedMsgs: []string{
159 "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