qiniu 6.4.2 → 6.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63cda6dcf5ebd659bdc35ee8e1a1b5adda2ded38
4
- data.tar.gz: 5cd9bb60b47ff6e938197b97cd204f2e29dc101f
3
+ metadata.gz: 445c1054edf50c45ea525aae13c712ecb4fbd00d
4
+ data.tar.gz: ffb5c071f5c74d7f49f00927767377ee8e868d93
5
5
  SHA512:
6
- metadata.gz: 67ca3c4009d3c1c8687171172f7b82a62c5446e329de50258091c51633d61ea652bc52aa4d69817fdb52490c5122f91527bda48a628fb193fe58e68533c05538
7
- data.tar.gz: bad9f549eaffe56fc660cff16cc6355f8ff44d9f69fe43074b7909c72cb631900f744f8b08e96fd16bde6935e29ecd17533d31bf8853455ab6552a386db3ccd8
6
+ metadata.gz: ab95ba7f0557d14af30f7fee674c36b88323cbf715ae756bf92d5c6774a2176d4c790434a6e59c55d36ac359d32950a8f9f62cc60e9996c3077de060b2b7f42b
7
+ data.tar.gz: c2893489903aaaf9ac55bcf4efd15866bcfa9703a838bb8b382f8feac7bf66b2a566285aad56a9158c9ee00acec2c51679cac286e0f10a08cccbe042674841f5
@@ -1,5 +1,9 @@
1
1
  ## CHANGE LOG
2
2
 
