Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error handling in auth0 ul customize to gracefully ignore specific prompt errors #1081

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions internal/cli/universal_login_customize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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{},
}
Expand Down Expand Up @@ -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
})
}
}
Expand Down
76 changes: 76 additions & 0 deletions internal/cli/universal_login_customize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("<html></html>"),
},
Theme: &management.BrandingTheme{},
Partials: []partialsData{
{
"login": {
management.ScreenName("login"): {
management.InsertionPointFormContentStart: "<div>Updated Form Content Start</div>",
},
},
},
},
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("<html></html>"),
}).
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: "<div>Updated Form Content Start</div>",
},
}).
Return(fmt.Errorf("Your account does not have custom prompts"))
mockAPI := &auth0.API{
Branding: mockBrandingAPI,
BrandingTheme: mockBrandingThemeAPI,
Prompt: mockPromptAPI,
}

return mockAPI
},
},
Expand Down
Loading