qiniu 6.4.2 → 6.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/qiniu.rb +1 -2
- data/lib/qiniu/auth.rb +15 -3
- data/lib/qiniu/version.rb +2 -2
- data/spec/qiniu/auth_spec.rb +35 -1
- data/spec/spec_helper.rb +3 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 445c1054edf50c45ea525aae13c712ecb4fbd00d
|
4
|
+
data.tar.gz: ffb5c071f5c74d7f49f00927767377ee8e868d93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab95ba7f0557d14af30f7fee674c36b88323cbf715ae756bf92d5c6774a2176d4c790434a6e59c55d36ac359d32950a8f9f62cc60e9996c3077de060b2b7f42b
|
7
|
+
data.tar.gz: c2893489903aaaf9ac55bcf4efd15866bcfa9703a838bb8b382f8feac7bf66b2a566285aad56a9158c9ee00acec2c51679cac286e0f10a08cccbe042674841f5
|
data/CHANGELOG.md
CHANGED
@@ -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)
|
data/Gemfile.lock
CHANGED
data/lib/qiniu.rb
CHANGED
@@ -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.
|
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])
|
data/lib/qiniu/auth.rb
CHANGED
@@ -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 =
|
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 =
|
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 =
|
253
|
+
sign = calculate_hmac_sha1_digest(secret_key, encoded_put_policy)
|
242
254
|
encoded_sign = Utils.urlsafe_base64_encode(sign)
|
243
255
|
|
244
256
|
### 生成上传授权凭证
|
data/lib/qiniu/version.rb
CHANGED
data/spec/qiniu/auth_spec.rb
CHANGED
@@ -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
|
107
|
+
end # module Exception_Auth
|
74
108
|
end # module Qiniu
|
data/spec/spec_helper.rb
CHANGED
@@ -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
|
+
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-
|
12
|
+
date: 2015-06-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|