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

azurerm_azuread_application urls are now required to be https #1960

Merged
merged 3 commits into from
Sep 21, 2018
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
4 changes: 4 additions & 0 deletions azurerm/helpers/validate/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
"github.com/hashicorp/terraform/helper/schema"
)

func URLIsHTTPS(i interface{}, k string) (_ []string, errors []error) {
return URLWithScheme([]string{"https"})(i, k)
}

func URLIsHTTPOrHTTPS(i interface{}, k string) (_ []string, errors []error) {
return URLWithScheme([]string{"http", "https"})(i, k)
}
Expand Down
42 changes: 42 additions & 0 deletions azurerm/helpers/validate/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,48 @@ import (
"testing"
)

func TestURLIsHTTPS(t *testing.T) {
cases := []struct {
Url string
Errors int
}{
{
Url: "",
Errors: 1,
},
{
Url: "this is not a url",
Errors: 1,
},
{
Url: "www.example.com",
Errors: 1,
},
{
Url: "ftp://www.example.com",
Errors: 1,
},
{
Url: "http://www.example.com",
Errors: 1,
},
{
Url: "https://www.example.com",
Errors: 0,
},
}

for _, tc := range cases {
t.Run(tc.Url, func(t *testing.T) {
_, errors := URLIsHTTPS(tc.Url, "test")

if len(errors) != tc.Errors {
t.Fatalf("Expected URLIsHTTPS to have %d not %d errors for %q", tc.Errors, len(errors), tc.Url)
}
})
}
}

