From b356686e28456b16e5910d67ead7806b1d0f98fd Mon Sep 17 00:00:00 2001 From: ramya18101 Date: Fri, 20 Dec 2024 13:43:31 +0530 Subject: [PATCH 01/10] Update logic to handle the standardMode in PATCH API --- management/prompt.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/management/prompt.go b/management/prompt.go index 069c9909..4aa85e08 100644 --- a/management/prompt.go +++ b/management/prompt.go @@ -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, @@ -475,6 +469,15 @@ func (c *PromptRendering) MarshalJSON() ([]byte, error) { }) } +func (c *PromptRendering) CleanForPatch() *PromptRendering { + if c.RenderingMode != nil && *c.RenderingMode == RenderingModeStandard { + return &PromptRendering{ + RenderingMode: c.RenderingMode, + } + } + return c +} + // MarshalJSON implements a custom [json.Marshaler]. func (c *PromptPartials) MarshalJSON() ([]byte, error) { body := map[string]PromptPartials{ @@ -644,5 +647,6 @@ func (m *PromptManager) ReadRendering(ctx context.Context, prompt PromptType, sc // // 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...) } From 134f218c7d3172ae3b1d1c3d74aad16c165e6192 Mon Sep 17 00:00:00 2001 From: ramya18101 Date: Fri, 20 Dec 2024 14:56:57 +0530 Subject: [PATCH 02/10] Fix unit tests & lint --- management/prompt.go | 4 +- management/prompt_test.go | 34 +++++- .../TestPromptManager_ReadRendering.yaml | 28 ++--- ...nager_UpdateRenderingWithStandardMode.yaml | 109 +++--------------- 4 files changed, 66 insertions(+), 109 deletions(-) diff --git a/management/prompt.go b/management/prompt.go index 4aa85e08..0249ab71 100644 --- a/management/prompt.go +++ b/management/prompt.go @@ -469,7 +469,7 @@ func (c *PromptRendering) MarshalJSON() ([]byte, error) { }) } -func (c *PromptRendering) CleanForPatch() *PromptRendering { +func (c *PromptRendering) cleanForPatch() *PromptRendering { if c.RenderingMode != nil && *c.RenderingMode == RenderingModeStandard { return &PromptRendering{ RenderingMode: c.RenderingMode, @@ -647,6 +647,6 @@ func (m *PromptManager) ReadRendering(ctx context.Context, prompt PromptType, sc // // 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() + c = c.cleanForPatch() return m.management.Request(ctx, "PATCH", m.management.URI("prompts", string(prompt), "screen", string(screen), "rendering"), c, opts...) } diff --git a/management/prompt_test.go b/management/prompt_test.go index 97cd716c..3f7892e4 100644 --- a/management/prompt_test.go +++ b/management/prompt_test.go @@ -167,9 +167,9 @@ func TestPromptManager_UpdateRendering(t *testing.T) { func TestPromptManager_UpdateRenderingWithStandardMode(t *testing.T) { configureHTTPTestRecordings(t) - _ = givenACustomDomain(t) + // _ = givenACustomDomain(t) _ = givenAUniversalLoginTemplate(t) - expected := givenAPromptRendering(t) + expected := givenAPromptStandardRendering(t) expected.RenderingMode = &RenderingModeStandard expected.ContextConfiguration = &[]string{"branding.settings", "branding.themes.default", "client.logo_uri"} expected.DefaultHeadTagsDisabled = auth0.Bool(true) @@ -356,6 +356,34 @@ func givenAPartialPrompt(t *testing.T, prompt PromptType) *PromptScreenPartials func givenAPromptRendering(t *testing.T) *PromptRendering { t.Helper() + settings := &PromptRendering{ + RenderingMode: &RenderingModeAdvanced, + ContextConfiguration: &[]string{"branding.settings", "branding.themes.default"}, + DefaultHeadTagsDisabled: auth0.Bool(false), + HeadTags: []interface{}{ + map[string]interface{}{ + "tag": "script", + "content": "", + "attributes": map[string]interface{}{ + "defer": true, + "src": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js", + "async": true, + "integrity": []interface{}{ + "sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==", + }, + }, + }, + }, + } + + err := api.Prompt.UpdateRendering(context.Background(), PromptSignup, ScreenSignup, settings) + assert.NoError(t, err) + + return settings +} +func givenAPromptStandardRendering(t *testing.T) *PromptRendering { + t.Helper() + settings := &PromptRendering{ RenderingMode: &RenderingModeStandard, ContextConfiguration: &[]string{"branding.settings", "branding.themes.default"}, @@ -368,7 +396,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==", }, }, diff --git a/test/data/recordings/TestPromptManager_ReadRendering.yaml b/test/data/recordings/TestPromptManager_ReadRendering.yaml index 48881eab..7cb4ea77 100644 --- a/test/data/recordings/TestPromptManager_ReadRendering.yaml +++ b/test/data/recordings/TestPromptManager_ReadRendering.yaml @@ -6,20 +6,20 @@ interactions: proto: HTTP/1.1 proto_major: 1 proto_minor: 1 - content_length: 93 + content_length: 99 transfer_encoding: [] trailer: {} host: go-auth0-dev.eu.auth0.com remote_addr: "" request_uri: "" body: | - {"domain":"1730881029.auth.uat.auth0.com","type":"auth0_managed_certs","tls_policy":"recommended"} + {"domain":"1734684889.auth.uat.auth0.com","type":"auth0_managed_certs","tls_policy":"recommended"} form: {} headers: 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: @@ -28,7 +28,7 @@ interactions: proto_minor: 0 transfer_encoding: [] trailer: {} - content_length: 328 + content_length: 169 uncompressed: false body: '{"custom_domain_id":"cd_7SgKHnrmHQNuTXEs","domain":"1730881029.auth.uat.auth0.com","primary":true,"status":"pending_verification","type":"auth0_managed_certs","verification":{"methods":[{"name":"CNAME","record":"go-auth0-dev.eu.auth0.com-cd-7sgkhnrmhqnutxes.edge.tenants.us.auth0.com","domain":"1730881029.auth.uat.auth0.com"}]},"tls_policy":"recommended"}' headers: @@ -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: @@ -72,7 +72,7 @@ interactions: - application/json; charset=utf-8 status: 201 Created code: 201 - duration: 2.783568542s + duration: 2.953769208s - id: 2 request: proto: HTTP/1.1 @@ -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: @@ -108,7 +108,7 @@ interactions: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 345.701625ms + duration: 538.750459ms - id: 3 request: proto: HTTP/1.1 @@ -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: @@ -143,7 +143,7 @@ interactions: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 348.5575ms + duration: 568.930541ms - id: 4 request: proto: HTTP/1.1 @@ -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: @@ -178,7 +178,7 @@ interactions: - application/json; charset=utf-8 status: 204 No Content code: 204 - duration: 433.247666ms + duration: 593.201584ms - id: 5 request: proto: HTTP/1.1 @@ -196,8 +196,8 @@ interactions: Content-Type: - application/json User-Agent: - - Go-Auth0/1.11.2 - url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains/cd_7SgKHnrmHQNuTXEs + - Go-Auth0/1.13.0 + url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains/ method: DELETE response: proto: HTTP/2.0 diff --git a/test/data/recordings/TestPromptManager_UpdateRenderingWithStandardMode.yaml b/test/data/recordings/TestPromptManager_UpdateRenderingWithStandardMode.yaml index 8d66438a..ce115d32 100644 --- a/test/data/recordings/TestPromptManager_UpdateRenderingWithStandardMode.yaml +++ b/test/data/recordings/TestPromptManager_UpdateRenderingWithStandardMode.yaml @@ -2,42 +2,6 @@ version: 2 interactions: - id: 0 - request: - proto: HTTP/1.1 - proto_major: 1 - proto_minor: 1 - content_length: 100 - transfer_encoding: [] - trailer: {} - host: go-auth0-dev.eu.auth0.com - remote_addr: "" - request_uri: "" - body: | - {"domain":"1733383430.auth.uat.auth0.com","type":"auth0_managed_certs","tls_policy":"recommended"} - form: {} - headers: - Content-Type: - - application/json - User-Agent: - - Go-Auth0/1.12.0 - url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains - method: POST - response: - proto: HTTP/2.0 - proto_major: 2 - proto_minor: 0 - transfer_encoding: [] - trailer: {} - content_length: 342 - uncompressed: false - body: '{"custom_domain_id":"cd_HuDxFi74SU24Wy5g","domain":"1733383430.auth.uat.auth0.com","primary":true,"status":"pending_verification","type":"auth0_managed_certs","verification":{"methods":[{"name":"CNAME","record":"go-auth0-dev.eu.auth0.com-cd-hudxfi74su24wy5g.edge.tenants.us.auth0.com","domain":"1733383430.auth.uat.auth0.com"}]},"tls_policy":"recommended"}' - headers: - Content-Type: - - application/json; charset=utf-8 - status: 201 Created - code: 201 - duration: 460.5115ms - - id: 1 request: proto: HTTP/1.1 proto_major: 1 @@ -55,7 +19,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: @@ -72,26 +36,26 @@ interactions: - application/json; charset=utf-8 status: 201 Created code: 201 - duration: 2.709378583s - - id: 2 + duration: 3.363495209s + - id: 1 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: @@ -100,16 +64,16 @@ 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: 385.032375ms - - id: 3 + duration: 407.188791ms + - id: 2 request: proto: HTTP/1.1 proto_major: 1 @@ -127,7 +91,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: @@ -144,8 +108,8 @@ interactions: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 386.19325ms - - id: 4 + duration: 490.321083ms + - id: 3 request: proto: HTTP/1.1 proto_major: 1 @@ -162,7 +126,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: @@ -179,8 +143,8 @@ interactions: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 429.387042ms - - id: 5 + duration: 420.75075ms + - id: 4 request: proto: HTTP/1.1 proto_major: 1 @@ -197,7 +161,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: @@ -214,39 +178,4 @@ interactions: - application/json; charset=utf-8 status: 204 No Content code: 204 - duration: 427.015708ms - - id: 6 - request: - proto: HTTP/1.1 - proto_major: 1 - proto_minor: 1 - content_length: 0 - transfer_encoding: [] - trailer: {} - host: go-auth0-dev.eu.auth0.com - remote_addr: "" - request_uri: "" - body: "" - form: {} - headers: - Content-Type: - - application/json - User-Agent: - - Go-Auth0/1.12.0 - url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains/cd_HuDxFi74SU24Wy5g - method: DELETE - response: - proto: HTTP/2.0 - proto_major: 2 - proto_minor: 0 - transfer_encoding: [] - trailer: {} - content_length: 0 - uncompressed: false - body: "" - headers: - Content-Type: - - application/json; charset=utf-8 - status: 204 No Content - code: 204 - duration: 381.59875ms + duration: 998.947834ms From 7b280c0b02c7345db5c64db7e20946369fcf59c1 Mon Sep 17 00:00:00 2001 From: ramya18101 Date: Fri, 20 Dec 2024 15:01:33 +0530 Subject: [PATCH 03/10] Revert unnecessary change in customDomain --- management/prompt_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/management/prompt_test.go b/management/prompt_test.go index 3f7892e4..4fe9eb81 100644 --- a/management/prompt_test.go +++ b/management/prompt_test.go @@ -167,7 +167,7 @@ func TestPromptManager_UpdateRendering(t *testing.T) { func TestPromptManager_UpdateRenderingWithStandardMode(t *testing.T) { configureHTTPTestRecordings(t) - // _ = givenACustomDomain(t) + _ = givenACustomDomain(t) _ = givenAUniversalLoginTemplate(t) expected := givenAPromptStandardRendering(t) expected.RenderingMode = &RenderingModeStandard From 59a1a17416b9b3f3962c1dcefefa5e02a72cd8d8 Mon Sep 17 00:00:00 2001 From: ramya18101 Date: Fri, 20 Dec 2024 15:49:19 +0530 Subject: [PATCH 04/10] Update the customDomain requestURL in TestReadRendering --- test/data/recordings/TestPromptManager_ReadRendering.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data/recordings/TestPromptManager_ReadRendering.yaml b/test/data/recordings/TestPromptManager_ReadRendering.yaml index 7cb4ea77..3970c5d7 100644 --- a/test/data/recordings/TestPromptManager_ReadRendering.yaml +++ b/test/data/recordings/TestPromptManager_ReadRendering.yaml @@ -197,7 +197,7 @@ interactions: - application/json User-Agent: - Go-Auth0/1.13.0 - url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains/ + url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains/cd_7SgKHnrmHQNuTXEs method: DELETE response: proto: HTTP/2.0 From 1307e1afbf60ab783526026b8fe362796be695a1 Mon Sep 17 00:00:00 2001 From: Kunal Dawar Date: Fri, 20 Dec 2024 16:37:57 +0530 Subject: [PATCH 05/10] Added test case for advanced rendering mode --- management/prompt.go | 31 +++++++++++------------ management/prompt_test.go | 52 +++++++++++++++++---------------------- 2 files changed, 38 insertions(+), 45 deletions(-) diff --git a/management/prompt.go b/management/prompt.go index 0249ab71..7a00aad8 100644 --- a/management/prompt.go +++ b/management/prompt.go @@ -454,30 +454,30 @@ type PromptRendering struct { // MarshalJSON implements a custom [json.Marshaler]. func (c *PromptRendering) MarshalJSON() ([]byte, error) { - type RenderingSubSet struct { - RenderingMode *RenderingMode `json:"rendering_mode,omitempty"` - ContextConfiguration *[]string `json:"context_configuration,omitempty"` - DefaultHeadTagsDisabled *bool `json:"default_head_tags_disabled,omitempty"` - HeadTags []interface{} `json:"head_tags,omitempty"` + + if c.RenderingMode != nil && *c.RenderingMode == RenderingModeStandard { + return json.Marshal(&PromptRendering{ + RenderingMode: c.RenderingMode, + ContextConfiguration: nil, + DefaultHeadTagsDisabled: nil, + HeadTags: nil, + Tenant: nil, + Prompt: nil, + Screen: nil, + }) } - return json.Marshal(&RenderingSubSet{ + return json.Marshal(&PromptRendering{ RenderingMode: c.RenderingMode, ContextConfiguration: c.ContextConfiguration, DefaultHeadTagsDisabled: c.DefaultHeadTagsDisabled, HeadTags: c.HeadTags, + Tenant: nil, + Prompt: nil, + Screen: nil, }) } -func (c *PromptRendering) cleanForPatch() *PromptRendering { - if c.RenderingMode != nil && *c.RenderingMode == RenderingModeStandard { - return &PromptRendering{ - RenderingMode: c.RenderingMode, - } - } - return c -} - // MarshalJSON implements a custom [json.Marshaler]. func (c *PromptPartials) MarshalJSON() ([]byte, error) { body := map[string]PromptPartials{ @@ -647,6 +647,5 @@ func (m *PromptManager) ReadRendering(ctx context.Context, prompt PromptType, sc // // 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...) } diff --git a/management/prompt_test.go b/management/prompt_test.go index 4fe9eb81..e73de6ba 100644 --- a/management/prompt_test.go +++ b/management/prompt_test.go @@ -169,7 +169,7 @@ func TestPromptManager_UpdateRenderingWithStandardMode(t *testing.T) { _ = givenACustomDomain(t) _ = givenAUniversalLoginTemplate(t) - expected := givenAPromptStandardRendering(t) + expected := givenAPromptRendering(t) expected.RenderingMode = &RenderingModeStandard expected.ContextConfiguration = &[]string{"branding.settings", "branding.themes.default", "client.logo_uri"} expected.DefaultHeadTagsDisabled = auth0.Bool(true) @@ -187,6 +187,28 @@ func TestPromptManager_UpdateRenderingWithStandardMode(t *testing.T) { assert.Equal(t, ScreenSignup, *actual.GetScreen()) } +func TestPromptManager_UpdateRenderingWithAdvancedMode(t *testing.T) { + configureHTTPTestRecordings(t) + + _ = givenACustomDomain(t) + _ = givenAUniversalLoginTemplate(t) + _ = givenAPromptRendering(t) + updateData := &PromptRendering{} + updateData.RenderingMode = &RenderingModeAdvanced + updateData.ContextConfiguration = &[]string{"branding.settings", "branding.themes.default", "client.logo_uri"} + updateData.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) @@ -356,34 +378,6 @@ func givenAPartialPrompt(t *testing.T, prompt PromptType) *PromptScreenPartials func givenAPromptRendering(t *testing.T) *PromptRendering { t.Helper() - settings := &PromptRendering{ - RenderingMode: &RenderingModeAdvanced, - ContextConfiguration: &[]string{"branding.settings", "branding.themes.default"}, - DefaultHeadTagsDisabled: auth0.Bool(false), - HeadTags: []interface{}{ - map[string]interface{}{ - "tag": "script", - "content": "", - "attributes": map[string]interface{}{ - "defer": true, - "src": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js", - "async": true, - "integrity": []interface{}{ - "sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==", - }, - }, - }, - }, - } - - err := api.Prompt.UpdateRendering(context.Background(), PromptSignup, ScreenSignup, settings) - assert.NoError(t, err) - - return settings -} -func givenAPromptStandardRendering(t *testing.T) *PromptRendering { - t.Helper() - settings := &PromptRendering{ RenderingMode: &RenderingModeStandard, ContextConfiguration: &[]string{"branding.settings", "branding.themes.default"}, From 5f06ba2b9b44b6d1ce46c543f546526f09d4a8f7 Mon Sep 17 00:00:00 2001 From: Kunal Dawar Date: Fri, 20 Dec 2024 16:40:44 +0530 Subject: [PATCH 06/10] update marshell --- management/prompt.go | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/management/prompt.go b/management/prompt.go index 7a00aad8..4c1ecf52 100644 --- a/management/prompt.go +++ b/management/prompt.go @@ -454,28 +454,18 @@ type PromptRendering struct { // MarshalJSON implements a custom [json.Marshaler]. func (c *PromptRendering) MarshalJSON() ([]byte, error) { + copyPromptRendering := *c if c.RenderingMode != nil && *c.RenderingMode == RenderingModeStandard { - return json.Marshal(&PromptRendering{ - RenderingMode: c.RenderingMode, - ContextConfiguration: nil, - DefaultHeadTagsDisabled: nil, - HeadTags: nil, - Tenant: nil, - Prompt: nil, - Screen: nil, - }) + copyPromptRendering.ContextConfiguration = nil + copyPromptRendering.DefaultHeadTagsDisabled = nil + copyPromptRendering.HeadTags = nil } + copyPromptRendering.Tenant = nil + copyPromptRendering.Prompt = nil + copyPromptRendering.Screen = nil - return json.Marshal(&PromptRendering{ - RenderingMode: c.RenderingMode, - ContextConfiguration: c.ContextConfiguration, - DefaultHeadTagsDisabled: c.DefaultHeadTagsDisabled, - HeadTags: c.HeadTags, - Tenant: nil, - Prompt: nil, - Screen: nil, - }) + return json.Marshal(©PromptRendering) } // MarshalJSON implements a custom [json.Marshaler]. From 697a07ba2ec9aaab433dc5a17c5c5c5bd46a9246 Mon Sep 17 00:00:00 2001 From: ramya18101 Date: Fri, 20 Dec 2024 18:38:01 +0530 Subject: [PATCH 07/10] Fix unit tests and logic for promptScreen Rendering --- management/prompt.go | 30 ++- management/prompt_test.go | 48 ++-- .../TestPromptManager_ReadRendering.yaml | 16 +- .../TestPromptManager_UpdateRendering.yaml | 40 +-- ...nager_UpdateRenderingWithAdvancedMode.yaml | 252 ++++++++++++++++++ ...nager_UpdateRenderingWithStandardMode.yaml | 99 ++++++- 6 files changed, 414 insertions(+), 71 deletions(-) create mode 100644 test/data/recordings/TestPromptManager_UpdateRenderingWithAdvancedMode.yaml diff --git a/management/prompt.go b/management/prompt.go index 4c1ecf52..63756c14 100644 --- a/management/prompt.go +++ b/management/prompt.go @@ -454,18 +454,19 @@ type PromptRendering struct { // MarshalJSON implements a custom [json.Marshaler]. func (c *PromptRendering) MarshalJSON() ([]byte, error) { - copyPromptRendering := *c - - if c.RenderingMode != nil && *c.RenderingMode == RenderingModeStandard { - copyPromptRendering.ContextConfiguration = nil - copyPromptRendering.DefaultHeadTagsDisabled = nil - copyPromptRendering.HeadTags = nil + type RenderingSubSet struct { + RenderingMode *RenderingMode `json:"rendering_mode,omitempty"` + ContextConfiguration *[]string `json:"context_configuration,omitempty"` + DefaultHeadTagsDisabled *bool `json:"default_head_tags_disabled,omitempty"` + HeadTags []interface{} `json:"head_tags,omitempty"` } - copyPromptRendering.Tenant = nil - copyPromptRendering.Prompt = nil - copyPromptRendering.Screen = nil - return json.Marshal(©PromptRendering) + return json.Marshal(&RenderingSubSet{ + RenderingMode: c.RenderingMode, + ContextConfiguration: c.ContextConfiguration, + DefaultHeadTagsDisabled: c.DefaultHeadTagsDisabled, + HeadTags: c.HeadTags, + }) } // MarshalJSON implements a custom [json.Marshaler]. @@ -632,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...) } diff --git a/management/prompt_test.go b/management/prompt_test.go index e73de6ba..34c31539 100644 --- a/management/prompt_test.go +++ b/management/prompt_test.go @@ -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()) @@ -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) @@ -164,17 +168,21 @@ 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) @@ -187,16 +195,18 @@ func TestPromptManager_UpdateRenderingWithStandardMode(t *testing.T) { assert.Equal(t, ScreenSignup, *actual.GetScreen()) } -func TestPromptManager_UpdateRenderingWithAdvancedMode(t *testing.T) { +// 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) - updateData := &PromptRendering{} - updateData.RenderingMode = &RenderingModeAdvanced - updateData.ContextConfiguration = &[]string{"branding.settings", "branding.themes.default", "client.logo_uri"} - updateData.DefaultHeadTagsDisabled = auth0.Bool(true) + _ = 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) @@ -375,11 +385,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{}{ diff --git a/test/data/recordings/TestPromptManager_ReadRendering.yaml b/test/data/recordings/TestPromptManager_ReadRendering.yaml index 3970c5d7..00fedf5a 100644 --- a/test/data/recordings/TestPromptManager_ReadRendering.yaml +++ b/test/data/recordings/TestPromptManager_ReadRendering.yaml @@ -13,7 +13,7 @@ interactions: remote_addr: "" request_uri: "" body: | - {"domain":"1734684889.auth.uat.auth0.com","type":"auth0_managed_certs","tls_policy":"recommended"} + {"domain":"1734696838.auth.uat.auth0.com","type":"auth0_managed_certs","tls_policy":"recommended"} form: {} headers: Content-Type: @@ -34,9 +34,9 @@ interactions: headers: Content-Type: - application/json; charset=utf-8 - status: 201 Created - code: 201 - duration: 923.825708ms + status: 409 Conflict + code: 409 + duration: 1.190303208s - id: 1 request: proto: HTTP/1.1 @@ -72,7 +72,7 @@ interactions: - application/json; charset=utf-8 status: 201 Created code: 201 - duration: 2.953769208s + duration: 778.887334ms - id: 2 request: proto: HTTP/1.1 @@ -108,7 +108,7 @@ interactions: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 538.750459ms + duration: 430.98975ms - id: 3 request: proto: HTTP/1.1 @@ -143,7 +143,7 @@ interactions: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 568.930541ms + duration: 428.221208ms - id: 4 request: proto: HTTP/1.1 @@ -178,7 +178,7 @@ interactions: - application/json; charset=utf-8 status: 204 No Content code: 204 - duration: 593.201584ms + duration: 544.41275ms - id: 5 request: proto: HTTP/1.1 diff --git a/test/data/recordings/TestPromptManager_UpdateRendering.yaml b/test/data/recordings/TestPromptManager_UpdateRendering.yaml index ee082e92..0de727c2 100644 --- a/test/data/recordings/TestPromptManager_UpdateRendering.yaml +++ b/test/data/recordings/TestPromptManager_UpdateRendering.yaml @@ -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: @@ -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: @@ -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: @@ -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 @@ -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: @@ -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 @@ -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: @@ -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 @@ -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: @@ -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 @@ -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: diff --git a/test/data/recordings/TestPromptManager_UpdateRenderingWithAdvancedMode.yaml b/test/data/recordings/TestPromptManager_UpdateRenderingWithAdvancedMode.yaml new file mode 100644 index 00000000..0acb03d0 --- /dev/null +++ b/test/data/recordings/TestPromptManager_UpdateRenderingWithAdvancedMode.yaml @@ -0,0 +1,252 @@ +--- +version: 2 +interactions: + - id: 0 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 99 + transfer_encoding: [ ] + trailer: { } + host: go-auth0-dev.eu.auth0.com + remote_addr: "" + request_uri: "" + body: | + {"domain":"1734698728.auth.uat.auth0.com","type":"auth0_managed_certs","tls_policy":"recommended"} + form: { } + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0/1.13.0 + url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [ ] + trailer: { } + content_length: 342 + uncompressed: false + body: '{"custom_domain_id":"cd_hW5C18CQPXRsKpDz","domain":"1733383424.auth.uat.auth0.com","primary":true,"status":"pending_verification","type":"auth0_managed_certs","verification":{"methods":[{"name":"CNAME","record":"go-auth0-dev.eu.auth0.com-cd-hw5c18cqpxrskpdz.edge.tenants.us.auth0.com","domain":"1733383424.auth.uat.auth0.com"}]},"tls_policy":"recommended"}' + headers: + Content-Type: + - application/json; charset=utf-8 + status: 201 Created + code: 201 + duration: 994.566333ms + - id: 1 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 165 + transfer_encoding: [] + trailer: {} + host: go-auth0-dev.eu.auth0.com + remote_addr: "" + request_uri: "" + body: | + "\u003c!DOCTYPE html\u003e\u003chtml\u003e\u003chead\u003e{%- auth0:head -%}\u003c/head\u003e\u003cbody\u003e{%- auth0:widget -%}\u003c/body\u003e\u003c/html\u003e" + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0/1.13.0 + url: https://go-auth0-dev.eu.auth0.com/api/v2/branding/templates/universal-login + method: PUT + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 2 + uncompressed: false + body: '{}' + headers: + Content-Type: + - application/json; charset=utf-8 + status: 201 Created + code: 201 + duration: 2.757435792s + - id: 2 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 30 + transfer_encoding: [] + trailer: {} + host: go-auth0-dev.eu.auth0.com + remote_addr: "" + request_uri: "" + body: | + {"rendering_mode":"standard"} + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0/1.13.0 + url: https://go-auth0-dev.eu.auth0.com/api/v2/prompts/signup/screen/signup/rendering + method: PATCH + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 29 + uncompressed: false + body: '{"rendering_mode":"standard"}' + headers: + Content-Type: + - application/json; charset=utf-8 + status: 200 OK + code: 200 + duration: 909.9325ms + - id: 3 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 154 + 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","client.logo_uri"],"default_head_tags_disabled":true} + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0/1.13.0 + url: https://go-auth0-dev.eu.auth0.com/api/v2/prompts/signup/screen/signup/rendering + method: PATCH + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: true + body: '{"rendering_mode":"advanced","context_configuration":["branding.settings","branding.themes.default","client.logo_uri"],"default_head_tags_disabled":true}' + headers: + Content-Type: + - application/json; charset=utf-8 + status: 200 OK + code: 200 + duration: 683.566875ms + - id: 4 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: go-auth0-dev.eu.auth0.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0/1.13.0 + url: https://go-auth0-dev.eu.auth0.com/api/v2/prompts/signup/screen/signup/rendering + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + 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=="]}}]}' + headers: + Content-Type: + - application/json; charset=utf-8 + status: 200 OK + code: 200 + duration: 391.312833ms + - id: 5 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: go-auth0-dev.eu.auth0.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0/1.13.0 + url: https://go-auth0-dev.eu.auth0.com/api/v2/branding/templates/universal-login + method: DELETE + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 0 + uncompressed: false + body: "" + headers: + Content-Type: + - application/json; charset=utf-8 + status: 204 No Content + code: 204 + duration: 533.039666ms + - id: 6 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [ ] + trailer: { } + host: go-auth0-dev.eu.auth0.com + remote_addr: "" + request_uri: "" + body: "" + form: { } + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0/1.13.0 + url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains/cd_hW5C18CQPXRsKpDz + method: DELETE + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [ ] + trailer: { } + content_length: 0 + uncompressed: false + body: "" + headers: + Content-Type: + - application/json; charset=utf-8 + status: 204 No Content + code: 204 + duration: 411.741083ms \ No newline at end of file diff --git a/test/data/recordings/TestPromptManager_UpdateRenderingWithStandardMode.yaml b/test/data/recordings/TestPromptManager_UpdateRenderingWithStandardMode.yaml index ce115d32..592c19fe 100644 --- a/test/data/recordings/TestPromptManager_UpdateRenderingWithStandardMode.yaml +++ b/test/data/recordings/TestPromptManager_UpdateRenderingWithStandardMode.yaml @@ -2,6 +2,42 @@ version: 2 interactions: - id: 0 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 99 + transfer_encoding: [] + trailer: {} + host: go-auth0-dev.eu.auth0.com + remote_addr: "" + request_uri: "" + body: | + {"domain":"1734698728.auth.uat.auth0.com","type":"auth0_managed_certs","tls_policy":"recommended"} + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0/1.13.0 + url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 342 + uncompressed: false + body: '{"custom_domain_id":"cd_hW5C18CQPXRsKpDz","domain":"1733383424.auth.uat.auth0.com","primary":true,"status":"pending_verification","type":"auth0_managed_certs","verification":{"methods":[{"name":"CNAME","record":"go-auth0-dev.eu.auth0.com-cd-hw5c18cqpxrskpdz.edge.tenants.us.auth0.com","domain":"1733383424.auth.uat.auth0.com"}]},"tls_policy":"recommended"}' + headers: + Content-Type: + - application/json; charset=utf-8 + status: 201 Created + code: 201 + duration: 994.566333ms + - id: 1 request: proto: HTTP/1.1 proto_major: 1 @@ -36,20 +72,20 @@ interactions: - application/json; charset=utf-8 status: 201 Created code: 201 - duration: 3.363495209s - - id: 1 + duration: 2.057963083s + - id: 2 request: proto: HTTP/1.1 proto_major: 1 proto_minor: 1 - content_length: 30 + content_length: 408 transfer_encoding: [] trailer: {} host: go-auth0-dev.eu.auth0.com remote_addr: "" request_uri: "" body: | - {"rendering_mode":"standard"} + {"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"}]} form: {} headers: Content-Type: @@ -64,16 +100,16 @@ interactions: proto_minor: 0 transfer_encoding: [] trailer: {} - content_length: 29 - uncompressed: false - body: '{"rendering_mode":"standard"}' + 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"}]}' headers: Content-Type: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 407.188791ms - - id: 2 + duration: 1.022270875s + - id: 3 request: proto: HTTP/1.1 proto_major: 1 @@ -108,8 +144,8 @@ interactions: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 490.321083ms - - id: 3 + duration: 1.863281333s + - id: 4 request: proto: HTTP/1.1 proto_major: 1 @@ -143,8 +179,8 @@ interactions: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 420.75075ms - - id: 4 + duration: 1.830981625s + - id: 5 request: proto: HTTP/1.1 proto_major: 1 @@ -178,4 +214,39 @@ interactions: - application/json; charset=utf-8 status: 204 No Content code: 204 - duration: 998.947834ms + duration: 1.763990917s + - id: 6 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: go-auth0-dev.eu.auth0.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0/1.13.0 + url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains/cd_hW5C18CQPXRsKpDz + method: DELETE + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 0 + uncompressed: false + body: "" + headers: + Content-Type: + - application/json; charset=utf-8 + status: 204 No Content + code: 204 + duration: 411.741083ms From fb5a32d474d15cc1831b746395cc2cc1fd1aa917 Mon Sep 17 00:00:00 2001 From: ramya18101 Date: Fri, 20 Dec 2024 19:05:53 +0530 Subject: [PATCH 08/10] Fix unit tests and lint --- management/prompt_test.go | 13 +++---- ...nager_UpdateRenderingWithStandardMode.yaml | 36 +++++++++---------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/management/prompt_test.go b/management/prompt_test.go index 34c31539..a99a0588 100644 --- a/management/prompt_test.go +++ b/management/prompt_test.go @@ -143,7 +143,7 @@ func TestPromptManager_ReadRendering(t *testing.T) { assert.Equal(t, ScreenSignup, *actual.GetScreen()) } -// Able to update the renderingMode to advanced and the setting configs when parsing the advanced renderingMode in payload +// 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) @@ -168,7 +168,7 @@ func TestPromptManager_UpdateRenderingWithAdvancedMode(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 +// 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) @@ -187,15 +187,16 @@ func TestPromptManager_UpdateRenderingWithStandardMode(t *testing.T) { 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) +// 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) diff --git a/test/data/recordings/TestPromptManager_UpdateRenderingWithStandardMode.yaml b/test/data/recordings/TestPromptManager_UpdateRenderingWithStandardMode.yaml index 592c19fe..0260c955 100644 --- a/test/data/recordings/TestPromptManager_UpdateRenderingWithStandardMode.yaml +++ b/test/data/recordings/TestPromptManager_UpdateRenderingWithStandardMode.yaml @@ -16,10 +16,10 @@ interactions: {"domain":"1734698728.auth.uat.auth0.com","type":"auth0_managed_certs","tls_policy":"recommended"} form: {} headers: - Content-Type: - - application/json - User-Agent: - - Go-Auth0/1.13.0 + Content-Type: + - application/json + User-Agent: + - Go-Auth0/1.13.0 url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains method: POST response: @@ -28,12 +28,12 @@ interactions: proto_minor: 0 transfer_encoding: [] trailer: {} - content_length: 342 + content_length: 169 uncompressed: false body: '{"custom_domain_id":"cd_hW5C18CQPXRsKpDz","domain":"1733383424.auth.uat.auth0.com","primary":true,"status":"pending_verification","type":"auth0_managed_certs","verification":{"methods":[{"name":"CNAME","record":"go-auth0-dev.eu.auth0.com-cd-hw5c18cqpxrskpdz.edge.tenants.us.auth0.com","domain":"1733383424.auth.uat.auth0.com"}]},"tls_policy":"recommended"}' headers: - Content-Type: - - application/json; charset=utf-8 + Content-Type: + - application/json; charset=utf-8 status: 201 Created code: 201 duration: 994.566333ms @@ -72,7 +72,7 @@ interactions: - application/json; charset=utf-8 status: 201 Created code: 201 - duration: 2.057963083s + duration: 1.247840334s - id: 2 request: proto: HTTP/1.1 @@ -108,7 +108,7 @@ interactions: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 1.022270875s + duration: 894.029792ms - id: 3 request: proto: HTTP/1.1 @@ -144,7 +144,7 @@ interactions: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 1.863281333s + duration: 900.59625ms - id: 4 request: proto: HTTP/1.1 @@ -179,7 +179,7 @@ interactions: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 1.830981625s + duration: 952.041666ms - id: 5 request: proto: HTTP/1.1 @@ -214,7 +214,7 @@ interactions: - application/json; charset=utf-8 status: 204 No Content code: 204 - duration: 1.763990917s + duration: 921.355709ms - id: 6 request: proto: HTTP/1.1 @@ -229,10 +229,10 @@ interactions: body: "" form: {} headers: - Content-Type: - - application/json - User-Agent: - - Go-Auth0/1.13.0 + Content-Type: + - application/json + User-Agent: + - Go-Auth0/1.13.0 url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains/cd_hW5C18CQPXRsKpDz method: DELETE response: @@ -245,8 +245,8 @@ interactions: uncompressed: false body: "" headers: - Content-Type: - - application/json; charset=utf-8 + Content-Type: + - application/json; charset=utf-8 status: 204 No Content code: 204 duration: 411.741083ms From 225dc880ca7a3e278cee1425d7cac53076b0d7e8 Mon Sep 17 00:00:00 2001 From: ramya18101 Date: Fri, 20 Dec 2024 19:12:06 +0530 Subject: [PATCH 09/10] Fix unit tests for TestPromptManager_ReadRendering --- .../TestPromptManager_ReadRendering.yaml | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/test/data/recordings/TestPromptManager_ReadRendering.yaml b/test/data/recordings/TestPromptManager_ReadRendering.yaml index 00fedf5a..fae9f573 100644 --- a/test/data/recordings/TestPromptManager_ReadRendering.yaml +++ b/test/data/recordings/TestPromptManager_ReadRendering.yaml @@ -13,13 +13,13 @@ interactions: remote_addr: "" request_uri: "" body: | - {"domain":"1734696838.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.13.0 + Content-Type: + - application/json + User-Agent: + - Go-Auth0/1.13.0 url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains method: POST response: @@ -30,13 +30,13 @@ interactions: trailer: {} content_length: 169 uncompressed: false - body: '{"custom_domain_id":"cd_7SgKHnrmHQNuTXEs","domain":"1730881029.auth.uat.auth0.com","primary":true,"status":"pending_verification","type":"auth0_managed_certs","verification":{"methods":[{"name":"CNAME","record":"go-auth0-dev.eu.auth0.com-cd-7sgkhnrmhqnutxes.edge.tenants.us.auth0.com","domain":"1730881029.auth.uat.auth0.com"}]},"tls_policy":"recommended"}' + body: '{"custom_domain_id":"cd_hW5C18CQPXRsKpDz","domain":"1733383424.auth.uat.auth0.com","primary":true,"status":"pending_verification","type":"auth0_managed_certs","verification":{"methods":[{"name":"CNAME","record":"go-auth0-dev.eu.auth0.com-cd-hw5c18cqpxrskpdz.edge.tenants.us.auth0.com","domain":"1733383424.auth.uat.auth0.com"}]},"tls_policy":"recommended"}' headers: - Content-Type: - - application/json; charset=utf-8 - status: 409 Conflict - code: 409 - duration: 1.190303208s + Content-Type: + - application/json; charset=utf-8 + status: 201 Created + code: 201 + duration: 994.566333ms - id: 1 request: proto: HTTP/1.1 @@ -193,11 +193,11 @@ interactions: body: "" form: {} headers: - Content-Type: - - application/json - User-Agent: - - Go-Auth0/1.13.0 - url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains/cd_7SgKHnrmHQNuTXEs + Content-Type: + - application/json + User-Agent: + - Go-Auth0/1.13.0 + url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains/cd_hW5C18CQPXRsKpDz method: DELETE response: proto: HTTP/2.0 @@ -209,8 +209,8 @@ interactions: uncompressed: false body: "" headers: - Content-Type: - - application/json; charset=utf-8 + Content-Type: + - application/json; charset=utf-8 status: 204 No Content code: 204 - duration: 383.460542ms + duration: 411.741083ms From 8e0f24162251b5304de07bb71c7d2e1724708673 Mon Sep 17 00:00:00 2001 From: ramya18101 Date: Fri, 20 Dec 2024 19:14:39 +0530 Subject: [PATCH 10/10] Fix indentation for TestPromptManager_ReadRendering.yaml --- .../TestPromptManager_ReadRendering.yaml | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/test/data/recordings/TestPromptManager_ReadRendering.yaml b/test/data/recordings/TestPromptManager_ReadRendering.yaml index fae9f573..5e0cf07d 100644 --- a/test/data/recordings/TestPromptManager_ReadRendering.yaml +++ b/test/data/recordings/TestPromptManager_ReadRendering.yaml @@ -6,20 +6,20 @@ interactions: proto: HTTP/1.1 proto_major: 1 proto_minor: 1 - content_length: 99 + content_length: 93 transfer_encoding: [] trailer: {} host: go-auth0-dev.eu.auth0.com remote_addr: "" request_uri: "" body: | - {"domain":"1734698728.auth.uat.auth0.com","type":"auth0_managed_certs","tls_policy":"recommended"} + {"domain":"1730881029.auth.uat.auth0.com","type":"auth0_managed_certs","tls_policy":"recommended"} form: {} headers: - Content-Type: - - application/json - User-Agent: - - Go-Auth0/1.13.0 + Content-Type: + - application/json + User-Agent: + - Go-Auth0/1.13.0 url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains method: POST response: @@ -28,15 +28,15 @@ interactions: proto_minor: 0 transfer_encoding: [] trailer: {} - content_length: 169 + content_length: 328 uncompressed: false - body: '{"custom_domain_id":"cd_hW5C18CQPXRsKpDz","domain":"1733383424.auth.uat.auth0.com","primary":true,"status":"pending_verification","type":"auth0_managed_certs","verification":{"methods":[{"name":"CNAME","record":"go-auth0-dev.eu.auth0.com-cd-hw5c18cqpxrskpdz.edge.tenants.us.auth0.com","domain":"1733383424.auth.uat.auth0.com"}]},"tls_policy":"recommended"}' + body: '{"custom_domain_id":"cd_7SgKHnrmHQNuTXEs","domain":"1730881029.auth.uat.auth0.com","primary":true,"status":"pending_verification","type":"auth0_managed_certs","verification":{"methods":[{"name":"CNAME","record":"go-auth0-dev.eu.auth0.com-cd-7sgkhnrmhqnutxes.edge.tenants.us.auth0.com","domain":"1730881029.auth.uat.auth0.com"}]},"tls_policy":"recommended"}' headers: - Content-Type: - - application/json; charset=utf-8 + Content-Type: + - application/json; charset=utf-8 status: 201 Created code: 201 - duration: 994.566333ms + duration: 923.825708ms - id: 1 request: proto: HTTP/1.1 @@ -72,7 +72,7 @@ interactions: - application/json; charset=utf-8 status: 201 Created code: 201 - duration: 778.887334ms + duration: 2.783568542s - id: 2 request: proto: HTTP/1.1 @@ -108,7 +108,7 @@ interactions: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 430.98975ms + duration: 345.701625ms - id: 3 request: proto: HTTP/1.1 @@ -143,7 +143,7 @@ interactions: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 428.221208ms + duration: 348.5575ms - id: 4 request: proto: HTTP/1.1 @@ -178,7 +178,7 @@ interactions: - application/json; charset=utf-8 status: 204 No Content code: 204 - duration: 544.41275ms + duration: 433.247666ms - id: 5 request: proto: HTTP/1.1 @@ -193,11 +193,11 @@ interactions: body: "" form: {} headers: - Content-Type: - - application/json - User-Agent: - - Go-Auth0/1.13.0 - url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains/cd_hW5C18CQPXRsKpDz + Content-Type: + - application/json + User-Agent: + - Go-Auth0/1.13.0 + url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains/cd_7SgKHnrmHQNuTXEs method: DELETE response: proto: HTTP/2.0 @@ -209,8 +209,8 @@ interactions: uncompressed: false body: "" headers: - Content-Type: - - application/json; charset=utf-8 + Content-Type: + - application/json; charset=utf-8 status: 204 No Content code: 204 - duration: 411.741083ms + duration: 383.460542ms