diff --git a/server/opts.go b/server/opts.go index da3479ea..1e249f4a 100644 --- a/server/opts.go +++ b/server/opts.go @@ -139,7 +139,7 @@ func parseAuthorization(am map[string]interface{}) authorization { case float64: at = mv.(float64) } - auth.timeout = at / float64(time.Second) + auth.timeout = at } } return auth diff --git a/server/route.go b/server/route.go index 74fb5386..a933b340 100644 --- a/server/route.go +++ b/server/route.go @@ -29,7 +29,8 @@ func (s *Server) createRoute(conn net.Conn, didSolicit bool) *client { // Check for Auth if s.routeInfo.AuthRequired { - c.setAuthTimer(AUTH_TIMEOUT) + ttl := secondsToDuration(s.opts.ClusterAuthTimeout) + c.setAuthTimer(ttl) } // Register with the server. diff --git a/server/server.go b/server/server.go index aaff33a5..742e7733 100644 --- a/server/server.go +++ b/server/server.go @@ -256,7 +256,8 @@ func (s *Server) createClient(conn net.Conn) *client { // Check for Auth if s.info.AuthRequired { - c.setAuthTimer(AUTH_TIMEOUT) // FIXME(dlc): Make option + ttl := secondsToDuration(s.opts.AuthTimeout) + c.setAuthTimer(ttl) } c.mu.Unlock() diff --git a/server/util.go b/server/util.go index e61db423..edf56d9d 100644 --- a/server/util.go +++ b/server/util.go @@ -6,6 +6,7 @@ import ( "crypto/rand" "encoding/hex" "io" + "time" ) func genId() string { @@ -34,3 +35,8 @@ func parseSize(d []byte) (n int) { } return n } + +func secondsToDuration(seconds float64) time.Duration { + ttl := seconds * float64(time.Second) + return time.Duration(ttl) +} \ No newline at end of file diff --git a/test/configs/cluster.conf b/test/configs/cluster.conf index 39d002da..43fe4754 100644 --- a/test/configs/cluster.conf +++ b/test/configs/cluster.conf @@ -11,7 +11,7 @@ cluster { authorization { user: route_user password: top_secret - timeout: 1 + timeout: 0.5 } # Routes are actively solicited and connected to from this server. diff --git a/test/routes_test.go b/test/routes_test.go index 1c2bd700..19cb7a94 100644 --- a/test/routes_test.go +++ b/test/routes_test.go @@ -19,8 +19,8 @@ func runRouteServer(t *testing.T) (*server.Server, *server.Options) { // Override for running in Go routine. opts.NoSigs = true - // opts.Debug = true - // opts.Trace = true + // opts.Debug = true + // opts.Trace = true opts.NoLog = true if err != nil { @@ -64,12 +64,17 @@ func TestSendRouteInfoOnConnect(t *testing.T) { s, opts := runRouteServer(t) defer s.Shutdown() rc := createRouteConn(t, opts.ClusterHost, opts.ClusterPort) + doRouteAuthConnect(t, rc, opts.ClusterUsername, opts.ClusterPassword) buf := expectResult(t, rc, infoRe) info := server.Info{} if err := json.Unmarshal(buf[4:], &info); err != nil { t.Fatalf("Could not unmarshal route info: %v", err) } + + if !info.AuthRequired { + t.Fatal("Expected to see AuthRequired") + } if info.Port != opts.ClusterPort { t.Fatalf("Received wrong information for port, expected %d, got %d", info.Port, opts.ClusterPort) @@ -86,7 +91,8 @@ func TestSendRouteSubAndUnsub(t *testing.T) { send, _ := setupConn(t, c) rc := createRouteConn(t, opts.ClusterHost, opts.ClusterPort) - doDefaultConnect(t, rc) + expectAuthRequired(t, rc) + doRouteAuthConnect(t, rc, opts.ClusterUsername, opts.ClusterPassword) // Send SUB via client connection send("SUB foo 22\r\n") @@ -95,7 +101,6 @@ func TestSendRouteSubAndUnsub(t *testing.T) { buf := expectResult(t, rc, subRe) matches := subRe.FindAllSubmatch(buf, -1) rsid := string(matches[0][5]) - fmt.Printf("Received rsid for SUB of %s\n", rsid) if !strings.HasPrefix(rsid, "RSID:") { t.Fatalf("Got wrong RSID: %s\n", rsid) } @@ -112,3 +117,8 @@ func TestSendRouteSubAndUnsub(t *testing.T) { t.Fatalf("Expected rsid's to match. %q vs %q\n", rsid, rsid2) } } + +func doRouteAuthConnect(t *testing.T, c net.Conn, user, pass string) { + cs := fmt.Sprintf("CONNECT {\"verbose\":false,\"user\":\"%s\",\"pass\":\"%s\"}\r\n", user, pass) + sendProto(t, c, cs) +}