3
+ ### v6.5.0
4
+
5
+ - 为 Qiniu::Auth 添加一个异常处理逻辑,在 Access Key 和 Secret Key 未正常设置(nil 值)的情况下给出正确提示。[https://github.com/qiniu/ruby-sdk/pull/126](https://github.com/qiniu/ruby-sdk/pull/126)
6
+
3
7
  ### v6.4.2
4
8
 
5
9
  - gem 兼容性调整 。 [https://github.com/qiniu/ruby-sdk/pull/122](https://github.com/qiniu/ruby-sdk/pull/122)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qiniu (6.4.1)
4
+ qiniu (6.5.0)
5
5
  json (~> 1.8)
6
6
  mime-types (~> 1.19)
7
7
  rest-client (~> 1.7.3)
@@ -64,12 +64,11 @@ module Qiniu
64
64
  opts[:enable_resumable_upload] = true unless opts.has_key?(:enable_resumable_upload)
65
65
 
66
66
  if opts[:enable_resumable_upload] && File::size(source_file) > Config.settings[:block_size]
67
- code, data, raw_headers = Storage.upload_with_token(opts[:uptoken],
67
+ code, data, raw_headers = Storage.resumable_upload_with_token(opts[:uptoken],
68
68
  opts[:file],
69
69
  opts[:bucket],
70
70
  opts[:key],
71
71
  opts[:mime_type],
72
- opts[:note],
73
72
  opts[:customer],
74
73
  opts[:callback_params],
75
74
  opts[:rotate])
@@ -25,6 +25,18 @@ module Qiniu
25
25
  # 默认授权期1小时
26
26
  return Time.now.to_i + DEFAULT_AUTH_SECONDS
27
27
  end # calculate_deadline
28
+
29
+ def calculate_hmac_sha1_digest(sk, str)
30
+ begin
31
+ sign = HMAC::SHA1.new(sk).update(str).digest
32
+ rescue RuntimeError => e
33
+ raise RuntimeError, "Please set Qiniu's access_key and secret_key before authorize any tokens."
34
+ rescue
35
+ raise
36
+ else
37
+ return sign
38
+ end
39
+ end
28
40
  end # class << self
29
41
 
30
42
  class PutPolicy
@@ -169,7 +181,7 @@ module Qiniu
169
181
  end
170
182
 
171
183
  ### 生成数字签名
172
- sign = HMAC::SHA1.new(secret_key).update(download_url).digest
184
+ sign = calculate_hmac_sha1_digest(secret_key, download_url)
173
185
  encoded_sign = Utils.urlsafe_base64_encode(sign)
174
186
 
175
187
  ### 生成下载授权凭证
@@ -219,7 +231,7 @@ module Qiniu
219
231
  end
220
232
 
221
233
  ### 生成数字签名
222
- sign = HMAC::SHA1.new(secret_key).update(signing_str).digest
234
+ sign = calculate_hmac_sha1_digest(secret_key, signing_str)
223
235
  encoded_sign = Utils.urlsafe_base64_encode(sign)
224
236
 
225
237
  ### 生成管理授权凭证
@@ -238,7 +250,7 @@ module Qiniu
238
250
  encoded_put_policy = Utils.urlsafe_base64_encode(put_policy.to_json)
239
251
 
240
252
  ### 生成数字签名
241
- sign = HMAC::SHA1.new(secret_key).update(encoded_put_policy).digest
253
+ sign = calculate_hmac_sha1_digest(secret_key, encoded_put_policy)
242
254
  encoded_sign = Utils.urlsafe_base64_encode(sign)
243
255
 
244
256
  ### 生成上传授权凭证
@@ -3,8 +3,8 @@
3
3
  module Qiniu
4
4
  module Version
5
5
  MAJOR = 6
6
- MINOR = 4
7
- PATCH = 2
6
+ MINOR = 5
7
+ PATCH = 0
8
8
  # Returns a version string by joining <tt>MAJOR</tt>, <tt>MINOR</tt>, and <tt>PATCH</tt> with <tt>'.'</tt>
9
9
  #
10
10
  # Example
@@ -68,7 +68,41 @@ module Qiniu
68
68
  puts data.inspect
69
69
  end
70
70
  end
71
+ end
72
+ end # module Auth
73
+
74
+ module Exception_Auth
75
+ describe Exception_Auth, :not_set_ak_sk => true do
76
+ ### 测试未设置 ak/sk 的异常抛出情况
77
+ context ".not_set_ak_sk" do
78
+ it "should works" do
79
+ puts Qiniu::Config.instance_variable_get("@settings").inspect
80
+
81
+ begin
82
+ uptoken = Qiniu::Auth.generate_uptoken({})
83
+ rescue => e
84
+ e.message.should == "Please set Qiniu's access_key and secret_key before authorize any tokens."
85
+ else
86
+ fail "Not raise any exception."
87
+ end
71
88
 
89
+ begin
90
+ download_url = Qiniu::Auth.authorize_download_url("http://test.qiniudn.com/a_private_file")
91
+ rescue => e
92
+ e.message.should == "Please set Qiniu's access_key and secret_key before authorize any tokens."
93
+ else
94
+ fail "Not raise any exception."
95
+ end
96
+
97
+ begin
98
+ acctoken = Qiniu::Auth.generate_acctoken("http://rsf.qbox.me/list")
99
+ rescue => e
100
+ e.message.should == "Please set Qiniu's access_key and secret_key before authorize any tokens."
101
+ else
102
+ fail "Not raise any exception."
103
+ end
104
+ end
105
+ end
72
106
  end
73
- end # module Storage
107
+ end # module Exception_Auth
74
108
  end # module Qiniu
@@ -8,6 +8,9 @@ RSpec.configure do |config|
8
8
  config.before :all do
9
9
  Qiniu.establish_connection! :access_key => ENV["QINIU_ACCESS_KEY"], :secret_key => ENV["QINIU_SECRET_KEY"]
10
10
  end
11
+ config.before :each, :not_set_ak_sk => true do
12
+ Qiniu.establish_connection! :access_key => nil, :secret_key => nil
13
+ end
11
14
  end
12
15
 
13
16
  def make_unique_bucket (bucket)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qiniu
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.4.2
4
+ version: 6.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - why404
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-08 00:00:00.000000000 Z
12
+ date: 2015-06-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake