From 0b01af987ae2f578f5babfe4adfc0af7bd9b8ae3 Mon Sep 17 00:00:00 2001 From: Kunal Dawar Date: Tue, 1 Oct 2024 12:53:12 +0530 Subject: [PATCH] Fix auth0 ul customize error handling --- internal/cli/universal_login_customize.go | 13 +++- .../cli/universal_login_customize_test.go | 76 +++++++++++++++++++ 2 files changed, 85 insertions(+), 4 deletions(-) diff --git a/internal/cli/universal_login_customize.go b/internal/cli/universal_login_customize.go index 540fc200..50330d81 100644 --- a/internal/cli/universal_login_customize.go +++ b/internal/cli/universal_login_customize.go @@ -413,7 +413,7 @@ func (h *webSocketHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { PromptName: "login", } _, err := fetchPartial(r.Context(), h.api, partial) - if err != nil && strings.Contains(err.Error(), "feature is not available for your plan") { + if err != nil && (strings.Contains(err.Error(), "feature is not available for your plan") || strings.Contains(err.Error(), "Your account does not have custom prompts")) { fetchPartialFlagMsg := webSocketMessage{ Type: fetchPartialFeatureFlag, Payload: &partialFlagData{FeatureFlag: false}, @@ -445,7 +445,7 @@ func (h *webSocketHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { partialToSend, err := fetchPartial(r.Context(), h.api, partialToFetch) if err != nil { - if strings.Contains(err.Error(), "feature is not available for your plan") { + if strings.Contains(err.Error(), "feature is not available for your plan") || strings.Contains(err.Error(), "Your account does not have custom prompts") { partialToSend = &management.PromptScreenPartials{} } else { h.display.Errorf("Failed to fetch partial for prompt: %v", err) @@ -731,7 +731,8 @@ func fetchAllPartials(ctx context.Context, api *auth0.API) ([]partialsData, erro for _, prompt := range allowedPromptsWithPartials { partial, err := api.Prompt.GetPartials(ctx, prompt) if err != nil { - if strings.Contains(err.Error(), "feature is not available for your plan") { + if strings.Contains(err.Error(), "feature is not available for your plan") || + strings.Contains(err.Error(), "Your account does not have custom prompts") { constructedPartial := partialsData{ string(prompt): &management.PromptScreenPartials{}, } @@ -787,7 +788,11 @@ func saveUniversalLoginBrandingData(ctx context.Context, api *auth0.API, data *u if screenPartials != nil { promptName := promptName group.Go(func() error { - return api.Prompt.SetPartials(ctx, management.PromptType(promptName), screenPartials) + err := api.Prompt.SetPartials(ctx, management.PromptType(promptName), screenPartials) + if err != nil && (strings.Contains(err.Error(), "feature is not available for your plan") || strings.Contains(err.Error(), "Your account does not have custom prompts")) { + return nil + } + return err }) } } diff --git a/internal/cli/universal_login_customize_test.go b/internal/cli/universal_login_customize_test.go index 86b585d2..703f717e 100644 --- a/internal/cli/universal_login_customize_test.go +++ b/internal/cli/universal_login_customize_test.go @@ -1842,6 +1842,82 @@ func TestSaveUniversalLoginBrandingData(t *testing.T) { Prompt: mockPromptAPI, } + return mockAPI + }, + }, + { + name: "it ignores errors of partial prompts for specific prompts error", + input: &universalLoginBrandingData{ + Settings: &management.Branding{ + Colors: &management.BrandingColors{ + Primary: auth0.String("#33ddff"), + PageBackground: auth0.String("#99aacc"), + }, + }, + Template: &management.BrandingUniversalLogin{ + Body: auth0.String(""), + }, + Theme: &management.BrandingTheme{}, + Partials: []partialsData{ + { + "login": { + management.ScreenName("login"): { + management.InsertionPointFormContentStart: "
Updated Form Content Start
", + }, + }, + }, + }, + Prompts: []*promptData{ + { + Language: "en", + Prompt: "login", + CustomText: map[string]interface{}{"key": "value"}, + }, + }, + }, + mockedAPI: func() *auth0.API { + mockBrandingAPI := mock.NewMockBrandingAPI(ctrl) + mockBrandingAPI.EXPECT(). + Update(gomock.Any(), &management.Branding{ + Colors: &management.BrandingColors{ + Primary: auth0.String("#33ddff"), + PageBackground: auth0.String("#99aacc"), + }, + }). + Return(nil) + mockBrandingAPI.EXPECT(). + SetUniversalLogin(gomock.Any(), &management.BrandingUniversalLogin{ + Body: auth0.String(""), + }). + Return(nil) + + mockBrandingThemeAPI := mock.NewMockBrandingThemeAPI(ctrl) + mockBrandingThemeAPI.EXPECT(). + Default(gomock.Any()). + Return(&management.BrandingTheme{ + ID: auth0.String("111"), + }, nil) + mockBrandingThemeAPI.EXPECT(). + Update(gomock.Any(), "111", &management.BrandingTheme{}). + Return(nil) + + mockPromptAPI := mock.NewMockPromptAPI(ctrl) + mockPromptAPI.EXPECT(). + SetCustomText(gomock.Any(), "login", "en", map[string]interface{}{"key": "value"}). + Return(nil) + mockPromptAPI.EXPECT(). + SetPartials(gomock.Any(), management.PromptLogin, &management.PromptScreenPartials{ + management.ScreenLogin: { + management.InsertionPointFormContentStart: "
Updated Form Content Start
", + }, + }). + Return(fmt.Errorf("Your account does not have custom prompts")) + mockAPI := &auth0.API{ + Branding: mockBrandingAPI, + BrandingTheme: mockBrandingThemeAPI, + Prompt: mockPromptAPI, + } + return mockAPI }, },