open_uri_redirections 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 700a295a62e1dcaa24dbb77e2c73cdfb99b25f26
4
- data.tar.gz: 9e4e1ce91c9443fbb229ee34b6de90bdc9aba6b5
5
- SHA512:
6
- metadata.gz: 60ceb82cdbded3b4af61108efa78342a8e9971bcebc2a3ddc718769e5abe2b653c846c1759a740c35a633ffab84d54049d95b1890338ef83d0363b2142801567
7
- data.tar.gz: d166c07b860618625f4dd0a67aeb251d9cf4f73bbe54642553c56cda007a2d6b3381f31b98342ab4316aa8dda4908373864e01018d58403d63464f1dc2179eef
1
+ ---
2
+ SHA512:
3
+ metadata.gz: 3188333a58a356a9c6453a60c85883c795ba37cc892593b53dd4745d924ad1cd826cc71801feee15f9a6a76eff7474dbbeea9f9eb843936ec5625dd7c097caac
4
+ data.tar.gz: db5c9b8b959cc73bb0d9dd30c510d372362580dcf4204f3a6f85354b8c1a8a74e9812a6c759bf9ef4c2b7cc2999e57090bc8c0e379e67377e94fa0bf4df2ec91
5
+ SHA1:
6
+ metadata.gz: 98bd6a10771e7d458abebd244f18b8ea03a34199
7
+ data.tar.gz: c9b7c6ca9b4caef0449827d936b7688bc3fae1a1
@@ -17,12 +17,7 @@ module OpenURI
17
17
  alias_method :redirectable_cautious?, :redirectable?
18
18
 
19
19
  def redirectable?(uri1, uri2)
20
- allow_redirections = Thread.current[:__open_uri_redirections__]
21
-
22
- # clear to prevent leaking (e.g. to block)
23
- Thread.current[:__open_uri_redirections__] = nil
24
-
25
- case allow_redirections
20
+ case Thread.current[:__open_uri_redirections__]
26
21
  when :safe
27
22
  redirectable_safe? uri1, uri2
28
23
  when :all
@@ -51,10 +46,14 @@ module OpenURI
51
46
  allow_redirections = options.delete :allow_redirections if options
52
47
  Thread.current[:__open_uri_redirections__] = allow_redirections
53
48
 
49
+ block2 = lambda { |io|
50
+ Thread.current[:__open_uri_redirections__] = nil
51
+ block[io]
52
+ }
53
+
54
54
  begin
55
- self.open_uri_original name, *rest, &block
55
+ self.open_uri_original name, *rest, &(block ? block2 : nil)
56
56
  ensure
57
- # clear (redirectable? might not be called due to an exception)
58
57
  Thread.current[:__open_uri_redirections__] = nil
59
58
  end
60
59
  end
@@ -1,3 +1,3 @@
1
1
  module OpenUriRedirections
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -41,6 +41,12 @@ describe "OpenURI" do
41
41
  ).to eq("Hello, this is Safe.")
42
42
  end
43
43
 
44
+ it "should follow safe double redirections" do
45
+ expect(
46
+ open("http://safe2.com", :allow_redirections => :safe).read
47
+ ).to eq("Hello, this is Safe.")
48
+ end
49
+
44
50
  it "should follow safe redirections with block" do
