Skip to content

Commit 6b85e2d

Browse files
committed
connection made in lua needs auth
For #39
1 parent c8ba259 commit 6b85e2d

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

cmd_connection_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ func TestAuth(t *testing.T) {
1414
ok(t, err)
1515

1616
_, err = c.Do("AUTH", "foo", "bar")
17-
assert(t, err != nil, "no password set")
17+
mustFail(t, err, "ERR wrong number of arguments for 'auth' command")
1818

1919
s.RequireAuth("nocomment")
2020
_, err = c.Do("PING", "foo", "bar")
21-
assert(t, err != nil, "need AUTH")
21+
mustFail(t, err, "NOAUTH Authentication required.")
2222

2323
_, err = c.Do("AUTH", "wrongpasswd")
24-
assert(t, err != nil, "wrong password")
24+
mustFail(t, err, "ERR invalid password")
2525

2626
_, err = c.Do("AUTH", "nocomment")
2727
ok(t, err)

cmd_scripting_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,3 +495,26 @@ func TestCmdEvalResponse(t *testing.T) {
495495
equals(t, []interface{}{nil, nil}, v)
496496
}
497497
}
498+
499+
func TestCmdEvalAuth(t *testing.T) {
500+
s, err := Run()
501+
ok(t, err)
502+
defer s.Close()
503+
504+
c, err := redis.Dial("tcp", s.Addr())
505+
ok(t, err)
506+
defer c.Close()
507+
508+
eval := "return redis.call('set','foo','bar')"
509+
510+
s.RequireAuth("123password")
511+
512+
_, err = c.Do("EVAL", eval, 0)
513+
mustFail(t, err, "NOAUTH Authentication required.")
514+
515+
_, err = c.Do("AUTH", "123password")
516+
ok(t, err)
517+
518+
_, err = c.Do("EVAL", eval, 0)
519+
ok(t, err)
520+
}

miniredis.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,13 @@ func (m *Miniredis) FastForward(duration time.Duration) {
244244
func (m *Miniredis) redigo() redigo.Conn {
245245
c1, c2 := net.Pipe()
246246
m.srv.ServeConn(c1)
247-
return redigo.NewConn(c2, 0, 0)
247+
c := redigo.NewConn(c2, 0, 0)
248+
if m.password != "" {
249+
if _, err := c.Do("AUTH", m.password); err != nil {
250+
// ?
251+
}
252+
}
253+
return c
248254
}
249255

250256
// Dump returns a text version of the selected DB, usable for debugging.

0 commit comments

Comments
 (0)