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

chore: Unskip auth config tests #3180

Merged
merged 13 commits into from
Nov 18, 2024
6 changes: 5 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ jobs:

- name: Create and populate .snowflake/config file
id: create_config
run: mkdir $HOME/.snowflake && echo "${{ secrets.SNOWFLAKE_CONFIG_FILE }}" > $HOME/.snowflake/config
run: mkdir -p $HOME/.snowflake && echo "${{ secrets.TMP_JMICHALAK_SNOWFLAKE_CONFIG_FILE }}" > $HOME/.snowflake/config

- name: Create and populate .snowflake/config_v097_compatible file
sfc-gh-asawicki marked this conversation as resolved.
Show resolved Hide resolved
id: create_config_v097_compatible
run: mkdir -p $HOME/.snowflake && echo "${{ secrets.TMP_JMICHALAK_SNOWFLAKE_CONFIG_FILE_V097_COMPATIBLE }}" > $HOME/.snowflake/config_v097_compatible

- run: make test
if: ${{ !cancelled() && steps.create_config.conclusion == 'success' }}
Expand Down
17 changes: 17 additions & 0 deletions pkg/acceptance/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/testenvs"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/testprofiles"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/snowflakeenvs"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/provider"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
Expand All @@ -23,6 +24,7 @@ import (
"github.com/hashicorp/terraform-plugin-testing/config"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/snowflakedb/gosnowflake"
"github.com/stretchr/testify/require"
)

const AcceptanceTestPrefix = "acc_test_"
Expand Down Expand Up @@ -208,3 +210,18 @@ func ExternalProviderWithExactVersion(version string) map[string]resource.Extern
},
}
}

// SetV097CompatibleConfigPathEnv sets a new config path in a relevant env variable for a file that is compatible with v0.97.
func SetV097CompatibleConfigPathEnv(t *testing.T) {
t.Helper()
home, err := os.UserHomeDir()
require.NoError(t, err)
configPath := filepath.Join(home, ".snowflake", "config_v097_compatible")
t.Setenv(snowflakeenvs.ConfigPath, configPath)
}

// UnsetConfigPathEnv unsets a config path env
func UnsetConfigPathEnv(t *testing.T) {
t.Helper()
t.Setenv(snowflakeenvs.ConfigPath, "")
}
4 changes: 4 additions & 0 deletions pkg/acceptance/testprofiles/testing_config_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ const (
CompleteFields = "complete_fields"
CompleteFieldsInvalid = "complete_fields_invalid"
DefaultWithPasscode = "default_with_passcode"

JwtAuth = "jwt_auth"
EncryptedJwtAuth = "encrypted_jwt_auth"
Okta = "okta"
)
2 changes: 1 addition & 1 deletion pkg/manual_tests/authentication_methods/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestAcc_Provider_OktaAuth(t *testing.T) {
},
Steps: []resource.TestStep{
{
Config: providerConfigWithAuthenticator("okta", sdk.AuthenticationTypeOkta),
Config: providerConfigWithAuthenticator(testprofiles.Okta, sdk.AuthenticationTypeOkta),
},
},
})
Expand Down
33 changes: 4 additions & 29 deletions pkg/provider/provider_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/testhelpers"
"github.com/snowflakedb/gosnowflake"
"github.com/stretchr/testify/assert"

Expand Down Expand Up @@ -165,8 +164,6 @@ func TestAcc_Provider_configureClientOnceSwitching(t *testing.T) {
}

