snapimage 0.0.6 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,260 +1,260 @@
1
- require "spec_helper"
2
- require "rack/test"
1
+ #require "spec_helper"
2
+ #require "rack/test"
3
3
 
4
- describe "Sync" do
5
- include Rack::Test::Methods
4
+ #describe "Sync" do
5
+ #include Rack::Test::Methods
6
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 = "abc/123"
11
- end
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 = "abc/123"
11
+ #end
12
12
 
13
- after do
14
- FileUtils.rm_rf(@local_root)
15
- end
13
+ #after do
14
+ #FileUtils.rm_rf(@local_root)
15
+ #end
16
16
 
17
- context "without security tokens" do
18
- def app
19
- app = Proc.new do |env|
20
- [200, {}, ""]
21
- end
22
- SnapImage::Middleware.new(
23
- app,
24
- path: "/snapimage_api",
25
- config: {
26
- "primary_storage_server" => "local",
27
- "storage_servers" => [
28
- {
29
- "name" => "local",
30
- "type" => "LOCAL",
31
- "local_root" => File.join(RSpec.root, "storage"),
32
- "public_url" => "//example.com/images"
33
- }
34
- ]
35
- }
36
- )
37
- end
17
+ #context "without security tokens" do
18
+ #def app
19
+ #app = Proc.new do |env|
20
+ #[200, {}, ""]
21
+ #end
22
+ #SnapImage::Middleware.new(
23
+ #app,
24
+ #path: "/snapimage_api",
25
+ #config: {
26
+ #"primary_storage_server" => "local",
27
+ #"storage_servers" => [
28
+ #{
29
+ #"name" => "local",
30
+ #"type" => "LOCAL",
31
+ #"local_root" => File.join(RSpec.root, "storage"),
32
+ #"public_url" => "//example.com/images"
33
+ #}
34
+ #]
35
+ #}
36
+ #)
37
+ #end
38
38
 
39
- before do
40
- # Store some images.
41
- json = { action: "generate_image", resource_identifier: @resource_id }.to_json
39
+ #before do
40
+ ## Store some images.
41
+ #json = { action: "generate_image", resource_identifier: @resource_id }.to_json
42
42
 
43
- @before_1 = DateTime.now
44
- post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
45
- @url_1 = JSON.parse(last_response.body)["image_url"]
43
+ #@before_1 = DateTime.now
44
+ #post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
45
+ #@url_1 = JSON.parse(last_response.body)["image_url"]
46
46
 
47
- @before_2 = DateTime.now
48
- post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
49
- @url_2 = "http:#{JSON.parse(last_response.body)["image_url"]}"
47
+ #@before_2 = DateTime.now
48
+ #post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
49
+ #@url_2 = "http:#{JSON.parse(last_response.body)["image_url"]}"
50
50
 
51
- @before_3 = DateTime.now
52
- post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
53
- @url_3 = "https:#{JSON.parse(last_response.body)["image_url"]}"
51
+ #@before_3 = DateTime.now
52
+ #post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
53
+ #@url_3 = "https:#{JSON.parse(last_response.body)["image_url"]}"
54
54
 
55
- sleep 1
56
- @before_4 = DateTime.now
57
- post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
58
- @url_4 = JSON.parse(last_response.body)["image_url"]
59
- end
55
+ #sleep 1
56
+ #@before_4 = DateTime.now
57
+ #post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
58
+ #@url_4 = JSON.parse(last_response.body)["image_url"]
59
+ #end
60
60
 
61
- it "does nothing when all the images are in the content" do
62
- json = {
63
- action: "sync_resource",
64
- content: {
65
- body: "Some #{@url_1} and another '#{@url_2}'",
66
- footer: "This is #{@url_3} a footer"
67
- },
68
- sync_date_time: (DateTime.now.to_time + 3).to_datetime.iso8601,
69
- resource_identifier: @resource_id
70
- }.to_json
71
- post "/snapimage_api", "json" => json
72
- last_response.should be_successful
73
- last_response["Content-Type"].should eq "text/json"
74
- json = JSON.parse(last_response.body)
75
- json["status_code"].should eq 200
76
- json["message"].should eq "Image Sync Successful"
77
- json["deleted_image_urls"].size.should eq 0
78
- end
61
+ #it "does nothing when all the images are in the content" do
62
+ #json = {
63
+ #action: "sync_resource",
64
+ #content: {
65
+ #body: "Some #{@url_1} and another '#{@url_2}'",
66
+ #footer: "This is #{@url_3} a footer"
67
+ #},
68
+ #sync_date_time: (DateTime.now.to_time + 3).to_datetime.iso8601,
69
+ #resource_identifier: @resource_id
70
+ #}.to_json
71
+ #post "/snapimage_api", "json" => json
72
+ #last_response.should be_successful
73
+ #last_response["Content-Type"].should eq "text/json"
74
+ #json = JSON.parse(last_response.body)
75
+ #json["status_code"].should eq 200
76
+ #json["message"].should eq "Image Sync Successful"
77
+ #json["deleted_image_urls"].size.should eq 0
78
+ #end
79
79
 
