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 issue when content security policy is null #2043

Merged
merged 1 commit into from
Aug 12, 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
6 changes: 0 additions & 6 deletions examples/resources/okta_customized_signin_page/basic.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,4 @@ resource "okta_customized_signin_page" "test" {
widget_customizations {
widget_generation = "G2"
}
content_security_policy_setting {
mode = "report_only"
report_uri = ""
src_list = ["https://idp.example.com/authorize", "https://idp.example.com/authoriz"]
}
}

19 changes: 19 additions & 0 deletions examples/resources/okta_customized_signin_page/update.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
resource "okta_brand" "test" {
name = "testBrand"
locale = "en"
}

resource "okta_customized_signin_page" "test" {
brand_id = resource.okta_brand.test.id
page_content = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n<head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <meta name=\"robots\" content=\"noindex,nofollow\" />\n <!-- Styles generated from theme -->\n <link href=\"{{themedStylesUrl}}\" rel=\"stylesheet\" type=\"text/css\">\n <!-- Favicon from theme -->\n <link rel=\"shortcut icon\" href=\"{{faviconUrl}}\" type=\"image/x-icon\"/>\n\n <title>{{pageTitle}}</title>\n {{{SignInWidgetResources}}}\n\n <style nonce=\"{{nonceValue}}\">\n #login-bg-image-id {\n background-image: {{bgImageUrl}}\n }\n </style>\n</head>\n<body>\n <div id=\"login-bg-image-id\" class=\"login-bg-image tb--background\"></div>\n <div id=\"okta-login-container\"></div>\n\n <!--\n \"OktaUtil\" defines a global OktaUtil object\n that contains methods used to complete the Okta login flow.\n -->\n {{{OktaUtil}}}\n\n <script type=\"text/javascript\" nonce=\"{{nonceValue}}\">\n // \"config\" object contains default widget configuration\n // with any custom overrides defined in your admin settings.\n var config = OktaUtil.getSignInWidgetConfig();\n\n // Render the Okta Sign-In Widget\n var oktaSignIn = new OktaSignIn(config);\n oktaSignIn.renderEl({ el: '#okta-login-container' },\n OktaUtil.completeLogin,\n function(error) {\n // Logs errors that occur when configuring the widget.\n // Remove or replace this with your own custom error handler.\n console.log(error.message, error);\n }\n );\n </script>\n</body>\n</html>\n"
widget_version = "^6"
widget_customizations {
widget_generation = "G2"
}
content_security_policy_setting {
mode = "report_only"
report_uri = ""
src_list = ["https://idp.example.com/authorize", "https://idp.example.com/authoriz"]
}
}

