Merge pull request #126 from BluntBlade/master

合并一些常规修正逻辑
This commit is contained in:
Bai Long
2015-06-26 14:04:07 +08:00
7 changed files with 62 additions and 10 deletions
+4
View File
@@ -1,5 +1,9 @@
## CHANGE LOG
### v6.5.0
- 为 Qiniu::Auth 添加一个异常处理逻辑,在 Access Key 和 Secret Key 未正常设置(nil 值)的情况下给出正确提示。[https://github.com/qiniu/ruby-sdk/pull/126](https://github.com/qiniu/ruby-sdk/pull/126)
### v6.4.2
- gem 兼容性调整 。 [https://github.com/qiniu/ruby-sdk/pull/122](https://github.com/qiniu/ruby-sdk/pull/122)
+1 -1
View File
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
qiniu (6.4.1)
qiniu (6.5.0)
json (~> 1.8)
mime-types (~> 1.19)
rest-client (~> 1.7.3)
+1 -2
View File
@@ -64,12 +64,11 @@ module Qiniu
opts[:enable_resumable_upload] = true unless opts.has_key?(:enable_resumable_upload)
if opts[:enable_resumable_upload] && File::size(source_file) > Config.settings[:block_size]
code, data, raw_headers = Storage.upload_with_token(opts[:uptoken],
code, data, raw_headers = Storage.resumable_upload_with_token(opts[:uptoken],
opts[:file],
opts[:bucket],
opts[:key],
opts[:mime_type],
opts[:note],
opts[:customer],
opts[:callback_params],
opts[:rotate])
+15 -3
View File
@@ -25,6 +25,18 @@ module Qiniu
# 默认授权期1小时
return Time.now.to_i + DEFAULT_AUTH_SECONDS
end # calculate_deadline
def calculate_hmac_sha1_digest(sk, str)
begin
sign = HMAC::SHA1.new(sk).update(str).digest
rescue RuntimeError => e
raise RuntimeError, "Please set Qiniu's access_key and secret_key before authorize any tokens."
rescue
raise
else
return sign
end
end
end # class << self
class PutPolicy
@@ -169,7 +181,7 @@ module Qiniu
end
### 生成数字签名
sign = HMAC::SHA1.new(secret_key).update(download_url).digest
sign = calculate_hmac_sha1_digest(secret_key, download_url)
encoded_sign = Utils.urlsafe_base64_encode(sign)
### 生成下载授权凭证
@@ -219,7 +231,7 @@ module Qiniu
end
### 生成数字签名
sign = HMAC::SHA1.new(secret_key).update(signing_str).digest
sign = calculate_hmac_sha1_digest(secret_key, signing_str)
encoded_sign = Utils.urlsafe_base64_encode(sign)
### 生成管理授权凭证
@@ -238,7 +250,7 @@ module Qiniu
encoded_put_policy = Utils.urlsafe_base64_encode(put_policy.to_json)
### 生成数字签名
sign = HMAC::SHA1.new(secret_key).update(encoded_put_policy).digest
sign = calculate_hmac_sha1_digest(secret_key, encoded_put_policy)
encoded_sign = Utils.urlsafe_base64_encode(sign)
### 生成上传授权凭证
+2 -2
View File
@@ -3,8 +3,8 @@
module Qiniu
module Version
MAJOR = 6
MINOR = 4
PATCH = 2
MINOR = 5
PATCH = 0
# Returns a version string by joining <tt>MAJOR</tt>, <tt>MINOR</tt>, and <tt>PATCH</tt> with <tt>'.'</tt>
#
# Example
+36 -2
View File
@@ -68,7 +68,41 @@ module Qiniu
puts data.inspect
end
end
end
end # module Storage
end # module Auth
module Exception_Auth
describe Exception_Auth, :not_set_ak_sk => true do
### 测试未设置 ak/sk 的异常抛出情况
context ".not_set_ak_sk" do
it "should works" do
puts Qiniu::Config.instance_variable_get("@settings").inspect
begin
uptoken = Qiniu::Auth.generate_uptoken({})
rescue => e
e.message.should == "Please set Qiniu's access_key and secret_key before authorize any tokens."
else
fail "Not raise any exception."
end
begin
download_url = Qiniu::Auth.authorize_download_url("http://test.qiniudn.com/a_private_file")
rescue => e
e.message.should == "Please set Qiniu's access_key and secret_key before authorize any tokens."
else
fail "Not raise any exception."
end
begin
acctoken = Qiniu::Auth.generate_acctoken("http://rsf.qbox.me/list")
rescue => e
e.message.should == "Please set Qiniu's access_key and secret_key before authorize any tokens."
else
fail "Not raise any exception."
end
end
end
end
end # module Exception_Auth
end # module Qiniu
+3
View File
@@ -8,6 +8,9 @@ RSpec.configure do |config|
config.before :all do
Qiniu.establish_connection! :access_key => ENV["QINIU_ACCESS_KEY"], :secret_key => ENV["QINIU_SECRET_KEY"]
end
config.before :each, :not_set_ak_sk => true do
Qiniu.establish_connection! :access_key => nil, :secret_key => nil
end
end
def make_unique_bucket (bucket)