forked from ably/ably-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth_spec.rb
79 lines (61 loc) · 1.97 KB
/
auth_spec.rb
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
require 'spec_helper'
require 'shared/protocol_msgbus_behaviour'
describe Ably::Auth do
let(:client) { double('client').as_null_object }
let(:client_id) { nil }
let(:auth_options) { { key: 'appid.keyuid:keysecret', client_id: client_id } }
let(:token_params) { { } }
subject do
Ably::Auth.new(client, token_params, auth_options)
end
describe 'client_id option' do
let(:client_id) { random_str.encode(encoding) }
context 'with nil value' do
let(:client_id) { nil }
it 'is permitted' do
expect(subject.client_id).to be_nil
end
end
context 'as UTF_8 string' do
let(:encoding) { Encoding::UTF_8 }
it 'is permitted' do
expect(subject.client_id).to eql(client_id)
end
it 'remains as UTF-8' do
expect(subject.client_id.encoding).to eql(encoding)
end
end
context 'as SHIFT_JIS string' do
let(:encoding) { Encoding::SHIFT_JIS }
it 'gets converted to UTF-8' do
expect(subject.client_id.encoding).to eql(Encoding::UTF_8)
end
it 'is compatible with original encoding' do
expect(subject.client_id.encode(encoding)).to eql(client_id)
end
end
context 'as ASCII_8BIT string' do
let(:encoding) { Encoding::ASCII_8BIT }
it 'gets converted to UTF-8' do
expect(subject.client_id.encoding).to eql(Encoding::UTF_8)
end
it 'is compatible with original encoding' do
expect(subject.client_id.encode(encoding)).to eql(client_id)
end
end
context 'as Integer' do
let(:client_id) { 1 }
it 'raises an argument error' do
expect { subject.client_id }.to raise_error ArgumentError, /must be a String/
end
end
end
context 'defaults' do
it 'should have no default TTL' do
expect(Ably::Auth::TOKEN_DEFAULTS[:ttl]).to be_nil
end
it 'should have no default capability' do
expect(Ably::Auth::TOKEN_DEFAULTS[:capability]).to be_nil
end
end
end