为authorize_download_url添加测试用例。

This commit is contained in:
Liang Tao
2014-03-27 11:34:36 +08:00
parent 5c9169b516
commit fc5afc332a
2 changed files with 80 additions and 2 deletions
+2 -2
View File
@@ -57,8 +57,8 @@ module Qiniu
### 生成下载授权凭证
dntoken = "#{access_key}:#{encoded_sign}"
### 返回下载授权URL及相关参数
return "#{download_url}&token=#{dntoken}", e, dntoken
### 返回下载授权URL
return "#{download_url}&token=#{dntoken}"
end # authorize_download_url
end # class << self
+78
View File
@@ -0,0 +1,78 @@
# -*- encoding: utf-8 -*-
require 'spec_helper'
require 'qiniu/auth'
require 'qiniu/storage'
require 'digest/sha1'
module Qiniu
module Auth
describe Auth do
before :all do
@bucket = 'RubySDK-Test-Private'
@bucket = make_unique_bucket(@bucket)
### 尝试创建Bucket
result = Qiniu::Storage.make_a_private_bucket(@bucket)
puts result.inspect
end
after :all do
### 不删除Bucket以备下次使用
end
### 测试私有资源下载
context ".download_private_file" do
it "should works" do
### 生成Key
key = 'a_private_file'
key = make_unique_key_in_bucket(key)
puts "key=#{key}"
### 上传测试文件
upopts = {:scope => @bucket, :expires_in => 3600, :endUser => "why404@gmail.com"}
uptoken = Qiniu.generate_upload_token(upopts)
code, data, raw_headers = Qiniu::Storage.upload_with_token_2(
uptoken,
__FILE__,
key
)
code.should == 200
puts data.inspect
puts raw_headers.inspect
### 获取下载地址
code, data = Qiniu::Storage.get(@bucket, key)
code.should == 200
puts data.inspect
url = data['url']
### 授权下载地址(不带参数)
download_url = Qiniu::Auth.authorize_download_url(url)
puts "download_url=#{download_url}"
result = RestClient.get(download_url)
result.code.should == 200
result.body.should_not be_empty
### 授权下载地址(带参数)
download_url = Qiniu::Auth.authorize_download_url(url + '?download/a.m3u8')
puts "download_url=#{download_url}"
result = RestClient.get(download_url)
result.code.should == 200
result.body.should_not be_empty
### 删除文件
code, data = Qiniu::Storage.delete(@bucket, key)
code.should == 200
puts data.inspect
end
end
end
end # module Storage
end # module Qiniu