3
0

Fix non-OIDC IdP skip due to invalid req. check

This commit is contained in:
Denis Arh
2021-07-23 06:39:20 +02:00
parent 205da42186
commit 02b137d19e
3 changed files with 143 additions and 2 deletions

View File

@@ -39,9 +39,10 @@ COVER_PKGS_pkg = ./pkg/...
COVER_PKGS_all = $(COVER_PKGS_pkg),$(COVER_PKGS_system),$(COVER_PKGS_compose),$(COVER_PKGS_federation),$(COVER_PKGS_automation)
COVER_PKGS_integration = $(COVER_PKGS_all)
TEST_SUITE_app = ./app/...
TEST_SUITE_pkg = ./pkg/...
TEST_SUITE_services = ./compose/... ./system/... ./federation/... ./auth/... ./automation/...
TEST_SUITE_unit = $(TEST_SUITE_pkg) $(TEST_SUITE_services)
TEST_SUITE_unit = $(TEST_SUITE_pkg) $(TEST_SUITE_app) $(TEST_SUITE_services)
TEST_SUITE_integration = ./tests/...
TEST_SUITE_store = ./store/tests/...
TEST_SUITE_all = $(TEST_SUITE_unit) $(TEST_SUITE_integration) $(TEST_SUITE_store)

View File

@@ -7,6 +7,7 @@ import (
"strings"
authService "github.com/cortezaproject/corteza-server/auth"
"github.com/cortezaproject/corteza-server/auth/external"
authHandlers "github.com/cortezaproject/corteza-server/auth/handlers"
"github.com/cortezaproject/corteza-server/auth/saml"
authSettings "github.com/cortezaproject/corteza-server/auth/settings"
@@ -523,10 +524,20 @@ func updateAuthSettings(svc authServicer, current *types.AppSettings) {
)
for _, p := range cas.External.Providers {
if !p.Enabled || p.Handle == "" || p.IssuerUrl == "" || p.Key == "" || p.Secret == "" {
if !p.Enabled || p.Handle == "" || p.Key == "" || p.Secret == "" {
continue
}
if strings.HasPrefix(p.Handle, external.OIDC_PROVIDER_PREFIX) {
if p.IssuerUrl == "" {
// OIDC IdPs need to have issuer URL
continue
}
} else {
// non-OIDC provider do not need issuer URL
p.IssuerUrl = ""
}
providers = append(providers, authSettings.Provider{
Handle: p.Handle,
Label: p.Label,

129
app/boot_levels_test.go Normal file
View File

@@ -0,0 +1,129 @@
package app
import (
"context"
"testing"
"github.com/cortezaproject/corteza-server/auth/external"
authSettings "github.com/cortezaproject/corteza-server/auth/settings"
"github.com/cortezaproject/corteza-server/system/types"
"github.com/go-chi/chi"
"github.com/stretchr/testify/require"
)
type (
authSettingsUpdaterMockedAuthService struct {
settings *authSettings.Settings
}
)
func (*authSettingsUpdaterMockedAuthService) MountHttpRoutes(string, chi.Router) {}
func (*authSettingsUpdaterMockedAuthService) Watch(context.Context) {}
func (m *authSettingsUpdaterMockedAuthService) UpdateSettings(settings *authSettings.Settings) {
m.settings = settings
}
func Test_updateAuthSettings(t *testing.T) {
cc := []struct {
name string
in types.AppSettings
out authSettings.Settings
}{
{
"enabled internal auth",
func() (s types.AppSettings) {
s.Auth.Internal.Enabled = true
return
}(),
func() (s authSettings.Settings) {
s.LocalEnabled = true
return
}(),
},
{
"add external providers",
func() (s types.AppSettings) {
s.Auth.External.Providers = []*types.ExternalAuthProvider{
{ // skip
Enabled: false,
Handle: "disabled",
Key: "key",
Secret: "sec",
},
{ // skip
Enabled: true,
Handle: "malformed",
Key: "",
Secret: "",
},
{ // skip
Enabled: true,
Handle: external.OIDC_PROVIDER_PREFIX + "without-issuer",
Key: "key",
Secret: "sec",
},
{ // add
Enabled: true,
Handle: external.OIDC_PROVIDER_PREFIX + "with-issuer",
IssuerUrl: "issuer",
Key: "key",
Secret: "sec",
},
{ // add (w/o issuer)
Enabled: true,
Handle: "google",
IssuerUrl: "issuer",
Key: "key",
Secret: "sec",
},
{ // add
Enabled: true,
Handle: "github",
Key: "key",
Secret: "sec",
},
{ // skip
Enabled: false,
Handle: "linkedin",
Key: "key",
Secret: "sec",
},
}
return
}(),
func() (s authSettings.Settings) {
s.Providers = []authSettings.Provider{
{
Handle: external.OIDC_PROVIDER_PREFIX + "with-issuer",
IssuerUrl: "issuer",
Key: "key",
Secret: "sec",
},
{
Handle: "google",
Key: "key",
Secret: "sec",
},
{
Handle: "github",
Key: "key",
Secret: "sec",
},
}
return
}(),
},
}
for _, c := range cc {
t.Run(c.name, func(t *testing.T) {
var (
req = require.New(t)
m = &authSettingsUpdaterMockedAuthService{}
)
updateAuthSettings(m, &c.in)
req.Equal(*m.settings, c.out)
})
}
}