diff --git a/internal/cli/universal_login_customize.go b/internal/cli/universal_login_customize.go index 5a038aa2d..9b1f7b627 100644 --- a/internal/cli/universal_login_customize.go +++ b/internal/cli/universal_login_customize.go @@ -28,9 +28,9 @@ type ( } promptData struct { - Language string `json:"language"` - Prompt string `json:"prompt"` - CustomText interface{} `json:"custom_text"` + Language string `json:"language"` + Prompt string `json:"prompt"` + CustomText map[string]map[string]interface{} `json:"custom_text"` } ) @@ -46,10 +46,16 @@ func customizeUniversalLoginCmd(cli *cli) *cobra.Command { Example: ` auth0 universal-login customize auth0 ul customize`, RunE: func(cmd *cobra.Command, args []string) error { + ctx := cmd.Context() + + if err := ensureCustomDomainIsEnabled(ctx, cli.api); err != nil { + return err + } + var universalLoginBrandingData *universalLoginBrandingData if err := ansi.Spinner("Fetching Universal Login branding data", func() (err error) { - universalLoginBrandingData, err = fetchUniversalLoginBrandingData(cmd.Context(), cli.api, cli.tenant) + universalLoginBrandingData, err = fetchUniversalLoginBrandingData(ctx, cli.api, cli.tenant) return err }); err != nil { return err @@ -71,10 +77,6 @@ func fetchUniversalLoginBrandingData( ) (*universalLoginBrandingData, error) { group, ctx := errgroup.WithContext(ctx) - group.Go(func() (err error) { - return ensureCustomDomainIsEnabled(ctx, api) - }) - var authenticationProfile *management.Prompt group.Go(func() (err error) { authenticationProfile, err = api.Prompt.Read(ctx) @@ -108,10 +110,7 @@ func fetchUniversalLoginBrandingData( } defaultPrompt := "login" - defaultLanguage := "en" - if len(tenant.GetEnabledLocales()) > 0 { - defaultLanguage = tenant.GetEnabledLocales()[0] - } + defaultLanguage := tenant.GetEnabledLocales()[0] prompt, err = fetchPromptCustomTextWithDefaults(ctx, api, defaultPrompt, defaultLanguage) return err diff --git a/internal/cli/universal_login_customize_test.go b/internal/cli/universal_login_customize_test.go index 1d5c6d4b8..25837a5b0 100644 --- a/internal/cli/universal_login_customize_test.go +++ b/internal/cli/universal_login_customize_test.go @@ -28,19 +28,6 @@ func TestFetchUniversalLoginBrandingData(t *testing.T) { { name: "it can correctly fetch universal login branding data", mockedAPI: func() *auth0.API { - mockCustomDomainAPI := mock.NewMockCustomDomainAPI(ctrl) - mockCustomDomainAPI. - EXPECT(). - List(gomock.Any()). - Return( - []*management.CustomDomain{ - { - Status: auth0.String("ready"), - }, - }, - nil, - ) - mockPromptAPI := mock.NewMockPromptAPI(ctrl) mockPromptAPI. EXPECT(). @@ -112,7 +99,6 @@ func TestFetchUniversalLoginBrandingData(t *testing.T) { mockAPI := &auth0.API{ Branding: mockBrandingAPI, BrandingTheme: mockBrandingThemeAPI, - CustomDomain: mockCustomDomainAPI, Prompt: mockPromptAPI, Tenant: mockTenantAPI, } @@ -190,19 +176,6 @@ func TestFetchUniversalLoginBrandingData(t *testing.T) { { name: "it uses default branding settings if it fails to fetch them", mockedAPI: func() *auth0.API { - mockCustomDomainAPI := mock.NewMockCustomDomainAPI(ctrl) - mockCustomDomainAPI. - EXPECT(). - List(gomock.Any()). - Return( - []*management.CustomDomain{ - { - Status: auth0.String("ready"), - }, - }, - nil, - ) - mockPromptAPI := mock.NewMockPromptAPI(ctrl) mockPromptAPI. EXPECT(). @@ -265,7 +238,6 @@ func TestFetchUniversalLoginBrandingData(t *testing.T) { mockAPI := &auth0.API{ Branding: mockBrandingAPI, BrandingTheme: mockBrandingThemeAPI, - CustomDomain: mockCustomDomainAPI, Prompt: mockPromptAPI, Tenant: mockTenantAPI, } @@ -343,19 +315,6 @@ func TestFetchUniversalLoginBrandingData(t *testing.T) { { name: "it uses an empty branding template if it fails to fetch it", mockedAPI: func() *auth0.API { - mockCustomDomainAPI := mock.NewMockCustomDomainAPI(ctrl) - mockCustomDomainAPI. - EXPECT(). - List(gomock.Any()). - Return( - []*management.CustomDomain{ - { - Status: auth0.String("ready"), - }, - }, - nil, - ) - mockPromptAPI := mock.NewMockPromptAPI(ctrl) mockPromptAPI. EXPECT(). @@ -422,7 +381,6 @@ func TestFetchUniversalLoginBrandingData(t *testing.T) { mockAPI := &auth0.API{ Branding: mockBrandingAPI, BrandingTheme: mockBrandingThemeAPI, - CustomDomain: mockCustomDomainAPI, Prompt: mockPromptAPI, Tenant: mockTenantAPI, } @@ -498,19 +456,6 @@ func TestFetchUniversalLoginBrandingData(t *testing.T) { { name: "it uses a default branding theme if it fails to fetch it", mockedAPI: func() *auth0.API { - mockCustomDomainAPI := mock.NewMockCustomDomainAPI(ctrl) - mockCustomDomainAPI. - EXPECT(). - List(gomock.Any()). - Return( - []*management.CustomDomain{ - { - Status: auth0.String("ready"), - }, - }, - nil, - ) - mockPromptAPI := mock.NewMockPromptAPI(ctrl) mockPromptAPI. EXPECT(). @@ -582,7 +527,6 @@ func TestFetchUniversalLoginBrandingData(t *testing.T) { mockAPI := &auth0.API{ Branding: mockBrandingAPI, BrandingTheme: mockBrandingThemeAPI, - CustomDomain: mockCustomDomainAPI, Prompt: mockPromptAPI, Tenant: mockTenantAPI, } @@ -733,19 +677,6 @@ func TestFetchUniversalLoginBrandingData(t *testing.T) { { name: "it fails to fetch branding data if there's an error retrieving tenant data", mockedAPI: func() *auth0.API { - mockCustomDomainAPI := mock.NewMockCustomDomainAPI(ctrl) - mockCustomDomainAPI. - EXPECT(). - List(gomock.Any()). - Return( - []*management.CustomDomain{ - { - Status: auth0.String("ready"), - }, - }, - nil, - ) - mockPromptAPI := mock.NewMockPromptAPI(ctrl) mockPromptAPI. EXPECT(). @@ -799,7 +730,6 @@ func TestFetchUniversalLoginBrandingData(t *testing.T) { mockAPI := &auth0.API{ Branding: mockBrandingAPI, BrandingTheme: mockBrandingThemeAPI, - CustomDomain: mockCustomDomainAPI, Prompt: mockPromptAPI, Tenant: mockTenantAPI, } @@ -811,19 +741,6 @@ func TestFetchUniversalLoginBrandingData(t *testing.T) { { name: "it fails to fetch branding data if there's an error retrieving prompt text data", mockedAPI: func() *auth0.API { - mockCustomDomainAPI := mock.NewMockCustomDomainAPI(ctrl) - mockCustomDomainAPI. - EXPECT(). - List(gomock.Any()). - Return( - []*management.CustomDomain{ - { - Status: auth0.String("ready"), - }, - }, - nil, - ) - mockPromptAPI := mock.NewMockPromptAPI(ctrl) mockPromptAPI. EXPECT(). @@ -888,7 +805,6 @@ func TestFetchUniversalLoginBrandingData(t *testing.T) { mockAPI := &auth0.API{ Branding: mockBrandingAPI, BrandingTheme: mockBrandingThemeAPI, - CustomDomain: mockCustomDomainAPI, Prompt: mockPromptAPI, Tenant: mockTenantAPI, } @@ -897,50 +813,6 @@ func TestFetchUniversalLoginBrandingData(t *testing.T) { }, expectedError: "failed to fetch custom text", }, - { - name: "it fails to fetch any data if a custom domain is not enabled", - mockedAPI: func() *auth0.API { - mockCustomDomainAPI := mock.NewMockCustomDomainAPI(ctrl) - mockCustomDomainAPI. - EXPECT(). - List(gomock.Any()). - Return( - []*management.CustomDomain{ - { - Status: auth0.String("pending"), - }, - }, - nil, - ) - - mockPromptAPI := mock.NewMockPromptAPI(ctrl) - mockPromptAPI.EXPECT().Read(gomock.Any()).Return(nil, nil) - - mockBrandingAPI := mock.NewMockBrandingAPI(ctrl) - mockBrandingAPI.EXPECT().Read(gomock.Any()).Return(nil, nil) - - mockBrandingAPI.EXPECT().UniversalLogin(gomock.Any()).Return(nil, nil) - - mockBrandingThemeAPI := mock.NewMockBrandingThemeAPI(ctrl) - mockBrandingThemeAPI.EXPECT().Default(gomock.Any()).Return(nil, nil) - - mockTenantAPI := mock.NewMockTenantAPI(ctrl) - mockTenantAPI.EXPECT().Read(gomock.Any()).Return(nil, nil) - - mockPromptAPI.EXPECT().CustomText(gomock.Any(), "login", "en").Return(map[string]interface{}{}, nil) - - mockAPI := &auth0.API{ - Branding: mockBrandingAPI, - BrandingTheme: mockBrandingThemeAPI, - CustomDomain: mockCustomDomainAPI, - Prompt: mockPromptAPI, - Tenant: mockTenantAPI, - } - - return mockAPI - }, - expectedError: "this feature requires at least one custom domain to be set and verified for the tenant, use 'auth0 domains create' to create one and 'auth0 domains verify' to have it verified", - }, } for _, test := range testCases {