Skip to content

Commit 621b0dc

Browse files
committed
fix: De Morgans law fix in lint
1 parent b55301a commit 621b0dc

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

cmd/saml.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,15 @@ func ConfigFromFlags(fileConfig *credentialexchange.CredentialConfig, rf *RootCm
227227

228228
func configValid(config *credentialexchange.CredentialConfig) error {
229229
v := validator.New()
230-
230+
ssoVal := !config.IsSso
231+
if config.IsSso {
232+
ssoVal = len(config.SsoRole) > 0 && len(config.SsoRegion) > 0
233+
}
231234
v.RequiredString(config.ProviderUrl, "provider-url", "provider url must be specified").
232235
RequiredString(config.BaseConfig.Role, "role", "role must be provided").
233236
RequiredString(config.PrincipalArn, "principal-arn", "principal ARN must be provided").
234-
CustomRule(!(len(config.BaseConfig.Role) > 1 && len(config.SsoRole) > 1), "sso-role", "sso-role cannot be specified when role is also set")
237+
CustomRule(ssoVal, "is-sso", "sso-role must be specified when is-sso is set").
238+
CustomRule((len(config.BaseConfig.Role) > 1 && len(config.SsoRole) < 1) || (len(config.BaseConfig.Role) < 1 && len(config.SsoRole) > 1), "sso-role", "sso-role cannot be specified when role is also set")
235239

236240
if v.IsFailed() {
237241
return fmt.Errorf("%w %#q", ErrValidationFailed, v.Errors())

cmd/saml_test.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,38 @@ func Test_ConfigMerge_fails_with_missing(t *testing.T) {
6868
t.Error(err)
6969
}
7070
})
71-
t.Run("role and sso-role provided", func(t *testing.T) {
71+
t.Run("is-sso set but sso-role not set", func(t *testing.T) {
7272

7373
conf := &credentialexchange.CredentialConfig{
7474
BaseConfig: credentialexchange.BaseConfig{
7575
BrowserExecutablePath: "/foo/path",
7676
Role: "",
7777
RoleChain: []string{"role-123"},
7878
},
79-
SsoRegion: "foo",
80-
SsoRole: "foo:bar",
81-
ProviderUrl: "https://my-idp.com/?app_id=testdd",
79+
PrincipalArn: "some-arn",
80+
SsoRegion: "foo",
81+
SsoRole: "foo:bar",
82+
ProviderUrl: "https://my-idp.com/?app_id=testdd",
8283
}
83-
err := cmd.ConfigFromFlags(conf, &cmd.RootCmdFlags{}, &cmd.SamlCmdFlags{}, "me")
84+
err := cmd.ConfigFromFlags(conf, &cmd.RootCmdFlags{}, &cmd.SamlCmdFlags{Role: "wrong-role"}, "me")
85+
if !errors.Is(err, cmd.ErrValidationFailed) {
86+
t.Error(err)
87+
}
88+
})
89+
t.Run("role and sso-role both provided", func(t *testing.T) {
90+
91+
conf := &credentialexchange.CredentialConfig{
92+
BaseConfig: credentialexchange.BaseConfig{
93+
BrowserExecutablePath: "/foo/path",
94+
Role: "",
95+
RoleChain: []string{"role-123"},
96+
},
97+
PrincipalArn: "some-arn",
98+
SsoRegion: "foo",
99+
SsoRole: "foo:bar",
100+
ProviderUrl: "https://my-idp.com/?app_id=testdd",
101+
}
102+
err := cmd.ConfigFromFlags(conf, &cmd.RootCmdFlags{}, &cmd.SamlCmdFlags{Role: "wrong-role"}, "me")
84103
if !errors.Is(err, cmd.ErrValidationFailed) {
85104
t.Error(err)
86105
}

0 commit comments

Comments
 (0)