Skip to content

Commit

Permalink
Fix inability to update http_only_cookie_attribute to false
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin-Holmes committed May 11, 2022
1 parent 315c8c4 commit 66fe79b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 8 deletions.
10 changes: 5 additions & 5 deletions cloudflare/resource_cloudflare_access_application.go
Expand Up @@ -40,17 +40,15 @@ func resourceCloudflareAccessApplicationCreate(ctx context.Context, d *schema.Re
EnableBindingCookie: d.Get("enable_binding_cookie").(bool),
CustomDenyMessage: d.Get("custom_deny_message").(string),
CustomDenyURL: d.Get("custom_deny_url").(string),
HttpOnlyCookieAttribute: d.Get("http_only_cookie_attribute").(bool),
SameSiteCookieAttribute: d.Get("same_site_cookie_attribute").(string),
LogoURL: d.Get("logo_url").(string),
SkipInterstitial: d.Get("skip_interstitial").(bool),
AppLauncherVisible: d.Get("app_launcher_visible").(bool),
ServiceAuth401Redirect: d.Get("service_auth_401_redirect").(bool),
}

if value, ok := d.GetOk("http_only_cookie_attribute"); ok {
newAccessApplication.HttpOnlyCookieAttribute = value.(bool)
}
value := d.Get("http_only_cookie_attribute").(bool)
newAccessApplication.HttpOnlyCookieAttribute = &value

if len(allowedIDPList) > 0 {
newAccessApplication.AllowedIdps = allowedIDPList
Expand Down Expand Up @@ -151,14 +149,16 @@ func resourceCloudflareAccessApplicationUpdate(ctx context.Context, d *schema.Re
EnableBindingCookie: d.Get("enable_binding_cookie").(bool),
CustomDenyMessage: d.Get("custom_deny_message").(string),
CustomDenyURL: d.Get("custom_deny_url").(string),
HttpOnlyCookieAttribute: d.Get("http_only_cookie_attribute").(bool),
SameSiteCookieAttribute: d.Get("same_site_cookie_attribute").(string),
LogoURL: d.Get("logo_url").(string),
SkipInterstitial: d.Get("skip_interstitial").(bool),
AppLauncherVisible: d.Get("app_launcher_visible").(bool),
ServiceAuth401Redirect: d.Get("service_auth_401_redirect").(bool),
}

value := d.Get("http_only_cookie_attribute").(bool)
updatedAccessApplication.HttpOnlyCookieAttribute = &value

if len(allowedIDPList) > 0 {
updatedAccessApplication.AllowedIdps = allowedIDPList
}
Expand Down
43 changes: 41 additions & 2 deletions cloudflare/resource_cloudflare_access_application_test.go
Expand Up @@ -215,7 +215,7 @@ func TestAccCloudflareAccessApplication_WithHttpOnlyCookieAttribute(t *testing.T
CheckDestroy: testAccCheckCloudflareAccessApplicationDestroy,
Steps: []resource.TestStep{
{
Config: testAccCloudflareAccessApplicationConfigWithHttpOnlyCookieAttribute(rnd, zoneID, domain),
Config: testAccCloudflareAccessApplicationConfigWithHTTPOnlyCookieAttribute(rnd, zoneID, domain),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "zone_id", zoneID),
resource.TestCheckResourceAttr(name, "name", rnd),
Expand All @@ -229,6 +229,32 @@ func TestAccCloudflareAccessApplication_WithHttpOnlyCookieAttribute(t *testing.T
})
}

func TestAccCloudflareAccessApplication_WithHTTPOnlyCookieAttributeSetToFalse(t *testing.T) {
rnd := generateRandomResourceName()
name := fmt.Sprintf("cloudflare_access_application.%s", rnd)

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccessAccPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testAccCheckCloudflareAccessApplicationDestroy,
Steps: []resource.TestStep{
{
Config: testAccCloudflareAccessApplicationConfigWithHTTPOnlyCookieAttributeSetToFalse(rnd, zoneID, domain),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "zone_id", zoneID),
resource.TestCheckResourceAttr(name, "name", rnd),
resource.TestCheckResourceAttr(name, "domain", fmt.Sprintf("%s.%s", rnd, domain)),
resource.TestCheckResourceAttr(name, "type", "self_hosted"),
resource.TestCheckResourceAttr(name, "session_duration", "24h"),
resource.TestCheckResourceAttr(name, "http_only_cookie_attribute", "false"),
),
},
},
})
}

func TestAccCloudflareAccessApplication_WithSameSiteCookieAttribute(t *testing.T) {
rnd := generateRandomResourceName()
name := fmt.Sprintf("cloudflare_access_application.%s", rnd)
Expand Down Expand Up @@ -424,7 +450,7 @@ resource "cloudflare_access_application" "%[1]s" {
`, rnd, zoneID, domain, accountID)
}

func testAccCloudflareAccessApplicationConfigWithHttpOnlyCookieAttribute(rnd, zoneID, domain string) string {
func testAccCloudflareAccessApplicationConfigWithHTTPOnlyCookieAttribute(rnd, zoneID, domain string) string {
return fmt.Sprintf(`
resource "cloudflare_access_application" "%[1]s" {
zone_id = "%[2]s"
Expand All @@ -437,6 +463,19 @@ resource "cloudflare_access_application" "%[1]s" {
`, rnd, zoneID, domain)
}

func testAccCloudflareAccessApplicationConfigWithHTTPOnlyCookieAttributeSetToFalse(rnd, zoneID, domain string) string {
return fmt.Sprintf(`
resource "cloudflare_access_application" "%[1]s" {
zone_id = "%[2]s"
name = "%[1]s"
domain = "%[1]s.%[3]s"
type = "self_hosted"
session_duration = "24h"
http_only_cookie_attribute = false
}
`, rnd, zoneID, domain)
}

func testAccCloudflareAccessApplicationConfigSameSiteCookieAttribute(rnd, zoneID, domain string) string {
return fmt.Sprintf(`
resource "cloudflare_access_application" "%[1]s" {
Expand Down
2 changes: 1 addition & 1 deletion cloudflare/schema_cloudflare_access_application.go
Expand Up @@ -133,7 +133,7 @@ func resourceCloudflareAccessApplicationSchema() map[string]*schema.Schema {
"http_only_cookie_attribute": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Default: true,
},
"same_site_cookie_attribute": {
Type: schema.TypeString,
Expand Down

0 comments on commit 66fe79b

Please sign in to comment.