Skip to content
4 changes: 4 additions & 0 deletions src/server/redis_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ Connection::Connection(bufferevent *bev, Worker *owner)
int64_t now = util::GetTimeStamp();
create_time_ = now;
last_interaction_ = now;
if (srv_->GetConfig()->requirepass.empty()) {
Comment thread
aviralgarg05 marked this conversation as resolved.
Outdated
BecomeAdmin();
SetNamespace(kDefaultNamespace);
}
}

Connection::~Connection() {
Expand Down
16 changes: 16 additions & 0 deletions tests/gocase/unit/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ func TestNoAuth(t *testing.T) {
r := rdb.Do(ctx, "AUTH", "foo")
require.ErrorContains(t, r.Err(), "no password")
})

t.Run("Connections accepted before requirepass is set remain usable", func(t *testing.T) {
idleConn := srv.NewTCPClient()
defer func() { require.NoError(t, idleConn.Close()) }()

require.NoError(t, rdb.ConfigSet(ctx, "requirepass", "foobar").Err())

require.NoError(t, idleConn.WriteArgs("PING"))
idleConn.MustRead(t, "+PONG")

newConn := srv.NewTCPClient()
defer func() { require.NoError(t, newConn.Close()) }()

require.NoError(t, newConn.WriteArgs("PING"))
newConn.MustRead(t, "-NOAUTH Authentication required.")
})
}

func TestAuth(t *testing.T) {
Expand Down