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

Update logic to handle the standardMode in PATCH API #476

Merged
merged 10 commits into from
Dec 20, 2024
15 changes: 9 additions & 6 deletions management/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,6 @@ func (c *PromptRendering) MarshalJSON() ([]byte, error) {
HeadTags []interface{} `json:"head_tags,omitempty"`
}

if c.RenderingMode != nil && *c.RenderingMode == RenderingModeStandard {
return json.Marshal(&RenderingSubSet{
RenderingMode: c.RenderingMode,
})
}

return json.Marshal(&RenderingSubSet{
RenderingMode: c.RenderingMode,
ContextConfiguration: c.ContextConfiguration,
Expand Down Expand Up @@ -639,10 +633,19 @@ func (m *PromptManager) ReadRendering(ctx context.Context, prompt PromptType, sc
err = m.management.Request(ctx, "GET", m.management.URI("prompts", string(prompt), "screen", string(screen), "rendering"), &c, opts...)
return
}
func (c *PromptRendering) cleanForPatch() *PromptRendering {
if c.RenderingMode != nil && *c.RenderingMode == RenderingModeStandard {
return &PromptRendering{
RenderingMode: c.RenderingMode,
}
}
return c
}

// UpdateRendering updates the settings for the ACUL.
//
// See: https://auth0.com/docs/api/management/v2/prompts/patch-rendering
func (m *PromptManager) UpdateRendering(ctx context.Context, prompt PromptType, screen ScreenName, c *PromptRendering, opts ...RequestOption) error {
c = c.cleanForPatch()
return m.management.Request(ctx, "PATCH", m.management.URI("prompts", string(prompt), "screen", string(screen), "rendering"), c, opts...)
}
67 changes: 50 additions & 17 deletions management/prompt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TestPromptManager_ReadRendering(t *testing.T) {

_ = givenACustomDomain(t)
_ = givenAUniversalLoginTemplate(t)
expected := givenAPromptRendering(t)
expected := givenAPromptRendering(t, RenderingModeAdvanced)
actual, err := api.Prompt.ReadRendering(context.Background(), PromptSignup, ScreenSignup)
assert.NoError(t, err)
assert.Equal(t, expected.GetRenderingMode(), actual.GetRenderingMode())
Expand All @@ -143,15 +143,19 @@ func TestPromptManager_ReadRendering(t *testing.T) {
assert.Equal(t, ScreenSignup, *actual.GetScreen())
}

func TestPromptManager_UpdateRendering(t *testing.T) {
// Able to update the renderingMode to advanced and the setting configs when parsing the advanced renderingMode in payload.
func TestPromptManager_UpdateRenderingWithAdvancedMode(t *testing.T) {
configureHTTPTestRecordings(t)

_ = givenACustomDomain(t)
_ = givenAUniversalLoginTemplate(t)
_ = givenAPromptRendering(t)
updateData := &PromptRendering{}
updateData.ContextConfiguration = &[]string{"branding.settings", "branding.themes.default", "client.logo_uri"}
updateData.DefaultHeadTagsDisabled = auth0.Bool(true)
_ = givenAPromptRendering(t, RenderingModeStandard)

updateData := &PromptRendering{
RenderingMode: &RenderingModeAdvanced,
ContextConfiguration: &[]string{"branding.settings", "branding.themes.default", "client.logo_uri"},
DefaultHeadTagsDisabled: auth0.Bool(true),
}

err := api.Prompt.UpdateRendering(context.Background(), PromptSignup, ScreenSignup, updateData)
assert.NoError(t, err)
Expand All @@ -164,29 +168,58 @@ func TestPromptManager_UpdateRendering(t *testing.T) {
assert.Equal(t, ScreenSignup, *actual.GetScreen())
}

// Unable to update the setting configs and only able to update the renderingMode to standard when parsing the standard renderingMode in payload.
func TestPromptManager_UpdateRenderingWithStandardMode(t *testing.T) {
configureHTTPTestRecordings(t)

_ = givenACustomDomain(t)
_ = givenAUniversalLoginTemplate(t)
expected := givenAPromptRendering(t)
expected.RenderingMode = &RenderingModeStandard
expected.ContextConfiguration = &[]string{"branding.settings", "branding.themes.default", "client.logo_uri"}
expected.DefaultHeadTagsDisabled = auth0.Bool(true)
expected := givenAPromptRendering(t, RenderingModeAdvanced)

updateData := &PromptRendering{
RenderingMode: &RenderingModeStandard,
ContextConfiguration: &[]string{"branding.settings", "branding.themes.default", "client.logo_uri"},
DefaultHeadTagsDisabled: auth0.Bool(true),
}

err := api.Prompt.UpdateRendering(context.Background(), PromptSignup, ScreenSignup, expected)
err := api.Prompt.UpdateRendering(context.Background(), PromptSignup, ScreenSignup, updateData)
assert.NoError(t, err)

actual, err := api.Prompt.ReadRendering(context.Background(), PromptSignup, ScreenSignup)
assert.NoError(t, err)
assert.Equal(t, expected.GetRenderingMode(), actual.GetRenderingMode())
assert.NotEqual(t, expected.GetContextConfiguration(), actual.GetContextConfiguration())
assert.NotEqual(t, expected.GetDefaultHeadTagsDisabled(), actual.GetDefaultHeadTagsDisabled())

assert.Equal(t, updateData.GetRenderingMode(), actual.GetRenderingMode())
assert.NotEqual(t, updateData.GetContextConfiguration(), actual.GetContextConfiguration())
assert.NotEqual(t, updateData.GetDefaultHeadTagsDisabled(), actual.GetDefaultHeadTagsDisabled())
assert.Equal(t, expected.HeadTags, actual.HeadTags)
assert.Equal(t, PromptSignup, *actual.GetPrompt())
assert.Equal(t, ScreenSignup, *actual.GetScreen())
}

// Able to update the setting's configs even the existing renderingMode is standard since renderingMode is not parsed in payload(updateData).
func TestPromptManager_UpdateRendering(t *testing.T) {
configureHTTPTestRecordings(t)

_ = givenACustomDomain(t)
_ = givenAUniversalLoginTemplate(t)
_ = givenAPromptRendering(t, RenderingModeStandard)

updateData := &PromptRendering{
ContextConfiguration: &[]string{"branding.settings", "branding.themes.default", "client.logo_uri"},
DefaultHeadTagsDisabled: auth0.Bool(true),
}

err := api.Prompt.UpdateRendering(context.Background(), PromptSignup, ScreenSignup, updateData)
assert.NoError(t, err)

actual, err := api.Prompt.ReadRendering(context.Background(), PromptSignup, ScreenSignup)
assert.NoError(t, err)
assert.Equal(t, updateData.GetContextConfiguration(), actual.GetContextConfiguration())
assert.Equal(t, updateData.GetDefaultHeadTagsDisabled(), actual.GetDefaultHeadTagsDisabled())
assert.Equal(t, PromptSignup, *actual.GetPrompt())
assert.Equal(t, ScreenSignup, *actual.GetScreen())
}

func TestPromptManager_GetPartialsGuardGuardError(t *testing.T) {
configureHTTPTestRecordings(t)

Expand Down Expand Up @@ -353,11 +386,11 @@ func givenAPartialPrompt(t *testing.T, prompt PromptType) *PromptScreenPartials
return partials
}

func givenAPromptRendering(t *testing.T) *PromptRendering {
func givenAPromptRendering(t *testing.T, mode RenderingMode) *PromptRendering {
t.Helper()

settings := &PromptRendering{
RenderingMode: &RenderingModeStandard,
RenderingMode: &mode,
ContextConfiguration: &[]string{"branding.settings", "branding.themes.default"},
DefaultHeadTagsDisabled: auth0.Bool(false),
HeadTags: []interface{}{
Expand All @@ -368,7 +401,7 @@ func givenAPromptRendering(t *testing.T) *PromptRendering {
"defer": true,
"src": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js",
"async": true,
"integrity": []string{
"integrity": []interface{}{
"sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==",
},
},
Expand Down
12 changes: 6 additions & 6 deletions test/data/recordings/TestPromptManager_ReadRendering.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interactions:
Content-Type:
- application/json
User-Agent:
- Go-Auth0/1.11.2
- Go-Auth0/1.13.0
url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains
method: POST
response:
Expand Down Expand Up @@ -55,7 +55,7 @@ interactions:
Content-Type:
- application/json
User-Agent:
- Go-Auth0/1.11.2
- Go-Auth0/1.13.0
url: https://go-auth0-dev.eu.auth0.com/api/v2/branding/templates/universal-login
method: PUT
response:
Expand Down Expand Up @@ -91,7 +91,7 @@ interactions:
Content-Type:
- application/json
User-Agent:
- Go-Auth0/1.11.2
- Go-Auth0/1.13.0
url: https://go-auth0-dev.eu.auth0.com/api/v2/prompts/signup/screen/signup/rendering
method: PATCH
response:
Expand Down Expand Up @@ -126,7 +126,7 @@ interactions:
Content-Type:
- application/json
User-Agent:
- Go-Auth0/1.11.2
- Go-Auth0/1.13.0
url: https://go-auth0-dev.eu.auth0.com/api/v2/prompts/signup/screen/signup/rendering
method: GET
response:
Expand Down Expand Up @@ -161,7 +161,7 @@ interactions:
Content-Type:
- application/json
User-Agent:
- Go-Auth0/1.11.2
- Go-Auth0/1.13.0
url: https://go-auth0-dev.eu.auth0.com/api/v2/branding/templates/universal-login
method: DELETE
response:
Expand Down Expand Up @@ -196,7 +196,7 @@ interactions:
Content-Type:
- application/json
User-Agent:
- Go-Auth0/1.11.2
- Go-Auth0/1.13.0
url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains/cd_7SgKHnrmHQNuTXEs
method: DELETE
response:
Expand Down
40 changes: 20 additions & 20 deletions test/data/recordings/TestPromptManager_UpdateRendering.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ interactions:
proto: HTTP/1.1
proto_major: 1
proto_minor: 1
content_length: 100
content_length: 99
transfer_encoding: []
trailer: {}
host: go-auth0-dev.eu.auth0.com
remote_addr: ""
request_uri: ""
body: |
{"domain":"1733383424.auth.uat.auth0.com","type":"auth0_managed_certs","tls_policy":"recommended"}
{"domain":"1734698728.auth.uat.auth0.com","type":"auth0_managed_certs","tls_policy":"recommended"}
form: {}
headers:
Content-Type:
- application/json
User-Agent:
- Go-Auth0/1.12.0
- Go-Auth0/1.13.0
url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains
method: POST
response:
Expand Down Expand Up @@ -55,7 +55,7 @@ interactions:
Content-Type:
- application/json
User-Agent:
- Go-Auth0/1.12.0
- Go-Auth0/1.13.0
url: https://go-auth0-dev.eu.auth0.com/api/v2/branding/templates/universal-login
method: PUT
response:
Expand All @@ -72,26 +72,26 @@ interactions:
- application/json; charset=utf-8
status: 201 Created
code: 201
duration: 2.698890708s
duration: 779.822584ms
- id: 2
request:
proto: HTTP/1.1
proto_major: 1
proto_minor: 1
content_length: 408
content_length: 30
transfer_encoding: []
trailer: {}
host: go-auth0-dev.eu.auth0.com
remote_addr: ""
request_uri: ""
body: |
{"rendering_mode":"advanced","context_configuration":["branding.settings","branding.themes.default"],"default_head_tags_disabled":false,"head_tags":[{"attributes":{"async":true,"defer":true,"integrity":["sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g=="],"src":"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"},"content":"","tag":"script"}]}
{"rendering_mode":"standard"}
form: {}
headers:
Content-Type:
- application/json
User-Agent:
- Go-Auth0/1.12.0
- Go-Auth0/1.13.0
url: https://go-auth0-dev.eu.auth0.com/api/v2/prompts/signup/screen/signup/rendering
method: PATCH
response:
Expand All @@ -100,15 +100,15 @@ interactions:
proto_minor: 0
transfer_encoding: []
trailer: {}
content_length: -1
uncompressed: true
body: '{"rendering_mode":"advanced","context_configuration":["branding.settings","branding.themes.default"],"default_head_tags_disabled":false,"head_tags":[{"attributes":{"async":true,"defer":true,"integrity":["sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g=="],"src":"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"},"content":"","tag":"script"}]}'
content_length: 29
uncompressed: false
body: '{"rendering_mode":"standard"}'
headers:
Content-Type:
- application/json; charset=utf-8
status: 200 OK
code: 200
duration: 442.125917ms
duration: 454.494375ms
- id: 3
request:
proto: HTTP/1.1
Expand All @@ -127,7 +127,7 @@ interactions:
Content-Type:
- application/json
User-Agent:
- Go-Auth0/1.12.0
- Go-Auth0/1.13.0
url: https://go-auth0-dev.eu.auth0.com/api/v2/prompts/signup/screen/signup/rendering
method: PATCH
response:
Expand All @@ -144,7 +144,7 @@ interactions:
- application/json; charset=utf-8
status: 200 OK
code: 200
duration: 431.61225ms
duration: 425.653542ms
- id: 4
request:
proto: HTTP/1.1
Expand All @@ -162,7 +162,7 @@ interactions:
Content-Type:
- application/json
User-Agent:
- Go-Auth0/1.12.0
- Go-Auth0/1.13.0
url: https://go-auth0-dev.eu.auth0.com/api/v2/prompts/signup/screen/signup/rendering
method: GET
response:
Expand All @@ -173,13 +173,13 @@ interactions:
trailer: {}
content_length: -1
uncompressed: true
body: '{"tenant":"go-auth0-dev.eu.auth0.com","prompt":"signup","screen":"signup","rendering_mode":"advanced","context_configuration":["branding.settings","branding.themes.default","client.logo_uri"],"default_head_tags_disabled":true,"head_tags":[{"tag":"script","content":"","attributes":{"src":"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js","async":true,"defer":true,"integrity":["sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g=="]}}]}'
body: '{"tenant":"go-auth0-dev.eu.auth0.com","prompt":"signup","screen":"signup","rendering_mode":"standard","context_configuration":["branding.settings","branding.themes.default","client.logo_uri"],"default_head_tags_disabled":true,"head_tags":[{"tag":"script","content":"","attributes":{"src":"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js","async":true,"defer":true,"integrity":["sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g=="]}}]}'
headers:
Content-Type:
- application/json; charset=utf-8
status: 200 OK
code: 200
duration: 418.176625ms
duration: 476.536875ms
- id: 5
request:
proto: HTTP/1.1
Expand All @@ -197,7 +197,7 @@ interactions:
Content-Type:
- application/json
User-Agent:
- Go-Auth0/1.12.0
- Go-Auth0/1.13.0
url: https://go-auth0-dev.eu.auth0.com/api/v2/branding/templates/universal-login
method: DELETE
response:
Expand All @@ -214,7 +214,7 @@ interactions:
- application/json; charset=utf-8
status: 204 No Content
code: 204
duration: 464.237167ms
duration: 699.654875ms
- id: 6
request:
proto: HTTP/1.1
Expand All @@ -232,7 +232,7 @@ interactions:
Content-Type:
- application/json
User-Agent:
- Go-Auth0/1.12.0
- Go-Auth0/1.13.0
url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains/cd_hW5C18CQPXRsKpDz
method: DELETE
response:
Expand Down
Loading
Loading