File: authentication.rb

package info (click to toggle)
ruby-redis 5.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,160 kB
  • sloc: ruby: 11,445; makefile: 117; sh: 24
file content (30 lines) | stat: -rw-r--r-- 801 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

module Lint
  module Authentication
    def test_auth_with_password
      mock(auth: ->(*_) { '+OK' }) do |r|
        assert_equal 'OK', r.auth('mysecret')
      end

      mock(auth: ->(*_) { '-ERR some error' }) do |r|
        assert_raises(Redis::BaseError) { r.auth('mysecret') }
      end
    end

    def test_auth_for_acl
      target_version "6.0.0" do
        with_acl do |username, password|
          assert_raises(Redis::CannotConnectError) { redis.auth(username, 'wrongpassword') }
          assert_equal 'OK', redis.auth(username, password)
          assert_equal 'PONG', redis.ping
          assert_raises(Redis::BaseError) { redis.echo('foo') }
        end
      end
    end

    def mock(*args, &block)
      redis_mock(*args, &block)
    end
  end
end