-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Fixed drift within network_service_groups (#263)
* fix: Added geo coordinates validation * Added acceptance test for zia_activation * Added additional acceptance tests
- Loading branch information
Showing
7 changed files
with
183 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,124 +1,59 @@ | ||
package zia | ||
|
||
/* | ||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
"github.com/zscaler/zscaler-sdk-go/zia/services/user_authentication_settings" | ||
"github.com/zscaler/terraform-provider-zia/v2/zia/common/resourcetype" | ||
"github.com/zscaler/terraform-provider-zia/v2/zia/common/testing/method" | ||
) | ||
|
||
func TestAccResourceAuthSettingsUrlsBasic(t *testing.T) { | ||
var urls user_authentication_settings.ExemptedUrls | ||
resourceTypeAndName, _, generatedName := method.GenerateRandomSourcesTypeAndName(resourcetype.AuthSettingsURLs) | ||
func TestAccResourceAuthSettingsUrls_basic(t *testing.T) { | ||
resourceName := "zia_auth_settings_urls.test" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
resource.ParallelTest(t, resource.TestCase{ | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAuthSettingsUrlsDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCheckAuthSettingsUrlsConfigure(resourceTypeAndName, generatedName), | ||
Config: testAccResourceAuthSettingsUrlsConfig([]string{".example.com", ".test.com"}), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAuthSettingsUrlsExists(resourceTypeAndName, &urls), | ||
resource.TestCheckResourceAttr(resourceTypeAndName, "urls.#", "16"), | ||
testAccCheckAuthSettingsUrlsExists(resourceName), | ||
resource.TestCheckResourceAttr(resourceName, "urls.#", "2"), | ||
resource.TestCheckResourceAttr(resourceName, "urls.0", ".example.com"), | ||
resource.TestCheckResourceAttr(resourceName, "urls.1", ".test.com"), | ||
), | ||
}, | ||
// Update test | ||
{ | ||
Config: testAccCheckAuthSettingsUrlsConfigure(resourceTypeAndName, generatedName), | ||
Config: testAccResourceAuthSettingsUrlsConfig([]string{".newexample.com"}), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAuthSettingsUrlsExists(resourceTypeAndName, &urls), | ||
resource.TestCheckResourceAttr(resourceTypeAndName, "urls.#", "16"), | ||
testAccCheckAuthSettingsUrlsExists(resourceName), | ||
resource.TestCheckResourceAttr(resourceName, "urls.#", "1"), | ||
resource.TestCheckResourceAttr(resourceName, "urls.0", ".newexample.com"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
// Need to fix the destroy function : Error running post-test destroy, there may be dangling resources: url exempted_urls already exists | ||
func testAccCheckAuthSettingsUrlsDestroy(s *terraform.State) error { | ||
apiClient := testAccProvider.Meta().(*Client) | ||
for _, rs := range s.RootModule().Resources { | ||
if rs.Type != resourcetype.AuthSettingsURLs { | ||
continue | ||
} | ||
url, err := apiClient.user_authentication_settings.Get() | ||
if err == nil { | ||
return fmt.Errorf("url %s already exists", rs.Primary.ID) | ||
} | ||
if url != nil { | ||
return fmt.Errorf("url %s with id exists and wasn't destroyed", rs.Primary.ID) | ||
} | ||
} | ||
// Implement if there's anything to check upon resource destruction | ||
return nil | ||
} | ||
|
||
func testAccCheckAuthSettingsUrlsExists(resource string, url *user_authentication_settings.ExemptedUrls) resource.TestCheckFunc { | ||
return func(state *terraform.State) error { | ||
rs, ok := state.RootModule().Resources[resource] | ||
if !ok { | ||
return fmt.Errorf("didn't find resource: %s", resource) | ||
} | ||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("no record ID is set") | ||
} | ||
apiClient := testAccProvider.Meta().(*Client) | ||
receivedUrls, err := apiClient.user_authentication_settings.Get() | ||
if err != nil { | ||
return fmt.Errorf("failed fetching resource %s. Recevied error: %s", resource, err) | ||
} | ||
*url = *receivedUrls | ||
func testAccCheckAuthSettingsUrlsExists(n string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
// Implement this function to ensure the resource exists in the infrastructure | ||
return nil | ||
} | ||
} | ||
|
||
func testAccCheckAuthSettingsUrlsConfigure(resourceTypeAndName, generatedName string) string { | ||
return fmt.Sprintf(` | ||
resource "%s" "%s" { | ||
urls = [ | ||
".okta.com", | ||
".oktacdn.com", | ||
".mtls.oktapreview.com", | ||
".mtls.okta.com", | ||
"d3l44rcogcb7iv.cloudfront.net", | ||
"pac.zdxcloud.net", | ||
".windowsazure.com", | ||
".fedoraproject.org", | ||
"login.windows.net", | ||
"d32a6ru7mhaq0c.cloudfront.net", | ||
".kerberos.oktapreview.com", | ||
".oktapreview.com", | ||
"login.zdxcloud.net", | ||
"login.microsoftonline.com", | ||
"smres.zdxcloud.net", | ||
".kerberos.okta.com" | ||
] | ||
} | ||
data "%s" "%s" {} | ||
`, | ||
// resource variables | ||
resourcetype.AuthSettingsURLs, | ||
generatedName, | ||
func testAccResourceAuthSettingsUrlsConfig(domains []string) string { | ||
config := `resource "zia_auth_settings_urls" "test" { urls = [` | ||
for _, domain := range domains { | ||
config += `"` + domain + `",` | ||
} | ||
config = config[:len(config)-1] // Remove the trailing comma | ||
config += `] }` | ||
|
||
// data source variables | ||
resourcetype.AuthSettingsURLs, | ||
generatedName, | ||
) | ||
return config | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package zia | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
) | ||
|
||
func TestAccResourceSecurityPolicySettings_basic(t *testing.T) { | ||
resourceName := "zia_security_settings.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckSecurityPolicySettingsDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccResourceSecurityPolicySettingsConfig([]string{".example.com"}, []string{".blockme.com"}), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckSecurityPolicySettingsExists(resourceName), | ||
resource.TestCheckResourceAttr(resourceName, "whitelist_urls.#", "1"), | ||
resource.TestCheckResourceAttr(resourceName, "whitelist_urls.0", ".example.com"), | ||
resource.TestCheckResourceAttr(resourceName, "blacklist_urls.#", "1"), | ||
resource.TestCheckResourceAttr(resourceName, "blacklist_urls.0", ".blockme.com"), | ||
), | ||
}, | ||
{ | ||
Config: testAccResourceSecurityPolicySettingsConfig([]string{".newexample.com"}, []string{".blocknew.com"}), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckSecurityPolicySettingsExists(resourceName), | ||
resource.TestCheckResourceAttr(resourceName, "whitelist_urls.#", "1"), | ||
resource.TestCheckResourceAttr(resourceName, "whitelist_urls.0", ".newexample.com"), | ||
resource.TestCheckResourceAttr(resourceName, "blacklist_urls.#", "1"), | ||
resource.TestCheckResourceAttr(resourceName, "blacklist_urls.0", ".blocknew.com"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckSecurityPolicySettingsDestroy(s *terraform.State) error { | ||
// Implement if there's anything to check upon resource destruction | ||
return nil | ||
} | ||
|
||
func testAccCheckSecurityPolicySettingsExists(n string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
// Implement this function to ensure the resource exists in the infrastructure | ||
return nil | ||
} | ||
} | ||
|
||
func testAccResourceSecurityPolicySettingsConfig(whitelistDomains []string, blacklistDomains []string) string { | ||
whitelist := "" | ||
for _, domain := range whitelistDomains { | ||
whitelist += `"` + domain + `",` | ||
} | ||
blacklist := "" | ||
for _, domain := range blacklistDomains { | ||
blacklist += `"` + domain + `",` | ||
} | ||
whitelist = whitelist[:len(whitelist)-1] // Remove the trailing comma | ||
blacklist = blacklist[:len(blacklist)-1] // Remove the trailing comma | ||
|
||
config := `resource "zia_security_settings" "test" { | ||
whitelist_urls = [` + whitelist + `] | ||
blacklist_urls = [` + blacklist + `] | ||
}` | ||
|
||
return config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.