-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathdsl_spec.rb
60 lines (49 loc) · 2.06 KB
/
dsl_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
# frozen_string_literal: true
describe Grape::Middleware::Auth::DSL do
subject { Class.new(Grape::API) }
let(:block) { -> {} }
let(:settings) do
{
opaque: 'secret',
proc: block,
realm: 'API Authorization',
type: :http_digest
}
end
describe '.auth' do
it 'sets auth parameters' do
expect(subject.base_instance).to receive(:use).with(Grape::Middleware::Auth::Base, settings)
subject.auth :http_digest, realm: settings[:realm], opaque: settings[:opaque], &settings[:proc]
expect(subject.auth).to eq(settings)
end
it 'can be called multiple times' do
expect(subject.base_instance).to receive(:use).with(Grape::Middleware::Auth::Base, settings)
expect(subject.base_instance).to receive(:use).with(Grape::Middleware::Auth::Base, settings.merge(realm: 'super_secret'))
subject.auth :http_digest, realm: settings[:realm], opaque: settings[:opaque], &settings[:proc]
first_settings = subject.auth
subject.auth :http_digest, realm: 'super_secret', opaque: settings[:opaque], &settings[:proc]
expect(subject.auth).to eq(settings.merge(realm: 'super_secret'))
expect(subject.auth.object_id).not_to eq(first_settings.object_id)
end
end
describe '.http_basic' do
it 'sets auth parameters' do
subject.http_basic realm: 'my_realm', &settings[:proc]
expect(subject.auth).to eq(realm: 'my_realm', type: :http_basic, proc: block)
end
end
describe '.http_digest' do
context 'when realm is a hash' do
it 'sets auth parameters' do
subject.http_digest realm: { realm: 'my_realm', opaque: 'my_opaque' }, &settings[:proc]
expect(subject.auth).to eq(realm: { realm: 'my_realm', opaque: 'my_opaque' }, type: :http_digest, proc: block)
end
end
context 'when realm is not hash' do
it 'sets auth parameters' do
subject.http_digest realm: 'my_realm', opaque: 'my_opaque', &settings[:proc]
expect(subject.auth).to eq(realm: 'my_realm', type: :http_digest, proc: block, opaque: 'my_opaque')
end
end
end
end