Skip to content

Commit a46ecef

Browse files
author
RTLcoil
authored
Improve validation of auth token generation
1 parent ae15a87 commit a46ecef

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/cloudinary/auth_token.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ def self.generate(options = {})
3333
end
3434
end
3535

36+
if url.blank? && acl.blank?
37+
raise 'AuthToken must contain either an acl or a url property'
38+
end
39+
3640
token = []
3741
token << "ip=#{ip}" if ip
3842
token << "st=#{start}" if start

spec/auth_token_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@
6262
token = { :key => KEY, :expiration => 0, :duration => 0 }
6363
expect{Cloudinary::Utils.generate_auth_token(token)}.to raise_error(/Must provide either expiration or duration/)
6464
end
65+
66+
it "should raise if generate_auth_token is missing acl or url" do
67+
expect{Cloudinary::Utils.generate_auth_token(:start_time => 1111111111, :duration => 300)}.to raise_error("AuthToken must contain either an acl or a url property")
68+
expect{Cloudinary::Utils.generate_auth_token(:start_time => 1111111111, :duration => 300, :acl => "/*/t_foobar")}.not_to raise_error
69+
expect{Cloudinary::Utils.generate_auth_token(:start_time => 1111111111, :duration => 300, :url => "http://res.cloudinary.com/test123/image/upload/v1486020273/sample.jpg")}.not_to raise_error
70+
end
6571
end
6672
describe "authentication token" do
6773
it "should generate token string" do

0 commit comments

Comments
 (0)