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

DXCDT-416: Add tests for updating universal login branding #692

Merged
merged 4 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
18 changes: 3 additions & 15 deletions internal/cli/universal_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func updateUniversalLoginCmd(cli *cli) *cobra.Command {
b := &management.Branding{}
isAccentColorSet := len(inputs.AccentColor) > 0
isBackgroundColorSet := len(inputs.BackgroundColor) > 0
currentHasColors := current.Colors != nil
currentHasColors := current.GetColors() != nil
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this error is solely for a new tenant/tenant that hasn't touched the values (due to this API being a PATCH API so it's difficult to reset the values)

But on first run of auth0 ul in my tenant I got the below error, this repeated for LogoURL and FaviconURL, looking at the API calls in the UI a GET /api/v2/branding only returned a subset of data {"colors":{"primary":"#FF4F40"}} rather than a full object

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x1009f2604]

goroutine 1 [running]:
github.com/auth0/auth0-cli/internal/cli.Execute.func1()
	/Users/ewanharris/dev/git/auth0-cli/internal/cli/root.go:53 +0xb4
panic({0x101050900, 0x1017f6f60})
	/opt/homebrew/Cellar/go/1.20.2/libexec/src/runtime/panic.go:884 +0x1f4
github.com/auth0/auth0-cli/internal/cli.updateUniversalLoginCmd.func1(0x1400001a900?, {0x140001201c0?, 0x2?, 0x2?})
	/Users/ewanharris/dev/git/auth0-cli/internal/cli/universal_login.go:181 +0x1c4
github.com/spf13/cobra.(*Command).execute(0x1400001a900, {0x140001201a0, 0x2, 0x2})
	/Users/ewanharris/dev/git/auth0-cli/vendor/github.com/spf13/cobra/command.go:916 +0x5c4
github.com/spf13/cobra.(*Command).ExecuteC(0x14000292600)
	/Users/ewanharris/dev/git/auth0-cli/vendor/github.com/spf13/cobra/command.go:1044 +0x340
github.com/spf13/cobra.(*Command).Execute(...)
	/Users/ewanharris/dev/git/auth0-cli/vendor/github.com/spf13/cobra/command.go:968
github.com/spf13/cobra.(*Command).ExecuteContext(...)
	/Users/ewanharris/dev/git/auth0-cli/vendor/github.com/spf13/cobra/command.go:961
github.com/auth0/auth0-cli/internal/cli.Execute()
	/Users/ewanharris/dev/git/auth0-cli/internal/cli/root.go:64 +0x1ac
main.main()
	/Users/ewanharris/dev/git/auth0-cli/cmd/auth0/main.go:6 +0x1c


if isAccentColorSet || isBackgroundColorSet || currentHasColors {
b.Colors = &management.BrandingColors{}
Expand All @@ -196,15 +196,11 @@ func updateUniversalLoginCmd(cli *cli) *cobra.Command {
}
}