func TestURLIsHTTPOrHTTPS(t *testing.T) {
cases := []struct {
Url string
Expand Down
54 changes: 0 additions & 54 deletions azurerm/import_arm_azuread_application_test.go

This file was deleted.

22 changes: 14 additions & 8 deletions azurerm/resource_arm_azuread_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package azurerm

import (
"fmt"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"log"

"github.com/Azure/azure-sdk-for-go/services/graphrbac/1.6/graphrbac"
Expand All @@ -21,14 +23,16 @@ func resourceArmActiveDirectoryApplication() *schema.Resource {

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.NoZeroValues,
},

"homepage": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validate.URLIsHTTPS,
},

"identifier_uris": {
Expand All @@ -37,7 +41,8 @@ func resourceArmActiveDirectoryApplication() *schema.Resource {
Computed: true,
MinItems: 1,
Elem: &schema.Schema{
Type: schema.TypeString,
Type: schema.TypeString,
ValidateFunc: validate.URLIsHTTPS,
},
},

Expand All @@ -46,7 +51,8 @@ func resourceArmActiveDirectoryApplication() *schema.Resource {
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Type: schema.TypeString,
ValidateFunc: validate.URLIsHTTPS,
},
},

Expand Down Expand Up @@ -205,7 +211,7 @@ func expandAzureRmActiveDirectoryApplicationHomepage(d *schema.ResourceData, nam
return utils.String(v.(string))
}

return utils.String(fmt.Sprintf("http://%s", name))
return utils.String(fmt.Sprintf("https://%s", name))
}

func expandAzureRmActiveDirectoryApplicationIdentifierUris(d *schema.ResourceData) *[]string {
Expand Down
31 changes: 23 additions & 8 deletions azurerm/resource_arm_azuread_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ func TestAccAzureRMActiveDirectoryApplication_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMActiveDirectoryApplicationExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctest%s", id)),
resource.TestCheckResourceAttr(resourceName, "homepage", fmt.Sprintf("http://acctest%s", id)),
resource.TestCheckResourceAttr(resourceName, "homepage", fmt.Sprintf("https://acctest%s", id)),
resource.TestCheckResourceAttrSet(resourceName, "application_id"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand All @@ -50,6 +55,11 @@ func TestAccAzureRMActiveDirectoryApplication_availableToOtherTenants(t *testing
resource.TestCheckResourceAttr(resourceName, "available_to_other_tenants", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand All @@ -69,12 +79,17 @@ func TestAccAzureRMActiveDirectoryApplication_complete(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMActiveDirectoryApplicationExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctest%s", id)),
resource.TestCheckResourceAttr(resourceName, "homepage", fmt.Sprintf("http://homepage-%s", id)),
resource.TestCheckResourceAttr(resourceName, "homepage", fmt.Sprintf("https://homepage-%s", id)),
resource.TestCheckResourceAttr(resourceName, "identifier_uris.#", "1"),
resource.TestCheckResourceAttr(resourceName, "reply_urls.#", "1"),
resource.TestCheckResourceAttrSet(resourceName, "application_id"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand All @@ -97,7 +112,7 @@ func TestAccAzureRMActiveDirectoryApplication_update(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMActiveDirectoryApplicationExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctest%s", id)),
resource.TestCheckResourceAttr(resourceName, "homepage", fmt.Sprintf("http://acctest%s", id)),
resource.TestCheckResourceAttr(resourceName, "homepage", fmt.Sprintf("https://acctest%s", id)),
resource.TestCheckResourceAttr(resourceName, "identifier_uris.#", "0"),
resource.TestCheckResourceAttr(resourceName, "reply_urls.#", "0"),
),
Expand All @@ -107,7 +122,7 @@ func TestAccAzureRMActiveDirectoryApplication_update(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMActiveDirectoryApplicationExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctest%s", updatedId)),
resource.TestCheckResourceAttr(resourceName, "homepage", fmt.Sprintf("http://homepage-%s", updatedId)),
resource.TestCheckResourceAttr(resourceName, "homepage", fmt.Sprintf("https://homepage-%s", updatedId)),
resource.TestCheckResourceAttr(resourceName, "identifier_uris.#", "1"),
resource.TestCheckResourceAttr(resourceName, "reply_urls.#", "1"),
),
Expand Down Expand Up @@ -174,7 +189,7 @@ func testAccAzureRMActiveDirectoryApplication_availableToOtherTenants(id string)
return fmt.Sprintf(`
resource "azurerm_azuread_application" "test" {
name = "acctest%s"
identifier_uris = ["http://%s.hashicorptest.com"]
identifier_uris = ["https://%s.hashicorptest.com"]
available_to_other_tenants = true
}
`, id, id)
Expand All @@ -184,9 +199,9 @@ func testAccAzureRMActiveDirectoryApplication_complete(id string) string {
return fmt.Sprintf(`
resource "azurerm_azuread_application" "test" {
name = "acctest%s"
homepage = "http://homepage-%s"
identifier_uris = ["http://%s.hashicorptest.com"]
reply_urls = ["http://replyurl-%s"]
homepage = "https://homepage-%s"
identifier_uris = ["https://%s.hashicorptest.com"]
reply_urls = ["https://replyurl-%s"]
oauth2_allow_implicit_flow = true
}
`, id, id, id, id)
Expand Down
8 changes: 4 additions & 4 deletions website/docs/r/azuread_application.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ Manages an Application within Azure Active Directory.
```hcl
resource "azurerm_azuread_application" "test" {
name = "example"
homepage = "http://homepage"
identifier_uris = ["http://uri"]
reply_urls = ["http://replyurl"]
homepage = "https://homepage"
identifier_uris = ["https://uri"]
reply_urls = ["https://replyurl"]
available_to_other_tenants = false
oauth2_allow_implicit_flow = true
}
Expand All @@ -32,7 +32,7 @@ The following arguments are supported:

* `name` - (Required) The display name for the application.

* `homepage` - (optional) The URL to the application's home page. If no homepage is specified this defaults to `http://{name}`.
* `homepage` - (optional) The URL to the application's home page. If no homepage is specified this defaults to `https://{name}`.

* `identifier_uris` - (Optional) A list of user-defined URI(s) that uniquely identify a Web application within it's Azure AD tenant, or within a verified custom domain if the application is multi-tenant.

Expand Down