Merge pull request #2518 from nats-io/fail_auth_token_where_not_supported

[FIXED] Report config error if "token" defined for cluster{} and gateway{}
This commit is contained in:
Ivan Kozlovic
2021-09-13 14:23:25 -06:00
committed by GitHub
2 changed files with 39 additions and 0 deletions

View File

@@ -1474,6 +1474,35 @@ func TestConfigCheck(t *testing.T) {
`,
err: fmt.Errorf(`Duplicate 'store_dir' configuration`),
},
{
name: "token not supported in cluster",
config: `
cluster {
port: -1
authorization {
token: "my_token"
}
}
`,
err: fmt.Errorf("Cluster authorization does not support tokens"),
errorLine: 4,
errorPos: 6,
},
{
name: "token not supported in gateway",
config: `
gateway {
port: -1
name: "A"
authorization {
token: "my_token"
}
}
`,
err: fmt.Errorf("Gateway authorization does not support tokens"),
errorLine: 5,
errorPos: 6,
},
}
checkConfig := func(config string) error {

View File

@@ -1364,6 +1364,11 @@ func parseCluster(v interface{}, opts *Options, errors *[]error, warnings *[]err
*errors = append(*errors, err)
continue
}
if auth.token != _EMPTY_ {
err := &configErr{tk, "Cluster authorization does not support tokens"}
*errors = append(*errors, err)
continue
}
opts.Cluster.Username = auth.user
opts.Cluster.Password = auth.pass
opts.Cluster.AuthTimeout = auth.timeout
@@ -1506,6 +1511,11 @@ func parseGateway(v interface{}, o *Options, errors *[]error, warnings *[]error)
*errors = append(*errors, &configErr{tk, "Gateway authorization does not allow multiple users"})
continue
}
if auth.token != _EMPTY_ {
err := &configErr{tk, "Gateway authorization does not support tokens"}
*errors = append(*errors, err)
continue
}
o.Gateway.Username = auth.user
o.Gateway.Password = auth.pass
o.Gateway.AuthTimeout = auth.timeout