Skip to content

Commit

Permalink
Tiny improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiught committed Oct 5, 2023
1 parent e4f0c82 commit dabdece
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 140 deletions.
23 changes: 11 additions & 12 deletions internal/cli/universal_login_customize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
)

Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
128 changes: 0 additions & 128 deletions internal/cli/universal_login_customize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down Expand Up @@ -112,7 +99,6 @@ func TestFetchUniversalLoginBrandingData(t *testing.T) {
mockAPI := &auth0.API{
Branding: mockBrandingAPI,
BrandingTheme: mockBrandingThemeAPI,
CustomDomain: mockCustomDomainAPI,
Prompt: mockPromptAPI,
Tenant: mockTenantAPI,
}
Expand Down Expand Up @@ -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().
Expand Down Expand Up @@ -265,7 +238,6 @@ func TestFetchUniversalLoginBrandingData(t *testing.T) {
mockAPI := &auth0.API{
Branding: mockBrandingAPI,
BrandingTheme: mockBrandingThemeAPI,
CustomDomain: mockCustomDomainAPI,
Prompt: mockPromptAPI,
Tenant: mockTenantAPI,
}
Expand Down Expand Up @@ -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().
Expand Down Expand Up @@ -422,7 +381,6 @@ func TestFetchUniversalLoginBrandingData(t *testing.T) {
mockAPI := &auth0.API{
Branding: mockBrandingAPI,
BrandingTheme: mockBrandingThemeAPI,
CustomDomain: mockCustomDomainAPI,
Prompt: mockPromptAPI,
Tenant: mockTenantAPI,
}
Expand Down Expand Up @@ -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().
Expand Down Expand Up @@ -582,7 +527,6 @@ func TestFetchUniversalLoginBrandingData(t *testing.T) {
mockAPI := &auth0.API{
Branding: mockBrandingAPI,
BrandingTheme: mockBrandingThemeAPI,
CustomDomain: mockCustomDomainAPI,
Prompt: mockPromptAPI,
Tenant: mockTenantAPI,
}
Expand Down Expand Up @@ -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().
Expand Down Expand Up @@ -799,7 +730,6 @@ func TestFetchUniversalLoginBrandingData(t *testing.T) {
mockAPI := &auth0.API{
Branding: mockBrandingAPI,
BrandingTheme: mockBrandingThemeAPI,
CustomDomain: mockCustomDomainAPI,
Prompt: mockPromptAPI,
Tenant: mockTenantAPI,
}
Expand All @@ -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().
Expand Down Expand Up @@ -888,7 +805,6 @@ func TestFetchUniversalLoginBrandingData(t *testing.T) {
mockAPI := &auth0.API{
Branding: mockBrandingAPI,
BrandingTheme: mockBrandingThemeAPI,
CustomDomain: mockCustomDomainAPI,
Prompt: mockPromptAPI,
Tenant: mockTenantAPI,
}
Expand All @@ -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 {
Expand Down

0 comments on commit dabdece

Please sign in to comment.