80
- it "deletes missing images" do
81
- # Add modified images.
82
- json = {
83
- action: "generate_image",
84
- url: "http:#{@url_1}",
85
- resource_identifier: @resource_id,
86
- crop_x: 10,
87
- crop_y: 50,
88
- crop_width: 40,
89
- crop_height: 60,
90
- width: 400,
91
- height: 600,
92
- sharpen: true
93
- }.to_json
94
- post "/snapimage_api", "json" => json
95
- last_response.should be_successful
96
- json = JSON.parse(last_response.body)
97
- json["status_code"].should eq 200
98
- url_1_modified = json["image_url"]
80
+ #it "deletes missing images" do
81
+ ## Add modified images.
82
+ #json = {
83
+ #action: "generate_image",
84
+ #url: "http:#{@url_1}",
85
+ #resource_identifier: @resource_id,
86
+ #crop_x: 10,
87
+ #crop_y: 50,
88
+ #crop_width: 40,
89
+ #crop_height: 60,
90
+ #width: 400,
91
+ #height: 600,
92
+ #sharpen: true
93
+ #}.to_json
94
+ #post "/snapimage_api", "json" => json
95
+ #last_response.should be_successful
96
+ #json = JSON.parse(last_response.body)
97
+ #json["status_code"].should eq 200
98
+ #url_1_modified = json["image_url"]
99
99
 
100
- json = {
101
- action: "generate_image",
102
- url: @url_2,
103
- resource_identifier: @resource_id,
104
- crop_x: 10,
105
- crop_y: 50,
106
- crop_width: 40,
107
- crop_height: 60,
108
- width: 400,
109
- height: 600,
110
- sharpen: true
111
- }.to_json
112
- post "/snapimage_api", "json" => json
113
- last_response.should be_successful
114
- json = JSON.parse(last_response.body)
115
- json["status_code"].should eq 200
116
- url_2_modified = json["image_url"]
100
+ #json = {
101
+ #action: "generate_image",
102
+ #url: @url_2,
103
+ #resource_identifier: @resource_id,
104
+ #crop_x: 10,
105
+ #crop_y: 50,
106
+ #crop_width: 40,
107
+ #crop_height: 60,
108
+ #width: 400,
109
+ #height: 600,
110
+ #sharpen: true
111
+ #}.to_json
112
+ #post "/snapimage_api", "json" => json
113
+ #last_response.should be_successful
114
+ #json = JSON.parse(last_response.body)
115
+ #json["status_code"].should eq 200
116
+ #url_2_modified = json["image_url"]
117
117
 
118
- json = {
119
- action: "generate_image",
120
- url: @url_3,
121
- resource_identifier: @resource_id,
122
- crop_x: 10,
123
- crop_y: 50,
124
- crop_width: 40,
125
- crop_height: 60,
126
- width: 400,
127
- height: 600,
128
- sharpen: true
129
- }.to_json
130
- post "/snapimage_api", "json" => json
131
- last_response.should be_successful
132
- json = JSON.parse(last_response.body)
133
- json["status_code"].should eq 200
134
- url_3_modified = json["image_url"]
118
+ #json = {
119
+ #action: "generate_image",
120
+ #url: @url_3,
121
+ #resource_identifier: @resource_id,
122
+ #crop_x: 10,
123
+ #crop_y: 50,
124
+ #crop_width: 40,
125
+ #crop_height: 60,
126
+ #width: 400,
127
+ #height: 600,
128
+ #sharpen: true
129
+ #}.to_json
130
+ #post "/snapimage_api", "json" => json
131
+ #last_response.should be_successful
132
+ #json = JSON.parse(last_response.body)
133
+ #json["status_code"].should eq 200
134
+ #url_3_modified = json["image_url"]
135
135
 
