From a8146e1d511f29c70b46e2eef2c1a2a3cd55cbf5 Mon Sep 17 00:00:00 2001 From: Sergiu Ghitea <28300158+sergiught@users.noreply.github.com> Date: Wed, 12 Apr 2023 18:33:45 +0200 Subject: [PATCH] Prevent panic in fetchBrandingSettingsOrUseDefaults (#731) --- internal/cli/universal_login_templates.go | 9 +++++---- internal/cli/universal_login_templates_test.go | 11 +++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/internal/cli/universal_login_templates.go b/internal/cli/universal_login_templates.go index ae0b5842b..d22d5b21f 100644 --- a/internal/cli/universal_login_templates.go +++ b/internal/cli/universal_login_templates.go @@ -275,17 +275,18 @@ func ensureCustomDomainIsEnabled(ctx context.Context, api *auth0.API) error { } func fetchBrandingSettingsOrUseDefaults(ctx context.Context, api *auth0.API) *management.Branding { - brandingSettings, err := api.Branding.Read(management.Context(ctx)) - if err != nil { - brandingSettings = &management.Branding{} // If we error we'll provide defaults. + brandingSettings, _ := api.Branding.Read(management.Context(ctx)) + if brandingSettings == nil { + brandingSettings = &management.Branding{} } - if brandingSettings.GetColors() == nil { + if brandingSettings.Colors == nil { brandingSettings.Colors = &management.BrandingColors{ Primary: auth0.String(defaultPrimaryColor), PageBackground: auth0.String(defaultBackgroundColor), } } + if brandingSettings.LogoURL == nil { brandingSettings.LogoURL = auth0.String(defaultLogoURL) } diff --git a/internal/cli/universal_login_templates_test.go b/internal/cli/universal_login_templates_test.go index 818c4501d..729d7e189 100644 --- a/internal/cli/universal_login_templates_test.go +++ b/internal/cli/universal_login_templates_test.go @@ -116,6 +116,17 @@ func TestFetchBrandingSettingsOrUseDefaults(t *testing.T) { }, { name: "no branding settings", + branding: nil, + assertOutput: func(t testing.TB, branding *management.Branding) { + assert.NotNil(t, branding) + assert.NotNil(t, branding.Colors) + assert.Equal(t, branding.Colors.GetPrimary(), defaultPrimaryColor) + assert.Equal(t, branding.Colors.GetPageBackground(), defaultBackgroundColor) + assert.Equal(t, branding.GetLogoURL(), defaultLogoURL) + }, + }, + { + name: "empty branding settings", branding: &management.Branding{}, assertOutput: func(t testing.TB, branding *management.Branding) { assert.NotNil(t, branding)