diff --git a/.gitignore b/.gitignore index 8ed7196..8c76aa0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ tmp/camouflage.pid -server.js tmp/camo.pid diff --git a/Rakefile b/Rakefile index 44c4112..f236fee 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,11 @@ namespace :test do + desc "Run the tests against localhost" task :check do |t| system("ruby test/proxy_test.rb") end end task :default => "test:check" + +Dir["tasks/*.rake"].each do |f| + load f +end diff --git a/server.coffee b/server.coffee index 9d1bd83..873fca2 100644 --- a/server.coffee +++ b/server.coffee @@ -4,14 +4,17 @@ Http = require 'http' Crypto = require 'crypto' QueryString = require 'querystring' -port = process.env.PORT || 8081 -version = "0.2.2" -shared_key = process.env.CAMO_KEY || '0x24FEEDFACEDEADBEEFCAFE' +port = process.env.PORT || 8081 +version = "0.3.0" +shared_key = process.env.CAMO_KEY || '0x24FEEDFACEDEADBEEFCAFE' +logging_enabled = process.env.CAMO_LOGGING_ENABLED || "disabled" +pidfile = process.env.PIDFILE || 'tmp/camo.pid' log = (msg) -> - console.log("--------------------------------------------") - console.log(msg) - console.log("--------------------------------------------") + unless logging_enabled == "disabled" + console.log("--------------------------------------------") + console.log(msg) + console.log("--------------------------------------------") server = Http.createServer (req, resp) -> if req.method != 'GET' || req.url == '/' @@ -102,7 +105,7 @@ server = Http.createServer (req, resp) -> resp.writeHead srcResp.statusCode, newHeaders else - four_oh_four("Responded with #{srcResp.statusCode}") + four_oh_four("Responded with #{srcResp.statusCode}:#{srcResp.headers}") srcReq.on 'error', -> resp.end() @@ -112,14 +115,14 @@ server = Http.createServer (req, resp) -> else four_oh_four("No host found") else - four_oh_four("checksum mismatch") + four_oh_four("checksum mismatch #{hmac_digest}:#{query_digest}") else four_oh_four("No pathname provided on the server") console.log "SSL-Proxy running on #{port} with pid:#{process.pid}." console.log "Using the secret key #{shared_key}" -Fs.open (process.env.PIDFILE || "tmp/camo.pid"), "w", 0600, (err, fd) -> +Fs.open (pidfile), "w", 0600, (err, fd) -> Fs.writeSync fd, process.pid server.listen port diff --git a/tasks/.gitignore b/tasks/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/test/proxy_test.rb b/test/proxy_test.rb index a09aa48..452f84d 100644 --- a/test/proxy_test.rb +++ b/test/proxy_test.rb @@ -7,10 +7,10 @@ require 'test/unit' -class AssetProxyTest < Test::Unit::TestCase +class CamoProxyTest < Test::Unit::TestCase def config - { 'key' => "0x24FEEDFACEDEADBEEFCAFE", - 'host' => "http://localhost:8081" } + { 'key' => ENV['CAMO_KEY'] || "0x24FEEDFACEDEADBEEFCAFE", + 'host' => ENV['CAMO_HOST'] || "http://localhost:8081" } end def request(image_url)