Skip to content
This repository has been archived by the owner on Apr 7, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' into open-source
Browse files Browse the repository at this point in the history
  • Loading branch information
atmos committed Jul 1, 2011
2 parents 8a951f0 + 4bc6d00 commit 3a19c2a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ server = Http.createServer (req, resp) ->
digest: query_digest
})

if url.pathname?
if url.pathname? && dest_url
hmac = Crypto.createHmac("sha1", shared_key)
hmac.update(dest_url)

hmac_digest = hmac.digest('hex')

if hmac_digest == query_digest
Expand Down
2 changes: 1 addition & 1 deletion server.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 12 additions & 5 deletions test/proxy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,18 @@ def test_404s_on_environmental_excludes
class CamoProxyQueryStringTest < Test::Unit::TestCase
include CamoProxyTests

def request(image_url)
def request_uri(image_url)
hexdigest = OpenSSL::HMAC.hexdigest(
OpenSSL::Digest::Digest.new('sha1'), config['key'], image_url)

uri = Addressable::URI.parse("#{config['host']}/#{hexdigest}")
uri.query_values = { 'url' => image_url, 'repo' => '', 'path' => '' }

RestClient.get(uri.to_s)
uri.to_s
end

def request(image_url)
RestClient.get(request_uri(image_url))
end
end

Expand All @@ -112,11 +116,14 @@ def hexenc(image_url)
image_url.to_enum(:each_byte).map { |byte| "%02x" % byte }.join
end

def request(image_url)
def request_uri(image_url)
hexdigest = OpenSSL::HMAC.hexdigest(
OpenSSL::Digest::Digest.new('sha1'), config['key'], image_url)
encoded_image_url = hexenc(image_url)
uri = "#{config['host']}/#{hexdigest}/#{encoded_image_url}"
RestClient.get(uri)
"#{config['host']}/#{hexdigest}/#{encoded_image_url}"
end

def request(image_url)
RestClient.get(request_uri(image_url))
end
end

0 comments on commit 3a19c2a

Please sign in to comment.