htty 1.4.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +2 -1
- data/.rspec +2 -0
- data/.travis.yml +21 -3
- data/.yardopts +1 -1
- data/Gemfile +2 -2
- data/Guardfile +12 -10
- data/History.markdown +14 -0
- data/{MIT-LICENSE.markdown → License.markdown} +1 -1
- data/README.markdown +50 -65
- data/Rakefile +2 -2
- data/htty.gemspec +2 -2
- data/lib/htty/cli.rb +59 -74
- data/lib/htty/cli/command.rb +21 -20
- data/lib/htty/cli/commands/body_edit.rb +89 -0
- data/lib/htty/cli/commands/query_add.rb +3 -0
- data/lib/htty/cli/commands/query_set.rb +3 -0
- data/lib/htty/cli/commands/userinfo_set.rb +8 -14
- data/lib/htty/cli/display.rb +14 -12
- data/lib/htty/cli/input_device.rb +75 -0
- data/lib/htty/cli/url_escaping.rb +2 -2
- data/lib/htty/headers.rb +81 -0
- data/lib/htty/no_header_error.rb +10 -0
- data/lib/htty/payload.rb +22 -9
- data/lib/htty/request.rb +67 -43
- data/lib/htty/requests_util.rb +22 -8
- data/lib/htty/response.rb +20 -1
- data/lib/htty/uri.rb +16 -0
- data/lib/htty/version.rb +1 -1
- data/spec/integration/htty/cli/commands/query_add_spec.rb +7 -1
- data/spec/integration/htty/cli/commands/query_remove_spec.rb +19 -1
- data/spec/integration/htty/cli/commands/query_set_spec.rb +9 -3
- data/spec/integration/htty/cli/commands/query_unset_spec.rb +8 -2
- data/spec/spec_helper.rb +69 -0
- data/spec/unit/htty/cli/commands/address_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/body_clear_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/body_edit_spec.rb +18 -0
- data/spec/unit/htty/cli/commands/body_request_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/body_response_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/body_set_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/body_unset_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/cd_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/cookie_add_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/cookie_remove_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/cookies_add_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/cookies_clear_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/cookies_remove_all_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/cookies_remove_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/cookies_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/cookies_use_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/delete_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/exit_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/follow_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/form_add_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/form_clear_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/form_remove_all_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/form_remove_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/form_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/fragment_clear_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/fragment_set_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/fragment_unset_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/get_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/header_set_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/header_unset_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/headers_clear_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/headers_request_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/headers_response_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/headers_set_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/headers_unset_all_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/headers_unset_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/help_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/history_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/history_verbose_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/host_set_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/http_delete_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/http_get_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/http_head_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/http_options_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/http_patch_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/http_post_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/http_put_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/http_trace_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/patch_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/path_set_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/port_set_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/post_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/put_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/query_add_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/query_clear_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/query_remove_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/query_set_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/query_unset_all_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/query_unset_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/quit_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/reuse_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/scheme_set_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/shared_examples_for_commands.rb +55 -0
- data/spec/unit/htty/cli/commands/ssl_verification_off_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/ssl_verification_on_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/ssl_verification_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/status_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/undo_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/userinfo_clear_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/userinfo_set_spec.rb +23 -1
- data/spec/unit/htty/cli/commands/userinfo_unset_spec.rb +1 -1
- data/spec/unit/htty/cli/display_spec.rb +84 -0
- data/spec/unit/htty/cli_spec.rb +1 -1
- data/spec/unit/htty/command.rb +47 -0
- data/spec/unit/htty/{ordered_hash_spec.rb → headers_spec.rb} +4 -4
- data/spec/unit/htty/payload_spec.rb +60 -0
- data/spec/unit/htty/preferences_spec.rb +1 -1
- data/spec/unit/htty/request_follow_spec.rb +94 -0
- data/spec/unit/htty/request_spec.rb +5 -187
- data/spec/unit/htty/request_userinfo_spec.rb +208 -0
- data/spec/unit/htty/session_spec.rb +1 -1
- data/spec/unit/htty/shared_examples_for_requests.rb +32 -0
- data/spec/unit/htty/url_escaping.rb +70 -0
- data/spec/unit/htty/version_spec.rb +1 -1
- metadata +43 -30
- data/lib/htty/ordered_hash.rb +0 -68
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/request")
|
|
3
|
+
require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/response")
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
describe HTTY::Request do
|
|
7
|
+
let(:request_address) {'http://example.com/a?b=c#d'}
|
|
8
|
+
let(:request) {HTTY::Request.new request_address}
|
|
9
|
+
|
|
10
|
+
describe '#follow a response' do
|
|
11
|
+
let(:response) do
|
|
12
|
+
HTTY::Response.new({:headers => {'Location' => response_location}})
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
before :each do
|
|
16
|
+
request.send :response=, response
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe 'with an absolute URI in Location header' do
|
|
20
|
+
let(:response_location) {'http://followme.com/a/b/c'}
|
|
21
|
+
|
|
22
|
+
it 'should return another request' do
|
|
23
|
+
request.follow(response).should_not == request
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'should return a request with the absolute URI as its HTTP URI' do
|
|
27
|
+
request.follow(response).uri.should == URI.parse(response_location)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe 'with an absolute path in Location header' do
|
|
32
|
+
let(:response_location) {'/a/b/c'}
|
|
33
|
+
|
|
34
|
+
it 'should return a request with the same URI host ' +
|
|
35
|
+
'and with the URI path changed to the absolute path in Location' do
|
|
36
|
+
expected_uri = URI.parse(request_address)
|
|
37
|
+
expected_uri.path = response_location
|
|
38
|
+
expected_uri.query = nil
|
|
39
|
+
expected_uri.fragment = nil
|
|
40
|
+
request.follow(response).uri.should == expected_uri
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe 'with a relative path in Location header' do
|
|
45
|
+
let(:response_location) {'a/b/c'}
|
|
46
|
+
|
|
47
|
+
it 'should return a request with the same URI host ' +
|
|
48
|
+
'and with the URI path changed joining the ' +
|
|
49
|
+
'original URI path to the relative path in Location' do
|
|
50
|
+
expected_uri = URI.parse(request_address)
|
|
51
|
+
expected_uri.path = File.join(expected_uri.path, response_location)
|
|
52
|
+
expected_uri.query = nil
|
|
53
|
+
expected_uri.fragment = nil
|
|
54
|
+
request.follow(response).uri.should == expected_uri
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
context 'when invoked more than once' do
|
|
58
|
+
let(:after_follow) {request.follow(response)}
|
|
59
|
+
|
|
60
|
+
it 'should return always the same request' do
|
|
61
|
+
after_follow.uri.should == after_follow.follow(response).uri
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
describe 'with an URI with query string in Location header' do
|
|
67
|
+
let(:response_location) {'a/b/c?d=e&f=g'}
|
|
68
|
+
|
|
69
|
+
it 'should return a request with URI query string ' +
|
|
70
|
+
'equal to the Location query string' do
|
|
71
|
+
expected_query = URI.parse(response_location).query
|
|
72
|
+
request.follow(response).uri.query.should == expected_query
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'should return a request without URI fragment' do
|
|
76
|
+
request.follow(response).uri.fragment.should be_nil
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe 'with an URI with fragment in Location header' do
|
|
81
|
+
let(:response_location) {'a/b/c#f'}
|
|
82
|
+
|
|
83
|
+
it 'should return a request with URI fragment ' +
|
|
84
|
+
'equal to the Location fragment' do
|
|
85
|
+
expected_fragment = URI.parse(response_location).fragment
|
|
86
|
+
request.follow(response).uri.fragment.should == expected_fragment
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it 'should return a request without URI query string' do
|
|
90
|
+
request.follow(response).uri.query.should be_nil
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
@@ -1,81 +1,19 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/request")
|
|
3
3
|
require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/response")
|
|
4
4
|
require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/version")
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
it 'should have only the default headers' do
|
|
8
|
-
request.headers.should == [['User-Agent', "htty/#{HTTY::VERSION}"]]
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it 'should have no body' do
|
|
12
|
-
request.body.should be_nil
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it 'should have no response' do
|
|
16
|
-
request.response.should be_nil
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
shared_examples_for 'an empty, authenticated request' do
|
|
21
|
-
it 'should the expected Authorization header plus the default headers' do
|
|
22
|
-
request.headers.should == [['User-Agent', "htty/#{HTTY::VERSION}"],
|
|
23
|
-
['Authorization', 'Basic bmpvbnNzb24=']]
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it 'should have no body' do
|
|
27
|
-
request.body.should be_nil
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it 'should have no response' do
|
|
31
|
-
request.response.should be_nil
|
|
32
|
-
end
|
|
33
|
-
end
|
|
6
|
+
require File.expand_path("#{File.dirname __FILE__}/shared_examples_for_requests")
|
|
34
7
|
|
|
35
8
|
describe HTTY::Request do
|
|
9
|
+
let(:username) {'njonsson'}
|
|
10
|
+
let(:password) {nil}
|
|
11
|
+
|
|
36
12
|
describe 'initializing with' do
|
|
37
13
|
let :klass do
|
|
38
14
|
HTTY::Request
|
|
39
15
|
end
|
|
40
16
|
|
|
41
|
-
describe 'an invalid IPv4 address having' do
|
|
42
|
-
describe 'consecutive dots' do
|
|
43
|
-
it 'should raise URI::InvalidURIError' do
|
|
44
|
-
expect { klass.new '1.2.3..4' }.to raise_error(URI::InvalidURIError)
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
describe 'no dots' do
|
|
49
|
-
it 'should raise URI::InvalidURIError' do
|
|
50
|
-
expect { klass.new '1234' }.to raise_error(URI::InvalidURIError)
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
describe 'too few dotted decimals' do
|
|
55
|
-
it 'should raise URI::InvalidURIError' do
|
|
56
|
-
expect { klass.new '1.2.3' }.to raise_error(URI::InvalidURIError)
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
describe 'too many dotted decimals' do
|
|
61
|
-
it 'should raise URI::InvalidURIError' do
|
|
62
|
-
expect { klass.new '1.2.3.4.5' }.to raise_error(URI::InvalidURIError)
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
describe 'a dotted decimal out of range' do
|
|
67
|
-
it 'should raise URI::InvalidURIError' do
|
|
68
|
-
expect { klass.new '1.2.3.1000' }.to raise_error(URI::InvalidURIError)
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
describe 'an invalid hostname having a leading hyphen' do
|
|
74
|
-
it 'should raise URI::InvalidURIError' do
|
|
75
|
-
expect { klass.new '-google.com' }.to raise_error(URI::InvalidURIError)
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
17
|
describe 'a valid FTP address' do
|
|
80
18
|
it 'should raise URI::InvalidURIError' do
|
|
81
19
|
expect do
|
|
@@ -390,93 +328,6 @@ describe HTTY::Request do
|
|
|
390
328
|
end
|
|
391
329
|
end
|
|
392
330
|
|
|
393
|
-
describe '-- when sent #userinfo_set with' do
|
|
394
|
-
describe 'the same userinfo --' do
|
|
395
|
-
before :each do
|
|
396
|
-
request.userinfo_set 'njonsson'
|
|
397
|
-
end
|
|
398
|
-
|
|
399
|
-
it 'should have an unchanged URI' do
|
|
400
|
-
request.uri.should == URI.parse('https://njonsson@github.com' +
|
|
401
|
-
':123' +
|
|
402
|
-
'/search/deep?q=http&lang=en' +
|
|
403
|
-
'#content')
|
|
404
|
-
end
|
|
405
|
-
|
|
406
|
-
it_should_behave_like 'an empty, authenticated request'
|
|
407
|
-
end
|
|
408
|
-
|
|
409
|
-
describe 'different userinfo' do
|
|
410
|
-
describe "that does not contain '@' --" do
|
|
411
|
-
before :each do
|
|
412
|
-
request.userinfo_set 'nils'
|
|
413
|
-
end
|
|
414
|
-
|
|
415
|
-
it 'should have the same URI, with the changed userinfo' do
|
|
416
|
-
request.uri.should == URI.parse('https://nils@github.com:123' +
|
|
417
|
-
'/search/deep?q=http&lang=en' +
|
|
418
|
-
'#content')
|
|
419
|
-
end
|
|
420
|
-
|
|
421
|
-
it 'should the expected Authorization header plus the default ' +
|
|
422
|
-
'headers' do
|
|
423
|
-
request.headers.should == [['User-Agent', 'htty/' +
|
|
424
|
-
HTTY::VERSION],
|
|
425
|
-
['Authorization', 'Basic bmlscw==']]
|
|
426
|
-
end
|
|
427
|
-
|
|
428
|
-
it 'should have no body' do
|
|
429
|
-
request.body.should be_nil
|
|
430
|
-
end
|
|
431
|
-
|
|
432
|
-
it 'should have no response' do
|
|
433
|
-
request.response.should be_nil
|
|
434
|
-
end
|
|
435
|
-
end
|
|
436
|
-
|
|
437
|
-
describe "that contains an escaped '@' --" do
|
|
438
|
-
before :each do
|
|
439
|
-
request.userinfo_set 'n%45'
|
|
440
|
-
end
|
|
441
|
-
|
|
442
|
-
it 'should have the same URI, with the changed userinfo' do
|
|
443
|
-
request.uri.should == URI.parse('https://n%45@github.com:123' +
|
|
444
|
-
'/search/deep?q=http&lang=en' +
|
|
445
|
-
'#content')
|
|
446
|
-
end
|
|
447
|
-
|
|
448
|
-
it 'should the expected Authorization header plus the default ' +
|
|
449
|
-
'headers' do
|
|
450
|
-
request.headers.should == [['User-Agent', 'htty/' +
|
|
451
|
-
HTTY::VERSION],
|
|
452
|
-
['Authorization', 'Basic bkU=']]
|
|
453
|
-
end
|
|
454
|
-
|
|
455
|
-
it 'should have no body' do
|
|
456
|
-
request.body.should be_nil
|
|
457
|
-
end
|
|
458
|
-
|
|
459
|
-
it 'should have no response' do
|
|
460
|
-
request.response.should be_nil
|
|
461
|
-
end
|
|
462
|
-
end
|
|
463
|
-
end
|
|
464
|
-
end
|
|
465
|
-
|
|
466
|
-
describe '-- when sent #userinfo_unset --' do
|
|
467
|
-
before :each do
|
|
468
|
-
request.userinfo_unset
|
|
469
|
-
end
|
|
470
|
-
|
|
471
|
-
it 'should have the same URI, without userinfo' do
|
|
472
|
-
request.uri.should == URI.parse('https://github.com:123' +
|
|
473
|
-
'/search/deep?q=http&lang=en' +
|
|
474
|
-
'#content')
|
|
475
|
-
end
|
|
476
|
-
|
|
477
|
-
it_should_behave_like 'an empty request'
|
|
478
|
-
end
|
|
479
|
-
|
|
480
331
|
describe '-- when sent #host_set with' do
|
|
481
332
|
describe 'the same host --' do
|
|
482
333
|
before :each do
|
|
@@ -1111,39 +962,6 @@ describe HTTY::Request do
|
|
|
1111
962
|
end
|
|
1112
963
|
end
|
|
1113
964
|
|
|
1114
|
-
describe '-- when sent #userinfo_set with different userinfo --' do
|
|
1115
|
-
let :new_request do
|
|
1116
|
-
request.userinfo_set 'nils'
|
|
1117
|
-
end
|
|
1118
|
-
|
|
1119
|
-
it 'should return a request with the same URI having the changed ' +
|
|
1120
|
-
'userinfo' do
|
|
1121
|
-
new_request.uri.should == URI.parse('https://nils@github.com:123' +
|
|
1122
|
-
'/search/deep?q=http&lang=en' +
|
|
1123
|
-
'#content')
|
|
1124
|
-
end
|
|
1125
|
-
|
|
1126
|
-
it 'should return a request without a response' do
|
|
1127
|
-
new_request.response.should be_nil
|
|
1128
|
-
end
|
|
1129
|
-
end
|
|
1130
|
-
|
|
1131
|
-
describe '-- when sent #userinfo_unset --' do
|
|
1132
|
-
let :new_request do
|
|
1133
|
-
request.userinfo_unset
|
|
1134
|
-
end
|
|
1135
|
-
|
|
1136
|
-
it 'should return a request with the same URI not having userinfo' do
|
|
1137
|
-
new_request.uri.should == URI.parse('https://github.com:123' +
|
|
1138
|
-
'/search/deep?q=http&lang=en' +
|
|
1139
|
-
'#content')
|
|
1140
|
-
end
|
|
1141
|
-
|
|
1142
|
-
it 'should return a request without a response' do
|
|
1143
|
-
new_request.response.should be_nil
|
|
1144
|
-
end
|
|
1145
|
-
end
|
|
1146
|
-
|
|
1147
965
|
describe '-- when sent #host_set with a different host --' do
|
|
1148
966
|
let :new_request do
|
|
1149
967
|
request.host_set 'gist.github.com'
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/request")
|
|
3
|
+
require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/response")
|
|
4
|
+
require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/version")
|
|
5
|
+
|
|
6
|
+
require File.expand_path("#{File.dirname __FILE__}/shared_examples_for_requests")
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
shared_examples_for 'a request with basic authentication' do
|
|
10
|
+
it 'should have userinfo in the URI' do
|
|
11
|
+
expected_uri = URI.parse(uri)
|
|
12
|
+
expected_uri.userinfo = [username, password].compact.join(':')
|
|
13
|
+
subject.uri.should == expected_uri
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'should have the Authorization header' do
|
|
17
|
+
subject.headers.should == [
|
|
18
|
+
user_agent_header,
|
|
19
|
+
HTTY::Headers.basic_authentication_for(
|
|
20
|
+
username, password
|
|
21
|
+
)
|
|
22
|
+
]
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
shared_examples_for 'a request without basic authentication' do
|
|
27
|
+
it 'should not have userinfo in the URI' do
|
|
28
|
+
expected_uri = URI.parse(uri)
|
|
29
|
+
expected_uri.userinfo = nil
|
|
30
|
+
subject.uri.should == expected_uri
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'should not have the Authorization header' do
|
|
34
|
+
subject.headers.should == [user_agent_header]
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
describe HTTY::Request do
|
|
40
|
+
let(:request) {HTTY::Request.new uri}
|
|
41
|
+
let(:user_agent_header) {['User-Agent', 'htty/' + HTTY::VERSION]}
|
|
42
|
+
|
|
43
|
+
subject {request}
|
|
44
|
+
|
|
45
|
+
describe 'without basic authentication' do
|
|
46
|
+
let(:uri) do
|
|
47
|
+
"https://github.com:80/search/deep?q=http#content"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it_should_behave_like 'an empty request'
|
|
51
|
+
it_should_behave_like 'a request without basic authentication'
|
|
52
|
+
|
|
53
|
+
describe '#userinfo_unset' do
|
|
54
|
+
before :each do
|
|
55
|
+
subject.userinfo_unset
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it_should_behave_like 'a request without basic authentication'
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
describe '#userinfo_set' do
|
|
62
|
+
let(:username) {'njonsson'}
|
|
63
|
+
let(:password) {'123'}
|
|
64
|
+
|
|
65
|
+
before :each do
|
|
66
|
+
subject.userinfo_set username, password
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it_should_behave_like 'a request with basic authentication'
|
|
70
|
+
|
|
71
|
+
context 'with empty password' do
|
|
72
|
+
let(:password) {nil}
|
|
73
|
+
|
|
74
|
+
it_should_behave_like 'a request with basic authentication'
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
describe '#headers_set Authorization' do
|
|
79
|
+
let(:username) {'njonsson'}
|
|
80
|
+
let(:password) {'123'}
|
|
81
|
+
|
|
82
|
+
before :each do
|
|
83
|
+
subject.header_set 'Authorization',
|
|
84
|
+
HTTY::Headers.basic_authentication_for(username, password).last
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it_should_behave_like 'a request with basic authentication'
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
describe 'with basic authentication' do
|
|
92
|
+
let(:username) {'njonsson'}
|
|
93
|
+
let(:password) {'123'}
|
|
94
|
+
let(:uri) do
|
|
95
|
+
"https://#{username}:#{password}@github.com:80/search/deep?q=http#content"
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
let(:basic_authentication) do
|
|
99
|
+
HTTY::Headers.basic_authentication_for(username, password)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it_should_behave_like 'an empty, authenticated request'
|
|
103
|
+
it_should_behave_like 'a request with basic authentication'
|
|
104
|
+
|
|
105
|
+
describe '#userinfo_unset' do
|
|
106
|
+
before :each do
|
|
107
|
+
subject.userinfo_unset
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it 'should have the same URI, without userinfo' do
|
|
111
|
+
expected_uri = URI.parse(uri)
|
|
112
|
+
expected_uri.user = nil
|
|
113
|
+
subject.uri.should == expected_uri
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
describe '#userinfo_set' do
|
|
118
|
+
context 'with the same credentials' do
|
|
119
|
+
before :each do
|
|
120
|
+
subject.userinfo_set username, password
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it 'should have the same URI' do
|
|
124
|
+
subject.uri.should == URI.parse(uri)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it 'should have the same Authorization header' do
|
|
128
|
+
subject.headers.should == [user_agent_header, basic_authentication]
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
context 'with different credentials' do
|
|
133
|
+
let(:different_username) {'gabrielelana'}
|
|
134
|
+
let(:different_password) {'456'}
|
|
135
|
+
|
|
136
|
+
before :each do
|
|
137
|
+
subject.userinfo_set different_username, different_password
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it 'should have the same URI, with the changed userinfo part' do
|
|
141
|
+
expected_uri = URI.parse(uri)
|
|
142
|
+
expected_uri.userinfo = [different_username, different_password].join(':')
|
|
143
|
+
subject.uri.should == expected_uri
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
it 'should have changed the Authorization header' do
|
|
147
|
+
subject.headers.should == [
|
|
148
|
+
user_agent_header,
|
|
149
|
+
HTTY::Headers.basic_authentication_for(
|
|
150
|
+
different_username, different_password
|
|
151
|
+
)
|
|
152
|
+
]
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
context 'with credentials that contains an escaped character' do
|
|
157
|
+
let(:username) {'n%40'}
|
|
158
|
+
|
|
159
|
+
it 'should be escaped in the URI' do
|
|
160
|
+
subject.uri.userinfo.should start_with(username)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
it 'should not be escaped in the Authorization header' do
|
|
164
|
+
subject.headers.should == [
|
|
165
|
+
user_agent_header,
|
|
166
|
+
HTTY::Headers.basic_authentication_for(
|
|
167
|
+
URI.unescape(username), password
|
|
168
|
+
)
|
|
169
|
+
]
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
context 'with a response' do
|
|
174
|
+
before :each do
|
|
175
|
+
subject.send :response=, HTTY::Response.new
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
it 'should return a request without a response' do
|
|
179
|
+
subject.userinfo_set(username, password).response.should be_nil
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
describe '#headers_unset Authorization' do
|
|
185
|
+
before :each do
|
|
186
|
+
subject.header_unset 'Authorization'
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
it 'should have the same URI, without userinfo' do
|
|
190
|
+
expected_uri = URI.parse(uri)
|
|
191
|
+
expected_uri.user = nil
|
|
192
|
+
subject.uri.should == expected_uri
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
describe '#headers_unset_all' do
|
|
197
|
+
before :each do
|
|
198
|
+
subject.headers_unset_all
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
it 'should have the same URI, without userinfo' do
|
|
202
|
+
expected_uri = URI.parse(uri)
|
|
203
|
+
expected_uri.user = nil
|
|
204
|
+
subject.uri.should == expected_uri
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
end
|