136
- # Missing url_1_modified and url_1. (Should delete both)
137
- # Missing url_2_modified but url_2 is there. (Should delete modified only)
138
- # url_3_modified is there. (Should not delete either)
139
- # Missing url_4 which has not been modified (Should delete)
140
- json = {
141
- action: "sync_resource",
142
- content: {
143
- body: "Some #{@url_2} and another '#{url_3_modified}'"
144
- },
145
- sync_date_time: (DateTime.now.to_time + 4).to_datetime.iso8601,
146
- resource_identifier: @resource_id
147
- }.to_json
148
- post "/snapimage_api", "json" => 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 "Image Sync Successful"
154
- json["deleted_image_urls"].size.should eq 4
155
- json["deleted_image_urls"].include?(@url_1).should be_true
156
- json["deleted_image_urls"].include?(url_1_modified).should be_true
157
- json["deleted_image_urls"].include?(url_2_modified).should be_true
158
- json["deleted_image_urls"].include?(@url_4).should be_true
159
- end
136
+ ## Missing url_1_modified and url_1. (Should delete both)
137
+ ## Missing url_2_modified but url_2 is there. (Should delete modified only)
138
+ ## url_3_modified is there. (Should not delete either)
139
+ ## Missing url_4 which has not been modified (Should delete)
140
+ #json = {
141
+ #action: "sync_resource",
142
+ #content: {
143
+ #body: "Some #{@url_2} and another '#{url_3_modified}'"
144
+ #},
145
+ #sync_date_time: (DateTime.now.to_time + 4).to_datetime.iso8601,
146
+ #resource_identifier: @resource_id
147
+ #}.to_json
148
+ #post "/snapimage_api", "json" => 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 "Image Sync Successful"
154
+ #json["deleted_image_urls"].size.should eq 4
155
+ #json["deleted_image_urls"].include?(@url_1).should be_true
156
+ #json["deleted_image_urls"].include?(url_1_modified).should be_true
157
+ #json["deleted_image_urls"].include?(url_2_modified).should be_true
158
+ #json["deleted_image_urls"].include?(@url_4).should be_true
159
+ #end
160
160
 
161
- it "does not delete missing images that are modified after the timestamp" do
162
- # Missing url_1 and url_4. (Deletes url_1 but not url_4)
163
- json = {
164
- action: "sync_resource",
165
- content: {
166
- body: "Some #{@url_2} and #{@url_3}"
167
- },
168
- sync_date_time: (@before_4.to_time + 3).to_datetime.iso8601,
169
- resource_identifier: @resource_id
170
- }.to_json
171
- post "/snapimage_api", "json" => json
172
- last_response.should be_successful
173
- last_response["Content-Type"].should eq "text/json"
174
- json = JSON.parse(last_response.body)
175
- json["status_code"].should eq 200
176
- json["message"].should eq "Image Sync Successful"
177
- json["deleted_image_urls"].size.should eq 1
178
- json["deleted_image_urls"][0].should eq @url_1
179
- end
180
- end
161
+ #it "does not delete missing images that are modified after the timestamp" do
162
+ ## Missing url_1 and url_4. (Deletes url_1 but not url_4)
163
+ #json = {
164
+ #action: "sync_resource",
165
+ #content: {
166
+ #body: "Some #{@url_2} and #{@url_3}"
167
+ #},
168
+ #sync_date_time: (@before_4.to_time + 3).to_datetime.iso8601,
169
+ #resource_identifier: @resource_id
170
+ #}.to_json
171
+ #post "/snapimage_api", "json" => json
172
+ #last_response.should be_successful
173
+ #last_response["Content-Type"].should eq "text/json"
174
+ #json = JSON.parse(last_response.body)
175
+ #json["status_code"].should eq 200
176
+ #json["message"].should eq "Image Sync Successful"
177
+ #json["deleted_image_urls"].size.should eq 1
178
+ #json["deleted_image_urls"][0].should eq @url_1
179
+ #end
180
+ #end
181
181
 
182
- context "with security tokens" do
183
- def app
184
- app = Proc.new do |env|
185
- [200, {}, ""]
186
- end
187
- SnapImage::Middleware.new(
188
- app,
189
- path: "/snapimage_api",
190
- config: {
191
- "security_salt" => "123456789",
192
- "primary_storage_server" => "local",
193
- "storage_servers" => [
194
- {
195
- "name" => "local",
196
- "type" => "LOCAL",
197
- "local_root" => File.join(RSpec.root, "storage"),
198
- "public_url" => "//example.com/images"
199
- }
200
- ]
201
- }
202
- )
203
- end
182
+ #context "with security tokens" do
183
+ #def app
184
+ #app = Proc.new do |env|
185
+ #[200, {}, ""]
186
+ #end
187
+ #SnapImage::Middleware.new(
188
+ #app,
189
+ #path: "/snapimage_api",
190
+ #config: {
191
+ #"security_salt" => "123456789",
192
+ #"primary_storage_server" => "local",
193
+ #"storage_servers" => [
194
+ #{
195
+ #"name" => "local",
196
+ #"type" => "LOCAL",
197
+ #"local_root" => File.join(RSpec.root, "storage"),
198
+ #"public_url" => "//example.com/images"
199
+ #}
200
+ #]
201
+ #}
202
+ #)
203
+ #end
204
204
 