94 changes: 51 additions & 43 deletions okta/customization.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,53 +114,61 @@ func buildSignInPageRequest(ctx context.Context, model signinPageModel) (okta.Si
sp.SetPageContent(model.PageContent.ValueString())
sp.SetWidgetVersion(model.WidgetVersion.ValueString())

wc := okta.SignInPageAllOfWidgetCustomizations{}
wcm := &widgetCustomizationsModel{}
model.WidgetCustomizations.As(ctx, wcm, basetypes.ObjectAsOptions{})
if !model.WidgetVersion.IsNull() {
wc := okta.SignInPageAllOfWidgetCustomizations{}
wcm := &widgetCustomizationsModel{}
diags := model.WidgetCustomizations.As(ctx, wcm, basetypes.ObjectAsOptions{})
if diags.HasError() {
return *okta.NewSignInPage(), diags
}
wc.SignInLabel = wcm.SignInLabel.ValueStringPointer()
wc.UsernameLabel = wcm.UsernameLabel.ValueStringPointer()
wc.UsernameInfoTip = wcm.UsernameInfoTip.ValueStringPointer()
wc.PasswordLabel = wcm.PasswordLabel.ValueStringPointer()
wc.PasswordInfoTip = wcm.PasswordInfoTip.ValueStringPointer()
wc.ShowPasswordVisibilityToggle = wcm.ShowPasswordVisibilityToggle.ValueBoolPointer()
wc.ShowUserIdentifier = wcm.ShowUserIdentifier.ValueBoolPointer()
wc.ForgotPasswordLabel = wcm.ForgotPasswordLabel.ValueStringPointer()
wc.ForgotPasswordUrl = wcm.ForgotPasswordURL.ValueStringPointer()
wc.UnlockAccountLabel = wcm.UnlockAccountLabel.ValueStringPointer()
wc.UnlockAccountUrl = wcm.UnlockAccountURL.ValueStringPointer()
wc.HelpLabel = wcm.HelpLabel.ValueStringPointer()
wc.HelpUrl = wcm.HelpURL.ValueStringPointer()
wc.CustomLink1Label = wcm.CustomLink1Label.ValueStringPointer()
wc.CustomLink1Url = wcm.CustomLink1URL.ValueStringPointer()
wc.CustomLink2Label = wcm.CustomLink2Label.ValueStringPointer()
wc.CustomLink2Url = wcm.CustomLink2URL.ValueStringPointer()
wc.AuthenticatorPageCustomLinkLabel = wcm.AuthenticatorPageCustomLinkLabel.ValueStringPointer()
wc.AuthenticatorPageCustomLinkUrl = wcm.AuthenticatorPageCustomLinkURL.ValueStringPointer()
wc.ClassicRecoveryFlowEmailOrUsernameLabel = wcm.ClassicRecoveryFlowEmailOrUsernameLabel.ValueStringPointer()
wc.SetWidgetGeneration(wcm.WidgetGeneration.ValueString())

wc.SignInLabel = wcm.SignInLabel.ValueStringPointer()
wc.UsernameLabel = wcm.UsernameLabel.ValueStringPointer()
wc.UsernameInfoTip = wcm.UsernameInfoTip.ValueStringPointer()
wc.PasswordLabel = wcm.PasswordLabel.ValueStringPointer()
wc.PasswordInfoTip = wcm.PasswordInfoTip.ValueStringPointer()
wc.ShowPasswordVisibilityToggle = wcm.ShowPasswordVisibilityToggle.ValueBoolPointer()
wc.ShowUserIdentifier = wcm.ShowUserIdentifier.ValueBoolPointer()
wc.ForgotPasswordLabel = wcm.ForgotPasswordLabel.ValueStringPointer()
wc.ForgotPasswordUrl = wcm.ForgotPasswordURL.ValueStringPointer()
wc.UnlockAccountLabel = wcm.UnlockAccountLabel.ValueStringPointer()
wc.UnlockAccountUrl = wcm.UnlockAccountURL.ValueStringPointer()
wc.HelpLabel = wcm.HelpLabel.ValueStringPointer()
wc.HelpUrl = wcm.HelpURL.ValueStringPointer()
wc.CustomLink1Label = wcm.CustomLink1Label.ValueStringPointer()
wc.CustomLink1Url = wcm.CustomLink1URL.ValueStringPointer()
wc.CustomLink2Label = wcm.CustomLink2Label.ValueStringPointer()
wc.CustomLink2Url = wcm.CustomLink2URL.ValueStringPointer()
wc.AuthenticatorPageCustomLinkLabel = wcm.AuthenticatorPageCustomLinkLabel.ValueStringPointer()
wc.AuthenticatorPageCustomLinkUrl = wcm.AuthenticatorPageCustomLinkURL.ValueStringPointer()
wc.ClassicRecoveryFlowEmailOrUsernameLabel = wcm.ClassicRecoveryFlowEmailOrUsernameLabel.ValueStringPointer()
wc.SetWidgetGeneration(wcm.WidgetGeneration.ValueString())
sp.SetWidgetCustomizations(wc)
}

sp.SetWidgetCustomizations(wc)
if !model.ContentSecurityPolicySetting.IsNull() {
csp := okta.ContentSecurityPolicySetting{}
cspm := &contentSecurityPolicySettingModel{}
diags := model.ContentSecurityPolicySetting.As(ctx, cspm, basetypes.ObjectAsOptions{})
if diags.HasError() {
return *okta.NewSignInPage(), diags
}
csp.Mode = cspm.Mode.ValueStringPointer()
csp.ReportUri = cspm.ReportUri.ValueStringPointer()
elements := make([]types.String, 0, len(cspm.SrcList.Elements()))
diags = cspm.SrcList.ElementsAs(ctx, &elements, false)
if diags.HasError() {
return *okta.NewSignInPage(), diags
}
convertElements := make([]string, 0)
for _, v := range elements {
convertElements = append(convertElements, v.ValueString())
}
csp.SrcList = convertElements

csp := okta.ContentSecurityPolicySetting{}
cspm := &contentSecurityPolicySettingModel{}
diags := model.ContentSecurityPolicySetting.As(ctx, cspm, basetypes.ObjectAsOptions{})
if diags.HasError() {
return *okta.NewSignInPage(), diags
}
csp.Mode = cspm.Mode.ValueStringPointer()
csp.ReportUri = cspm.ReportUri.ValueStringPointer()
elements := make([]types.String, 0, len(cspm.SrcList.Elements()))
diags = cspm.SrcList.ElementsAs(ctx, &elements, false)
if diags.HasError() {
return *okta.NewSignInPage(), diags
sp.SetContentSecurityPolicySetting(csp)
}
convertElements := make([]string, 0)
for _, v := range elements {
convertElements = append(convertElements, v.ValueString())
}
csp.SrcList = convertElements
sp.SetContentSecurityPolicySetting(csp)

return sp, nil
}

Expand Down
6 changes: 4 additions & 2 deletions okta/resource_okta_customized_signin_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ func (r *customizedSigninPageResource) Create(ctx context.Context, req resource.
}

reqBody, diags := buildSignInPageRequest(ctx, state)
if diags.HasError() {
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

Expand Down Expand Up @@ -118,7 +119,8 @@ func (r *customizedSigninPageResource) Update(ctx context.Context, req resource.
}

reqBody, diags := buildSignInPageRequest(ctx, state)
if diags.HasError() {
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

Expand Down
9 changes: 9 additions & 0 deletions okta/resource_okta_customized_signin_page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ func TestAccResourceOktaCustomizedSignInPage_crud(t *testing.T) {
Steps: []resource.TestStep{
{
Config: mgr.GetFixtures("basic.tf", t),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("okta_customized_signin_page.test", "page_content", "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n<head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <meta name=\"robots\" content=\"noindex,nofollow\" />\n <!-- Styles generated from theme -->\n <link href=\"{{themedStylesUrl}}\" rel=\"stylesheet\" type=\"text/css\">\n <!-- Favicon from theme -->\n <link rel=\"shortcut icon\" href=\"{{faviconUrl}}\" type=\"image/x-icon\"/>\n\n <title>{{pageTitle}}</title>\n {{{SignInWidgetResources}}}\n\n <style nonce=\"{{nonceValue}}\">\n #login-bg-image-id {\n background-image: {{bgImageUrl}}\n }\n </style>\n</head>\n<body>\n <div id=\"login-bg-image-id\" class=\"login-bg-image tb--background\"></div>\n <div id=\"okta-login-container\"></div>\n\n <!--\n \"OktaUtil\" defines a global OktaUtil object\n that contains methods used to complete the Okta login flow.\n -->\n {{{OktaUtil}}}\n\n <script type=\"text/javascript\" nonce=\"{{nonceValue}}\">\n // \"config\" object contains default widget configuration\n // with any custom overrides defined in your admin settings.\n var config = OktaUtil.getSignInWidgetConfig();\n\n // Render the Okta Sign-In Widget\n var oktaSignIn = new OktaSignIn(config);\n oktaSignIn.renderEl({ el: '#okta-login-container' },\n OktaUtil.completeLogin,\n function(error) {\n // Logs errors that occur when configuring the widget.\n // Remove or replace this with your own custom error handler.\n console.log(error.message, error);\n }\n );\n </script>\n</body>\n</html>\n"),
resource.TestCheckResourceAttr("okta_customized_signin_page.test", "widget_version", "^6"),
resource.TestCheckResourceAttr("okta_customized_signin_page.test", "widget_customizations.widget_generation", "G2"),
resource.TestCheckNoResourceAttr("okta_customized_signin_page.test", "content_security_policy_setting"),
),
},
{
Config: mgr.GetFixtures("update.tf", t),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("okta_customized_signin_page.test", "page_content", "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n<head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <meta name=\"robots\" content=\"noindex,nofollow\" />\n <!-- Styles generated from theme -->\n <link href=\"{{themedStylesUrl}}\" rel=\"stylesheet\" type=\"text/css\">\n <!-- Favicon from theme -->\n <link rel=\"shortcut icon\" href=\"{{faviconUrl}}\" type=\"image/x-icon\"/>\n\n <title>{{pageTitle}}</title>\n {{{SignInWidgetResources}}}\n\n <style nonce=\"{{nonceValue}}\">\n #login-bg-image-id {\n background-image: {{bgImageUrl}}\n }\n </style>\n</head>\n<body>\n <div id=\"login-bg-image-id\" class=\"login-bg-image tb--background\"></div>\n <div id=\"okta-login-container\"></div>\n\n <!--\n \"OktaUtil\" defines a global OktaUtil object\n that contains methods used to complete the Okta login flow.\n -->\n {{{OktaUtil}}}\n\n <script type=\"text/javascript\" nonce=\"{{nonceValue}}\">\n // \"config\" object contains default widget configuration\n // with any custom overrides defined in your admin settings.\n var config = OktaUtil.getSignInWidgetConfig();\n\n // Render the Okta Sign-In Widget\n var oktaSignIn = new OktaSignIn(config);\n oktaSignIn.renderEl({ el: '#okta-login-container' },\n OktaUtil.completeLogin,\n function(error) {\n // Logs errors that occur when configuring the widget.\n // Remove or replace this with your own custom error handler.\n console.log(error.message, error);\n }\n );\n </script>\n</body>\n</html>\n"),
resource.TestCheckResourceAttr("okta_customized_signin_page.test", "widget_version", "^6"),
Expand Down