|
7 | 7 | require 'async/redis/protocol/authenticated'
|
8 | 8 | require 'sus/fixtures/async'
|
9 | 9 |
|
10 |
| -describe Async::Redis::Protocol::Authenticated do |
| 10 | +describe Async::Redis::Endpoint do |
11 | 11 | include Sus::Fixtures::Async::ReactorContext
|
12 | 12 |
|
13 | 13 | let(:endpoint) {Async::Redis.local_endpoint}
|
14 |
| - let(:credentials) {["testuser", "testpassword"]} |
15 |
| - let(:protocol) {subject.new(credentials)} |
16 |
| - let(:client) {Async::Redis::Client.new(endpoint, protocol: protocol)} |
17 | 14 |
|
18 |
| - before do |
19 |
| - # Setup ACL user with limited permissions for testing. |
20 |
| - admin_client = Async::Redis::Client.new(endpoint) |
21 |
| - admin_client.call("ACL", "SETUSER", "testuser", "on", ">" + credentials[1], "+ping", "+auth") |
22 |
| - ensure |
23 |
| - admin_client.close |
24 |
| - end |
25 |
| - |
26 |
| - after do |
27 |
| - # Cleanup ACL user after tests. |
28 |
| - admin_client = Async::Redis::Client.new(endpoint) |
29 |
| - admin_client.call("ACL", "DELUSER", "testuser") |
30 |
| - admin_client.close |
31 |
| - end |
32 |
| - |
33 |
| - it "can authenticate and send allowed commands" do |
34 |
| - response = client.call("PING") |
35 |
| - expect(response).to be == "PONG" |
36 |
| - end |
37 |
| - |
38 |
| - it "rejects commands not allowed by ACL" do |
39 |
| - expect do |
40 |
| - client.call("SET", "key", "value") |
41 |
| - end.to raise_exception(Protocol::Redis::ServerError, message: be =~ /NOPERM/) |
| 15 | + with '#protocol' do |
| 16 | + it "defaults to RESP2" do |
| 17 | + expect(endpoint.protocol).to be == Async::Redis::Protocol::RESP2 |
| 18 | + end |
| 19 | + |
| 20 | + with 'database selection' do |
| 21 | + let(:endpoint) {Async::Redis.local_endpoint(database: 1)} |
| 22 | + |
| 23 | + it "selects the database" do |
| 24 | + expect(endpoint.protocol).to be_a(Async::Redis::Protocol::Selected) |
| 25 | + expect(endpoint.protocol.index).to be == 1 |
| 26 | + end |
| 27 | + end |
| 28 | + |
| 29 | + with 'credentials' do |
| 30 | + let(:credentials) {["testuser", "testpassword"]} |
| 31 | + let(:endpoint) {Async::Redis.local_endpoint(credentials: credentials)} |
| 32 | + |
| 33 | + it "authenticates with credentials" do |
| 34 | + expect(endpoint.protocol).to be_a(Async::Redis::Protocol::Authenticated) |
| 35 | + expect(endpoint.protocol.credentials).to be == credentials |
| 36 | + end |
| 37 | + end |
42 | 38 | end
|
43 | 39 | end
|
0 commit comments