snapimage 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. data/.gitignore +2 -0
  2. data/bin/snapimage_generate_config +9 -11
  3. data/bin/snapimage_server +1 -1
  4. data/lib/snapimage.rb +12 -12
  5. data/lib/snapimage/config.rb +2 -9
  6. data/lib/snapimage/exceptions.rb +7 -10
  7. data/lib/snapimage/rack/request.rb +1 -6
  8. data/lib/snapimage/rack/request_file.rb +3 -6
  9. data/lib/snapimage/rack/response.rb +13 -13
  10. data/lib/snapimage/server.rb +24 -28
  11. data/lib/snapimage/version.rb +1 -1
  12. data/spec/acceptance/delete_resource_images_spec.rb +166 -166
  13. data/spec/acceptance/list_resource_images_spec.rb +158 -158
  14. data/spec/acceptance/modify_spec.rb +165 -165
  15. data/spec/acceptance/sync_spec.rb +237 -237
  16. data/spec/acceptance/upload_spec.rb +28 -189
  17. data/spec/snapimage/config_spec.rb +5 -13
  18. data/spec/snapimage/image/image_name_utils_spec.rb +113 -113
  19. data/spec/snapimage/image/image_spec.rb +55 -55
  20. data/spec/snapimage/rack/request_file_spec.rb +0 -11
  21. data/spec/snapimage/rack/request_spec.rb +6 -25
  22. data/spec/snapimage/server_actions/server_actions.authorize_spec.rb +56 -56
  23. data/spec/snapimage/server_actions/server_actions.generate_image_spec.rb +146 -146
  24. data/spec/snapimage/server_actions/server_actions.sync_resource_spec.rb +81 -81
  25. data/spec/snapimage/server_spec.rb +57 -20
  26. data/spec/snapimage/storage/storage_server.local_spec.rb +150 -150
  27. data/spec/snapimage/storage/storage_server_spec.rb +83 -83
  28. data/spec/snapimage/storage/storage_spec.rb +42 -42
  29. data/spec/support/assets/config.json +2 -6
  30. data/spec/support/assets/config.yml +2 -9
  31. metadata +4 -4
