open_uri_allow_redirect 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 10f64f42a083302fd575ac975489bbe336313ff4
4
+ data.tar.gz: 39dd100ba63faf7bd6ba6c870a488a85e788172e
5
+ SHA512:
6
+ metadata.gz: aadf3c91f7c5dc35452ae6643773f4471c32c6c2af79e3338310b9c42318bb620576dd3637b253644e1944b264872da269d171f84bae78d7b729dcc64d08a72d
7
+ data.tar.gz: 3ad45c609ff9a8d2b82397ce2bd7b1226f73fa8214b4baf8646723652535752066af22a163106ff6fead002575ae0c4944d9bb2bc3f7e6156dd11fa687b2fbc6
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .bin
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development, :test do
4
+ gem 'rspec', '>= 2.14'
5
+ gem 'fakeweb'
6
+ end
7
+
8
+ # Specify your gem's dependencies in open_uri_allow_redirect.gemspec
9
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 xoyip
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # OpenUriAllowRedirect
2
+
3
+ This gem adds new `allow_redirect` method to OpenURI.
4
+
5
+ In the code block passed to this method, redirections from HTTP to HTTPS are allowed.
6
+
7
+ This gem is inspired by [this gem](https://github.com/jaimeiniesta/open_uri_redirections).
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'open_uri_allow_redirect'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install open_uri_allow_redirect
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ require "open_uri_allow_redirect"
27
+
28
+ open("http://github.com") # => raises RuntimeError, redirected to https://github.com
29
+
30
+ OpenURI.allow_redirect do
31
+ open("http://github.com") # => no error
32
+ end
33
+ ```
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it ( https://github.com/[my-github-username]/open_uri_allow_redirect/fork )
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,21 @@
1
+ require "rubygems"
2
+
3
+ $:.unshift File.expand_path("../lib", File.dirname(__FILE__))
4
+ require "open_uri_allow_redirect"
5
+
6
+ url = "http://github.com"
7
+
8
+ begin
9
+ OpenURI.allow_redirect do
10
+ open(url) # redirected to https from http
11
+ end
12
+ rescue => e
13
+ puts e # never be called
14
+ end
15
+
16
+ begin
17
+ open(url)
18
+ rescue => e
19
+ puts e # => redirection forbidden: http://github.com -> https://github.com/
20
+ end
21
+
@@ -0,0 +1,3 @@
1
+ require "open_uri_allow_redirect/version"
2
+ require "open_uri_allow_redirect/open-uri-patch"
3
+
@@ -0,0 +1,27 @@
1
+ require "open-uri"
2
+
3
+ module OpenURI
4
+ class << self
5
+ alias_method :redirectable_cautious?, :redirectable?
6
+ @_allow_redirect = false
7
+
8
+ def allow_redirect
9
+ old_redirect, @_allow_redirect = @_allow_redirect, true
10
+ yield
11
+ ensure
12
+ @_allow_redirect = old_redirect
13
+ end
14
+
15
+ def redirectable_safe?(uri1, uri2)
16
+ uri1.scheme.downcase == uri2.scheme.downcase || (uri1.scheme.downcase == "http" && uri2.scheme.downcase == "https")
17
+ end
18
+
19
+ def redirectable?(uri1, uri2)
20
+ if @_allow_redirect
21
+ redirectable_safe?(uri1, uri2) || (uri1.scheme.downcase == "https" && uri2.scheme.downcase == "http")
22
+ else
23
+ redirectable_cautious?(uri1, uri2)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module OpenUriAllowRedirect
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'open_uri_allow_redirect/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "open_uri_allow_redirect"
8
+ spec.version = OpenUriAllowRedirect::VERSION
9
+ spec.authors = ["xoyip"]
10
+ spec.email = ["xoyip@piyox.info"]
11
+ spec.summary = %q{OpenURI patch to allow redirections between HTTP and HTTPs inside the block}
12
+ spec.description = %q{}
13
+ spec.homepage = "https://github.com/xoyip/open-uri-allow-redirect"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ # spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -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: 186
6
+ Connection: close
7
+ Location: https://redirect.com/
8
+
9
+ Redirecting to https://redirect.com/
@@ -0,0 +1,15 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx
3
+ Date: Mon, 03 Dec 2012 11:37:51 GMT
4
+ Content-Type: text/html; charset=utf-8
5
+ Connection: keep-alive
6
+ Status: 200 OK
7
+ X-Runtime: 10
8
+ ETag: "a9e1dd587bb233eb670ec06f7d553dbc"
9
+ X-Frame-Options: deny
10
+ Set-Cookie: _gh_sess=BAh7BzoPc2Vzc2lvbl9pZCIlZTc4ZDNlOGEwM2NlZDQ3Y2VhMDdlMTQyOTA4NWVmYzA6EF9jc3JmX3Rva2VuIjE0U2xsYUoybFFNSWxhWEtudHNvalJCVjZtVnJZcFVlRVk4WlpMbEZKWktRPQ%3D%3D--8ea4a235fd3c5e727d462e24b992fabd8f50050d; path=/; expires=Sat, 01-Jan-2022 00:00:00 GMT; secure; HttpOnly
11
+ Content-Length: 21815
12
+ Cache-Control: private, max-age=0, must-revalidate
13
+ Strict-Transport-Security: max-age=2592000
14
+
15
+ Hello, this is Https.
@@ -0,0 +1,24 @@
1
+ require "spec_helper"
2
+
3
+ describe "OpenURI" do
4
+ describe "open" do
5
+ context "Default" do
6
+ specify "HTTP => HTTPS redirection should not be allowed" do
7
+ expect do
8
+ open("http://redirect.com")
9
+ end.to raise_error(RuntimeError, "redirection forbidden: http://redirect.com -> https://redirect.com/")
10
+ end
11
+ end
12
+
13
+ context "with #allow_redirect" do
14
+ specify "HTTP => HTTPS redirection should be allowed" do
15
+ expect do
16
+ OpenURI.allow_redirect do
17
+ open("http://redirect.com")
18
+ end
19
+ end.not_to raise_error
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ require 'open_uri_allow_redirect'
9
+ require 'rspec'
10
+ require 'fakeweb'
11
+
12
+ RSpec.configure do |config|
13
+ config.expect_with :rspec do |c|
14
+ c.syntax = :expect
15
+ end
16
+ end
17
+
18
+ def fixture_path
19
+ File.expand_path("../fixtures", __FILE__)
20
+ end
21
+
22
+ def fixture(file)
23
+ open(File.join(fixture_path, file)).read
24
+ end
25
+
26
+ FakeWeb.register_uri(:get, "http://redirect.com/" , response: fixture("http.response" ))
27
+ FakeWeb.register_uri(:get, "https://redirect.com/", response: fixture("https.response"))
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: open_uri_allow_redirect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - xoyip
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
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'
41
+ description: ''
42
+ email:
43
+ - xoyip@piyox.info
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - example/example.rb
54
+ - lib/open_uri_allow_redirect.rb
55
+ - lib/open_uri_allow_redirect/open-uri-patch.rb
56
+ - lib/open_uri_allow_redirect/version.rb
57
+ - open_uri_allow_redirect.gemspec
58
+ - spec/fixtures/http.response
59
+ - spec/fixtures/https.response
60
+ - spec/open-uri_spec.rb
61
+ - spec/spec_helper.rb
62
+ homepage: https://github.com/xoyip/open-uri-allow-redirect
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.2.0
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: OpenURI patch to allow redirections between HTTP and HTTPs inside the block
86
+ test_files:
87
+ - spec/fixtures/http.response
88
+ - spec/fixtures/https.response
89
+ - spec/open-uri_spec.rb
90
+ - spec/spec_helper.rb