@@ -1,101 +0,0 @@ |
||
1 |
-require 'spec_helper' |
|
2 |
- |
|
3 |
-describe WebRequestConcern do |
|
4 |
- before do |
|
5 |
- class WebRequestConcernTest < Agent |
|
6 |
- include WebRequestConcern |
|
7 |
- end |
|
8 |
- end |
|
9 |
- |
|
10 |
- describe '#faraday' do |
|
11 |
- it 'should set up the User-Agent headers' do |
|
12 |
- web_request = WebRequestConcernTest.new() |
|
13 |
- faraday = web_request.faraday |
|
14 |
- expect(faraday.headers['User-Agent']).to eq(web_request.user_agent) |
|
15 |
- end |
|
16 |
- |
|
17 |
- it 'should follow redirects' do |
|
18 |
- web_request = WebRequestConcernTest.new() |
|
19 |
- faraday = web_request.faraday |
|
20 |
- expect(faraday.builder.handlers).to include(FaradayMiddleware::FollowRedirects) |
|
21 |
- end |
|
22 |
- |
|
23 |
- it 'should enable SSL verification by default' do |
|
24 |
- web_request = WebRequestConcernTest.new() |
|
25 |
- faraday = web_request.faraday |
|
26 |
- expect(faraday.ssl.verify).to eq(true) |
|
27 |
- end |
|
28 |
- |
|
29 |
- it 'should disable SSL verification if disable_ssl_verification option is true' do |
|
30 |
- web_request = WebRequestConcernTest.new(options: { disable_ssl_verification: true }) |
|
31 |
- faraday = web_request.faraday |
|
32 |
- expect(faraday.ssl.verify).to eq(false) |
|
33 |
- end |
|
34 |
- end |
|
35 |
- |
|
36 |
- describe '#validate_web_request_options!' do |
|
37 |
- it 'should be valid with only default options' do |
|
38 |
- web_request = WebRequestConcernTest.new() |
|
39 |
- web_request.validate_web_request_options! |
|
40 |
- expect(web_request.errors[:base]).to be_empty |
|
41 |
- end |
|
42 |
- |
|
43 |
- describe 'user_agent' do |
|
44 |
- it 'should be a string' do |
|
45 |
- web_request = WebRequestConcernTest.new(options: { user_agent: 'Huginn' } ) |
|
46 |
- web_request.validate_web_request_options! |
|
47 |
- expect(web_request.errors[:base]).to be_empty |
|
48 |
- end |
|
49 |
- |
|
50 |
- it 'should be invalid if not a string' do |
|
51 |
- web_request = WebRequestConcernTest.new(options: { user_agent: 42 } ) |
|
52 |
- web_request.validate_web_request_options! |
|
53 |
- expect(web_request.errors[:base]).to_not be_empty |
|
54 |
- end |
|
55 |
- end |
|
56 |
- |
|
57 |
- describe 'headers' do |
|
58 |
- it 'should be a hash' do |
|
59 |
- web_request = WebRequestConcernTest.new(options: { headers: {} } ) |
|
60 |
- web_request.validate_web_request_options! |
|
61 |
- expect(web_request.errors[:base]).to be_empty |
|
62 |
- end |
|
63 |
- |
|
64 |
- it 'should be invalid if not a hash' do |
|
65 |
- web_request = WebRequestConcernTest.new(options: { headers: 42 } ) |
|
66 |
- web_request.validate_web_request_options! |
|
67 |
- expect(web_request.errors[:base]).to_not be_empty |
|
68 |
- end |
|
69 |
- end |
|
70 |
- |
|
71 |
- describe 'basic_auth' do |
|
72 |
- it 'should be valid if basic_auth_credentials doesnt raise error' do |
|
73 |
- web_request = WebRequestConcernTest.new() |
|
74 |
- expect { web_request.basic_auth_credentials }.to_not raise_error |
|
75 |
- web_request.validate_web_request_options! |
|
76 |
- expect(web_request.errors[:base]).to be_empty |
|
77 |
- end |
|
78 |
- |
|
79 |
- it 'should be invalid if basic_auth_credentials raises error' do |
|
80 |
- web_request = WebRequestConcernTest.new(options: { basic_auth: 'invalid' }) |
|
81 |
- expect { web_request.basic_auth_credentials }.to raise_error(ArgumentError) |
|
82 |
- web_request.validate_web_request_options! |
|
83 |
- expect(web_request.errors[:base]).to_not be_empty |
|
84 |
- end |
|
85 |
- end |
|
86 |
- |
|
87 |
- describe 'disable_ssl_verification' do |
|
88 |
- it 'should be a boolean' do |
|
89 |
- web_request = WebRequestConcernTest.new(options: { disable_ssl_verification: true } ) |
|
90 |
- web_request.validate_web_request_options! |
|
91 |
- expect(web_request.errors[:base]).to be_empty |
|
92 |
- end |
|
93 |
- |
|
94 |
- it 'should be invalid if not a boolean' do |
|
95 |
- web_request = WebRequestConcernTest.new(options: { disable_ssl_verification: 42 } ) |
|
96 |
- web_request.validate_web_request_options! |
|
97 |
- expect(web_request.errors[:base]).to_not be_empty |
|
98 |
- end |
|
99 |
- end |
|
100 |
- end |
|
101 |
-end |
@@ -62,6 +62,23 @@ shared_examples_for WebRequestConcern do |
||
62 | 62 |
agent.options['basic_auth'] = ["blah"] |
63 | 63 |
expect(agent).not_to be_valid |
64 | 64 |
end |
65 |
+ |
|
66 |
+ it "should validate disable_ssl_verification" do |
|
67 |
+ agent.options['disable_ssl_verification'] = nil |
|
68 |
+ expect(agent).to be_valid |
|
69 |
+ |
|
70 |
+ agent.options['disable_ssl_verification'] = true |
|
71 |
+ expect(agent).to be_valid |
|
72 |
+ |
|
73 |
+ agent.options['disable_ssl_verification'] = false |
|
74 |
+ expect(agent).to be_valid |
|
75 |
+ |
|
76 |
+ agent.options['disable_ssl_verification'] = 'blah' |
|
77 |
+ expect(agent).not_to be_valid |
|
78 |
+ |
|
79 |
+ agent.options['disable_ssl_verification'] = 51 |
|
80 |
+ expect(agent).not_to be_valid |
|
81 |
+ end |
|
65 | 82 |
end |
66 | 83 |
|
67 | 84 |
describe "User-Agent" do |
@@ -88,4 +105,15 @@ shared_examples_for WebRequestConcern do |
||
88 | 105 |
expect(agent.user_agent).to eq('Override') |
89 | 106 |
end |
90 | 107 |
end |
108 |
+ |
|
109 |
+ describe "#faraday" do |
|
110 |
+ it "should enable SSL verification by default" do |
|
111 |
+ expect(agent.faraday.ssl.verify).to eq(true) |
|
112 |
+ end |
|
113 |
+ |
|
114 |
+ it "should disable SSL verification if disable_ssl_verification option is true" do |
|
115 |
+ agent.options['disable_ssl_verification'] = true |
|
116 |
+ expect(agent.faraday.ssl.verify).to eq(false) |
|
117 |
+ end |
|
118 |
+ end |
|
91 | 119 |
end |