Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jmichalak committed May 16, 2024
1 parent 939f823 commit 3cc3724
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 48 deletions.
16 changes: 8 additions & 8 deletions pkg/sdk/security_integrations_dto_builders_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions pkg/sdk/security_integrations_dto_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package sdk
//go:generate go run ./dto-builder-generator/main.go

var (
_ optionsProvider[CreateSaml2SecurityIntegrationOptions] = new(CreateSaml2SecurityIntegrationRequest)
_ optionsProvider[CreateScimSecurityIntegrationOptions] = new(CreateScimSecurityIntegrationRequest)
_ optionsProvider[AlterSaml2SecurityIntegrationOptions] = new(AlterSaml2SecurityIntegrationRequest)
_ optionsProvider[AlterScimIntegrationSecurityIntegrationOptions] = new(AlterScimIntegrationSecurityIntegrationRequest)
_ optionsProvider[DropSecurityIntegrationOptions] = new(DropSecurityIntegrationRequest)
_ optionsProvider[DescribeSecurityIntegrationOptions] = new(DescribeSecurityIntegrationRequest)
_ optionsProvider[ShowSecurityIntegrationOptions] = new(ShowSecurityIntegrationRequest)
_ optionsProvider[CreateSaml2SecurityIntegrationOptions] = new(CreateSaml2SecurityIntegrationRequest)
_ optionsProvider[CreateScimSecurityIntegrationOptions] = new(CreateScimSecurityIntegrationRequest)
_ optionsProvider[AlterSaml2SecurityIntegrationOptions] = new(AlterSaml2SecurityIntegrationRequest)
_ optionsProvider[AlterScimSecurityIntegrationOptions] = new(AlterScimSecurityIntegrationRequest)
_ optionsProvider[DropSecurityIntegrationOptions] = new(DropSecurityIntegrationRequest)
_ optionsProvider[DescribeSecurityIntegrationOptions] = new(DescribeSecurityIntegrationRequest)
_ optionsProvider[ShowSecurityIntegrationOptions] = new(ShowSecurityIntegrationRequest)
)

