roadie 3.1.0.rc1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +9 -1
- data/lib/roadie/net_http_provider.rb +24 -2
- data/lib/roadie/version.rb +1 -1
- data/spec/lib/roadie/net_http_provider_spec.rb +28 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ea2ec3b852bbfcc4562e71aad5d934164f513ca
|
4
|
+
data.tar.gz: cdde955813d54457a745a16b81be79185884a997
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d89044d3d2ac136f025b86a1a92df95f44b895411840478f127642875a40f8cbc4f743c4a4b6be6ee2e9fb95c95c328e5386262142a92cf7dfc26004f274b4b7
|
7
|
+
data.tar.gz: f53d0fca7bf1fd95bfcc2036c434d242e67babefe183b2752bb82d1ca506c0f5bfb9c19114842d4fcaed104fbbdfa8dceb943375493f30231584113640b20005
|
data/Changelog.md
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
### dev
|
2
2
|
|
3
|
-
[full changelog](https://github.com/Mange/roadie/compare/v3.1.0
|
3
|
+
[full changelog](https://github.com/Mange/roadie/compare/v3.1.0...master)
|
4
4
|
|
5
5
|
* Nothing yet.
|
6
6
|
|
7
|
+
### 3.1.0
|
8
|
+
|
9
|
+
[full changelog](https://github.com/Mange/roadie/compare/v3.1.0.rc1...v3.1.0)
|
10
|
+
|
11
|
+
* Enchancements:
|
12
|
+
* `NetHttpProvider` validates the whitelist hostnames; passing an invalid hostname will raise `ArgumentError`.
|
13
|
+
* `NetHttpProvider` supports scheme-less URLs (`//foo.com/`), defaulting to `https`.
|
14
|
+
|
7
15
|
### 3.1.0.rc1
|
8
16
|
|
9
17
|
[full changelog](https://github.com/Mange/roadie/compare/v3.0.5...v3.1.0.rc1)
|
@@ -2,6 +2,7 @@
|
|
2
2
|
require 'set'
|
3
3
|
require 'uri'
|
4
4
|
require 'net/http'
|
5
|
+
require 'net/https' # For Ruby 1.9.3 support
|
5
6
|
|
6
7
|
module Roadie
|
7
8
|
# @api public
|
@@ -22,7 +23,7 @@ module Roadie
|
|
22
23
|
|
23
24
|
# @option options [Array<String>] :whitelist ([]) A list of host names that downloads are allowed from. Empty set means everything is allowed.
|
24
25
|
def initialize(options = {})
|
25
|
-
@whitelist = Array(options.fetch(:whitelist, []))
|
26
|
+
@whitelist = host_set(Array(options.fetch(:whitelist, [])))
|
26
27
|
end
|
27
28
|
|
28
29
|
def find_stylesheet(url)
|
@@ -46,15 +47,36 @@ module Roadie
|
|
46
47
|
def inspect() "#<#{self.class} whitelist: #{whitelist.inspect}>" end
|
47
48
|
|
48
49
|
private
|
50
|
+
def host_set(hosts)
|
51
|
+
hosts.each { |host| validate_host(host) }.to_set
|
52
|
+
end
|
53
|
+
|
54
|
+
def validate_host(host)
|
55
|
+
if host.nil? || host.empty? || host == "." || host.include?("/")
|
56
|
+
raise ArgumentError, "#{host.inspect} is not a valid hostname"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
49
60
|
def download(url)
|
61
|
+
url = "https:#{url}" if url.start_with?("//")
|
50
62
|
uri = URI.parse(url)
|
51
63
|
if access_granted_to?(uri.host)
|
52
|
-
|
64
|
+
get_response(uri)
|
53
65
|
else
|
54
66
|
raise CssNotFound.new(url, "#{uri.host} is not part of whitelist!", self)
|
55
67
|
end
|
56
68
|
end
|
57
69
|
|
70
|
+
def get_response(uri)
|
71
|
+
if RUBY_VERSION >= "2.0.0"
|
72
|
+
Net::HTTP.get_response(uri)
|
73
|
+
else
|
74
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: (uri.scheme == 'https')) do |http|
|
75
|
+
http.request(Net::HTTP::Get.new(uri.request_uri))
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
58
80
|
def access_granted_to?(host)
|
59
81
|
whitelist.empty? || whitelist.include?(host)
|
60
82
|
end
|
data/lib/roadie/version.rb
CHANGED
@@ -23,6 +23,26 @@ module Roadie
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
it "can download over HTTPS" do
|
27
|
+
stub_request(:get, "https://example.com/style.css").and_return(body: "p { color: green; }")
|
28
|
+
expect {
|
29
|
+
NetHttpProvider.new.find_stylesheet!("https://example.com/style.css")
|
30
|
+
}.to_not raise_error
|
31
|
+
end
|
32
|
+
|
33
|
+
it "assumes HTTPS when given a scheme-less URL" do
|
34
|
+
# Some people might re-use the same template as they use on a webpage,
|
35
|
+
# and browsers support URLs without a scheme in them, replacing the
|
36
|
+
# scheme with the current one. There's no "current" scheme when doing
|
37
|
+
# asset inlining, but the scheme-less URL implies that there should exist
|
38
|
+
# both a HTTP and a HTTPS endpoint. Let's take the secure one in that
|
39
|
+
# case!
|
40
|
+
stub_request(:get, "https://example.com/style.css").and_return(body: "p { color: green; }")
|
41
|
+
expect {
|
42
|
+
NetHttpProvider.new.find_stylesheet!("//example.com/style.css")
|
43
|
+
}.to_not raise_error
|
44
|
+
end
|
45
|
+
|
26
46
|
describe "error handling" do
|
27
47
|
it "handles timeouts" do
|
28
48
|
stub_request(:get, url).and_timeout
|
@@ -84,6 +104,14 @@ module Roadie
|
|
84
104
|
it "is displayed in the string representation" do
|
85
105
|
expect(NetHttpProvider.new(whitelist: ["bar.baz"]).to_s).to include "bar.baz"
|
86
106
|
end
|
107
|
+
|
108
|
+
it "raises error when given invalid hostnames" do
|
109
|
+
expect { NetHttpProvider.new(whitelist: [nil]) }.to raise_error(ArgumentError)
|
110
|
+
expect { NetHttpProvider.new(whitelist: [""]) }.to raise_error(ArgumentError)
|
111
|
+
expect { NetHttpProvider.new(whitelist: ["."]) }.to raise_error(ArgumentError)
|
112
|
+
expect { NetHttpProvider.new(whitelist: ["http://foo.bar"]) }.to raise_error(ArgumentError)
|
113
|
+
expect { NetHttpProvider.new(whitelist: ["foo/bar"]) }.to raise_error(ArgumentError)
|
114
|
+
end
|
87
115
|
end
|
88
116
|
end
|
89
117
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roadie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Magnus Bergmark
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -182,12 +182,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
182
182
|
version: '1.9'
|
183
183
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
|
-
- - "
|
185
|
+
- - ">="
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version:
|
187
|
+
version: '0'
|
188
188
|
requirements: []
|
189
189
|
rubyforge_project:
|
190
|
-
rubygems_version: 2.
|
190
|
+
rubygems_version: 2.2.2
|
191
191
|
signing_key:
|
192
192
|
specification_version: 4
|
193
193
|
summary: Making HTML emails comfortable for the Ruby rockstars
|