mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Use authTimeout in setAuthTimer
This commit is contained in:
@@ -264,6 +264,11 @@ func (c *client) processConnect(arg []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *client) authTimeout() {
|
||||
c.sendErr("Authorization Timeout")
|
||||
c.closeConnection()
|
||||
}
|
||||
|
||||
func (c *client) authViolation() {
|
||||
c.sendErr("Authorization Violation")
|
||||
c.closeConnection()
|
||||
@@ -800,7 +805,7 @@ func (c *client) clearPingTimer() {
|
||||
|
||||
// Lock should be held
|
||||
func (c *client) setAuthTimer(d time.Duration) {
|
||||
c.atmr = time.AfterFunc(d, func() { c.authViolation() })
|
||||
c.atmr = time.AfterFunc(d, func() { c.authTimeout() })
|
||||
}
|
||||
|
||||
// Lock should be held
|
||||
|
||||
@@ -38,10 +38,10 @@ var defaultServerOptions = Options{
|
||||
NoSigs: true,
|
||||
}
|
||||
|
||||
func rawSetup() (*Server, *client, *bufio.Reader, string) {
|
||||
func rawSetup(serverOption Options) (*Server, *client, *bufio.Reader, string) {
|
||||
cli, srv := net.Pipe()
|
||||
cr := bufio.NewReaderSize(cli, defaultBufSize)
|
||||
s := New(&defaultServerOptions)
|
||||
s := New(&serverOption)
|
||||
ch := make(chan *client)
|
||||
createClientAsync(ch, s, srv)
|
||||
l, _ := cr.ReadString('\n')
|
||||
@@ -52,12 +52,12 @@ func rawSetup() (*Server, *client, *bufio.Reader, string) {
|
||||
}
|
||||
|
||||
func setUpClientWithResponse() (*client, string) {
|
||||
_, c, _, l := rawSetup()
|
||||
_, c, _, l := rawSetup(defaultServerOptions)
|
||||
return c, l
|
||||
}
|
||||
|
||||
func setupClient() (*Server, *client, *bufio.Reader) {
|
||||
s, c, cr, _ := rawSetup()
|
||||
s, c, cr, _ := rawSetup(defaultServerOptions)
|
||||
return s, c, cr
|
||||
}
|
||||
|
||||
@@ -498,6 +498,22 @@ func TestClientMapRemoval(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuthorizationTimeout(t *testing.T) {
|
||||
serverOptions := defaultServerOptions
|
||||
serverOptions.Authorization = "my_token"
|
||||
serverOptions.AuthTimeout = 1
|
||||
_, _, cr, _ := rawSetup(serverOptions)
|
||||
|
||||
time.Sleep(secondsToDuration(serverOptions.AuthTimeout))
|
||||
l, err := cr.ReadString('\n')
|
||||
if err != nil {
|
||||
t.Fatalf("Error receiving info from server: %v\n", err)
|
||||
}
|
||||
if !strings.Contains (l, "Authorization Timeout") {
|
||||
t.Fatalf("Authorization Timeout response incorrect: %q\n", l)
|
||||
}
|
||||
}
|
||||
|
||||
// This is from bug report #18
|
||||
func TestTwoTokenPubMatchSingleTokenSub(t *testing.T) {
|
||||
_, c, cr := setupClient()
|
||||
|
||||
Reference in New Issue
Block a user