if len(inputs.LogoURL) == 0 {
b.LogoURL = current.LogoURL
} else {
if len(inputs.LogoURL) != 0 {
b.LogoURL = &inputs.LogoURL
}

if len(inputs.FaviconURL) == 0 {
b.FaviconURL = current.FaviconURL
} else {
if len(inputs.FaviconURL) != 0 {
b.FaviconURL = &inputs.FaviconURL
}

Expand All @@ -213,14 +209,6 @@ func updateUniversalLoginCmd(cli *cli) *cobra.Command {
b.Font = &management.BrandingFont{URL: &inputs.CustomFontURL}
}

if b.Font != nil {
Copy link
Contributor Author

@ewanharris ewanharris Mar 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From testing, this code is not required. The only case where b.Font is not nil is when inputs.CustomFontURL is not set due to the if on line 212.

Given that, we will always repeat exactly what the if statement on 212 achieves, i.e. if a --font option has been provided then set it

if len(inputs.CustomFontURL) == 0 {
b.Font.URL = current.Font.URL
} else {
b.Font.URL = &inputs.CustomFontURL
}
}

// Update branding
if err := ansi.Waiting(func() error {
return cli.api.Branding.Update(b)
Expand Down
3 changes: 3 additions & 0 deletions test/integration/scripts/test-cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,7 @@ for action in $( echo "${actions}" | jq -r '.[] | @base64' ); do
fi
done

# Reset universal login branding
auth0 ul update --accent "#2A2E35" --background "#FF4F40" --logo "https://example.com/logo.png" --favicon "https://example.com/favicon.png" --font https://example.com/font.woff --no-input

rm -rf test/integration/identifiers
73 changes: 73 additions & 0 deletions test/integration/universal-login-test-cases.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
config:
inherit-env: true

tests:
001 - sets default expected values:
command: auth0 ul update --accent "#2A2E35" --background "#FF4F40" --logo "https://example.com/logo.png" --favicon "https://example.com/favicon.png" --font https://example.com/font.woff --no-input
exit-code: 0

002 - it successfully shows universal login branding:
command: auth0 ul show
exit-code: 0
stdout:
contains:
- ACCENT COLOR #2A2E35
- BACKGROUND COLOR #FF4F40
ewanharris marked this conversation as resolved.
Show resolved Hide resolved
- LOGO URL https://example.com/logo.png
- FAVICON URL https://example.com/favicon.png
- CUSTOM FONT URL https://example.com/font.woff

003 - it successfully shows universal login branding in json:
command: auth0 ul show --json
exit-code: 0
stdout:
json:
colors.primary: "#2A2E35"
colors.page_background: "#FF4F40"
favicon_url: "https://example.com/favicon.png"
logo_url: "https://example.com/logo.png"
font.url: "https://example.com/font.woff"

004 - it successfully updates universal login branding:
command: auth0 ul update --accent "#2A2E35" --background "#FF4F40" --logo "https://example.com/logo-updated.png" --favicon "https://example.com/favicon-updated.png" --font https://example.com/font-updated.woff
exit-code: 0
stdout:
contains:
- ACCENT COLOR #2A2E35
- BACKGROUND COLOR #FF4F40
ewanharris marked this conversation as resolved.
Show resolved Hide resolved
- LOGO URL https://example.com/logo-updated.png
- FAVICON URL https://example.com/favicon-updated.png
- CUSTOM FONT URL https://example.com/font-updated.woff

005 - it successfully updates universal login branding and outputs as json:
command: auth0 ul update --accent "#FF4F40" --background "#2A2E35" --logo "https://example.com/logo-updated-json.png" --favicon "https://example.com/favicon-updated-json.png" --font https://example.com/font-updated-json.woff --json
exit-code: 0
stdout:
json:
colors.primary: "#FF4F40"
colors.page_background: "#2A2E35"
favicon_url: "https://example.com/favicon-updated-json.png"
logo_url: "https://example.com/logo-updated-json.png"
font.url: "https://example.com/font-updated-json.woff"

006 - it successfully updates universal login branding and persists previous colors:
command: auth0 ul update --logo "https://example.com/logo-updated-2.png" --favicon "https://example.com/favicon-updated-2.png" --font https://example.com/font-updated-2.woff --json
exit-code: 0
stdout:
json:
colors.primary: "#FF4F40"
colors.page_background: "#2A2E35"
favicon_url: "https://example.com/favicon-updated-2.png"
logo_url: "https://example.com/logo-updated-2.png"
font.url: "https://example.com/font-updated-2.woff"

007 - it successfully updates universal login branding and persists previous URLs:
command: auth0 ul update --accent "#2A2E35" --background "#FF4F40" --json
exit-code: 0
stdout:
json:
colors.primary: "#2A2E35"
colors.page_background: "#FF4F40"
favicon_url: "https://example.com/favicon-updated-2.png"
logo_url: "https://example.com/logo-updated-2.png"
font.url: "https://example.com/font-updated-2.woff"