Skip to content

Commit

Permalink
Updated tests, added clause for custom-token-exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
duedares-rvj committed Feb 4, 2025
1 parent 8b8cb90 commit 04a1b14
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/auth0/action/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func expandAction(data *schema.ResourceData) *management.Action {
action.Secrets = expandActionSecrets(config.GetAttr("secrets"))
}

if action.GetRuntime() == "node18" {
if action.GetRuntime() == "node18" && !isTokenExchangeInSupportedTriggers(action.SupportedTriggers) {
action.Runtime = auth0.String("node18-actions")
}

Expand Down
14 changes: 13 additions & 1 deletion internal/auth0/action/flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ func flattenAction(data *schema.ResourceData, action *management.Action) error {
data.Set("runtime", action.GetRuntime()),
)

if action.GetRuntime() == "node18-actions" {
// If custom-token-exchange is part of SupportedTriggers for an action,
// we'd not manipulate it's runtime value.
// This is done, to support node18-actions as runtime.

if action.GetRuntime() == "node18-actions" && !isTokenExchangeInSupportedTriggers(action.SupportedTriggers) {
result = multierror.Append(result, data.Set("runtime", "node18"))
}

Expand All @@ -26,6 +30,14 @@ func flattenAction(data *schema.ResourceData, action *management.Action) error {
return result.ErrorOrNil()
}

func isTokenExchangeInSupportedTriggers(actionTriggers []management.ActionTrigger) bool {
for _, actionTrigger := range actionTriggers {
if actionTrigger.GetID() == "custom-token-exchange" {
return true
}
}
return false
}
func flattenActionTriggers(triggers []management.ActionTrigger) []interface{} {
var result []interface{}

Expand Down
22 changes: 21 additions & 1 deletion internal/auth0/client/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const testAccCreateMobileClient = `
resource "auth0_client" "my_client" {
name = "Acceptance Test - Mobile - {{.testName}}"
app_type = "native"
oidc_conformant = true
token_exchange {
allow_any_profile_of_type = ["custom_authentication"]
}
Expand Down Expand Up @@ -92,6 +92,11 @@ resource "auth0_client" "my_client" {
name = "Acceptance Test - Mobile - {{.testName}}"
app_type = "native"
oidc_conformant = true
token_exchange {
allow_any_profile_of_type = ["custom_authentication"]
}
mobile {
android {
app_package_name = "com.example"
Expand Down Expand Up @@ -121,6 +126,10 @@ resource "auth0_client" "my_client" {
name = "Acceptance Test - Mobile - {{.testName}}"
app_type = "native"
oidc_conformant = true
token_exchange {
allow_any_profile_of_type = ["custom_authentication"]
}
mobile {
android {
app_package_name = "com.example"
Expand All @@ -141,6 +150,10 @@ resource "auth0_client" "my_client" {
name = "Acceptance Test - Mobile - {{.testName}}"
app_type = "non_interactive"
oidc_conformant = true
token_exchange {
allow_any_profile_of_type = ["custom_authentication"]
}
native_social_login {
apple {
enabled = false
Expand All @@ -161,6 +174,7 @@ func TestAccClientMobile(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_client.my_client", "name", fmt.Sprintf("Acceptance Test - Mobile - %s", t.Name())),
resource.TestCheckResourceAttr("auth0_client.my_client", "app_type", "native"),
resource.TestCheckResourceAttr("auth0_client.my_client", "oidc_conformant", "true"),
resource.TestCheckResourceAttr("auth0_client.my_client", "token_exchange.0.allow_any_profile_of_type.0", "custom_authentication"),
resource.TestCheckResourceAttr("auth0_client.my_client", "mobile.#", "1"),
resource.TestCheckResourceAttr("auth0_client.my_client", "mobile.0.android.#", "1"),
Expand All @@ -181,6 +195,8 @@ func TestAccClientMobile(t *testing.T) {
Config: acctest.ParseTestName(testAccUpdateMobileClient, t.Name()),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_client.my_client", "name", fmt.Sprintf("Acceptance Test - Mobile - %s", t.Name())),
resource.TestCheckResourceAttr("auth0_client.my_client", "oidc_conformant", "true"),
resource.TestCheckResourceAttr("auth0_client.my_client", "token_exchange.0.allow_any_profile_of_type.0", "custom_authentication"),
resource.TestCheckResourceAttr("auth0_client.my_client", "app_type", "native"),
resource.TestCheckResourceAttr("auth0_client.my_client", "mobile.#", "1"),
resource.TestCheckResourceAttr("auth0_client.my_client", "mobile.0.android.#", "1"),
Expand All @@ -202,6 +218,8 @@ func TestAccClientMobile(t *testing.T) {
Config: acctest.ParseTestName(testAccUpdateMobileClientAgainByRemovingSomeFields, t.Name()),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_client.my_client", "name", fmt.Sprintf("Acceptance Test - Mobile - %s", t.Name())),
resource.TestCheckResourceAttr("auth0_client.my_client", "oidc_conformant", "true"),
resource.TestCheckResourceAttr("auth0_client.my_client", "token_exchange.0.allow_any_profile_of_type.0", "custom_authentication"),
resource.TestCheckResourceAttr("auth0_client.my_client", "app_type", "native"),
resource.TestCheckResourceAttr("auth0_client.my_client", "mobile.#", "1"),
resource.TestCheckResourceAttr("auth0_client.my_client", "mobile.0.android.#", "1"),
Expand All @@ -228,6 +246,8 @@ func TestAccClientMobile(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_client.my_client", "name", fmt.Sprintf("Acceptance Test - Mobile - %s", t.Name())),
resource.TestCheckResourceAttr("auth0_client.my_client", "app_type", "non_interactive"),
resource.TestCheckResourceAttr("auth0_client.my_client", "oidc_conformant", "true"),
resource.TestCheckResourceAttr("auth0_client.my_client", "token_exchange.0.allow_any_profile_of_type.0", "custom_authentication"),
resource.TestCheckResourceAttr("auth0_client.my_client", "mobile.#", "1"),
resource.TestCheckResourceAttr("auth0_client.my_client", "mobile.0.android.#", "1"),
resource.TestCheckResourceAttr("auth0_client.my_client", "mobile.0.android.0.app_package_name", "com.example"),
Expand Down

0 comments on commit 04a1b14

Please sign in to comment.