205
- before do
206
- @client_security_token = Digest::SHA1.hexdigest("client:#{Time.now.strftime("%Y-%m-%d")}:123456789:#{@resource_id}")
207
- @server_security_token = Digest::SHA1.hexdigest("server:#{Time.now.strftime("%Y-%m-%d")}:123456789:#{@resource_id}")
205
+ #before do
206
+ #@client_security_token = Digest::SHA1.hexdigest("client:#{Time.now.strftime("%Y-%m-%d")}:123456789:#{@resource_id}")
207
+ #@server_security_token = Digest::SHA1.hexdigest("server:#{Time.now.strftime("%Y-%m-%d")}:123456789:#{@resource_id}")
208
208
 
209
- # Store some images.
210
- json = {
211
- action: "generate_image",
212
- resource_identifier: @resource_id,
213
- client_security_token: @client_security_token
214
- }.to_json
209
+ ## Store some images.
210
+ #json = {
211
+ #action: "generate_image",
212
+ #resource_identifier: @resource_id,
213
+ #client_security_token: @client_security_token
214
+ #}.to_json
215
215
 
216
- post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
217
- @url_1 = JSON.parse(last_response.body)["image_url"]
216
+ #post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
217
+ #@url_1 = JSON.parse(last_response.body)["image_url"]
218
218
 
219
- @options = {
220
- action: "sync_resource",
221
- content: {
222
- body: "Some #{@url_1}",
223
- },
224
- sync_date_time: (DateTime.now.to_time + 3).to_datetime.iso8601,
225
- resource_identifier: @resource_id
226
- }
227
- end
219
+ #@options = {
220
+ #action: "sync_resource",
221
+ #content: {
222
+ #body: "Some #{@url_1}",
223
+ #},
224
+ #sync_date_time: (DateTime.now.to_time + 3).to_datetime.iso8601,
225
+ #resource_identifier: @resource_id
226
+ #}
227
+ #end
228
228
 
229
- it "requires authorization when no security token is provided" do
230
- request_json = @options.to_json
231
- post "/snapimage_api", "json" => request_json
232
- last_response.should be_successful
233
- last_response["content-type"].should eq "text/json"
234
- json = JSON.parse(last_response.body)
235
- json["status_code"].should eq 401
236
- json["message"].should eq "Authorization Required"
237
- end
229
+ #it "requires authorization when no security token is provided" do
230
+ #request_json = @options.to_json
231
+ #post "/snapimage_api", "json" => request_json
232
+ #last_response.should be_successful
233
+ #last_response["content-type"].should eq "text/json"
234
+ #json = JSON.parse(last_response.body)
235
+ #json["status_code"].should eq 401
236
+ #json["message"].should eq "Authorization Required"
237
+ #end
238
238
 
239
- it "fails authorization when the security token is invalid" do
240
- request_json = @options.merge!({"server_security_token" => "abc"}).to_json
241
- post "/snapimage_api", "json" => request_json
242
- last_response.should be_successful
243
- last_response["content-type"].should eq "text/json"
244
- json = JSON.parse(last_response.body)
245
- json["status_code"].should eq 402
246
- json["message"].should eq "Authorization Failed"
247
- end
239
+ #it "fails authorization when the security token is invalid" do
240
+ #request_json = @options.merge!({"server_security_token" => "abc"}).to_json
241
+ #post "/snapimage_api", "json" => request_json
242
+ #last_response.should be_successful
243
+ #last_response["content-type"].should eq "text/json"
244
+ #json = JSON.parse(last_response.body)
245
+ #json["status_code"].should eq 402
246
+ #json["message"].should eq "Authorization Failed"
247
+ #end
248
248
 
249
- it "syncs successfully" do
250
- json = @options.merge!({"server_security_token" => @server_security_token}).to_json
251
- post "/snapimage_api", "json" => json
252
- last_response.should be_successful
253
- last_response["Content-Type"].should eq "text/json"
254
- json = JSON.parse(last_response.body)
255
- json["status_code"].should eq 200
256
- json["message"].should eq "Image Sync Successful"
257
- json["deleted_image_urls"].size.should eq 0
258
- end
259
- end
260
- end
249
+ #it "syncs successfully" do
250
+ #json = @options.merge!({"server_security_token" => @server_security_token}).to_json
251
+ #post "/snapimage_api", "json" => json
252
+ #last_response.should be_successful
253
+ #last_response["Content-Type"].should eq "text/json"
254
+ #json = JSON.parse(last_response.body)
255
+ #json["status_code"].should eq 200
256
+ #json["message"].should eq "Image Sync Successful"
257
+ #json["deleted_image_urls"].size.should eq 0
258
+ #end
259
+ #end
260
+ #end