httpimagestore 1.8.1 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Gemfile +7 -7
- data/Gemfile.lock +20 -20
- data/README.md +165 -37
- data/Rakefile +7 -2
- data/VERSION +1 -1
- data/bin/httpimagestore +74 -41
- data/lib/httpimagestore/configuration/file.rb +20 -11
- data/lib/httpimagestore/configuration/handler.rb +96 -257
- data/lib/httpimagestore/configuration/handler/source_store_base.rb +37 -0
- data/lib/httpimagestore/configuration/handler/statement.rb +114 -0
- data/lib/httpimagestore/configuration/identify.rb +17 -9
- data/lib/httpimagestore/configuration/output.rb +33 -61
- data/lib/httpimagestore/configuration/path.rb +2 -2
- data/lib/httpimagestore/configuration/request_state.rb +131 -0
- data/lib/httpimagestore/configuration/s3.rb +41 -29
- data/lib/httpimagestore/configuration/thumbnailer.rb +189 -96
- data/lib/httpimagestore/configuration/validate_hmac.rb +170 -0
- data/lib/httpimagestore/error_reporter.rb +6 -1
- data/lib/httpimagestore/ruby_string_template.rb +10 -19
- metadata +40 -102
- data/.rspec +0 -1
- data/features/cache-control.feature +0 -41
- data/features/compatibility.feature +0 -165
- data/features/data-uri.feature +0 -55
- data/features/encoding.feature +0 -103
- data/features/error-reporting.feature +0 -281
- data/features/flexi.feature +0 -259
- data/features/health-check.feature +0 -29
- data/features/request-matching.feature +0 -211
- data/features/rewrite.feature +0 -122
- data/features/s3-store-and-thumbnail.feature +0 -82
- data/features/source-failover.feature +0 -71
- data/features/step_definitions/httpimagestore_steps.rb +0 -203
- data/features/storage.feature +0 -198
- data/features/support/env.rb +0 -116
- data/features/support/test-large.jpg +0 -0
- data/features/support/test.empty +0 -0
- data/features/support/test.jpg +0 -0
- data/features/support/test.png +0 -0
- data/features/support/test.txt +0 -1
- data/features/support/tiny.png +0 -0
- data/features/xid-forwarding.feature +0 -49
- data/httpimagestore.gemspec +0 -145
- data/load_test/load_test.1k.23a022f6e.m1.small-comp.csv +0 -3
- data/load_test/load_test.1k.ec9bde794.m1.small.csv +0 -4
- data/load_test/load_test.jmx +0 -317
- data/load_test/thumbnail_specs.csv +0 -11
- data/load_test/thumbnail_specs_v2.csv +0 -10
- data/spec/configuration_file_spec.rb +0 -333
- data/spec/configuration_handler_spec.rb +0 -255
- data/spec/configuration_identify_spec.rb +0 -67
- data/spec/configuration_output_spec.rb +0 -821
- data/spec/configuration_path_spec.rb +0 -138
- data/spec/configuration_s3_spec.rb +0 -911
- data/spec/configuration_source_failover_spec.rb +0 -101
- data/spec/configuration_spec.rb +0 -90
- data/spec/configuration_thumbnailer_spec.rb +0 -483
- data/spec/ruby_string_template_spec.rb +0 -61
- data/spec/spec_helper.rb +0 -89
- data/spec/support/compute.jpg +0 -0
- data/spec/support/cuba_response_env.rb +0 -40
- data/spec/support/full.cfg +0 -183
- data/spec/support/utf_string.txt +0 -1
data/features/rewrite.feature
DELETED
@@ -1,122 +0,0 @@
|
|
1
|
-
Feature: Rewrite of the output path and URL
|
2
|
-
Output path or URL can be rewritten with variables to customise further the API output.
|
3
|
-
|
4
|
-
Background:
|
5
|
-
Given httpthumbnailer server is running at http://localhost:3100/health_check
|
6
|
-
Given httpimagestore server is running at http://localhost:3000/health_check with the following configuration
|
7
|
-
"""
|
8
|
-
path "input_digest" "#{input_digest}"
|
9
|
-
path "rewritten" "hello/#{prefix}/#{input_sha256}.jpg"
|
10
|
-
path "rewritten-absolute" "/hello/#{prefix}/#{input_sha256}.jpg"
|
11
|
-
path "demo" "image/#{input_sha256}.jpg"
|
12
|
-
|
13
|
-
post "rewrite" "path" "&:prefix" {
|
14
|
-
store_file "input" root="/tmp" path="input_digest"
|
15
|
-
output_store_path "input" path="rewritten"
|
16
|
-
}
|
17
|
-
|
18
|
-
post "rewrite" "uri" "path" "&:prefix" {
|
19
|
-
store_file "input" root="/tmp" path="input_digest"
|
20
|
-
output_store_uri "input" path="rewritten"
|
21
|
-
}
|
22
|
-
|
23
|
-
post "rewrite" "uri" "path-absolute" "&:prefix" {
|
24
|
-
store_file "input" root="/tmp" path="input_digest"
|
25
|
-
output_store_uri "input" path="rewritten-absolute"
|
26
|
-
}
|
27
|
-
|
28
|
-
post "rewrite" "url" "path" "&:prefix" {
|
29
|
-
store_file "input" root="/tmp" path="input_digest"
|
30
|
-
output_store_url "input" path="rewritten"
|
31
|
-
}
|
32
|
-
|
33
|
-
post "rewrite" "url" "path-absolute" "&:prefix" {
|
34
|
-
store_file "input" root="/tmp" path="input_digest"
|
35
|
-
output_store_url "input" path="rewritten-absolute"
|
36
|
-
}
|
37
|
-
|
38
|
-
post "rewrite" "url" "scheme" "&:proto" {
|
39
|
-
store_file "input" root="/tmp" path="input_digest"
|
40
|
-
output_store_url "input" scheme="#{proto}"
|
41
|
-
}
|
42
|
-
|
43
|
-
post "rewrite" "url" "host" "&:target" {
|
44
|
-
store_file "input" root="/tmp" path="input_digest"
|
45
|
-
output_store_url "input" host="www.#{target}"
|
46
|
-
}
|
47
|
-
|
48
|
-
post "rewrite" "url" "port" "&:number" {
|
49
|
-
store_file "input" root="/tmp" path="input_digest"
|
50
|
-
output_store_url "input" port="#{number}"
|
51
|
-
}
|
52
|
-
|
53
|
-
post "rewrite" "demo" {
|
54
|
-
store_file "input" root="/tmp" path="input_digest"
|
55
|
-
output_store_url "input" scheme="ftp" host="example.com" port="421" path="demo"
|
56
|
-
}
|
57
|
-
"""
|
58
|
-
|
59
|
-
Scenario: Store path rewriting
|
60
|
-
Given test.png file content as request body
|
61
|
-
When I do POST request http://localhost:3000/rewrite/path?prefix=world
|
62
|
-
And response body will be CRLF ended lines
|
63
|
-
"""
|
64
|
-
hello/world/b0fe25319ba5909aa97fded546847a96d7fdf26e18715b0cfccfcbee52dce57e.jpg
|
65
|
-
"""
|
66
|
-
|
67
|
-
Scenario: Store URI path rewriting
|
68
|
-
Given test.png file content as request body
|
69
|
-
When I do POST request http://localhost:3000/rewrite/uri/path?prefix=world
|
70
|
-
And response body will be CRLF ended lines
|
71
|
-
"""
|
72
|
-
/hello/world/b0fe25319ba5909aa97fded546847a96d7fdf26e18715b0cfccfcbee52dce57e.jpg
|
73
|
-
"""
|
74
|
-
|
75
|
-
Scenario: Store URI path rewriting - absolute path
|
76
|
-
Given test.png file content as request body
|
77
|
-
When I do POST request http://localhost:3000/rewrite/uri/path-absolute?prefix=world
|
78
|
-
And response body will be CRLF ended lines
|
79
|
-
"""
|
80
|
-
/hello/world/b0fe25319ba5909aa97fded546847a96d7fdf26e18715b0cfccfcbee52dce57e.jpg
|
81
|
-
"""
|
82
|
-
|
83
|
-
Scenario: Store URL path rewriting
|
84
|
-
Given test.png file content as request body
|
85
|
-
When I do POST request http://localhost:3000/rewrite/url/path?prefix=world
|
86
|
-
And response body will be CRLF ended lines
|
87
|
-
"""
|
88
|
-
file:/hello/world/b0fe25319ba5909aa97fded546847a96d7fdf26e18715b0cfccfcbee52dce57e.jpg
|
89
|
-
"""
|
90
|
-
|
91
|
-
Scenario: Store URL path rewriting - absolute path
|
92
|
-
Given test.png file content as request body
|
93
|
-
When I do POST request http://localhost:3000/rewrite/url/path-absolute?prefix=world
|
94
|
-
And response body will be CRLF ended lines
|
95
|
-
"""
|
96
|
-
file:/hello/world/b0fe25319ba5909aa97fded546847a96d7fdf26e18715b0cfccfcbee52dce57e.jpg
|
97
|
-
"""
|
98
|
-
|
99
|
-
Scenario: Store URL scheme rewriting
|
100
|
-
Given test.png file content as request body
|
101
|
-
When I do POST request http://localhost:3000/rewrite/url/host?target=example.com
|
102
|
-
And response body will be CRLF ended lines
|
103
|
-
"""
|
104
|
-
file://www.example.com/b0fe25319ba5909a
|
105
|
-
"""
|
106
|
-
|
107
|
-
Scenario: Store URL port rewriting
|
108
|
-
Given test.png file content as request body
|
109
|
-
When I do POST request http://localhost:3000/rewrite/url/port?number=41
|
110
|
-
And response body will be CRLF ended lines
|
111
|
-
"""
|
112
|
-
file://localhost:41/b0fe25319ba5909a
|
113
|
-
"""
|
114
|
-
|
115
|
-
Scenario: Store URL rewriting demo
|
116
|
-
Given test.png file content as request body
|
117
|
-
When I do POST request http://localhost:3000/rewrite/demo
|
118
|
-
And response body will be CRLF ended lines
|
119
|
-
"""
|
120
|
-
ftp://example.com:421/image/b0fe25319ba5909aa97fded546847a96d7fdf26e18715b0cfccfcbee52dce57e.jpg
|
121
|
-
"""
|
122
|
-
|
@@ -1,82 +0,0 @@
|
|
1
|
-
Feature: Store limited original image in S3 and thumbnail based on request
|
2
|
-
Posted image will be converted to JPEG and resized if it is bigger that given dimensions.
|
3
|
-
Than it will get stored on S3.
|
4
|
-
Get interface will allow to fetch the image from S3 and thumbnailing to given parameters.
|
5
|
-
|
6
|
-
Background:
|
7
|
-
Given S3 settings in AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_S3_TEST_BUCKET environment variables
|
8
|
-
Given httpthumbnailer server is running at http://localhost:3100/health_check
|
9
|
-
Given httpimagestore server is running at http://localhost:3000/health_check with the following configuration
|
10
|
-
"""
|
11
|
-
s3 key="@AWS_ACCESS_KEY_ID@" secret="@AWS_SECRET_ACCESS_KEY@" ssl=false
|
12
|
-
|
13
|
-
path "original-hash" "#{input_digest}.#{image_mime_extension}"
|
14
|
-
path "path" "#{path}"
|
15
|
-
|
16
|
-
put "original" {
|
17
|
-
thumbnail "input" "original" operation="limit" width=100 height=100 format="jpeg" quality=95
|
18
|
-
store_s3 "original" bucket="@AWS_S3_TEST_BUCKET@" path="original-hash" cache-root="/tmp"
|
19
|
-
output_store_uri "original"
|
20
|
-
}
|
21
|
-
|
22
|
-
get "thumbnail" "v1" ":path" ":operation" ":width" ":height" ":options?" {
|
23
|
-
source_s3 "original" bucket="@AWS_S3_TEST_BUCKET@" path="path"
|
24
|
-
thumbnail "original" "thumbnail" operation="#{operation}" width="#{width}" height="#{height}" options="#{options}" quality=84 format="png"
|
25
|
-
output_image "thumbnail" cache-control="public, max-age=31557600, s-maxage=0"
|
26
|
-
}
|
27
|
-
|
28
|
-
get "thumbnail" "v2" ":operation" ":width" ":height" {
|
29
|
-
source_s3 "original" bucket="@AWS_S3_TEST_BUCKET@" path="path" cache-root="/tmp"
|
30
|
-
thumbnail "original" "thumbnail" operation="#{operation}" width="#{width}" height="#{height}" options="#{query_string_options}" quality=84 format="png"
|
31
|
-
output_image "thumbnail" cache-control="public, max-age=31557600, s-maxage=0"
|
32
|
-
}
|
33
|
-
"""
|
34
|
-
|
35
|
-
@s3-store-and-thumbnail
|
36
|
-
Scenario: Putting original to S3 bucket
|
37
|
-
Given there is no 4006450256177f4a.jpg file in S3 bucket
|
38
|
-
Given test.jpg file content as request body
|
39
|
-
When I do PUT request http://localhost:3000/original
|
40
|
-
Then response status will be 200
|
41
|
-
And response content type will be text/uri-list
|
42
|
-
And response body will be CRLF ended lines
|
43
|
-
"""
|
44
|
-
/4006450256177f4a.jpg
|
45
|
-
"""
|
46
|
-
Then S3 object 4006450256177f4a.jpg will contain JPEG image of size 71x100
|
47
|
-
When I do GET request http://@AWS_S3_TEST_BUCKET@.s3.amazonaws.com/4006450256177f4a.jpg
|
48
|
-
Then response status will be 403
|
49
|
-
|
50
|
-
@s3-store-and-thumbnail
|
51
|
-
Scenario: Getting thumbnail to spec based on uploaded S3 image
|
52
|
-
Given test.jpg file content is stored in S3 under 4006450256177f4a.jpg
|
53
|
-
When I do GET request http://localhost:3000/thumbnail/v1/4006450256177f4a.jpg/pad/50/50
|
54
|
-
Then response status will be 200
|
55
|
-
And response content type will be image/png
|
56
|
-
Then response body will contain PNG image of size 50x50
|
57
|
-
|
58
|
-
@s3-store-and-thumbnail
|
59
|
-
Scenario: Getting thumbnail to spec based on uploaded S3 image - with options passed
|
60
|
-
Given test.jpg file content is stored in S3 under 4006450256177f4a.jpg
|
61
|
-
When I do GET request http://localhost:3000/thumbnail/v1/4006450256177f4a.jpg/pad/50/50/background-color:green
|
62
|
-
Then response status will be 200
|
63
|
-
And response content type will be image/png
|
64
|
-
Then response body will contain PNG image of size 50x50
|
65
|
-
And that image pixel at 2x2 should be of color green
|
66
|
-
|
67
|
-
@s3-store-and-thumbnail @v2
|
68
|
-
Scenario: Getting thumbnail to spec based on uploaded S3 image - v2
|
69
|
-
Given test.jpg file content is stored in S3 under 4006450256177f4a.jpg
|
70
|
-
When I do GET request http://localhost:3000/thumbnail/v2/pad/50/50/4006450256177f4a.jpg
|
71
|
-
Then response status will be 200
|
72
|
-
And response content type will be image/png
|
73
|
-
Then response body will contain PNG image of size 50x50
|
74
|
-
|
75
|
-
@s3-store-and-thumbnail @v2
|
76
|
-
Scenario: Getting thumbnail to spec based on uploaded S3 image - with options passed
|
77
|
-
Given test.jpg file content is stored in S3 under 4006450256177f4a.jpg
|
78
|
-
When I do GET request http://localhost:3000/thumbnail/v2/pad/50/50/4006450256177f4a.jpg?background-color=green
|
79
|
-
Then response status will be 200
|
80
|
-
And response content type will be image/png
|
81
|
-
Then response body will contain PNG image of size 50x50
|
82
|
-
And that image pixel at 2x2 should be of color green
|
@@ -1,71 +0,0 @@
|
|
1
|
-
Feature: More than one source can be tried in canse of source problem
|
2
|
-
Sources can be grouped under source_failover group.
|
3
|
-
HTTP Image Store will try each source until working one is found.
|
4
|
-
|
5
|
-
Background:
|
6
|
-
Given S3 settings in AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_S3_TEST_BUCKET environment variables
|
7
|
-
Given httpimagestore server is running at http://localhost:3000/ with the following configuration
|
8
|
-
"""
|
9
|
-
s3 key="@AWS_ACCESS_KEY_ID@" secret="@AWS_SECRET_ACCESS_KEY@" ssl=false
|
10
|
-
|
11
|
-
path "test-file" "test.file"
|
12
|
-
path "bogus" "bogus"
|
13
|
-
|
14
|
-
put "input" {
|
15
|
-
store_s3 "input" bucket="@AWS_S3_TEST_BUCKET@" path="test-file"
|
16
|
-
}
|
17
|
-
|
18
|
-
get "s3_fail" {
|
19
|
-
source_s3 "image" bucket="@AWS_S3_TEST_BUCKET@" path="bogus"
|
20
|
-
source_s3 "image" bucket="@AWS_S3_TEST_BUCKET@" path="test-file"
|
21
|
-
output_image "image"
|
22
|
-
}
|
23
|
-
|
24
|
-
get "s3_failover" {
|
25
|
-
source_failover {
|
26
|
-
source_s3 "image" bucket="@AWS_S3_TEST_BUCKET@" path="bogus"
|
27
|
-
source_s3 "image" bucket="@AWS_S3_TEST_BUCKET@" path="test-file"
|
28
|
-
}
|
29
|
-
output_image "image"
|
30
|
-
}
|
31
|
-
|
32
|
-
get "s3_all_fail" {
|
33
|
-
source_failover {
|
34
|
-
source_s3 "image" bucket="@AWS_S3_TEST_BUCKET@" path="bogus"
|
35
|
-
source_s3 "image" bucket="@AWS_S3_TEST_BUCKET@" path="bogus"
|
36
|
-
}
|
37
|
-
output_image "image"
|
38
|
-
}
|
39
|
-
"""
|
40
|
-
|
41
|
-
@source-failover
|
42
|
-
Scenario: Sourcing S3 object without failover
|
43
|
-
Given there is no test.file file in S3 bucket
|
44
|
-
Given test.jpg file content as request body
|
45
|
-
When I do PUT request http://localhost:3000/input
|
46
|
-
Then response status will be 200
|
47
|
-
When I do GET request http://localhost:3000/s3_fail
|
48
|
-
Then response status will be 404
|
49
|
-
|
50
|
-
@source-failover
|
51
|
-
Scenario: Sourcing S3 object with failover
|
52
|
-
Given there is no test.file file in S3 bucket
|
53
|
-
Given test.jpg file content as request body
|
54
|
-
When I do PUT request http://localhost:3000/input
|
55
|
-
Then response status will be 200
|
56
|
-
When I do GET request http://localhost:3000/s3_failover
|
57
|
-
Then response status will be 200
|
58
|
-
|
59
|
-
@source-failover
|
60
|
-
Scenario: Sourcing S3 object with all sources failing
|
61
|
-
Given there is no test.file file in S3 bucket
|
62
|
-
Given test.jpg file content as request body
|
63
|
-
When I do PUT request http://localhost:3000/input
|
64
|
-
Then response status will be 200
|
65
|
-
When I do GET request http://localhost:3000/s3_all_fail
|
66
|
-
Then response status will be 404
|
67
|
-
And response content type will be text/plain
|
68
|
-
And response body will be CRLF ended lines
|
69
|
-
"""
|
70
|
-
all sources failed: S3Source[image_name: 'image' bucket: 'httpimagestoretest' prefix: '' path_spec: 'bogus'](Configuration::S3NoSuchKeyError: S3 bucket 'httpimagestoretest' does not contain key 'bogus'), S3Source[image_name: 'image' bucket: 'httpimagestoretest' prefix: '' path_spec: 'bogus'](Configuration::S3NoSuchKeyError: S3 bucket 'httpimagestoretest' does not contain key 'bogus')
|
71
|
-
"""
|
@@ -1,203 +0,0 @@
|
|
1
|
-
Given /httpimagestore argument (.*)/ do |arg|
|
2
|
-
(@httpimagestore_args ||= []) << arg
|
3
|
-
end
|
4
|
-
|
5
|
-
Given /httpimagestore server is running at (.*) with the following configuration/ do |url, config|
|
6
|
-
$temp_dir = Pathname.new(Dir.mktmpdir) unless $temp_dir
|
7
|
-
|
8
|
-
cfile = $temp_dir + Digest.hexencode(Digest::MD5.digest(config))
|
9
|
-
cfile.open('w') do |io|
|
10
|
-
io.write(config.replace_s3_variables)
|
11
|
-
end
|
12
|
-
|
13
|
-
begin
|
14
|
-
log = support_dir + 'server.log'
|
15
|
-
start_server(
|
16
|
-
"bundle exec #{script('httpimagestore')} -f -d -x XID -l #{log} -w 1 #{(@httpimagestore_args ||= []).join(' ')} #{cfile.to_s}",
|
17
|
-
'/tmp/httpimagestore.pid',
|
18
|
-
log,
|
19
|
-
url
|
20
|
-
)
|
21
|
-
ensure
|
22
|
-
cfile.unlink
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
Given /httpthumbnailer server is running at (.*)/ do |url|
|
27
|
-
log = support_dir + 'thumbniler.log'
|
28
|
-
start_server(
|
29
|
-
"httpthumbnailer -f -d -x XID -l #{log} -a #{log}.access -w 1",
|
30
|
-
'/tmp/httpthumbnailer.pid',
|
31
|
-
log,
|
32
|
-
url
|
33
|
-
)
|
34
|
-
end
|
35
|
-
|
36
|
-
Given /httpthumbnailer server is not running/ do
|
37
|
-
stop_server('/tmp/httpthumbnailer.pid')
|
38
|
-
end
|
39
|
-
|
40
|
-
Given /httpimagestore log is empty/ do
|
41
|
-
log = support_dir + 'server.log'
|
42
|
-
log.truncate(0) if log.exist?
|
43
|
-
end
|
44
|
-
|
45
|
-
Given /httpthumbnailer log is empty/ do
|
46
|
-
log = support_dir + 'thumbniler.log'
|
47
|
-
log.truncate(0) if log.exist?
|
48
|
-
end
|
49
|
-
|
50
|
-
Given /^([^ ]*) file content as request body/ do |file|
|
51
|
-
@request_body = File.open(support_dir + file){|f| f.read }
|
52
|
-
end
|
53
|
-
|
54
|
-
Given /there is no file (.*)/ do |file|
|
55
|
-
Pathname.new(file).exist? and Pathname.new(file).unlink
|
56
|
-
end
|
57
|
-
|
58
|
-
Given /S3 settings in AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_S3_TEST_BUCKET environment variables/ do
|
59
|
-
|
60
|
-
unless ENV['AWS_ACCESS_KEY_ID'] and ENV['AWS_SECRET_ACCESS_KEY'] and ENV['AWS_S3_TEST_BUCKET']
|
61
|
-
fail "AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY or AWS_S3_TEST_BUCKET environment variables not set"
|
62
|
-
end
|
63
|
-
|
64
|
-
@bucket = AWS::S3.new(access_key_id: ENV['AWS_ACCESS_KEY_ID'], secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'], use_ssl: false).buckets[ENV['AWS_S3_TEST_BUCKET']]
|
65
|
-
end
|
66
|
-
|
67
|
-
Given /there is no (.*) file in S3 bucket/ do |path|
|
68
|
-
@bucket.objects[path].delete # rescue S3::Error::NoSuchKey
|
69
|
-
end
|
70
|
-
|
71
|
-
Given /(.*) header set to (.*)/ do |header, value|
|
72
|
-
@request_headers ||= {}
|
73
|
-
@request_headers[header] = value
|
74
|
-
end
|
75
|
-
|
76
|
-
Given /(.*) file content is stored in S3 under (.*)/ do |file, key|
|
77
|
-
@bucket.objects[key].write(File.open(support_dir + file){|f| f.read }, content_type: 'image/jpeg')
|
78
|
-
end
|
79
|
-
|
80
|
-
Then /S3 bucket will not contain (.*)/ do |key|
|
81
|
-
@bucket.objects[key].exists?.should_not be_true
|
82
|
-
end
|
83
|
-
|
84
|
-
When /I do (.*) request ([^ ]+)$/ do |method, uri|
|
85
|
-
@request_body = nil if method == 'GET'
|
86
|
-
|
87
|
-
@response = request(method, uri, @request_body, (@request_headers or {}))
|
88
|
-
end
|
89
|
-
|
90
|
-
When /I do (.*) request with encoded URL (.*)/ do |method, uri|
|
91
|
-
step "I do #{method} request #{URI.encode(uri)}"
|
92
|
-
end
|
93
|
-
|
94
|
-
Then /response status will be (.*)/ do |status|
|
95
|
-
@response.status.should == status.to_i
|
96
|
-
end
|
97
|
-
|
98
|
-
Then /response content type will be (.*)/ do |content_type|
|
99
|
-
@response.headers['Content-Type'].should == content_type
|
100
|
-
end
|
101
|
-
|
102
|
-
Then /response Cache-Control will be (.*)/ do |content_type|
|
103
|
-
@response.headers['Cache-Control'].should == content_type
|
104
|
-
end
|
105
|
-
|
106
|
-
Then /response body will be CRLF ended lines like/ do |body|
|
107
|
-
@response.body.should match(body.replace_s3_variables)
|
108
|
-
@response.body.each_line do |line|
|
109
|
-
line[-2,2].should == "\r\n"
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
Then /response body will be$/ do |body|
|
114
|
-
@response.body.should == body.replace_s3_variables
|
115
|
-
end
|
116
|
-
|
117
|
-
Then /response body will be CRLF ended lines$/ do |body|
|
118
|
-
res = @response.body.dup
|
119
|
-
res.force_encoding('UTF-8')
|
120
|
-
res.should == body.replace_s3_variables.gsub("\n", "\r\n") + "\r\n"
|
121
|
-
end
|
122
|
-
|
123
|
-
Then /(http.*) content type will be (.*)/ do |url, content_type|
|
124
|
-
get_headers(url.replace_s3_variables)['Content-Type'].should == content_type
|
125
|
-
end
|
126
|
-
|
127
|
-
Then /(http.*) ([^ ]+) header will be (.*)/ do |url, header, value|
|
128
|
-
get_headers(url.replace_s3_variables)[header].should == value
|
129
|
-
end
|
130
|
-
|
131
|
-
Then /(http.*) ([^ ]+) header will not be set/ do |url, header|
|
132
|
-
get_headers(url.replace_s3_variables)[header].should be_nil
|
133
|
-
end
|
134
|
-
|
135
|
-
Then /^(http[^ ]+) will contain (.*) image of size (.*)x(.*)/ do |url, format, width, height|
|
136
|
-
data = get(url.replace_s3_variables)
|
137
|
-
|
138
|
-
@image.destroy! if @image
|
139
|
-
@image = Magick::Image.from_blob(data).first
|
140
|
-
|
141
|
-
@image.format.should == format
|
142
|
-
@image.columns.should == width.to_i
|
143
|
-
@image.rows.should == height.to_i
|
144
|
-
end
|
145
|
-
|
146
|
-
|
147
|
-
Then /Encoded URL (http.*) will contain (.*) image of size (.*)x(.*)/ do |url, format, width, height|
|
148
|
-
step "#{URI.encode(url)} will contain #{format} image of size #{width}x#{height}"
|
149
|
-
end
|
150
|
-
|
151
|
-
Then /S3 object (.*) will contain (.*) image of size (.*)x(.*)/ do |key, format, width, height|
|
152
|
-
data = @bucket.objects[key].read
|
153
|
-
|
154
|
-
@image.destroy! if @image
|
155
|
-
@image = Magick::Image.from_blob(data).first
|
156
|
-
|
157
|
-
@image.format.should == format
|
158
|
-
@image.columns.should == width.to_i
|
159
|
-
@image.rows.should == height.to_i
|
160
|
-
end
|
161
|
-
|
162
|
-
Then /S3 object (.*) content type will be (.*)/ do |key, content_type|
|
163
|
-
@bucket.objects[key].content_type.should == content_type
|
164
|
-
end
|
165
|
-
|
166
|
-
Then /response body will contain (.*) image of size (.*)x(.*)/ do |format, width, height|
|
167
|
-
data = @response.body
|
168
|
-
Pathname.new('/tmp/out.jpg').open('w'){|io| io.write data}
|
169
|
-
|
170
|
-
@image.destroy! if @image
|
171
|
-
@image = Magick::Image.from_blob(data).first
|
172
|
-
|
173
|
-
@image.format.should == format
|
174
|
-
@image.columns.should == width.to_i
|
175
|
-
@image.rows.should == height.to_i
|
176
|
-
end
|
177
|
-
|
178
|
-
Then /response body will contain UUID/ do
|
179
|
-
@response.body.should ~ /[0-f]{8}-[0-f]{4}-[0-f]{4}-[0-f]{4}-[0-f]{12}/
|
180
|
-
end
|
181
|
-
|
182
|
-
And /that image pixel at (.*)x(.*) should be of color (.*)/ do |x, y, color|
|
183
|
-
@image.pixel_color(x.to_i, y.to_i).to_color.sub(/^#/, '0x').should == color
|
184
|
-
end
|
185
|
-
|
186
|
-
Then /file (.*) will contain (.*) image of size (.*)x(.*)/ do |file, format, width, height|
|
187
|
-
data = Pathname.new(file).read
|
188
|
-
|
189
|
-
@image.destroy! if @image
|
190
|
-
@image = Magick::Image.from_blob(data).first
|
191
|
-
|
192
|
-
@image.format.should == format
|
193
|
-
@image.columns.should == width.to_i
|
194
|
-
@image.rows.should == height.to_i
|
195
|
-
end
|
196
|
-
|
197
|
-
Then /httpimagestore log will contain (.*)/ do |entry|
|
198
|
-
(support_dir + 'server.log').read.should include entry
|
199
|
-
end
|
200
|
-
|
201
|
-
Then /httpthumbnailer log will contain (.*)/ do |entry|
|
202
|
-
(support_dir + 'thumbniler.log').read.should include entry
|
203
|
-
end
|