@@ -1,158 +1,158 @@
1
- require "spec_helper"
2
- require "rack/test"
3
-
4
- describe "List Resource Images" do
5
- include Rack::Test::Methods
6
-
7
- before do
8
- @local_root = File.join(RSpec.root, "storage")
9
- @image_path = File.join(RSpec.root, "support/assets/stub-300x200.png")
10
- @resource_id_1 = "abc/123"
11
- @resource_id_2 = "abc/456"
12
- end
13
-
14
- after do
15
- FileUtils.rm_rf(@local_root)
16
- end
17
-
18
- context "without security tokens" do
19
- def app
20
- app = Proc.new do |env|
21
- [200, {}, ""]
22
- end
23
- SnapImage::Middleware.new(
24
- app,
25
- path: "/snapimage_api",
26
- config: {
27
- "primary_storage_server" => "local",
28
- "storage_servers" => [
29
- {
30
- "name" => "local",
31
- "type" => "LOCAL",
32
- "local_root" => File.join(RSpec.root, "storage"),
33
- "public_url" => "//example.com/images"
34
- }
35
- ]
36
- }
37
- )
38
- end
39
-
40
- before do
41
- # Store some images.
42
- json = { action: "generate_image", resource_identifier: @resource_id_1 }.to_json
43
- post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
44
- @url_1 = JSON.parse(last_response.body)["image_url"]
45
- post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
46
- @url_2 = JSON.parse(last_response.body)["image_url"]
47
-
48
- json = { action: "generate_image", resource_identifier: @resource_id_2 }.to_json
49
- post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
50
- @url_3 = JSON.parse(last_response.body)["image_url"]
51
- post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
52
- @url_4 = JSON.parse(last_response.body)["image_url"]
53
-
54
- json = {
55
- action: "list_resource_images",
56
- resource_identifier: @resource_id_1
57
- }.to_json
58
- post "/snapimage_api", "json" => json
59
- end
60
-
61
- it "is successful" do
62
- last_response.should be_successful
63
- last_response["Content-Type"].should eq "text/json"
64
- json = JSON.parse(last_response.body)
65
- json["status_code"].should eq 200
66
- json["message"].should eq "List Resource Images Successful"
67
- json["image_urls"].size.should eq 2
68
- json["image_urls"].include?(@url_1).should be_true
69
- json["image_urls"].include?(@url_2).should be_true
70
- end
71
- end
72
-
73
- context "with security tokens" do
74
- def app
75
- app = Proc.new do |env|
76
- [200, {}, ""]
77
- end
78
- SnapImage::Middleware.new(
79
- app,
80
- path: "/snapimage_api",
81
- config: {
82
- "security_salt" => "123456789",
83
- "primary_storage_server" => "local",
84
- "storage_servers" => [
85
- {
86
- "name" => "local",
87
- "type" => "LOCAL",
88
- "local_root" => File.join(RSpec.root, "storage"),
89
- "public_url" => "//example.com/images"
90
- }
91
- ]
92
- }
93
- )
94
- end
95
-
96
- before do
97
- @client_security_token_1 = Digest::SHA1.hexdigest("client:#{Time.now.strftime("%Y-%m-%d")}:123456789:#{@resource_id_1}")
98
- @client_security_token_2 = Digest::SHA1.hexdigest("client:#{Time.now.strftime("%Y-%m-%d")}:123456789:#{@resource_id_2}")
99
- @server_security_token = Digest::SHA1.hexdigest("server:#{Time.now.strftime("%Y-%m-%d")}:123456789:#{@resource_id_1}")
100
-
101
- # Store some images.
102
- json = {
103
- action: "generate_image",
104
- resource_identifier: @resource_id_1,
105
- client_security_token: @client_security_token_1
106
- }.to_json
107
- post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
108
- @url_1 = JSON.parse(last_response.body)["image_url"]
109
- post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
110
- @url_2 = JSON.parse(last_response.body)["image_url"]
111
-
112
- json = {
113
- action: "generate_image",
114
- resource_identifier: @resource_id_2,
115
- client_security_token: @client_security_token_2
116
- }.to_json
117
- post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
118
- @url_3 = JSON.parse(last_response.body)["image_url"]
119
- post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
120
- @url_4 = JSON.parse(last_response.body)["image_url"]
121
-
122
- @options = { action: "list_resource_images", resource_identifier: @resource_id_1 }
123
- end
124
-
125
- it "requires authorization when no security token is provided" do
126
- request_json = @options.to_json
127
- post "/snapimage_api", "json" => request_json
128
- last_response.should be_successful
129
- last_response["content-type"].should eq "text/json"
130
- json = JSON.parse(last_response.body)
131
- json["status_code"].should eq 401
132
- json["message"].should eq "Authorization Required"
133
- end
134
-
135
- it "fails authorization when the security token is invalid" do
136
- request_json = @options.merge!({"server_security_token" => "abc"}).to_json
137
- post "/snapimage_api", "json" => request_json
138
- last_response.should be_successful
139
- last_response["content-type"].should eq "text/json"
140
- json = JSON.parse(last_response.body)
141
- json["status_code"].should eq 402
142
- json["message"].should eq "Authorization Failed"
143
- end
144
-
145
- it "lists successfully" do
146
- request_json = @options.merge!({"server_security_token" => @server_security_token}).to_json
147
- post "/snapimage_api", "json" => request_json
148
- last_response.should be_successful
149
- last_response["Content-Type"].should eq "text/json"
150
- json = JSON.parse(last_response.body)
151
- json["status_code"].should eq 200
152
- json["message"].should eq "List Resource Images Successful"
153
- json["image_urls"].size.should eq 2
154
- json["image_urls"].include?(@url_1).should be_true
155
- json["image_urls"].include?(@url_2).should be_true
156
- end
157
- end
158
- end
1
+ #require "spec_helper"
2
+ #require "rack/test"
3
+
4
+ #describe "List Resource Images" do
5
+ #include Rack::Test::Methods
6
+
7
+ #before do
8
+ #@local_root = File.join(RSpec.root, "storage")
9
+ #@image_path = File.join(RSpec.root, "support/assets/stub-300x200.png")
10
+ #@resource_id_1 = "abc/123"
11
+ #@resource_id_2 = "abc/456"
12
+ #end
13
+
14
+ #after do
15
+ #FileUtils.rm_rf(@local_root)
16
+ #end
17
+
18
+ #context "without security tokens" do
19
+ #def app
20
+ #app = Proc.new do |env|
21
+ #[200, {}, ""]
22
+ #end
23
+ #SnapImage::Middleware.new(
24
+ #app,
25
+ #path: "/snapimage_api",
26
+ #config: {
27
+ #"primary_storage_server" => "local",
28
+ #"storage_servers" => [
29
+ #{
30
+ #"name" => "local",
31
+ #"type" => "LOCAL",
32
+ #"local_root" => File.join(RSpec.root, "storage"),
33
+ #"public_url" => "//example.com/images"
34
+ #}
35
+ #]
36
+ #}
37
+ #)
38
+ #end
39
+
40
+ #before do
41
+ ## Store some images.
42
+ #json = { action: "generate_image", resource_identifier: @resource_id_1 }.to_json
43
+ #post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
44
+ #@url_1 = JSON.parse(last_response.body)["image_url"]
45
+ #post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
46
+ #@url_2 = JSON.parse(last_response.body)["image_url"]
47
+
48
+ #json = { action: "generate_image", resource_identifier: @resource_id_2 }.to_json
49
+ #post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
50
+ #@url_3 = JSON.parse(last_response.body)["image_url"]
51
+ #post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
52
+ #@url_4 = JSON.parse(last_response.body)["image_url"]
53
+
54
+ #json = {
55
+ #action: "list_resource_images",
56
+ #resource_identifier: @resource_id_1
57
+ #}.to_json
58
+ #post "/snapimage_api", "json" => json
59
+ #end
60
+
61
+ #it "is successful" do
62
+ #last_response.should be_successful
63
+ #last_response["Content-Type"].should eq "text/json"
64
+ #json = JSON.parse(last_response.body)
65
+ #json["status_code"].should eq 200
66
+ #json["message"].should eq "List Resource Images Successful"
67
+ #json["image_urls"].size.should eq 2
68
+ #json["image_urls"].include?(@url_1).should be_true
69
+ #json["image_urls"].include?(@url_2).should be_true
70
+ #end
71
+ #end
72
+
73
+ #context "with security tokens" do
74
+ #def app
75
+ #app = Proc.new do |env|
76
+ #[200, {}, ""]
77
+ #end
78
+ #SnapImage::Middleware.new(
79
+ #app,
80
+ #path: "/snapimage_api",
81
+ #config: {
82
+ #"security_salt" => "123456789",
83
+ #"primary_storage_server" => "local",
84
+ #"storage_servers" => [
85
+ #{
86
+ #"name" => "local",
87
+ #"type" => "LOCAL",
88
+ #"local_root" => File.join(RSpec.root, "storage"),
89
+ #"public_url" => "//example.com/images"
90
+ #}
91
+ #]
92
+ #}
93
+ #)
94
+ #end
95
+
96
+ #before do
97
+ #@client_security_token_1 = Digest::SHA1.hexdigest("client:#{Time.now.strftime("%Y-%m-%d")}:123456789:#{@resource_id_1}")
98
+ #@client_security_token_2 = Digest::SHA1.hexdigest("client:#{Time.now.strftime("%Y-%m-%d")}:123456789:#{@resource_id_2}")
99
+ #@server_security_token = Digest::SHA1.hexdigest("server:#{Time.now.strftime("%Y-%m-%d")}:123456789:#{@resource_id_1}")
100
+
101
+ ## Store some images.
102
+ #json = {
103
+ #action: "generate_image",
104
+ #resource_identifier: @resource_id_1,
105
+ #client_security_token: @client_security_token_1
106
+ #}.to_json
107
+ #post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
108
+ #@url_1 = JSON.parse(last_response.body)["image_url"]
109
+ #post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
110
+ #@url_2 = JSON.parse(last_response.body)["image_url"]
111
+
112
+ #json = {
113
+ #action: "generate_image",
114
+ #resource_identifier: @resource_id_2,
115
+ #client_security_token: @client_security_token_2
116
+ #}.to_json
117
+ #post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
118
+ #@url_3 = JSON.parse(last_response.body)["image_url"]
119
+ #post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
120
+ #@url_4 = JSON.parse(last_response.body)["image_url"]
121
+
122
+ #@options = { action: "list_resource_images", resource_identifier: @resource_id_1 }
123
+ #end
124
+
125
+ #it "requires authorization when no security token is provided" do
126
+ #request_json = @options.to_json
127
+ #post "/snapimage_api", "json" => request_json
128
+ #last_response.should be_successful
129
+ #last_response["content-type"].should eq "text/json"
130
+ #json = JSON.parse(last_response.body)
131
+ #json["status_code"].should eq 401
132
+ #json["message"].should eq "Authorization Required"
133
+ #end
134
+
135
+ #it "fails authorization when the security token is invalid" do
136
+ #request_json = @options.merge!({"server_security_token" => "abc"}).to_json
137
+ #post "/snapimage_api", "json" => request_json
138
+ #last_response.should be_successful
139
+ #last_response["content-type"].should eq "text/json"
140
+ #json = JSON.parse(last_response.body)
141
+ #json["status_code"].should eq 402
142
+ #json["message"].should eq "Authorization Failed"
143
+ #end
144
+
145
+ #it "lists successfully" do
146
+ #request_json = @options.merge!({"server_security_token" => @server_security_token}).to_json
147
+ #post "/snapimage_api", "json" => request_json
148
+ #last_response.should be_successful
149
+ #last_response["Content-Type"].should eq "text/json"
150
+ #json = JSON.parse(last_response.body)
151
+ #json["status_code"].should eq 200
152
+ #json["message"].should eq "List Resource Images Successful"
153
+ #json["image_urls"].size.should eq 2
154
+ #json["image_urls"].include?(@url_1).should be_true
155
+ #json["image_urls"].include?(@url_2).should be_true
156
+ #end
157
+ #end
158
+ #end
@@ -1,165 +1,165 @@
1
- require "spec_helper"
2
- require "rack/test"
3
-
4
- describe "Modify" do
5
- include Rack::Test::Methods
6
-
7
- before do
8
- @local_root = File.join(RSpec.root, "storage")
9
- @image_path = File.join(RSpec.root, "support/assets/stub-300x200.png")
10
- @large_image_path = File.join(RSpec.root, "support/assets/stub-2048x100.png")
11
- @resource_id = "abc/123"
12
- end
13
-
14
- after do
15
- FileUtils.rm_rf(@local_root)
16
- end
17
-
18
- context "without security tokens" do
19
- def app
20
- app = Proc.new do |env|
21
- [200, {}, ""]
22
- end
23
- SnapImage::Middleware.new(
24
- app,
25
- path: "/snapimage_api",
26
- config: {
27
- "primary_storage_server" => "local",
28
- "storage_servers" => [
29
- {
30
- "name" => "local",
31
- "type" => "LOCAL",
32
- "local_root" => File.join(RSpec.root, "storage"),
33
- "public_url" => "//example.com/images"
34
- }
35
- ]
36
- }
37
- )
38
- end
39
-
40
- before do
41
- # Store the image.
42
- json = { action: "generate_image", resource_identifier: @resource_id }.to_json
43
- post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
44
-
45
- json = {
46
- action: "generate_image",
47
- url: "http:#{JSON.parse(last_response.body)["image_url"]}",
48
- resource_identifier: @resource_id,
49
- crop_x: 10,
50
- crop_y: 50,
51
- crop_width: 40,
52
- crop_height: 60,
53
- width: 400,
54
- height: 600,
55
- sharpen: true
56
- }.to_json
57
- post "/snapimage_api", "json" => json
58
- end
59
-
60
- it "modifies successfully" do
61
- last_response.should be_successful
62
- last_response["Content-Type"].should eq "text/json"
63
- json = JSON.parse(last_response.body)
64
- json["status_code"].should eq 200
65
- json["message"].should eq "Get Modified Image Successful"
66
- json["image_url"].should match Regexp.new("^//example.com/images/abc/123/[a-z0-9]{8}-300x200-10x50x40x60-400x600-1.png$")
67
- json["image_width"].should eq 400
68
- json["image_height"].should eq 600
69
- end
70
-
71
- it "stores the image" do
72
- json = JSON.parse(last_response.body)
73
- path = File.join(@local_root, @resource_id, File.basename(json["image_url"]))
74
- File.exist?(path).should be_true
75
- end
76
- end
77
-
78
- context "with security tokens" do
79
- def app
80
- app = Proc.new do |env|
81
- [200, {}, ""]
82
- end
83
- SnapImage::Middleware.new(
84
- app,
85
- path: "/snapimage_api",
86
- config: {
87
- "security_salt" => "123456789",
88
- "primary_storage_server" => "local",
89
- "storage_servers" => [
90
- {
91
- "name" => "local",
92
- "type" => "LOCAL",
93
- "local_root" => File.join(RSpec.root, "storage"),
94
- "public_url" => "//example.com/images"
95
- }
96
- ]
97
- }
98
- )
99
- end
100
-
101
- before do
102
- @security_token = Digest::SHA1.hexdigest("client:#{Time.now.strftime("%Y-%m-%d")}:123456789:#{@resource_id}")
103
-
104
- # Store the image.
105
- json = {
106
- action: "generate_image",
107
- resource_identifier: @resource_id,
108
- client_security_token: @security_token
109
- }.to_json
110
- post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
111
-
112
- @options = {
113
- action: "generate_image",
114
- url: "http:#{JSON.parse(last_response.body)["image_url"]}",
115
- resource_identifier: @resource_id,
116
- crop_x: 10,
117
- crop_y: 50,
118
- crop_width: 40,
119
- crop_height: 60,
120
- width: 400,
121
- height: 600,
122
- sharpen: true
123
- }
124
- end
125
-
126
- it "requires authorization when no security token is provided" do
127
- request_json = @options.to_json
128
- post "/snapimage_api", "json" => request_json
129
- last_response.should be_successful
130
- last_response["content-type"].should eq "text/json"
131
- json = JSON.parse(last_response.body)
132
- json["status_code"].should eq 401
133
- json["message"].should eq "Authorization Required"
134
- end
135
-
136
- it "fails authorization when the security token is invalid" do
137
- request_json = @options.merge!({"client_security_token" => "abc"}).to_json
138
- post "/snapimage_api", "json" => request_json
139
- last_response.should be_successful
140
- last_response["content-type"].should eq "text/json"
141
- json = JSON.parse(last_response.body)
142
- json["status_code"].should eq 402
143
- json["message"].should eq "Authorization Failed"
144
- end
145
-
146
- it "modifies successfully" do
147
- request_json = @options.merge!({"client_security_token" => @security_token}).to_json
148
- post "/snapimage_api", "json" => request_json
149
- last_response.should be_successful
150
- last_response["Content-Type"].should eq "text/json"
151
- json = JSON.parse(last_response.body)
152
- json["status_code"].should eq 200
153
- json["message"].should eq "Get Modified Image Successful"
154
- json["image_url"].should match Regexp.new("^//example.com/images/abc/123/[a-z0-9]{8}-300x200-10x50x40x60-400x600-1.png$")
155
- json["image_width"].should eq 400
156
- json["image_height"].should eq 600
157
- end
158
-
159
- it "stores the image" do
160
- json = JSON.parse(last_response.body)
161
- path = File.join(@local_root, @resource_id, File.basename(json["image_url"]))
162
- File.exist?(path).should be_true
163
- end
164
- end
165
- end
1
+ #require "spec_helper"
2
+ #require "rack/test"
3
+
4
+ #describe "Modify" do
5
+ #include Rack::Test::Methods
6
+
7
+ #before do
8
+ #@local_root = File.join(RSpec.root, "storage")
9
+ #@image_path = File.join(RSpec.root, "support/assets/stub-300x200.png")
10
+ #@large_image_path = File.join(RSpec.root, "support/assets/stub-2048x100.png")
11
+ #@resource_id = "abc/123"
12
+ #end
13
+
14
+ #after do
15
+ #FileUtils.rm_rf(@local_root)
16
+ #end
17
+
18
+ #context "without security tokens" do
19
+ #def app
20
+ #app = Proc.new do |env|
21
+ #[200, {}, ""]
22
+ #end
23
+ #SnapImage::Middleware.new(
24
+ #app,
25
+ #path: "/snapimage_api",
26
+ #config: {
27
+ #"primary_storage_server" => "local",
28
+ #"storage_servers" => [
29
+ #{
30
+ #"name" => "local",
31
+ #"type" => "LOCAL",
32
+ #"local_root" => File.join(RSpec.root, "storage"),
33
+ #"public_url" => "//example.com/images"
34
+ #}
35
+ #]
36
+ #}
37
+ #)
38
+ #end
39
+
40
+ #before do
41
+ ## Store the image.
42
+ #json = { action: "generate_image", resource_identifier: @resource_id }.to_json
43
+ #post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
44
+
45
+ #json = {
46
+ #action: "generate_image",
47
+ #url: "http:#{JSON.parse(last_response.body)["image_url"]}",
48
+ #resource_identifier: @resource_id,
49
+ #crop_x: 10,
50
+ #crop_y: 50,
51
+ #crop_width: 40,
52
+ #crop_height: 60,
53
+ #width: 400,
54
+ #height: 600,
55
+ #sharpen: true
56
+ #}.to_json
57
+ #post "/snapimage_api", "json" => json
58
+ #end
59
+
60
+ #it "modifies successfully" do
61
+ #last_response.should be_successful
62
+ #last_response["Content-Type"].should eq "text/json"
63
+ #json = JSON.parse(last_response.body)
64
+ #json["status_code"].should eq 200
65
+ #json["message"].should eq "Get Modified Image Successful"
66
+ #json["image_url"].should match Regexp.new("^//example.com/images/abc/123/[a-z0-9]{8}-300x200-10x50x40x60-400x600-1.png$")
67
+ #json["image_width"].should eq 400
68
+ #json["image_height"].should eq 600
69
+ #end
70
+
71
+ #it "stores the image" do
72
+ #json = JSON.parse(last_response.body)
73
+ #path = File.join(@local_root, @resource_id, File.basename(json["image_url"]))
74
+ #File.exist?(path).should be_true
75
+ #end
76
+ #end
77
+
78
+ #context "with security tokens" do
79
+ #def app
80
+ #app = Proc.new do |env|
81
+ #[200, {}, ""]
82
+ #end
83
+ #SnapImage::Middleware.new(
84
+ #app,
85
+ #path: "/snapimage_api",
86
+ #config: {
87
+ #"security_salt" => "123456789",
88
+ #"primary_storage_server" => "local",
89
+ #"storage_servers" => [
90
+ #{
91
+ #"name" => "local",
92
+ #"type" => "LOCAL",
93
+ #"local_root" => File.join(RSpec.root, "storage"),
94
+ #"public_url" => "//example.com/images"
95
+ #}
96
+ #]
97
+ #}
98
+ #)
99
+ #end
100
+
101
+ #before do
102
+ #@security_token = Digest::SHA1.hexdigest("client:#{Time.now.strftime("%Y-%m-%d")}:123456789:#{@resource_id}")
103
+
104
+ ## Store the image.
105
+ #json = {
106
+ #action: "generate_image",
107
+ #resource_identifier: @resource_id,
108
+ #client_security_token: @security_token
109
+ #}.to_json
110
+ #post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
111
+
112
+ #@options = {
113
+ #action: "generate_image",
114
+ #url: "http:#{JSON.parse(last_response.body)["image_url"]}",
115
+ #resource_identifier: @resource_id,
116
+ #crop_x: 10,
117
+ #crop_y: 50,
118
+ #crop_width: 40,
119
+ #crop_height: 60,
120
+ #width: 400,
121
+ #height: 600,
122
+ #sharpen: true
123
+ #}
124
+ #end
125
+
126
+ #it "requires authorization when no security token is provided" do
127
+ #request_json = @options.to_json
128
+ #post "/snapimage_api", "json" => request_json
129
+ #last_response.should be_successful
130
+ #last_response["content-type"].should eq "text/json"
131
+ #json = JSON.parse(last_response.body)
132
+ #json["status_code"].should eq 401
133
+ #json["message"].should eq "Authorization Required"
134
+ #end
135
+
136
+ #it "fails authorization when the security token is invalid" do
137
+ #request_json = @options.merge!({"client_security_token" => "abc"}).to_json
138
+ #post "/snapimage_api", "json" => request_json
139
+ #last_response.should be_successful
140
+ #last_response["content-type"].should eq "text/json"
141
+ #json = JSON.parse(last_response.body)
142
+ #json["status_code"].should eq 402
143
+ #json["message"].should eq "Authorization Failed"
144
+ #end
145
+
146
+ #it "modifies successfully" do
147
+ #request_json = @options.merge!({"client_security_token" => @security_token}).to_json
148
+ #post "/snapimage_api", "json" => request_json
149
+ #last_response.should be_successful
150
+ #last_response["Content-Type"].should eq "text/json"
151
+ #json = JSON.parse(last_response.body)
152
+ #json["status_code"].should eq 200
153
+ #json["message"].should eq "Get Modified Image Successful"
154
+ #json["image_url"].should match Regexp.new("^//example.com/images/abc/123/[a-z0-9]{8}-300x200-10x50x40x60-400x600-1.png$")
155
+ #json["image_width"].should eq 400
156
+ #json["image_height"].should eq 600
157
+ #end
158
+
159
+ #it "stores the image" do
160
+ #json = JSON.parse(last_response.body)
161
+ #path = File.join(@local_root, @resource_id, File.basename(json["image_url"]))
162
+ #File.exist?(path).should be_true
163
+ #end
164
+ #end
165
+ #end