Skip to content

Commit f18ee31

Browse files
author
Amir Tocker
committed
Handle auth_token == false.
1 parent 74110d5 commit f18ee31

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

lib/utils.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/utils.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/auth_token.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = (options)->
3131
start = params.start_time ? Math.round(Date.now() / 1000)
3232
params.expiration = start + params.duration
3333
else
34-
throw new Error( "Must provide either end_time or window")
34+
throw new Error( "Must provide either expiration or duration")
3535

3636
tokenParts = []
3737
tokenParts.push("ip=#{params.ip}") if params.ip?

src/utils.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ exports.url = (public_id, options = {}) ->
396396
api_secret = utils.option_consume(options, "api_secret", config().api_secret)
397397
url_suffix = utils.option_consume(options, "url_suffix")
398398
use_root_path = utils.option_consume(options, "use_root_path", config().use_root_path)
399-
auth_token = utils.option_consume(options, "auth_token", config().auth_token)
399+
auth_token = if options.auth_token == false then false else exports.merge config().auth_token, utils.option_consume(options, "auth_token")
400400

401401
preloaded = /^(image|raw)\/([a-z0-9_]+)\/v(\d+)\/([^#]+)$/.exec(public_id)
402402
if preloaded

test/authtoken_spec.coffee

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ utils = cloudinary.utils
55
KEY = "00112233FF99"
66
ALT_KEY = "CCBB2233FF00"
77
describe "authToken", ->
8-
urlBackup = process.env.CLOUDINARY_URL
8+
urlBackup = null
9+
before ->
10+
urlBackup = process.env.CLOUDINARY_URL
911

1012
beforeEach ->
11-
process.env.CLOUDINARY_URL = "cloudinary://a:b@test123?load_strategies=false"
13+
process.env.CLOUDINARY_URL = "cloudinary://a:b@test123"
1214
cloudinary.config true
1315
cloudinary.config().auth_token = {key: KEY, duration: 300, start_time: 11111111}
1416
after ->
@@ -27,24 +29,24 @@ describe "authToken", ->
2729
url = cloudinary.url "sample.jpg", sign_url: true, resource_type: "image", type: "authenticated", version: "1486020273"
2830
expect(url).to.eql("http://test123-res.cloudinary.com/image/authenticated/v1486020273/sample.jpg?__cld_token__=st=11111111~exp=11111411~hmac=8db0d753ee7bbb9e2eaf8698ca3797436ba4c20e31f44527e43b6a6e995cfdb3")
2931

30-
it "should add token for 'public' resource", ->
32+
it "should add token for 'public' resource", ->
3133
url = cloudinary.url "sample.jpg", sign_url: true, resource_type: "image", type: "public", version: "1486020273"
3234
expect(url).to.eql("http://test123-res.cloudinary.com/image/public/v1486020273/sample.jpg?__cld_token__=st=11111111~exp=11111411~hmac=c2b77d9f81be6d89b5d0ebc67b671557e88a40bcf03dd4a6997ff4b994ceb80e")
3335

34-
it "should not add token if signed is false", ->
36+
it "should not add token if signed is false", ->
3537
url = cloudinary.url "sample.jpg", type: "authenticated", version: "1486020273"
3638
expect(url).to.eql("http://test123-res.cloudinary.com/image/authenticated/v1486020273/sample.jpg")
3739

38-
it "should not add token if authToken is globally set but null auth token is explicitly set and signed = true", ->
40+
it "should not add token if authToken is globally set but null auth token is explicitly set and signed = true", ->
3941
url = cloudinary.url "sample.jpg", auth_token: false, sign_url: true, type: "authenticated", version: "1486020273"
4042
expect(url).to.eql("http://test123-res.cloudinary.com/image/authenticated/s--v2fTPYTu--/v1486020273/sample.jpg")
4143

42-
it "explicit authToken should override global setting", ->
44+
it "explicit authToken should override global setting", ->
4345
url = cloudinary.url "sample.jpg", sign_url: true, auth_token: {key: ALT_KEY, start_time: 222222222, duration: 100}, type: "authenticated", transformation: {crop: "scale", width: 300}
4446
expect(url).to.eql("http://test123-res.cloudinary.com/image/authenticated/c_scale,w_300/sample.jpg?__cld_token__=st=222222222~exp=222222322~hmac=7d276841d70c4ecbd0708275cd6a82e1f08e47838fbb0bceb2538e06ddfa3029")
4547

46-
it "should compute expiration as start time + duration", ->
47-
token = {key: KEY, start_time: 11111111, duration: 300}
48+
it "should compute expiration as start time + duration", ->
49+
token = {start_time: 11111111, duration: 300}
4850
url = cloudinary.url "sample.jpg", sign_url: true, auth_token: token, resource_type: "image", type: "authenticated", version: "1486020273"
4951
expect(url).to.eql("http://test123-res.cloudinary.com/image/authenticated/v1486020273/sample.jpg?__cld_token__=st=11111111~exp=11111411~hmac=8db0d753ee7bbb9e2eaf8698ca3797436ba4c20e31f44527e43b6a6e995cfdb3")
5052

0 commit comments

Comments
 (0)