func TestAcc_Provider_tomlConfig(t *testing.T) {
// TODO(SNOW-1752038): unskip
t.Skip("Skip because this test needs a TOML config incompatible with older versions, causing tests with ExternalProvider to fail.")
t.Setenv(string(testenvs.ConfigureClientOnce), "")

user := acc.DefaultConfig(t).User
Expand Down Expand Up @@ -239,8 +236,6 @@ func TestAcc_Provider_tomlConfig(t *testing.T) {
}

func TestAcc_Provider_envConfig(t *testing.T) {
// TODO(SNOW-1752038): unskip
t.Skip("Skip because this test needs a TOML config incompatible with older versions, causing tests with ExternalProvider to fail.")
t.Setenv(string(testenvs.ConfigureClientOnce), "")

user := acc.DefaultConfig(t).User
Expand Down Expand Up @@ -352,8 +347,6 @@ func TestAcc_Provider_envConfig(t *testing.T) {
}

func TestAcc_Provider_tfConfig(t *testing.T) {
// TODO(SNOW-1752038): unskip
t.Skip("Skip because this test needs a TOML config incompatible with older versions, causing tests with ExternalProvider to fail.")
t.Setenv(string(testenvs.ConfigureClientOnce), "")

user := acc.DefaultConfig(t).User
Expand Down Expand Up @@ -499,19 +492,6 @@ func TestAcc_Provider_useNonExistentDefaultParams(t *testing.T) {
// prove we can use tri-value booleans, similarly to the ones in resources
func TestAcc_Provider_triValueBoolean(t *testing.T) {
t.Setenv(string(testenvs.ConfigureClientOnce), "")
account := acc.DefaultConfig(t).Account
user := acc.DefaultConfig(t).User
password := acc.DefaultConfig(t).Password

// Prepare a temporary TOML config that is valid for v0.97.0.
// The default TOML is not valid because we set new fields, which is incorrect from v0.97.0's point of view.
c := fmt.Sprintf(`
[default]
account='%s'
user='%s'
password='%s'
`, account, user, password)
configPath := testhelpers.TestFile(t, "config", []byte(c))

resource.Test(t, resource.TestCase{
PreCheck: func() {
Expand All @@ -524,9 +504,7 @@ func TestAcc_Provider_triValueBoolean(t *testing.T) {
},
Steps: []resource.TestStep{
{
PreConfig: func() {
t.Setenv(snowflakeenvs.ConfigPath, configPath)
},
PreConfig: func() { acc.SetV097CompatibleConfigPathEnv(t) },
ExternalProviders: acc.ExternalProviderWithExactVersion("0.97.0"),
Config: providerConfigWithClientStoreTemporaryCredential(testprofiles.Default, `true`),
},
Expand Down Expand Up @@ -572,9 +550,6 @@ func TestAcc_Provider_sessionParameters(t *testing.T) {
}

func TestAcc_Provider_JwtAuth(t *testing.T) {
// TODO(SNOW-1752038): unskip
t.Skip("Skip because this test needs a TOML config incompatible with older versions, causing tests with ExternalProvider to fail.")

t.Setenv(string(testenvs.ConfigureClientOnce), "")

resource.Test(t, resource.TestCase{
Expand All @@ -590,16 +565,16 @@ func TestAcc_Provider_JwtAuth(t *testing.T) {
Steps: []resource.TestStep{
// authenticate with unencrypted private key
{
Config: providerConfigWithAuthenticator("jwt_test", sdk.AuthenticationTypeJwt),
Config: providerConfigWithAuthenticator(testprofiles.JwtAuth, sdk.AuthenticationTypeJwt),
},
// authenticate with unencrypted private key with a legacy authenticator value
// solves https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2983
{
Config: providerConfigWithAuthenticator("jwt_test", sdk.AuthenticationTypeJwtLegacy),
Config: providerConfigWithAuthenticator(testprofiles.JwtAuth, sdk.AuthenticationTypeJwtLegacy),
},
// authenticate with encrypted private key
{
Config: providerConfigWithAuthenticator("jwt_encrypted_test", sdk.AuthenticationTypeJwt),
Config: providerConfigWithAuthenticator(testprofiles.EncryptedJwtAuth, sdk.AuthenticationTypeJwt),
},
},
})
Expand Down
4 changes: 4 additions & 0 deletions pkg/resources/account_role_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ func TestAcc_AccountRole_migrateFromV0941_ensureSmoothUpgradeWithNewResourceId(t
CheckDestroy: acc.CheckDestroy(t, resources.AccountRole),
Steps: []resource.TestStep{
{
PreConfig: func() { acc.SetV097CompatibleConfigPathEnv(t) },
ExternalProviders: map[string]resource.ExternalProvider{
"snowflake": {
VersionConstraint: "=0.94.1",
Expand All @@ -229,6 +230,7 @@ func TestAcc_AccountRole_migrateFromV0941_ensureSmoothUpgradeWithNewResourceId(t
),
},
{
PreConfig: func() { acc.UnsetConfigPathEnv(t) },
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Config: accountRoleBasicConfig(id.Name(), comment),
Check: resource.ComposeAggregateTestCheckFunc(
Expand All @@ -252,6 +254,7 @@ func TestAcc_AccountRole_WithQuotedName(t *testing.T) {
CheckDestroy: acc.CheckDestroy(t, resources.AccountRole),
Steps: []resource.TestStep{
{
PreConfig: func() { acc.SetV097CompatibleConfigPathEnv(t) },
ExternalProviders: map[string]resource.ExternalProvider{
"snowflake": {
VersionConstraint: "=0.94.1",
Expand All @@ -266,6 +269,7 @@ func TestAcc_AccountRole_WithQuotedName(t *testing.T) {
),
},
{
PreConfig: func() { acc.UnsetConfigPathEnv(t) },
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Config: accountRoleBasicConfig(quotedId, comment),
ConfigPlanChecks: resource.ConfigPlanChecks{
Expand Down
3 changes: 2 additions & 1 deletion pkg/resources/alert_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ resource "snowflake_alert" "test_alert" {
// Can't reproduce the issue, leaving the test for now.
func TestAcc_Alert_Issue3117(t *testing.T) {
id := acc.TestClient().Ids.RandomSchemaObjectIdentifierWithPrefix("small caps with spaces")

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
Expand All @@ -217,6 +216,7 @@ func TestAcc_Alert_Issue3117(t *testing.T) {
CheckDestroy: acc.CheckDestroy(t, resources.Alert),
Steps: []resource.TestStep{
{
PreConfig: func() { acc.SetV097CompatibleConfigPathEnv(t) },
ExternalProviders: map[string]resource.ExternalProvider{
"snowflake": {
VersionConstraint: "=0.92.0",
Expand All @@ -229,6 +229,7 @@ func TestAcc_Alert_Issue3117(t *testing.T) {
),
},
{
PreConfig: func() { acc.UnsetConfigPathEnv(t) },
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Config: alertIssue3117Config(id, acc.TestClient().Ids.WarehouseId(), "test_alert"),
Check: resource.ComposeTestCheckFunc(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ func TestAcc_ApiAuthenticationIntegrationWithAuthorizationCodeGrant_migrateFromV
CheckDestroy: acc.CheckDestroy(t, resources.ApiAuthenticationIntegrationWithAuthorizationCodeGrant),
Steps: []resource.TestStep{
{
PreConfig: func() { acc.SetV097CompatibleConfigPathEnv(t) },
ExternalProviders: map[string]resource.ExternalProvider{
"snowflake": {
VersionConstraint: "=0.94.1",
Expand All @@ -283,6 +284,7 @@ func TestAcc_ApiAuthenticationIntegrationWithAuthorizationCodeGrant_migrateFromV
),
},
{
PreConfig: func() { acc.UnsetConfigPathEnv(t) },
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Config: apiAuthenticationIntegrationWithAuthorizationCodeGrantBasicConfig(id.Name()),
Check: resource.ComposeAggregateTestCheckFunc(
Expand All @@ -305,6 +307,7 @@ func TestAcc_ApiAuthenticationIntegrationWithAuthorizationCodeGrant_WithQuotedNa
CheckDestroy: acc.CheckDestroy(t, resources.ApiAuthenticationIntegrationWithAuthorizationCodeGrant),
Steps: []resource.TestStep{
{
PreConfig: func() { acc.SetV097CompatibleConfigPathEnv(t) },
ExternalProviders: map[string]resource.ExternalProvider{
"snowflake": {
VersionConstraint: "=0.94.1",
Expand All @@ -319,6 +322,7 @@ func TestAcc_ApiAuthenticationIntegrationWithAuthorizationCodeGrant_WithQuotedNa
),
},
{
PreConfig: func() { acc.UnsetConfigPathEnv(t) },
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Config: apiAuthenticationIntegrationWithAuthorizationCodeGrantBasicConfig(quotedId),
ConfigPlanChecks: resource.ConfigPlanChecks{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ func TestAcc_ApiAuthenticationIntegrationWithClientCredentials_migrateFromV0941_
CheckDestroy: acc.CheckDestroy(t, resources.ApiAuthenticationIntegrationWithClientCredentials),
Steps: []resource.TestStep{
{
PreConfig: func() { acc.SetV097CompatibleConfigPathEnv(t) },
ExternalProviders: map[string]resource.ExternalProvider{
"snowflake": {
VersionConstraint: "=0.94.1",
Expand All @@ -276,6 +277,7 @@ func TestAcc_ApiAuthenticationIntegrationWithClientCredentials_migrateFromV0941_
),
},
{
PreConfig: func() { acc.UnsetConfigPathEnv(t) },
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Config: apiAuthenticationIntegrationWithClientCredentialsBasicConfig(id.Name()),
Check: resource.ComposeAggregateTestCheckFunc(
Expand All @@ -298,6 +300,7 @@ func TestAcc_ApiAuthenticationIntegrationWithClientCredentials_WithQuotedName(t
CheckDestroy: acc.CheckDestroy(t, resources.ApiAuthenticationIntegrationWithClientCredentials),
Steps: []resource.TestStep{
{
PreConfig: func() { acc.SetV097CompatibleConfigPathEnv(t) },
ExternalProviders: map[string]resource.ExternalProvider{
"snowflake": {
VersionConstraint: "=0.94.1",
Expand All @@ -312,6 +315,7 @@ func TestAcc_ApiAuthenticationIntegrationWithClientCredentials_WithQuotedName(t
),
},
{
PreConfig: func() { acc.UnsetConfigPathEnv(t) },
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Config: apiAuthenticationIntegrationWithClientCredentialsBasicConfig(quotedId),
ConfigPlanChecks: resource.ConfigPlanChecks{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ func TestAcc_ApiAuthenticationIntegrationWithJwtBearer_migrateFromV0941_ensureSm
CheckDestroy: acc.CheckDestroy(t, resources.ApiAuthenticationIntegrationWithJwtBearer),
Steps: []resource.TestStep{
{
PreConfig: func() { acc.SetV097CompatibleConfigPathEnv(t) },
ExternalProviders: map[string]resource.ExternalProvider{
"snowflake": {
VersionConstraint: "=0.94.1",
Expand All @@ -244,6 +245,7 @@ func TestAcc_ApiAuthenticationIntegrationWithJwtBearer_migrateFromV0941_ensureSm
),
},
{
PreConfig: func() { acc.UnsetConfigPathEnv(t) },
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Config: apiAuthenticationIntegrationWithJwtBearerBasicConfig(id.Name()),
Check: resource.ComposeAggregateTestCheckFunc(
Expand All @@ -268,6 +270,7 @@ func TestAcc_ApiAuthenticationIntegrationWithJwtBearer_IdentifierQuotingDiffSupp
CheckDestroy: acc.CheckDestroy(t, resources.ApiAuthenticationIntegrationWithJwtBearer),
Steps: []resource.TestStep{
{
PreConfig: func() { acc.SetV097CompatibleConfigPathEnv(t) },
ExternalProviders: map[string]resource.ExternalProvider{
"snowflake": {
VersionConstraint: "=0.94.1",
Expand All @@ -282,6 +285,7 @@ func TestAcc_ApiAuthenticationIntegrationWithJwtBearer_IdentifierQuotingDiffSupp
),
},
{
PreConfig: func() { acc.UnsetConfigPathEnv(t) },
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Config: apiAuthenticationIntegrationWithJwtBearerBasicConfig(quotedId),
ConfigPlanChecks: resource.ConfigPlanChecks{
Expand Down
8 changes: 8 additions & 0 deletions pkg/resources/database_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,7 @@ func TestAcc_Database_UpgradeWithTheSameFieldsAsInTheOldOne(t *testing.T) {
CheckDestroy: acc.CheckDestroy(t, resources.Database),
Steps: []resource.TestStep{
{
PreConfig: func() { acc.SetV097CompatibleConfigPathEnv(t) },
ExternalProviders: map[string]resource.ExternalProvider{
"snowflake": {
VersionConstraint: "=0.92.0",
Expand Down Expand Up @@ -1045,6 +1046,7 @@ func TestAcc_Database_UpgradeWithDataRetentionSet(t *testing.T) {
CheckDestroy: acc.CheckDestroy(t, resources.Database),
Steps: []resource.TestStep{
{
PreConfig: func() { acc.SetV097CompatibleConfigPathEnv(t) },
ExternalProviders: map[string]resource.ExternalProvider{
"snowflake": {
VersionConstraint: "=0.92.0",
Expand Down Expand Up @@ -1108,6 +1110,7 @@ func TestAcc_Database_WithReplication(t *testing.T) {
CheckDestroy: acc.CheckDestroy(t, resources.Database),
Steps: []resource.TestStep{
{
PreConfig: func() { acc.SetV097CompatibleConfigPathEnv(t) },
ExternalProviders: map[string]resource.ExternalProvider{
"snowflake": {
VersionConstraint: "=0.92.0",
Expand All @@ -1125,6 +1128,7 @@ func TestAcc_Database_WithReplication(t *testing.T) {
),
},
{
PreConfig: func() { acc.UnsetConfigPathEnv(t) },
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Config: databaseStateUpgraderWithReplicationNew(id, secondaryAccountIdentifier),
ConfigPlanChecks: resource.ConfigPlanChecks{
Expand Down Expand Up @@ -1267,6 +1271,7 @@ func TestAcc_Database_migrateFromV0941_ensureSmoothUpgradeWithNewResourceId(t *t
CheckDestroy: acc.CheckDestroy(t, resources.Database),
Steps: []resource.TestStep{
{
PreConfig: func() { acc.SetV097CompatibleConfigPathEnv(t) },
ExternalProviders: map[string]resource.ExternalProvider{
"snowflake": {
VersionConstraint: "=0.94.1",
Expand All @@ -1279,6 +1284,7 @@ func TestAcc_Database_migrateFromV0941_ensureSmoothUpgradeWithNewResourceId(t *t
),
},
{
PreConfig: func() { acc.UnsetConfigPathEnv(t) },
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Config: databaseConfigBasic(id.Name()),
Check: resource.ComposeAggregateTestCheckFunc(
Expand Down Expand Up @@ -1315,6 +1321,7 @@ func TestAcc_Database_IdentifierQuotingDiffSuppression(t *testing.T) {
CheckDestroy: acc.CheckDestroy(t, resources.Database),
Steps: []resource.TestStep{
{
PreConfig: func() { acc.SetV097CompatibleConfigPathEnv(t) },
ExternalProviders: map[string]resource.ExternalProvider{
"snowflake": {
VersionConstraint: "=0.94.1",
Expand All @@ -1331,6 +1338,7 @@ func TestAcc_Database_IdentifierQuotingDiffSuppression(t *testing.T) {
),
},
{
PreConfig: func() { acc.UnsetConfigPathEnv(t) },
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Config: databaseConfigBasicWithExternalVolumeAndCatalog(quotedId, quotedExternalVolumeId, quotedCatalogId),
ConfigPlanChecks: resource.ConfigPlanChecks{
Expand Down
Loading
Loading