1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2024-12-12 11:15:02 +02:00
oauth2-proxy/pkg/validation/providers_test.go
yanasega 42475c28f7
Multiple providers in alpha config (#947)
* Initial commit of multiple provider logic:
1. Created new provider options.
2. Created legacy provider options and conversion options.
3. Added Providers to alpha Options.
4. Started Validation migration of multiple providers
5. Tests.

* fixed lint issues

* additional lint fixes

* Nits and alterations based on CR: manliy splitting large providers validation function and adding comments to provider options

* fixed typo

* removed weird : file

* small CR changes

* Removed GoogleGroups validation due to new allowed-groups (including tests). Added line in CHANGELOG

* Update pkg/apis/options/providers.go

Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>

* Update pkg/apis/options/providers.go

Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>

* Update pkg/apis/options/providers.go

Co-authored-by: Nick Meves <nick.meves@greenhouse.io>

* Initial commit of multiple provider logic:
1. Created new provider options.
2. Created legacy provider options and conversion options.
3. Added Providers to alpha Options.
4. Started Validation migration of multiple providers
5. Tests.

* fixed lint issues

* additional lint fixes

* Nits and alterations based on CR: manliy splitting large providers validation function and adding comments to provider options

* small CR changes

* auto generates alpha_config.md

* rebase (mainly service alpha options related conflicts)

* removed :

* Nits and alterations based on CR: manliy splitting large providers validation function and adding comments to provider options

* small CR changes

* Removed GoogleGroups validation due to new allowed-groups (including tests). Added line in CHANGELOG

* "cntd. rebase"

* ran make generate again

* last conflicts

* removed duplicate client id validation

* 1. Removed provider prefixes
2. altered optionsWithNilProvider logic
3. altered default provider logic
4. moved change in CHANELOG to 7.0.0

* fixed TestGoogleGroupOptions test

* ran make generate

* moved CHANGLOG line to 7.1.1

* moved changelog comment to 7.1.2 (additional rebase)

Co-authored-by: Yana Segal <yana.segal@nielsen.com>
Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
Co-authored-by: Nick Meves <nick.meves@greenhouse.io>
2021-04-03 17:06:30 +01:00

85 lines
2.3 KiB
Go

package validation
import (
"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
)
var _ = Describe("Providers", func() {
type validateProvidersTableInput struct {
options *options.Options
errStrings []string
}
validProvider := options.Provider{
ID: "ProviderID",
ClientID: "ClientID",
ClientSecret: "ClientSecret",
}
validLoginGovProvider := options.Provider{
Type: "login.gov",
ID: "ProviderIDLoginGov",
ClientID: "ClientID",
ClientSecret: "ClientSecret",
}
missingIDProvider := options.Provider{
ClientID: "ClientID",
ClientSecret: "ClientSecret",
}
missingProvider := "at least one provider has to be defined"
emptyIDMsg := "provider has empty id: ids are required for all providers"
duplicateProviderIDMsg := "multiple providers found with id ProviderID: provider ids must be unique"
skipButtonAndMultipleProvidersMsg := "SkipProviderButton and multiple providers are mutually exclusive"
DescribeTable("validateProviders",
func(o *validateProvidersTableInput) {
Expect(validateProviders(o.options)).To(ConsistOf(o.errStrings))
},
Entry("with no providers", &validateProvidersTableInput{
options: &options.Options{},
errStrings: []string{missingProvider},
}),
Entry("with valid providers", &validateProvidersTableInput{
options: &options.Options{
Providers: options.Providers{
validProvider,
validLoginGovProvider,
},
},
errStrings: []string{},
}),
Entry("with an empty providerID", &validateProvidersTableInput{
options: &options.Options{
Providers: options.Providers{
missingIDProvider,
},
},
errStrings: []string{emptyIDMsg},
}),
Entry("with same providerID", &validateProvidersTableInput{
options: &options.Options{
Providers: options.Providers{
validProvider,
validProvider,
},
},
errStrings: []string{duplicateProviderIDMsg},
}),
Entry("with multiple providers and skip provider button", &validateProvidersTableInput{
options: &options.Options{
SkipProviderButton: true,
Providers: options.Providers{
validProvider,
validLoginGovProvider,
},
},
errStrings: []string{skipButtonAndMultipleProvidersMsg},
}),
)
})