From 3302ecde6a219a9e4b5f649a046175e8a9aa3d4d Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Tue, 28 Jan 2014 16:04:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=BF=87=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=A1=88=E4=BE=8B=EF=BC=8C=E5=B9=B6=E4=B8=BA?= =?UTF-8?q?=E6=96=B0=E6=94=B9=E5=8A=A8=E9=80=BB=E8=BE=91=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=96=B0=E6=A1=88=E4=BE=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/qiniu/rs/config.rb | 4 +- lib/qiniu/rs/rs.rb | 2 + spec/qiniu/rs/auth_spec.rb | 58 ----------------------- spec/qiniu/rs/image_spec.rb | 2 + spec/qiniu/rs/rs_spec.rb | 2 + spec/qiniu/rs/up_spec.rb | 93 +++++++++++++++++++++++++++++++++++++ spec/qiniu/rs_spec.rb | 4 ++ 7 files changed, 105 insertions(+), 60 deletions(-) delete mode 100755 spec/qiniu/rs/auth_spec.rb diff --git a/lib/qiniu/rs/config.rb b/lib/qiniu/rs/config.rb index 159447c..d7f65df 100755 --- a/lib/qiniu/rs/config.rb +++ b/lib/qiniu/rs/config.rb @@ -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", diff --git a/lib/qiniu/rs/rs.rb b/lib/qiniu/rs/rs.rb index 79bbd1e..d95c7b6 100755 --- a/lib/qiniu/rs/rs.rb +++ b/lib/qiniu/rs/rs.rb @@ -103,6 +103,7 @@ module Qiniu %Q(/#{command}/#{source_encoded_entry_uri}/#{target_encoded_entry_uri}) end +=begin def _batch_cp_or_mv(command, *op_args) execs = [] op_args.each do |e| @@ -110,6 +111,7 @@ module Qiniu end Auth.request Config.settings[:rs_host] + "/batch?" + execs.join("&") end +=end end end diff --git a/spec/qiniu/rs/auth_spec.rb b/spec/qiniu/rs/auth_spec.rb deleted file mode 100755 index e7b9d6a..0000000 --- a/spec/qiniu/rs/auth_spec.rb +++ /dev/null @@ -1,58 +0,0 @@ -# -*- encoding: utf-8 -*- - -require 'spec_helper' -require 'qiniu/rs/auth' - -module Qiniu - module RS - describe Auth do - - before :all do - @username = "qboxtest" - @password = "qboxtest123" - - code, data = Qiniu::RS::Auth.exchange_by_password!(@username, @password) - code.should == 200 - data.should be_an_instance_of(Hash) - data["access_token"].should_not be_empty - data["refresh_token"].should_not be_empty - data["refresh_token"].should_not be_empty - - @access_token = data["access_token"] - @refresh_token = data["refresh_token"] - puts data.inspect - end - - context ".exchange_by_password" do - it "should sign in failed when pass a non-existent username" do - code, data = Qiniu::RS::Auth.exchange_by_password!("a_non_existent_user@example.com", "password") - code.should == 401 - data["error_code"].should == 11 - data["error"].should == "failed_authentication" - puts data.inspect - end - - it "should sign in failed when pass a wrong password" do - code, data = Qiniu::RS::Auth.exchange_by_password!(@username, "a-wrong-password") - code.should == 401 - data["error_code"].should == 11 - data["error"].should == "failed_authentication" - puts data.inspect - end - end - - context ".exchange_by_refresh_token" do - it "should works" do - @refresh_token.should_not be_empty - code, data = Qiniu::RS::Auth.exchange_by_refresh_token!(@refresh_token) - code.should == 200 - data["access_token"].should_not be_empty - data["refresh_token"].should_not be_empty - data["expires_in"].should_not be_zero - puts data.inspect - end - end - - end - end -end diff --git a/spec/qiniu/rs/image_spec.rb b/spec/qiniu/rs/image_spec.rb index 135897c..5cfee7e 100755 --- a/spec/qiniu/rs/image_spec.rb +++ b/spec/qiniu/rs/image_spec.rb @@ -66,12 +66,14 @@ module Qiniu end end +=begin context ".exif" do it "should works" do code, data = Qiniu::RS::Image.exif(@source_image_url) puts data.inspect end end +=end context ".mogrify_preview_url" do it "should works" do diff --git a/spec/qiniu/rs/rs_spec.rb b/spec/qiniu/rs/rs_spec.rb index 3e3a785..67569ae 100755 --- a/spec/qiniu/rs/rs_spec.rb +++ b/spec/qiniu/rs/rs_spec.rb @@ -90,6 +90,7 @@ module Qiniu end end +=begin context ".batch_copy" do it "should works" do code, data = Qiniu::RS::RS.batch_copy [@bucket, @key, @bucket, @key2] @@ -117,6 +118,7 @@ module Qiniu puts data3.inspect end end +=end =begin context ".publish" do diff --git a/spec/qiniu/rs/up_spec.rb b/spec/qiniu/rs/up_spec.rb index 91b0849..0c22a34 100755 --- a/spec/qiniu/rs/up_spec.rb +++ b/spec/qiniu/rs/up_spec.rb @@ -15,6 +15,18 @@ module Qiniu @bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s @key = Digest::SHA1.hexdigest(@localfile+Time.now.to_s) + @localfile2 = "bigfile2.txt" + File.open(@localfile2, "w"){|f| (1 << 22).times{f.write(rand(9).to_s)}} + @key2 = Digest::SHA1.hexdigest(@localfile2+Time.now.to_s) + + @localfile3 = "bigfile3.txt" + File.open(@localfile3, "w"){|f| (1 << 23).times{f.write(rand(9).to_s)}} + @key3 = Digest::SHA1.hexdigest(@localfile3+Time.now.to_s) + + @localfile4 = "smallfile.txt" + File.open(@localfile4, "w"){|f| (1 << 20).times{f.write(rand(9).to_s)}} + @key4 = Digest::SHA1.hexdigest(@localfile4+Time.now.to_s) + code, data = Qiniu::RS::RS.mkbucket(@bucket) puts [code, data].inspect code.should == 200 @@ -22,6 +34,9 @@ module Qiniu after :all do File.unlink(@localfile) if File.exists?(@localfile) + File.unlink(@localfile2) if File.exists?(@localfile2) + File.unlink(@localfile3) if File.exists?(@localfile3) + File.unlink(@localfile4) if File.exists?(@localfile4) code, data = Qiniu::RS::RS.drop(@bucket) puts [code, data].inspect @@ -54,6 +69,84 @@ module Qiniu end end + context ".upload_with_token2" do + it "should works" do + upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"} + uptoken = Qiniu::RS.generate_upload_token(upopts) + code, data = Qiniu::RS::UP.upload_with_token(uptoken, @localfile2, @bucket, @key2) + puts data.inspect + (code/100).should == 2 + end + end + + context ".stat" do + it "should exists" do + code, data = Qiniu::RS::RS.stat(@bucket, @key2) + puts data.inspect + code.should == 200 + end + end + + context ".delete" do + it "should works" do + code, data = Qiniu::RS::RS.delete(@bucket, @key2) + puts data.inspect + code.should == 200 + end + end + + context ".upload_with_token3" do + it "should works" do + upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"} + uptoken = Qiniu::RS.generate_upload_token(upopts) + code, data = Qiniu::RS::UP.upload_with_token(uptoken, @localfile3, @bucket, @key3) + puts data.inspect + (code/100).should == 2 + end + end + + context ".stat" do + it "should exists" do + code, data = Qiniu::RS::RS.stat(@bucket, @key3) + puts data.inspect + code.should == 200 + end + end + + context ".delete" do + it "should works" do + code, data = Qiniu::RS::RS.delete(@bucket, @key3) + puts data.inspect + code.should == 200 + end + end + + context ".upload_with_token4" do + it "should works" do + upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"} + uptoken = Qiniu::RS.generate_upload_token(upopts) + code, data = Qiniu::RS::UP.upload_with_token(uptoken, @localfile4, @bucket, @key4) + puts data.inspect + (code/100).should == 2 + end + end + + context ".stat" do + it "should exists" do + code, data = Qiniu::RS::RS.stat(@bucket, @key4) + puts data.inspect + code.should == 200 + end + end + + context ".delete" do + it "should works" do + code, data = Qiniu::RS::RS.delete(@bucket, @key4) + puts data.inspect + code.should == 200 + end + end + end end end diff --git a/spec/qiniu/rs_spec.rb b/spec/qiniu/rs_spec.rb index fa2cdb3..22a1699 100755 --- a/spec/qiniu/rs_spec.rb +++ b/spec/qiniu/rs_spec.rb @@ -296,6 +296,7 @@ module Qiniu end =end +=begin context ".batch_copy" do it "should works" do result = Qiniu::RS.batch_copy [@bucket, @key, @bucket, @key2] @@ -318,6 +319,7 @@ module Qiniu result3.should_not be_false end end +=end context ".move" do it "should works" do @@ -369,6 +371,7 @@ module Qiniu end end +=begin context ".image_exif" do it "should works" do data = Qiniu::RS.get(@test_image_bucket, @test_image_key) @@ -379,6 +382,7 @@ module Qiniu puts result.inspect end end +=end context ".image_mogrify_save_as" do it "should works" do