type CreateSaml2SecurityIntegrationRequest struct {
Expand Down Expand Up @@ -93,7 +93,7 @@ type Saml2IntegrationUnsetRequest struct {
Comment *bool
}

type AlterScimIntegrationSecurityIntegrationRequest struct {
type AlterScimSecurityIntegrationRequest struct {
IfExists *bool
name AccountObjectIdentifier // required
SetTags []TagAssociation
Expand Down
6 changes: 3 additions & 3 deletions pkg/sdk/security_integrations_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type SecurityIntegrations interface {
CreateSaml2(ctx context.Context, request *CreateSaml2SecurityIntegrationRequest) error
CreateScim(ctx context.Context, request *CreateScimSecurityIntegrationRequest) error
AlterSaml2(ctx context.Context, request *AlterSaml2SecurityIntegrationRequest) error
AlterScimIntegration(ctx context.Context, request *AlterScimIntegrationSecurityIntegrationRequest) error
AlterScim(ctx context.Context, request *AlterScimSecurityIntegrationRequest) error
Drop(ctx context.Context, request *DropSecurityIntegrationRequest) error
Describe(ctx context.Context, id AccountObjectIdentifier) ([]SecurityIntegrationProperty, error)
Show(ctx context.Context, request *ShowSecurityIntegrationRequest) ([]SecurityIntegration, error)
Expand Down Expand Up @@ -109,8 +109,8 @@ type Saml2IntegrationUnset struct {
Comment *bool `ddl:"keyword" sql:"COMMENT"`
}

// AlterScimIntegrationSecurityIntegrationOptions is based on https://docs.snowflake.com/en/sql-reference/sql/alter-security-integration-scim.
type AlterScimIntegrationSecurityIntegrationOptions struct {
// AlterScimSecurityIntegrationOptions is based on https://docs.snowflake.com/en/sql-reference/sql/alter-security-integration-scim.
type AlterScimSecurityIntegrationOptions struct {
alter bool `ddl:"static" sql:"ALTER"`
securityIntegration bool `ddl:"static" sql:"SECURITY INTEGRATION"`
IfExists *bool `ddl:"keyword" sql:"IF EXISTS"`
Expand Down
101 changes: 88 additions & 13 deletions pkg/sdk/security_integrations_gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ func TestSecurityIntegrations_CreateSaml2(t *testing.T) {

t.Run("basic", func(t *testing.T) {
opts := defaultOpts()
assertOptsValidAndSQLEquals(t, opts, "CREATE SECURITY INTEGRATION %s TYPE = SAML2 ENABLED = true SAML2_ISSUER = 'issuer' SAML2_SSO_URL = 'url' SAML2_PROVIDER = 'provider' SAML2_X509_CERT = 'cert'", id.FullyQualifiedName())
opts.OrReplace = Bool(true)
assertOptsValidAndSQLEquals(t, opts, "CREATE OR REPLACE SECURITY INTEGRATION %s TYPE = SAML2 ENABLED = true SAML2_ISSUER = 'issuer' SAML2_SSO_URL = 'url' SAML2_PROVIDER = 'provider' SAML2_X509_CERT = 'cert'", id.FullyQualifiedName())
})

t.Run("all options", func(t *testing.T) {
opts := defaultOpts()
opts.IfNotExists = Bool(true)
opts.AllowedEmailPatterns = []EmailPattern{{Pattern: "pattern"}}
opts.AllowedUserDomains = []UserDomain{{Domain: "domain"}}
opts.Comment = Pointer("a")
Expand All @@ -49,9 +51,10 @@ func TestSecurityIntegrations_CreateSaml2(t *testing.T) {
opts.Saml2SnowflakeAcsUrl = Pointer("acs")
opts.Saml2SnowflakeIssuerUrl = Pointer("issuer")
opts.Saml2SpInitiatedLoginPageLabel = Pointer("label")
opts.Saml2SnowflakeX509Cert = Pointer("cert")

assertOptsValidAndSQLEquals(t, opts, "CREATE SECURITY INTEGRATION %s TYPE = SAML2 ENABLED = true SAML2_ISSUER = 'issuer' SAML2_SSO_URL = 'url' SAML2_PROVIDER = 'provider' SAML2_X509_CERT = 'cert'"+
" ALLOWED_USER_DOMAINS = ('domain') ALLOWED_EMAIL_PATTERNS = ('pattern') SAML2_SP_INITIATED_LOGIN_PAGE_LABEL = 'label' SAML2_ENABLE_SP_INITIATED = true SAML2_SIGN_REQUEST = true"+
assertOptsValidAndSQLEquals(t, opts, "CREATE SECURITY INTEGRATION IF NOT EXISTS %s TYPE = SAML2 ENABLED = true SAML2_ISSUER = 'issuer' SAML2_SSO_URL = 'url' SAML2_PROVIDER = 'provider' SAML2_X509_CERT = 'cert'"+
" ALLOWED_USER_DOMAINS = ('domain') ALLOWED_EMAIL_PATTERNS = ('pattern') SAML2_SP_INITIATED_LOGIN_PAGE_LABEL = 'label' SAML2_ENABLE_SP_INITIATED = true SAML2_SNOWFLAKE_X509_CERT = 'cert' SAML2_SIGN_REQUEST = true"+
" SAML2_REQUESTED_NAMEID_FORMAT = 'format' SAML2_POST_LOGOUT_REDIRECT_URL = 'redirect' SAML2_FORCE_AUTHN = true SAML2_SNOWFLAKE_ISSUER_URL = 'issuer' SAML2_SNOWFLAKE_ACS_URL = 'acs'"+
" COMMENT = 'a'", id.FullyQualifiedName())
})
Expand Down Expand Up @@ -97,7 +100,7 @@ func TestSecurityIntegrations_CreateScim(t *testing.T) {
})
}

func TestSecurityIntegrations_AlterSaml2Integration(t *testing.T) {
func TestSecurityIntegrations_AlterSaml2(t *testing.T) {
id := randomAccountObjectIdentifier()

// Minimal valid AlterSaml2IntegrationSecurityIntegrationOptions
Expand All @@ -121,21 +124,33 @@ func TestSecurityIntegrations_AlterSaml2Integration(t *testing.T) {
assertOptsInvalidJoinedErrors(t, opts, ErrInvalidObjectIdentifier)
})

t.Run("validation: exactly of the fields [opts.*] should be set", func(t *testing.T) {
opts := defaultOpts()
assertOptsInvalidJoinedErrors(t, opts, errExactlyOneOf("AlterSaml2SecurityIntegrationOptions", "Set", "Unset", "RefreshSaml2SnowflakePrivateKey", "SetTags", "UnsetTags"))
})

t.Run("validation: at least one of the fields [opts.Set.*] should be set", func(t *testing.T) {
opts := defaultOpts()
opts.Set = &Saml2IntegrationSet{}
assertOptsInvalidJoinedErrors(t, opts, errAtLeastOneOf("AlterSaml2IntegrationSecurityIntegrationOptions.Set", "Enabled", "Saml2Issuer", "Saml2SsoUrl", "Saml2Provider",
assertOptsInvalidJoinedErrors(t, opts, errAtLeastOneOf("AlterSaml2SecurityIntegrationOptions.Set", "Enabled", "Saml2Issuer", "Saml2SsoUrl", "Saml2Provider",
"Saml2X509Cert", "AllowedUserDomains", "AllowedEmailPatterns", "Saml2SpInitiatedLoginPageLabel", "Saml2EnableSpInitiated", "Saml2SnowflakeX509Cert", "Saml2SignRequest",
"Saml2RequestedNameidFormat", "Saml2PostLogoutRedirectUrl", "Saml2ForceAuthn", "Saml2SnowflakeIssuerUrl", "Saml2SnowflakeAcsUrl", "Comment"))
})

t.Run("validation: at least one of the fields [opts.Unset.*] should be set", func(t *testing.T) {
opts := defaultOpts()
opts.Unset = &Saml2IntegrationUnset{}
assertOptsInvalidJoinedErrors(t, opts, errAtLeastOneOf("AlterSaml2IntegrationSecurityIntegrationOptions.Unset",
assertOptsInvalidJoinedErrors(t, opts, errAtLeastOneOf("AlterSaml2SecurityIntegrationOptions.Unset",
"Enabled", "Saml2ForceAuthn", "Saml2RequestedNameidFormat", "Saml2PostLogoutRedirectUrl", "Comment"))
})

t.Run("validation: exactly one of the fields [opts.*] should be set", func(t *testing.T) {
opts := defaultOpts()
opts.Set = &Saml2IntegrationSet{}
opts.Unset = &Saml2IntegrationUnset{}
assertOptsInvalidJoinedErrors(t, opts, errExactlyOneOf("AlterSaml2SecurityIntegrationOptions", "Set", "Unset", "RefreshSaml2SnowflakePrivateKey", "SetTags", "UnsetTags"))
})

t.Run("all options - set", func(t *testing.T) {
opts := defaultOpts()
opts.Set = &Saml2IntegrationSet{
Expand Down Expand Up @@ -180,20 +195,44 @@ func TestSecurityIntegrations_AlterSaml2Integration(t *testing.T) {
opts.RefreshSaml2SnowflakePrivateKey = Pointer(true)
assertOptsValidAndSQLEquals(t, opts, "ALTER SECURITY INTEGRATION %s REFRESH SAML2_SNOWFLAKE_PRIVATE_KEY", id.FullyQualifiedName())
})

t.Run("set tags", func(t *testing.T) {
opts := defaultOpts()
opts.SetTags = []TagAssociation{
{
Name: NewAccountObjectIdentifier("name"),
Value: "value",
},
{
Name: NewAccountObjectIdentifier("second-name"),
Value: "second-value",
},
}
assertOptsValidAndSQLEquals(t, opts, `ALTER SECURITY INTEGRATION %s SET TAG "name" = 'value', "second-name" = 'second-value'`, id.FullyQualifiedName())
})

t.Run("unset tags", func(t *testing.T) {
opts := defaultOpts()
opts.UnsetTags = []ObjectIdentifier{
NewAccountObjectIdentifier("name"),
NewAccountObjectIdentifier("second-name"),
}
assertOptsValidAndSQLEquals(t, opts, `ALTER SECURITY INTEGRATION %s UNSET TAG "name", "second-name"`, id.FullyQualifiedName())
})
}

func TestSecurityIntegrations_AlterScimIntegration(t *testing.T) {
func TestSecurityIntegrations_AlterScim(t *testing.T) {
id := randomAccountObjectIdentifier()

// Minimal valid AlterScimIntegrationSecurityIntegrationOptions
defaultOpts := func() *AlterScimIntegrationSecurityIntegrationOptions {
return &AlterScimIntegrationSecurityIntegrationOptions{
// Minimal valid AlterScimSecurityIntegrationOptions
defaultOpts := func() *AlterScimSecurityIntegrationOptions {
return &AlterScimSecurityIntegrationOptions{
name: id,
}
}

t.Run("validation: nil options", func(t *testing.T) {
var opts *AlterScimIntegrationSecurityIntegrationOptions = nil
var opts *AlterScimSecurityIntegrationOptions = nil
assertOptsInvalidJoinedErrors(t, opts, ErrNilOptions)
})

Expand All @@ -206,16 +245,28 @@ func TestSecurityIntegrations_AlterScimIntegration(t *testing.T) {
assertOptsInvalidJoinedErrors(t, opts, ErrInvalidObjectIdentifier)
})

t.Run("validation: exactly of the fields [opts.*] should be set", func(t *testing.T) {
opts := defaultOpts()
assertOptsInvalidJoinedErrors(t, opts, errExactlyOneOf("AlterScimSecurityIntegrationOptions", "Set", "Unset", "SetTags", "UnsetTags"))
})

t.Run("validation: exactly one of the fields [opts.*] should be set", func(t *testing.T) {
opts := defaultOpts()
opts.Set = &ScimIntegrationSet{}
opts.Unset = &ScimIntegrationUnset{}
assertOptsInvalidJoinedErrors(t, opts, errExactlyOneOf("AlterScimSecurityIntegrationOptions", "Set", "Unset", "SetTags", "UnsetTags"))
})

t.Run("validation: at least one of the fields [opts.Set.*] should be set", func(t *testing.T) {
opts := defaultOpts()
opts.Set = &ScimIntegrationSet{}
assertOptsInvalidJoinedErrors(t, opts, errAtLeastOneOf("AlterScimIntegrationSecurityIntegrationOptions.Set", "Enabled", "NetworkPolicy", "SyncPassword", "Comment"))
assertOptsInvalidJoinedErrors(t, opts, errAtLeastOneOf("AlterScimSecurityIntegrationOptions.Set", "Enabled", "NetworkPolicy", "SyncPassword", "Comment"))
})

t.Run("validation: at least one of the fields [opts.Unset.*] should be set", func(t *testing.T) {
opts := defaultOpts()
opts.Unset = &ScimIntegrationUnset{}
assertOptsInvalidJoinedErrors(t, opts, errAtLeastOneOf("AlterScimIntegrationSecurityIntegrationOptions.Unset", "Enabled", "NetworkPolicy", "SyncPassword", "Comment"))
assertOptsInvalidJoinedErrors(t, opts, errAtLeastOneOf("AlterScimSecurityIntegrationOptions.Unset", "Enabled", "NetworkPolicy", "SyncPassword", "Comment"))
})

t.Run("all options - set", func(t *testing.T) {
Expand All @@ -241,6 +292,30 @@ func TestSecurityIntegrations_AlterScimIntegration(t *testing.T) {
}
assertOptsValidAndSQLEquals(t, opts, "ALTER SECURITY INTEGRATION %s UNSET ENABLED, NETWORK_POLICY, SYNC_PASSWORD, COMMENT", id.FullyQualifiedName())
})

t.Run("set tags", func(t *testing.T) {
opts := defaultOpts()
opts.SetTags = []TagAssociation{
{
Name: NewAccountObjectIdentifier("name"),
Value: "value",
},
{
Name: NewAccountObjectIdentifier("second-name"),
Value: "second-value",
},
}
assertOptsValidAndSQLEquals(t, opts, `ALTER SECURITY INTEGRATION %s SET TAG "name" = 'value', "second-name" = 'second-value'`, id.FullyQualifiedName())
})

t.Run("unset tags", func(t *testing.T) {
opts := defaultOpts()
opts.UnsetTags = []ObjectIdentifier{
NewAccountObjectIdentifier("name"),
NewAccountObjectIdentifier("second-name"),
}
assertOptsValidAndSQLEquals(t, opts, `ALTER SECURITY INTEGRATION %s UNSET TAG "name", "second-name"`, id.FullyQualifiedName())
})
}

func TestSecurityIntegrations_Drop(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/sdk/security_integrations_impl_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (v *securityIntegrations) AlterSaml2(ctx context.Context, request *AlterSam
return validateAndExec(v.client, ctx, opts)
}

func (v *securityIntegrations) AlterScimIntegration(ctx context.Context, request *AlterScimIntegrationSecurityIntegrationRequest) error {
func (v *securityIntegrations) AlterScim(ctx context.Context, request *AlterScimSecurityIntegrationRequest) error {
opts := request.toOpts()
return validateAndExec(v.client, ctx, opts)
}
Expand Down Expand Up @@ -151,8 +151,8 @@ func (r *AlterSaml2SecurityIntegrationRequest) toOpts() *AlterSaml2SecurityInteg
return opts
}

func (r *AlterScimIntegrationSecurityIntegrationRequest) toOpts() *AlterScimIntegrationSecurityIntegrationOptions {
opts := &AlterScimIntegrationSecurityIntegrationOptions{
func (r *AlterScimSecurityIntegrationRequest) toOpts() *AlterScimSecurityIntegrationOptions {
opts := &AlterScimSecurityIntegrationOptions{
IfExists: r.IfExists,
name: r.name,
SetTags: r.SetTags,
Expand Down
10 changes: 5 additions & 5 deletions pkg/sdk/security_integrations_validations_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var (
_ validatable = new(CreateSaml2SecurityIntegrationOptions)
_ validatable = new(CreateScimSecurityIntegrationOptions)
_ validatable = new(AlterSaml2SecurityIntegrationOptions)
_ validatable = new(AlterScimIntegrationSecurityIntegrationOptions)
_ validatable = new(AlterScimSecurityIntegrationOptions)
_ validatable = new(DropSecurityIntegrationOptions)
_ validatable = new(DescribeSecurityIntegrationOptions)
_ validatable = new(ShowSecurityIntegrationOptions)
Expand Down Expand Up @@ -62,7 +62,7 @@ func (opts *AlterSaml2SecurityIntegrationOptions) validate() error {
return JoinErrors(errs...)
}

func (opts *AlterScimIntegrationSecurityIntegrationOptions) validate() error {
func (opts *AlterScimSecurityIntegrationOptions) validate() error {
if opts == nil {
return ErrNilOptions
}
Expand All @@ -71,16 +71,16 @@ func (opts *AlterScimIntegrationSecurityIntegrationOptions) validate() error {
errs = append(errs, ErrInvalidObjectIdentifier)
}
if !exactlyOneValueSet(opts.Set, opts.Unset, opts.SetTags, opts.UnsetTags) {
errs = append(errs, errExactlyOneOf("AlterScimIntegrationSecurityIntegrationOptions", "Set", "Unset", "SetTags", "UnsetTags"))
errs = append(errs, errExactlyOneOf("AlterScimSecurityIntegrationOptions", "Set", "Unset", "SetTags", "UnsetTags"))
}
if valueSet(opts.Set) {
if !anyValueSet(opts.Set.Enabled, opts.Set.NetworkPolicy, opts.Set.SyncPassword, opts.Set.Comment) {
errs = append(errs, errAtLeastOneOf("AlterScimIntegrationSecurityIntegrationOptions.Set", "Enabled", "NetworkPolicy", "SyncPassword", "Comment"))
errs = append(errs, errAtLeastOneOf("AlterScimSecurityIntegrationOptions.Set", "Enabled", "NetworkPolicy", "SyncPassword", "Comment"))
}
}
if valueSet(opts.Unset) {
if !anyValueSet(opts.Unset.Enabled, opts.Unset.NetworkPolicy, opts.Unset.SyncPassword, opts.Unset.Comment) {
errs = append(errs, errAtLeastOneOf("AlterScimIntegrationSecurityIntegrationOptions.Unset", "Enabled", "NetworkPolicy", "SyncPassword", "Comment"))
errs = append(errs, errAtLeastOneOf("AlterScimSecurityIntegrationOptions.Unset", "Enabled", "NetworkPolicy", "SyncPassword", "Comment"))
}
}
return JoinErrors(errs...)
Expand Down
Loading

0 comments on commit 3cc3724

Please sign in to comment.