@@ -0,0 +1,164 @@
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"
12+var _ = Describe("Headers", func() {
13+ type validateHeaderTableInput struct {
14+ headers []options.Header
15+ expectedMsgs []string
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+ Value: []byte("secret"),
159+ expectedMsgs: []string{
160+ "invalid header \"With-Invalid-Basic-Auth\": invalid values: invalid basicAuthPassword: error decoding secret value: illegal base64 data at input byte 4",