mirror of
https://github.com/wahyd4/ruby-sdk.git
synced 2026-08-13 14:56:41 +10:00
修正授权凭证生成算法,并调整测试用例。
This commit is contained in:
+2
-2
@@ -182,12 +182,12 @@ module Qiniu
|
||||
end
|
||||
|
||||
def batch_copy(*args)
|
||||
code, data = RS.batch_copy(args)
|
||||
code, data = RS.batch_copy(*args)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def batch_move(*args)
|
||||
code, data = RS.batch_move(args)
|
||||
code, data = RS.batch_move(*args)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ module Qiniu
|
||||
end
|
||||
|
||||
def call_with_signature(url, data, retry_times = 0, options = {})
|
||||
code, data = http_request url, data, options.merge({:qbox_signature_token => generate_qbox_signature(url, data)})
|
||||
code, data = http_request url, data, options.merge({:qbox_signature_token => generate_qbox_signature(url, data, options[:mime])})
|
||||
[code, data]
|
||||
end
|
||||
|
||||
|
||||
@@ -20,9 +20,9 @@ module Qiniu
|
||||
:method => :post,
|
||||
:content_type => 'application/x-www-form-urlencoded',
|
||||
:auth_url => "https://acc.qbox.me/oauth2/token",
|
||||
:rs_host => "http://rs.qbox.me",
|
||||
:rs_host => "http://rs.qiniu.com",
|
||||
:io_host => "http://iovip.qbox.me",
|
||||
:up_host => "http://up.qbox.me",
|
||||
:up_host => "http://up.qiniu.com",
|
||||
:pub_host => "http://pu.qbox.me:10200",
|
||||
:eu_host => "http://eu.qbox.me",
|
||||
:client_id => "a75604760c4da4caaa456c0c5895c061c3065c5a",
|
||||
|
||||
+2
-2
@@ -60,7 +60,7 @@ module Qiniu
|
||||
encoded_uri = encode_entry_uri(bucket, key)
|
||||
execs << "op=/#{command}/#{encoded_uri}"
|
||||
end
|
||||
Auth.request Config.settings[:rs_host] + "/batch?" + execs.join("&")
|
||||
Auth.request Config.settings[:rs_host] + "/batch", execs.join("&"), {:mime => "application/x-www-form-urlencoded" }
|
||||
end
|
||||
|
||||
def batch_get(bucket, keys)
|
||||
@@ -108,7 +108,7 @@ module Qiniu
|
||||
op_args.each do |e|
|
||||
execs << 'op=' + _generate_cp_or_mv_opstr(command, e[0], e[1], e[2], e[3]) if e.size == 4
|
||||
end
|
||||
Auth.request Config.settings[:rs_host] + "/batch?" + execs.join("&")
|
||||
Auth.request Config.settings[:rs_host] + "/batch", execs.join("&"), {:mime => "application/x-www-form-urlencoded" }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -127,7 +127,7 @@ module Qiniu
|
||||
File.open(filepath, "rb") { |f| Zlib.crc32 f.read }
|
||||
end
|
||||
|
||||
def generate_qbox_signature(url, params)
|
||||
def generate_qbox_signature(url, params, mime = nil)
|
||||
access_key = Config.settings[:access_key]
|
||||
secret_key = Config.settings[:secret_key]
|
||||
uri = URI.parse(url)
|
||||
@@ -139,6 +139,9 @@ module Qiniu
|
||||
params_string = generate_query_string(params)
|
||||
signature += params_string
|
||||
end
|
||||
if mime.is_a?(String) && mime == "application/x-www-form-urlencoded" && params.is_a?(String)
|
||||
signature += params
|
||||
end
|
||||
hmac = HMAC::SHA1.new(secret_key)
|
||||
hmac.update(signature)
|
||||
encoded_digest = urlsafe_base64_encode(hmac.digest)
|
||||
|
||||
@@ -92,19 +92,24 @@ module Qiniu
|
||||
|
||||
context ".batch_copy" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::RS.batch_copy [@bucket, @key, @bucket, @key2]
|
||||
code, data = Qiniu::RS::RS.batch_copy @bucket, @key, @bucket, @key2
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
|
||||
#code2, data2 = Qiniu::RS::RS.stat(@bucket, @key2)
|
||||
#code2.should == 200
|
||||
#puts data2.inspect
|
||||
#
|
||||
code, data = Qiniu::RS::RS.delete(@bucket, @key2)
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
context ".batch_move" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::RS.batch_move [@bucket, @key, @bucket, @key2]
|
||||
code, data = Qiniu::RS::RS.batch_move @bucket, @key, @bucket, @key2
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
|
||||
@@ -112,7 +117,7 @@ module Qiniu
|
||||
#code2.should == 200
|
||||
#puts data2.inspect
|
||||
|
||||
code3, data3 = Qiniu::RS::RS.batch_move [@bucket, @key2, @bucket, @key]
|
||||
code3, data3 = Qiniu::RS::RS.batch_move @bucket, @key2, @bucket, @key
|
||||
code3.should == 200
|
||||
puts data3.inspect
|
||||
end
|
||||
|
||||
@@ -298,23 +298,26 @@ module Qiniu
|
||||
|
||||
context ".batch_copy" do
|
||||
it "should works" do
|
||||
result = Qiniu::RS.batch_copy [@bucket, @key, @bucket, @key2]
|
||||
result = Qiniu::RS.batch_copy @bucket, @key, @bucket, @key2
|
||||
result.should_not be_false
|
||||
|
||||
#result2 = Qiniu::RS.stat(@bucket, @key2)
|
||||
#result2.should_not be_false
|
||||
|
||||
result = Qiniu::RS.delete @bucket, @key2
|
||||
result.should_not be_false
|
||||
end
|
||||
end
|
||||
|
||||
context ".batch_move" do
|
||||
it "should works" do
|
||||
result = Qiniu::RS::RS.batch_move [@bucket, @key, @bucket, @key2]
|
||||
result = Qiniu::RS.batch_move @bucket, @key, @bucket, @key2
|
||||
result.should_not be_false
|
||||
|
||||
#result2 = Qiniu::RS.stat(@bucket, @key2)
|
||||
#result2.should_not be_false
|
||||
|
||||
result3 = Qiniu::RS.batch_move [@bucket, @key2, @bucket, @key]
|
||||
result3 = Qiniu::RS.batch_move @bucket, @key2, @bucket, @key
|
||||
result3.should_not be_false
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user