mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
fixes, auth checks
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user