Skip to content

Commit

Permalink
connection made in lua needs auth
Browse files Browse the repository at this point in the history
For #39
  • Loading branch information
alicebob committed May 22, 2018
1 parent c8ba259 commit 6b85e2d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
6 changes: 3 additions & 3 deletions cmd_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ func TestAuth(t *testing.T) {
ok(t, err)

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

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

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

_, err = c.Do("AUTH", "nocomment")
ok(t, err)
Expand Down
23 changes: 23 additions & 0 deletions cmd_scripting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,3 +495,26 @@ func TestCmdEvalResponse(t *testing.T) {
equals(t, []interface{}{nil, nil}, v)
}
}

func TestCmdEvalAuth(t *testing.T) {
s, err := Run()
ok(t, err)
defer s.Close()

c, err := redis.Dial("tcp", s.Addr())
ok(t, err)
defer c.Close()

eval := "return redis.call('set','foo','bar')"

s.RequireAuth("123password")

_, err = c.Do("EVAL", eval, 0)
mustFail(t, err, "NOAUTH Authentication required.")

_, err = c.Do("AUTH", "123password")
ok(t, err)

_, err = c.Do("EVAL", eval, 0)
ok(t, err)
}
8 changes: 7 additions & 1 deletion miniredis.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,13 @@ func (m *Miniredis) FastForward(duration time.Duration) {
func (m *Miniredis) redigo() redigo.Conn {
c1, c2 := net.Pipe()
m.srv.ServeConn(c1)
return redigo.NewConn(c2, 0, 0)
c := redigo.NewConn(c2, 0, 0)
if m.password != "" {
if _, err := c.Do("AUTH", m.password); err != nil {
// ?
}
}
return c
}

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

0 comments on commit 6b85e2d

Please sign in to comment.