dragonfly 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of dragonfly might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile +7 -1
- data/History.md +12 -0
- data/README.md +1 -1
- data/dev/irbrc.rb +13 -1
- data/dragonfly.gemspec +1 -0
- data/lib/dragonfly/app.rb +2 -7
- data/lib/dragonfly/content.rb +6 -2
- data/lib/dragonfly/core_ext/tempfile.rb +19 -0
- data/lib/dragonfly/job.rb +5 -0
- data/lib/dragonfly/job/fetch_url.rb +5 -1
- data/lib/dragonfly/routed_endpoint.rb +1 -1
- data/lib/dragonfly/temp_object.rb +4 -1
- data/lib/dragonfly/version.rb +1 -1
- data/spec/dragonfly/content_spec.rb +1 -10
- data/spec/dragonfly/job/fetch_url_spec.rb +3 -3
- data/spec/dragonfly/job_spec.rb +5 -0
- data/spec/dragonfly/routed_endpoint_spec.rb +16 -6
- data/spec/spec_helper.rb +2 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6a1155a49050b3a3077261fae1e4171180f96df
|
4
|
+
data.tar.gz: c45adb992820172d12aa9a2dc2e6da9d283a93a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8510a94d6b279c349b99db139015bd36fa098b0badebfad02245e14d21a7d1a29a180b8a17790b49b5082f9c6833843bf77027b3cf72d522e69e2bc99e92332a
|
7
|
+
data.tar.gz: f087a85e74a5c47955caaae28e1fff406cdfad07fbbc6babc55b2eba6771158ffb1921e9a3fad95484146ca605660deee583955d213eb45bf84de26a8da79abc
|
data/Gemfile
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
|
+
|
2
3
|
gemspec
|
3
|
-
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
gem 'pry'
|
7
|
+
gem 'rake'
|
8
|
+
end
|
9
|
+
|
4
10
|
if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx' && RUBY_VERSION >= '2.0'
|
5
11
|
gem "rubysl", "~> 2.0", :group => :development
|
6
12
|
end
|
data/History.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
1.0.6 (2014-08-22)
|
2
|
+
===================
|
3
|
+
Features
|
4
|
+
--------
|
5
|
+
- env can be accessed by routed endpoint blocks
|
6
|
+
|
7
|
+
Fixes
|
8
|
+
-----
|
9
|
+
- analyser cache doesn't get stored in meta for a given piece of meta - can mess with stringifying analyser return values
|
10
|
+
- removed default secret, forcing user to specify one explicitly
|
11
|
+
- deal with "[" character problems in urls https://github.com/markevans/dragonfly/pull/337
|
12
|
+
|
1
13
|
1.0.5 (2014-05-15)
|
2
14
|
===================
|
3
15
|
Fixes
|
data/README.md
CHANGED
data/dev/irbrc.rb
CHANGED
@@ -2,7 +2,7 @@ require "rubygems"
|
|
2
2
|
require "bundler/setup"
|
3
3
|
$:.unshift(File.expand_path('../../lib', __FILE__))
|
4
4
|
require 'dragonfly'
|
5
|
-
|
5
|
+
require 'pry'
|
6
6
|
|
7
7
|
APP = Dragonfly.app.configure do
|
8
8
|
plugin :imagemagick
|
@@ -16,6 +16,18 @@ class Model
|
|
16
16
|
dragonfly_accessor :small_image
|
17
17
|
end
|
18
18
|
|
19
|
+
def reload
|
20
|
+
self.class.send(:remove_const, :APP)
|
21
|
+
Dragonfly.constants.each do |const|
|
22
|
+
Dragonfly.send(:remove_const, const)
|
23
|
+
end
|
24
|
+
$LOADED_FEATURES.grep(/dragonfly/).each do |path|
|
25
|
+
load path
|
26
|
+
end
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
alias reload! reload
|
30
|
+
|
19
31
|
puts "Loaded stuff from dragonfly irbrc"
|
20
32
|
puts "\nAvailable sample images:\n"
|
21
33
|
puts Dir['samples/*']
|
data/dragonfly.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.add_runtime_dependency("rack", [">= 0"])
|
25
25
|
spec.add_runtime_dependency("multi_json", ["~> 1.0"])
|
26
|
+
spec.add_runtime_dependency("addressable", ["~> 2.3"])
|
26
27
|
|
27
28
|
spec.add_development_dependency("rspec", ["~> 2.5"])
|
28
29
|
spec.add_development_dependency("webmock")
|
data/lib/dragonfly/app.rb
CHANGED
@@ -233,7 +233,7 @@ module Dragonfly
|
|
233
233
|
|
234
234
|
def remote_url_for(uid, opts={})
|
235
235
|
datastore.url_for(uid, opts)
|
236
|
-
rescue NoMethodError
|
236
|
+
rescue NoMethodError
|
237
237
|
raise NotImplementedError, "The datastore doesn't support serving content directly - #{datastore.inspect}"
|
238
238
|
end
|
239
239
|
|
@@ -258,12 +258,7 @@ module Dragonfly
|
|
258
258
|
'application/octet-stream'
|
259
259
|
end
|
260
260
|
|
261
|
-
|
262
|
-
@secret ||= 'secret yo'
|
263
|
-
end
|
264
|
-
attr_writer :secret
|
265
|
-
|
266
|
-
attr_accessor :allow_legacy_urls
|
261
|
+
attr_accessor :allow_legacy_urls, :secret
|
267
262
|
|
268
263
|
def define_macro(klass, name)
|
269
264
|
raise NoMethodError, "define_macro is deprecated - instead of defining #{name}, just extend #{klass.name} with Dragonfly::Model and use dragonfly_accessor"
|
data/lib/dragonfly/content.rb
CHANGED
@@ -115,7 +115,7 @@ module Dragonfly
|
|
115
115
|
self.temp_object = TempObject.new(obj)
|
116
116
|
original_filename = temp_object.original_filename
|
117
117
|
self.meta['name'] ||= original_filename if original_filename
|
118
|
-
|
118
|
+
clear_analyser_cache
|
119
119
|
add_meta(obj.meta) if obj.respond_to?(:meta)
|
120
120
|
add_meta(meta) if meta
|
121
121
|
self
|
@@ -205,7 +205,11 @@ module Dragonfly
|
|
205
205
|
end
|
206
206
|
|
207
207
|
def analyser_cache
|
208
|
-
|
208
|
+
@analyser_cache ||= {}
|
209
|
+
end
|
210
|
+
|
211
|
+
def clear_analyser_cache
|
212
|
+
analyser_cache.clear
|
209
213
|
end
|
210
214
|
|
211
215
|
def run(command, opts)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Tempfile#size reports size of 0 after the tempfile has been
|
2
|
+
# closed (without unlinking). This happens because internal
|
3
|
+
# @tmpfile is set to nil when the Tempfile is closed.
|
4
|
+
# Alternatively @tmpname is set to nil when file is unlinked.
|
5
|
+
|
6
|
+
if RUBY_VERSION < '1.9'
|
7
|
+
class Tempfile
|
8
|
+
def size
|
9
|
+
if @tmpfile
|
10
|
+
@tmpfile.flush
|
11
|
+
@tmpfile.stat.size
|
12
|
+
elsif @tmpname
|
13
|
+
File.size(@tmpname)
|
14
|
+
else
|
15
|
+
0
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/dragonfly/job.rb
CHANGED
@@ -15,6 +15,7 @@ module Dragonfly
|
|
15
15
|
class InvalidArray < StandardError; end
|
16
16
|
class NoSHAGiven < StandardError; end
|
17
17
|
class IncorrectSHA < StandardError; end
|
18
|
+
class CannotGenerateSha < StandardError; end
|
18
19
|
|
19
20
|
extend Forwardable
|
20
21
|
def_delegators :result,
|
@@ -150,6 +151,10 @@ module Dragonfly
|
|
150
151
|
end
|
151
152
|
|
152
153
|
def sha
|
154
|
+
unless app.secret
|
155
|
+
raise CannotGenerateSha, "A secret is required to sign and verify Dragonfly job requests. "\
|
156
|
+
"Use `secret '...'` or disable `protect_from_dos_attacks` in your config."
|
157
|
+
end
|
153
158
|
Digest::SHA1.hexdigest("#{to_unique_s}#{app.secret}")[0...8]
|
154
159
|
end
|
155
160
|
|
@@ -2,6 +2,7 @@ require 'uri'
|
|
2
2
|
require 'net/http'
|
3
3
|
require 'base64'
|
4
4
|
require 'dragonfly/job/step'
|
5
|
+
require 'addressable/uri'
|
5
6
|
|
6
7
|
module Dragonfly
|
7
8
|
class Job
|
@@ -84,7 +85,10 @@ module Dragonfly
|
|
84
85
|
URI.parse(url)
|
85
86
|
rescue URI::InvalidURIError
|
86
87
|
begin
|
87
|
-
URI.parse(
|
88
|
+
encoded_uri = Addressable::URI.parse(url).normalize.to_s
|
89
|
+
URI.parse(encoded_uri)
|
90
|
+
rescue Addressable::URI::InvalidURIError => e
|
91
|
+
raise BadURI, e.message
|
88
92
|
rescue URI::InvalidURIError => e
|
89
93
|
raise BadURI, e.message
|
90
94
|
end
|
@@ -14,7 +14,7 @@ module Dragonfly
|
|
14
14
|
|
15
15
|
def call(env)
|
16
16
|
params = Utils.symbolize_keys Rack::Request.new(env).params
|
17
|
-
value = @block.call(params.merge(routing_params(env)), @app)
|
17
|
+
value = @block.call(params.merge(routing_params(env)), @app, env)
|
18
18
|
case value
|
19
19
|
when nil then plain_response(404, "Not Found")
|
20
20
|
when Job, Model::Attachment
|
@@ -2,6 +2,7 @@ require 'stringio'
|
|
2
2
|
require 'tempfile'
|
3
3
|
require 'pathname'
|
4
4
|
require 'fileutils'
|
5
|
+
require 'dragonfly/core_ext/tempfile'
|
5
6
|
|
6
7
|
module Dragonfly
|
7
8
|
|
@@ -98,7 +99,9 @@ module Dragonfly
|
|
98
99
|
end
|
99
100
|
|
100
101
|
def size
|
101
|
-
@
|
102
|
+
@tempfile && @tempfile.size ||
|
103
|
+
@data && @data.bytesize ||
|
104
|
+
File.size(path)
|
102
105
|
end
|
103
106
|
|
104
107
|
def each(&block)
|
data/lib/dragonfly/version.rb
CHANGED
@@ -108,19 +108,10 @@ describe Dragonfly::Content do
|
|
108
108
|
content.analyse(:len).should == 7
|
109
109
|
end
|
110
110
|
|
111
|
-
it "
|
112
|
-
content.meta["analyser_cache"].should be_nil
|
111
|
+
it "updates when updated (i.e. clears cache)" do
|
113
112
|
content.analyse(:len).should == 7
|
114
|
-
content.meta["analyser_cache"].should == {"len" => 7}
|
115
|
-
end
|
116
|
-
|
117
|
-
it "empties the cache if updated" do
|
118
|
-
content.analyse(:len).should == 7
|
119
|
-
content.meta["analyser_cache"].should == {"len" => 7}
|
120
113
|
content.update("something else")
|
121
|
-
content.meta["analyser_cache"].should be_nil
|
122
114
|
content.analyse(:len).should == 14
|
123
|
-
content.meta["analyser_cache"].should == {"len" => 14}
|
124
115
|
end
|
125
116
|
end
|
126
117
|
|
@@ -96,15 +96,15 @@ describe Dragonfly::Job::FetchUrl do
|
|
96
96
|
|
97
97
|
describe "escaping" do
|
98
98
|
before do
|
99
|
-
stub_request(:get, "escapedurl.com/escaped%20url.jpg").to_return(:body => "OK!")
|
99
|
+
stub_request(:get, "escapedurl.com/escaped%20url%5B1%5D.jpg").to_return(:body => "OK!")
|
100
100
|
end
|
101
101
|
|
102
102
|
it "works with escaped urls" do
|
103
|
-
job.fetch_url('escapedurl.com/escaped%20url.jpg').data.should == 'OK!'
|
103
|
+
job.fetch_url('escapedurl.com/escaped%20url%5B1%5D.jpg').data.should == 'OK!'
|
104
104
|
end
|
105
105
|
|
106
106
|
it "tries to escape unescaped urls" do
|
107
|
-
job.fetch_url('escapedurl.com/escaped url.jpg').data.should == 'OK!'
|
107
|
+
job.fetch_url('escapedurl.com/escaped url[1].jpg').data.should == 'OK!'
|
108
108
|
end
|
109
109
|
|
110
110
|
it "still blows up with bad urls" do
|
data/spec/dragonfly/job_spec.rb
CHANGED
@@ -415,6 +415,11 @@ describe Dragonfly::Job do
|
|
415
415
|
it "should be different for different jobs" do
|
416
416
|
@app.fetch('figs').sha.should_not == @job.sha
|
417
417
|
end
|
418
|
+
|
419
|
+
it "should raise error when secret is unspecified" do
|
420
|
+
@app.secret = nil
|
421
|
+
expect{ @app.fetch('figs').sha }.to raise_error(Dragonfly::Job::CannotGenerateSha)
|
422
|
+
end
|
418
423
|
end
|
419
424
|
|
420
425
|
describe "validate_sha!" do
|
@@ -11,6 +11,7 @@ describe Dragonfly::RoutedEndpoint do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
let (:app) { test_app }
|
14
|
+
let (:uid) { app.store('wassup') }
|
14
15
|
|
15
16
|
describe "endpoint returning a job" do
|
16
17
|
let (:endpoint) {
|
@@ -19,10 +20,6 @@ describe Dragonfly::RoutedEndpoint do
|
|
19
20
|
}
|
20
21
|
}
|
21
22
|
|
22
|
-
before(:each) do
|
23
|
-
@uid = app.store('wassup')
|
24
|
-
end
|
25
|
-
|
26
23
|
it "should raise an error when there are no routing parameters" do
|
27
24
|
lambda{
|
28
25
|
endpoint.call(env_for('/blah'))
|
@@ -37,14 +34,14 @@ describe Dragonfly::RoutedEndpoint do
|
|
37
34
|
}.each do |name, key|
|
38
35
|
|
39
36
|
it "should work with #{name} routing args" do
|
40
|
-
response = response_for endpoint.call(env_for('/blah', key => {:uid =>
|
37
|
+
response = response_for endpoint.call(env_for('/blah', key => {:uid => uid}))
|
41
38
|
response.body.should == 'wassup'
|
42
39
|
end
|
43
40
|
|
44
41
|
end
|
45
42
|
|
46
43
|
it "should merge with query parameters" do
|
47
|
-
env = Rack::MockRequest.env_for("/big/buns?uid=#{
|
44
|
+
env = Rack::MockRequest.env_for("/big/buns?uid=#{uid}", 'dragonfly.params' => {:something => 'else'})
|
48
45
|
response = response_for endpoint.call(env)
|
49
46
|
response.body.should == 'wassup'
|
50
47
|
end
|
@@ -54,6 +51,19 @@ describe Dragonfly::RoutedEndpoint do
|
|
54
51
|
end
|
55
52
|
end
|
56
53
|
|
54
|
+
describe "env argument" do
|
55
|
+
let (:endpoint) {
|
56
|
+
Dragonfly::RoutedEndpoint.new(app) {|params, app, env|
|
57
|
+
app.fetch(env['THE_UID'])
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
it "adds the env to the arguments" do
|
62
|
+
response = response_for endpoint.call(env_for('/blah', {"THE_UID" => uid, 'dragonfly.params' => {}}))
|
63
|
+
response.body.should == 'wassup'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
57
67
|
describe "endpoint returning other things" do
|
58
68
|
let (:model_class) {
|
59
69
|
Class.new do
|
data/spec/spec_helper.rb
CHANGED
@@ -9,7 +9,7 @@ require 'dragonfly'
|
|
9
9
|
require 'fileutils'
|
10
10
|
require 'tempfile'
|
11
11
|
require 'webmock/rspec'
|
12
|
-
require 'pry'
|
12
|
+
require 'pry' if RUBY_VERSION >= '1.9'
|
13
13
|
|
14
14
|
# Requires supporting files with custom matchers and macros, etc,
|
15
15
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
@@ -38,6 +38,7 @@ end
|
|
38
38
|
def test_app(name=nil)
|
39
39
|
app = Dragonfly::App.instance(name)
|
40
40
|
app.datastore = Dragonfly::MemoryDataStore.new
|
41
|
+
app.secret = "test secret"
|
41
42
|
app
|
42
43
|
end
|
43
44
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dragonfly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: addressable
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.3'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.3'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,6 +126,7 @@ files:
|
|
112
126
|
- lib/dragonfly/core_ext/array.rb
|
113
127
|
- lib/dragonfly/core_ext/hash.rb
|
114
128
|
- lib/dragonfly/core_ext/object.rb
|
129
|
+
- lib/dragonfly/core_ext/tempfile.rb
|
115
130
|
- lib/dragonfly/file_data_store.rb
|
116
131
|
- lib/dragonfly/has_filename.rb
|
117
132
|
- lib/dragonfly/hash_with_css_style_keys.rb
|
@@ -250,7 +265,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
250
265
|
version: '0'
|
251
266
|
requirements: []
|
252
267
|
rubyforge_project:
|
253
|
-
rubygems_version: 2.2.
|
268
|
+
rubygems_version: 2.2.2
|
254
269
|
signing_key:
|
255
270
|
specification_version: 4
|
256
271
|
summary: Ideal gem for handling attachments in Rails, Sinatra and Rack applications.
|