Skip to content

Commit

Permalink
Merge pull request #1381 from nats-io/validateOnReload
Browse files Browse the repository at this point in the history
[FIXED] on reload, check error conditions checked in validateOptions
  • Loading branch information
kozlovic authored May 6, 2020
2 parents 7e60769 + 0eae400 commit 1ab26df
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
7 changes: 7 additions & 0 deletions server/reload.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,13 @@ func (s *Server) reloadOptions(curOpts, newOpts *Options) error {
if err != nil {
return err
}

if len(changed) != 0 {
if err := validateOptions(newOpts); err != nil {
return err
}
}

// Create a context that is used to pass special info that we may need
// while applying the new options.
ctx := reloadContext{oldClusterPerms: curOpts.Cluster.Permissions}
Expand Down
34 changes: 34 additions & 0 deletions server/reload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4121,3 +4121,37 @@ func TestLoggingReload(t *testing.T) {
check("on.log", tracingPresent)
check("off-post.log", tracingAbsent)
}

func TestReloadValidate(t *testing.T) {
confFileName := createConfFile(t, []byte(`
listen: "127.0.0.1:-1"
no_auth_user: a
authorization {
users [
{user: "a", password: "a"},
{user: "b", password: "b"}
]
}
`))
defer os.Remove(confFileName)
srv, _ := RunServerWithConfig(confFileName)
if srv == nil {
t.Fatal("Server did not start")
}
// Induce error by removing the user no_auth_user points to
changeCurrentConfigContentWithNewContent(t, confFileName, []byte(`
listen: "127.0.0.1:-1"
no_auth_user: a
authorization {
users [
{user: "b", password: "b"}
]
}
`))
if err := srv.Reload(); err == nil {
t.Fatal("Expected error on reload, got none")
} else if strings.HasPrefix(err.Error(), " no_auth_user:") {
t.Logf("Expected no_auth_user error, got different one %s", err)
}
srv.Shutdown()
}
2 changes: 2 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ func validateOptions(o *Options) error {
if err := validateAuth(o); err != nil {
return err
}
// Check that gateway is properly configured. Returns no error
// if there is no gateway defined.
return validateGatewayOptions(o)
}

Expand Down

0 comments on commit 1ab26df

Please sign in to comment.