@@ -0,0 +1,138 @@
8+ "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
9+ . "github.com/onsi/ginkgo"
10+ . "github.com/onsi/ginkgo/extensions/table"
11+ . "github.com/onsi/gomega"
14+var _ = Describe("Common", func() {
15+ var validSecretSourceValue []byte
16+ const validSecretSourceEnv = "OAUTH2_PROXY_TEST_SECRET_SOURCE_ENV"
17+ var validSecretSourceFile string
20+ validSecretSourceValue = []byte(base64.StdEncoding.EncodeToString([]byte("This is a secret source value")))
21+ Expect(os.Setenv(validSecretSourceEnv, "This is a secret source env")).To(Succeed())
22+ tmp, err := ioutil.TempFile("", "oauth2-proxy-secret-source-test")
23+ Expect(err).ToNot(HaveOccurred())
26+ _, err = tmp.Write([]byte("This is a secret source file"))
27+ Expect(err).ToNot(HaveOccurred())
29+ validSecretSourceFile = tmp.Name()
33+ Expect(os.Unsetenv(validSecretSourceEnv)).To(Succeed())
34+ Expect(os.Remove(validSecretSourceFile)).To(Succeed())
37+ type validateSecretSourceTableInput struct {
38+ source func() options.SecretSource
42+ DescribeTable("validateSecretSource should",
43+ func(in validateSecretSourceTableInput) {
44+ Expect(validateSecretSource(in.source())).To(Equal(in.expectedMsg))
46+ Entry("with no entries", validateSecretSourceTableInput{
47+ source: func() options.SecretSource {
48+ return options.SecretSource{}
50+ expectedMsg: multipleValuesForSecretSource,
52+ Entry("with a Value and FromEnv", validateSecretSourceTableInput{
53+ source: func() options.SecretSource {
54+ return options.SecretSource{
55+ Value: validSecretSourceValue,
56+ FromEnv: validSecretSourceEnv,
59+ expectedMsg: multipleValuesForSecretSource,
61+ Entry("with a Value and FromFile", validateSecretSourceTableInput{
62+ source: func() options.SecretSource {
63+ return options.SecretSource{
64+ Value: validSecretSourceValue,
65+ FromFile: validSecretSourceFile,
68+ expectedMsg: multipleValuesForSecretSource,
70+ Entry("with FromEnv and FromFile", validateSecretSourceTableInput{
71+ source: func() options.SecretSource {
72+ return options.SecretSource{
73+ FromEnv: validSecretSourceEnv,
74+ FromFile: validSecretSourceFile,
77+ expectedMsg: multipleValuesForSecretSource,
79+ Entry("with a Value, FromEnv and FromFile", validateSecretSourceTableInput{
80+ source: func() options.SecretSource {
81+ return options.SecretSource{
82+ Value: validSecretSourceValue,
83+ FromEnv: validSecretSourceEnv,
84+ FromFile: validSecretSourceFile,
87+ expectedMsg: multipleValuesForSecretSource,
89+ Entry("with a valid Value", validateSecretSourceTableInput{
90+ source: func() options.SecretSource {
91+ return options.SecretSource{
92+ Value: validSecretSourceValue,
97+ Entry("with a valid FromEnv", validateSecretSourceTableInput{
98+ source: func() options.SecretSource {
99+ return options.SecretSource{
100+ FromEnv: validSecretSourceEnv,
105+ Entry("with a valid FromFile", validateSecretSourceTableInput{
106+ source: func() options.SecretSource {
107+ return options.SecretSource{
108+ FromFile: validSecretSourceFile,
113+ Entry("with an invalid Value", validateSecretSourceTableInput{
114+ source: func() options.SecretSource {
115+ return options.SecretSource{
116+ Value: []byte("Invalid Base64 Value"),
119+ expectedMsg: "error decoding secret value: illegal base64 data at input byte 7",
121+ Entry("with an invalid FromEnv", validateSecretSourceTableInput{
122+ source: func() options.SecretSource {
123+ return options.SecretSource{
124+ FromEnv: "INVALID_ENV",
127+ expectedMsg: "error loading secret from environent: no value for for key \"INVALID_ENV\"",
129+ Entry("with an invalid FromFile", validateSecretSourceTableInput{
130+ source: func() options.SecretSource {
131+ return options.SecretSource{
132+ FromFile: "invalidFile",
135+ expectedMsg: "error loadig secret from file: stat invalidFile: no such file or directory",