viki_utils 0.0.3 → 0.0.4

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.
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use ruby-1.9.3-p194@viki-utils-gem --create
@@ -18,7 +18,7 @@ module Viki
18
18
 
19
19
  signed_uri.query_values = query
20
20
  to_sign = [signed_uri.path, signed_uri.query].join('?')
21
- to_sign += Oj.dump(body) if body
21
+ to_sign += dump(body) if body
22
22
 
23
23
  sig = UriSigner.sign(@secret, to_sign)
24
24
  query.merge!(sig: sig)
@@ -29,5 +29,20 @@ module Viki
29
29
  def self.sign(secret, data)
30
30
  OpenSSL::HMAC.hexdigest(DIGEST, secret, data)
31
31
  end
32
+
33
+ private
34
+
35
+ def dump(body)
36
+ serializable = body.select { |k, v| !v.is_a?(IO) }
37
+ response = Oj.dump(serializable)
38
+
39
+ files = body.select { |k, v| v.is_a?(IO) }.values
40
+ files.each do |f|
41
+ response += Digest::MD5.hexdigest f.read
42
+ f.rewind
43
+ end
44
+
45
+ response
46
+ end
32
47
  end
33
48
  end
@@ -1,3 +1,3 @@
1
1
  module VikiUtils
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -39,6 +39,20 @@ describe Viki::UriSigner do
39
39
  Viki::UriSigner.new(secret).sign_request(uri, body).to_s.should include("sig=signature")
40
40
  end
41
41
  end
42
+
43
+ it 'includes the MD5 of the uploads as part of the signature' do
44
+ time = Time.now
45
+ file = __FILE__
46
+ body = {"body" => File.open(file)}
47
+ Timecop.freeze(time) do
48
+ OpenSSL::HMAC.should_receive(:hexdigest).with(
49
+ Viki::UriSigner::DIGEST,
50
+ secret,
51
+ "/endpoint?t=#{time.to_i.to_s}{}#{Digest::MD5.file(file)}"
52
+ ).and_return "signature"
53
+ Viki::UriSigner.new(secret).sign_request(uri, body).to_s.should include("sig=signature")
54
+ end
55
+ end
42
56
  end
43
57
 
44
58
  describe ".sign" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: viki_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-30 00:00:00.000000000 Z
13
+ date: 2013-02-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -85,6 +85,7 @@ extra_rdoc_files: []
85
85
  files:
86
86
  - .gitignore
87
87
  - .rspec
88
+ - .rvmrc
88
89
  - Gemfile
89
90
  - README.md
90
91
  - Rakefile