Use authTimeout in setAuthTimer

This commit is contained in:
w00228948
2014-08-11 15:22:32 +00:00
parent c01c3e15d9
commit 31bc0bdb8c
2 changed files with 26 additions and 5 deletions

View File

@@ -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

View File

@@ -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()