mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-16 19:14:41 -07:00
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:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user