dangerous_open_uri 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/dangerous_open_uri.gemspec +1 -0
- data/lib/dangerous_open_uri.rb +17 -0
- data/lib/dangerous_open_uri/version.rb +1 -1
- data/spec/lib/dangerous_open_uri_spec.rb +120 -37
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1774c7f5e6349bfe47e3df9e9582a320c5211d3
|
4
|
+
data.tar.gz: ed993845fb4a3d7dcaaac9a98ead82a371a5422a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02aa3a06fdb61e911d36ce549ca89ba0c75396010c2b5809c09e03849b2ca65f93045e33439961a3039ba17be7239c56ed189d27be2ce7296fd55de51a5ef1c9
|
7
|
+
data.tar.gz: 0b6464fea953389b4d84d4a3720f4fdf4fdc11dfcb6445ed234dbc70d4a79e6d9c75c6a7c00513fd62f24c3897a1973ef3f1ba4ab32092b6f85e36e785cbd28e
|
data/dangerous_open_uri.gemspec
CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler"
|
22
|
+
spec.add_development_dependency "pry"
|
22
23
|
spec.add_development_dependency "rake"
|
23
24
|
spec.add_development_dependency "rspec"
|
24
25
|
spec.add_development_dependency "webmock"
|
data/lib/dangerous_open_uri.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "dangerous_open_uri/version"
|
2
2
|
require 'open-uri'
|
3
|
+
require 'uri/ftp'
|
3
4
|
|
4
5
|
module OpenURI
|
5
6
|
instance_eval { alias :original_open_http :open_http }
|
@@ -26,3 +27,19 @@ module OpenURI
|
|
26
27
|
original_open_http(buf, _target, proxy, options)
|
27
28
|
end
|
28
29
|
end
|
30
|
+
|
31
|
+
module URI
|
32
|
+
class FTP
|
33
|
+
alias_method :original_userinfo, :userinfo
|
34
|
+
|
35
|
+
def userinfo
|
36
|
+
_userinfo = original_userinfo.dup
|
37
|
+
_userinfo.instance_variable_set(:@__user, user)
|
38
|
+
_userinfo.instance_variable_set(:@__password, password)
|
39
|
+
def _userinfo.split(*args)
|
40
|
+
[@__user, @__password]
|
41
|
+
end
|
42
|
+
_userinfo
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'net/ftp'
|
2
|
+
|
1
3
|
describe OpenURI do
|
2
4
|
describe '.open_http' do
|
3
5
|
context 'when request with basic authentication' do
|
@@ -22,61 +24,82 @@ describe OpenURI do
|
|
22
24
|
open('http://user:pass@www.example.com/secret/page.html')
|
23
25
|
end
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
context 'given userinfo has two ":"' do
|
28
|
+
it 'opens with user and password(includes ":")' do
|
29
|
+
stub_request(:any, 'user:pass:broken@www.example.com/secret/page.html')
|
30
|
+
.to_return(body: 'aaa')
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
32
|
+
expect(
|
33
|
+
# user = "user", password = "pass:broken"
|
34
|
+
open('http://user:pass:broken@www.example.com/secret/page.html').read
|
35
|
+
).to eq('aaa')
|
36
|
+
end
|
33
37
|
end
|
34
38
|
|
35
|
-
|
36
|
-
|
37
|
-
|
39
|
+
context 'given has user but no password' do
|
40
|
+
it 'opens with user only' do
|
41
|
+
stub_request(:any, 'user:@www.example.com/secret/page.html')
|
42
|
+
.to_return(body: 'aaa')
|
38
43
|
|
39
|
-
|
40
|
-
|
41
|
-
|
44
|
+
expect(
|
45
|
+
open('http://user:@www.example.com/secret/page.html').read
|
46
|
+
).to eq('aaa')
|
47
|
+
end
|
42
48
|
end
|
43
49
|
|
44
|
-
|
45
|
-
|
46
|
-
|
50
|
+
context 'given no user but has password' do
|
51
|
+
it 'opens with password only' do
|
52
|
+
stub_request(:any, ':pass@www.example.com/secret/page.html')
|
53
|
+
.to_return(body: 'aaa')
|
47
54
|
|
48
|
-
|
49
|
-
|
50
|
-
|
55
|
+
expect(
|
56
|
+
open('http://:pass@www.example.com/secret/page.html').read
|
57
|
+
).to eq('aaa')
|
58
|
+
end
|
51
59
|
end
|
52
60
|
|
53
|
-
|
54
|
-
|
55
|
-
|
61
|
+
context 'given userinfo == ":"' do
|
62
|
+
it 'opens with no user and password' do
|
63
|
+
stub_request(:any, 'www.example.com/secret/page.html')
|
64
|
+
.to_return(body: 'aaa')
|
56
65
|
|
57
|
-
|
58
|
-
|
59
|
-
|
66
|
+
expect(
|
67
|
+
open('http://:@www.example.com/secret/page.html').read
|
68
|
+
).to eq('aaa')
|
69
|
+
end
|
60
70
|
end
|
61
71
|
|
62
|
-
|
63
|
-
|
64
|
-
|
72
|
+
context 'given userinfo not include ":"' do
|
73
|
+
it 'opens with only user' do
|
74
|
+
stub_request(:any, 'baduserinfo:@www.example.com/secret/page.html')
|
75
|
+
.to_return(body: 'aaa')
|
65
76
|
|
66
|
-
|
67
|
-
|
68
|
-
|
77
|
+
expect(
|
78
|
+
open('http://baduserinfo@www.example.com/secret/page.html').read
|
79
|
+
).to eq('aaa')
|
80
|
+
end
|
69
81
|
end
|
70
82
|
|
71
|
-
|
72
|
-
|
83
|
+
describe 'given URI::Generic object' do
|
84
|
+
it ' does not change the argument object' do
|
85
|
+
stub_request(:any, 'http://user:pass@www.example.com/secret/page.html')
|
86
|
+
.to_return(body: 'aaa')
|
73
87
|
|
74
|
-
|
75
|
-
.to_return(body: 'aaa')
|
88
|
+
uri = URI.parse('http://user:pass@www.example.com/secret/page.html')
|
76
89
|
|
77
|
-
|
90
|
+
open(uri)
|
91
|
+
expect(uri).to eq(uri)
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'when password includes ":"' do
|
95
|
+
it 'opens with user and password(includes ":")' do
|
96
|
+
stub_request(:any, 'http://user:pass:word@www.example.com/secret/page.html')
|
97
|
+
.to_return(body: 'aaa')
|
78
98
|
|
79
|
-
|
99
|
+
uri = URI.parse('http://user:pass:word@www.example.com/secret/page.html')
|
100
|
+
expect(open(uri).read).to eq('aaa')
|
101
|
+
end
|
102
|
+
end
|
80
103
|
end
|
81
104
|
|
82
105
|
describe 'given proxy' do
|
@@ -114,3 +137,63 @@ describe OpenURI do
|
|
114
137
|
end
|
115
138
|
end
|
116
139
|
end
|
140
|
+
|
141
|
+
describe URI::FTP do
|
142
|
+
let(:ftp) { double(:ftp) }
|
143
|
+
|
144
|
+
describe 'password includes ":"' do
|
145
|
+
context 'when the arguments is String(likely URI)' do
|
146
|
+
it 'logins with user and password' do
|
147
|
+
allow(Net::FTP).to receive(:new).and_return(ftp)
|
148
|
+
expect(ftp).to receive(:connect).with('ftp.example.com', 21)
|
149
|
+
expect(ftp).to receive(:passive=).with(true)
|
150
|
+
expect(ftp).to receive(:login).with('user', 'pass:word')
|
151
|
+
expect(ftp).to receive(:retrbinary).with("RETR test.txt", 4096)
|
152
|
+
expect(ftp).to receive(:close)
|
153
|
+
open('ftp://user:pass:word@ftp.example.com/test.txt')
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'when the arguments is URI::FTP' do
|
158
|
+
it 'logins with user and password' do
|
159
|
+
allow(Net::FTP).to receive(:new).and_return(ftp)
|
160
|
+
expect(ftp).to receive(:connect).with('ftp.example.com', 21)
|
161
|
+
expect(ftp).to receive(:passive=).with(true)
|
162
|
+
expect(ftp).to receive(:login).with('user', 'pa:ss:wo:rd')
|
163
|
+
expect(ftp).to receive(:retrbinary).with("RETR test.txt", 4096)
|
164
|
+
expect(ftp).to receive(:close)
|
165
|
+
|
166
|
+
uri = URI.parse('ftp://user:pa:ss:wo:rd@ftp.example.com/test.txt')
|
167
|
+
open(uri)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe 'password does not include ":"' do
|
173
|
+
context 'when the arguments is String(likely URI)' do
|
174
|
+
it 'logins with user and password' do
|
175
|
+
allow(Net::FTP).to receive(:new).and_return(ftp)
|
176
|
+
expect(ftp).to receive(:connect).with('ftp.example.com', 21)
|
177
|
+
expect(ftp).to receive(:passive=).with(true)
|
178
|
+
expect(ftp).to receive(:login).with('user', 'password')
|
179
|
+
expect(ftp).to receive(:retrbinary).with("RETR test.txt", 4096)
|
180
|
+
expect(ftp).to receive(:close)
|
181
|
+
open('ftp://user:password@ftp.example.com/test.txt')
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context 'when the arguments is URI::FTP' do
|
186
|
+
it 'logins with user and password' do
|
187
|
+
allow(Net::FTP).to receive(:new).and_return(ftp)
|
188
|
+
expect(ftp).to receive(:connect).with('ftp.example.com', 21)
|
189
|
+
expect(ftp).to receive(:passive=).with(true)
|
190
|
+
expect(ftp).to receive(:login).with('user', 'password')
|
191
|
+
expect(ftp).to receive(:retrbinary).with("RETR test.txt", 4096)
|
192
|
+
expect(ftp).to receive(:close)
|
193
|
+
|
194
|
+
uri = URI.parse('ftp://user:password@ftp.example.com/test.txt')
|
195
|
+
open(uri)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dangerous_open_uri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mgi166
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|