45
51
  expect { |b|
46
52
  open("http://safe.com", :allow_redirections => :safe, &b)
@@ -107,7 +113,7 @@ describe "OpenURI" do
107
113
  end
108
114
 
109
115
  describe "threads" do
110
- it "works" do
116
+ it "seems to work (could be false positive)" do
111
117
  allow(OpenURI).to receive(:open_uri_original) { |*a,&b| sleep rand; OpenURI.open_uri_original__ *a, &b }
112
118
  ts = []
113
119
  Thread.abort_on_exception = true
@@ -0,0 +1,9 @@
1
+ HTTP/1.1 301 Moved Permanently
2
+ Server: nginx
3
+ Date: Mon, 03 Dec 2012 11:36:17 GMT
4
+ Content-Type: text/html
5
+ Content-Length: 178
6
+ Connection: close
7
+ Location: http://safe.com/
8
+
9
+ Redirecting to http://safe.com/
@@ -15,5 +15,7 @@ $samples_dir = File.dirname(__FILE__) + '/samples'
15
15
  FakeWeb.register_uri(:get, "http://safe.com/", :response => open("#{$samples_dir}/http_safe.response").read)
16
16
  FakeWeb.register_uri(:get, "https://safe.com/", :response => open("#{$samples_dir}/https_safe.response").read)
17
17
 
18
+ FakeWeb.register_uri(:get, "http://safe2.com/", :response => open("#{$samples_dir}/http_safe2.response").read)
19
+
18
20
  FakeWeb.register_uri(:get, "https://unsafe.com/", :response => open("#{$samples_dir}/https_unsafe.response").read)
19
21
  FakeWeb.register_uri(:get, "http://unsafe.com/", :response => open("#{$samples_dir}/http_unsafe.response").read)
metadata CHANGED
@@ -1,68 +1,60 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: open_uri_redirections
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Jaime Iniesta
8
8
  - Gabriel Cebrian
9
9
  - Felix C. Stegerman
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-11-24 00:00:00.000000000 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
13
+
14
+ date: 2014-11-26 00:00:00 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
16
17
  name: rspec
17
- requirement: !ruby/object:Gem::Requirement
18
- requirements:
19
- - - "~>"
20
- - !ruby/object:Gem::Version
21
- version: 3.1.0
22
- type: :development
23
18
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- requirements:
26
- - - "~>"
27
- - !ruby/object:Gem::Version
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
28
23
  version: 3.1.0
29
- - !ruby/object:Gem::Dependency
30
- name: fakeweb
31
- requirement: !ruby/object:Gem::Requirement
32
- requirements:
33
- - - "~>"
34
- - !ruby/object:Gem::Version
35
- version: 1.3.0
36
24
  type: :development
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: fakeweb
37
28
  prerelease: false
38
- version_requirements: !ruby/object:Gem::Requirement
39
- requirements:
40
- - - "~>"
41
- - !ruby/object:Gem::Version
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
42
33
  version: 1.3.0
43
- - !ruby/object:Gem::Dependency
44
- name: rake
45
- requirement: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - "~>"
48
- - !ruby/object:Gem::Version
49
- version: 10.3.2
50
34
  type: :development
35
+ version_requirements: *id002
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
51
38
  prerelease: false
52
- version_requirements: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - "~>"
55
- - !ruby/object:Gem::Version
39
+ requirement: &id003 !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
56
43
  version: 10.3.2
44
+ type: :development
45
+ version_requirements: *id003
57
46
  description: OpenURI patch to allow redirections between HTTP and HTTPS
58
- email:
47
+ email:
59
48
  - jaimeiniesta@gmail.com
60
49
  executables: []
50
+
61
51
  extensions: []
52
+
62
53
  extra_rdoc_files: []
63
- files:
64
- - ".gitignore"
65
- - ".travis.yml"
54
+
55
+ files:
56
+ - .gitignore
57
+ - .travis.yml
66
58
  - Gemfile
67
59
  - LICENSE.txt
68
60
  - README.md
@@ -73,37 +65,41 @@ files:
73
65
  - open_uri_redirections.gemspec
74
66
  - spec/redirections_spec.rb
75
67
  - spec/samples/http_safe.response
68
+ - spec/samples/http_safe2.response
76
69
  - spec/samples/http_unsafe.response
77
70
  - spec/samples/https_safe.response
78
71
  - spec/samples/https_unsafe.response
79
72
  - spec/spec_helper.rb
80
73
  homepage: https://github.com/jaimeiniesta/open_uri_redirections
81
- licenses:
74
+ licenses:
82
75
  - MIT
83
76
  metadata: {}
77
+
84
78
  post_install_message:
85
79
  rdoc_options: []
86
- require_paths:
80
+
81
+ require_paths:
87
82
  - lib
88
- required_ruby_version: !ruby/object:Gem::Requirement
89
- requirements:
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- version: '0'
93
- required_rubygems_version: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- version: '0'
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - &id004
86
+ - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - *id004
98
92
  requirements: []
93
+
99
94
  rubyforge_project:
100
- rubygems_version: 2.2.2
95
+ rubygems_version: 2.0.14
101
96
  signing_key:
102
97
  specification_version: 4
103
98
  summary: OpenURI patch to allow redirections between HTTP and HTTPS
104
- test_files:
99
+ test_files:
105
100
  - spec/redirections_spec.rb
106
101
  - spec/samples/http_safe.response
102
+ - spec/samples/http_safe2.response
107
103
  - spec/samples/http_unsafe.response
108
104
  - spec/samples/https_safe.response
109
105
  - spec/samples/https_unsafe.response