Skip to content

Commit

Permalink
Prevent panic in fetchBrandingSettingsOrUseDefaults (#731)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiught authored Apr 12, 2023
1 parent ac090d1 commit a8146e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/cli/universal_login_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
11 changes: 11 additions & 0 deletions internal/cli/universal_login_templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a8146e1

Please sign in to comment.