From af421ecb49b96e4279e7202c18084c02bab01acb Mon Sep 17 00:00:00 2001 From: Jake Date: Mon, 9 Feb 2015 21:48:54 -0600 Subject: [PATCH 01/17] Start http.server tests --- server.js | 41 ++++++++++++++++++++++----------- test/test.js | 65 +++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 89 insertions(+), 17 deletions(-) diff --git a/server.js b/server.js index c036803..325b9eb 100644 --- a/server.js +++ b/server.js @@ -7,6 +7,7 @@ var http = require("http"); var mime = require("mime"); var url = require("url"); var fs = require("fs"); +var server = null; var routes = { index: require("./routes/index"), @@ -53,22 +54,22 @@ function requestHandler(req, res) { try { switch (local_path) { case "": - routes.index(request, res); - break; + routes.index(request, res); + break; case "avatars": - routes.avatars(request, res); - break; + routes.avatars(request, res); + break; case "skins": - routes.skins(request, res); - break; + routes.skins(request, res); + break; case "renders": - routes.renders(request, res); - break; + routes.renders(request, res); + break; case "capes": - routes.capes(request, res); - break; + routes.capes(request, res); + break; default: - asset_request(request, res); + asset_request(request, res); } } catch(e) { var error = JSON.stringify(req.headers) + "\n" + e.stack; @@ -86,15 +87,27 @@ function requestHandler(req, res) { } } -var boot = module.exports = function () { +var exp = {}; + +exp.boot = function(callback) { var port = process.env.PORT || 3000; var bind_ip = process.env.BIND || "127.0.0.1"; console.log("Server running on http://" + bind_ip + ":" + port + "/"); - http.createServer(requestHandler).listen(port, bind_ip); + server = http.createServer(requestHandler).listen(port, bind_ip, function() { + callback(); + }); }; +exp.close = function(callback) { + server.close(function() { + callback(); + }); +} + +module.exports = exp; + if (require.main === module) { - boot(); + exp.boot(function(){}); // cleaning worker setInterval(clean.run, config.cleaning_interval * 1000); diff --git a/test/test.js b/test/test.js index 0c38539..08950f0 100644 --- a/test/test.js +++ b/test/test.js @@ -8,7 +8,8 @@ var config = require("../modules/config"); var skins = require("../modules/skins"); var cache = require("../modules/cache"); var renders = require("../modules/renders"); -var cleaner = require("../modules/cleaner"); +var server = require("../server"); +var request = require("request"); // we don't want tests to fail because of slow internet config.http_timeout *= 3; @@ -33,7 +34,7 @@ var ids = [ uuid.toLowerCase(), name.toLowerCase(), uuid.toUpperCase(), - name.toUpperCase() + name.toUpperCase(), ]; describe("Crafatar", function() { @@ -42,7 +43,6 @@ describe("Crafatar", function() { before(function() { cache.get_redis().flushall(); - cleaner.run(); }); describe("UUID/username", function() { @@ -330,4 +330,63 @@ describe("Crafatar", function() { }); })(id, id_type); } + describe("Server", function() { + before(function(done) { + server.boot(function() { + done(); + }); + }); + + // Test the home page + it("should return a 200", function(done) { + request.get('http://localhost:3000', function(error, res, body) { + assert.equal(200, res.statusCode); + done(); + }); + }); + + // invalid method, we only allow GET and HEAD requests + it("should return a 405", function(done) { + request.post('http://localhost:3000/avatars/Jake0oo0', function(error, res, body) { + assert.equal(405, res.statusCode); + done(); + }); + }); + + it("should return a 422 (invalid scale)", function(done) { + var scale = config.max_scale + 1; + request.get('http://localhost:3000/avatars/Jake0oo0?scale=' + scale, function(error, res, body) { + assert.equal(422, res.statusCode); + done(); + }); + }); + + it("should return a 422 (invalid uuid)", function(done) { + request.get('http://localhost:3000/avatars/thisisaninvaliduuid', function(error, res, body) { + assert.equal(422, res.statusCode); + done(); + }); + }); + + it("should return a 422 (invalid size)", function(done) { + var size = config.max_size + 1; + request.get('http://localhost:3000/renders/Jake0oo0?size=' + size, function(error, res, body) { + assert.equal(422, res.statusCode); + done(); + }); + }); + + it("should return a 301 (default image)", function(done) { + request.get('http://localhost:3000/renders/invalidjsvns?def=steve', function(error, res, body) { + assert.equal(301, res.statusCode); + done(); + }); + }); + + after(function(done) { + server.close(function() { + done(); + }) + }); + }); }); \ No newline at end of file From 4e870ff88933b112459c224fc90a832b8a3c6834 Mon Sep 17 00:00:00 2001 From: Jake Date: Mon, 9 Feb 2015 21:53:09 -0600 Subject: [PATCH 02/17] Test node 0.12 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 47893fc..5709651 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: node_js node_js: - "0.10" + - "0.12" before_script: - cp "modules/config.example.js" "modules/config.js" before_install: From df56c38d03fab3dcdd1b3821734d5f37c3961f31 Mon Sep 17 00:00:00 2001 From: Jake Date: Mon, 9 Feb 2015 21:57:50 -0600 Subject: [PATCH 03/17] Try caching dependencies --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 5709651..9ea3bea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,3 +13,6 @@ notifications: skip_join: true services: - redis-server +cache: + directories: + - node_modules \ No newline at end of file From 04cd39ae9f3b4589d2710c81924d3780f820a315 Mon Sep 17 00:00:00 2001 From: Jake Date: Mon, 9 Feb 2015 22:09:34 -0600 Subject: [PATCH 04/17] Test invalid UUIDs on all routes --- test/test.js | 329 +++++++++++++++++++++++++++------------------------ 1 file changed, 174 insertions(+), 155 deletions(-) diff --git a/test/test.js b/test/test.js index 08950f0..a451bcd 100644 --- a/test/test.js +++ b/test/test.js @@ -31,10 +31,10 @@ function getRandomInt(min, max) { } var ids = [ - uuid.toLowerCase(), - name.toLowerCase(), - uuid.toUpperCase(), - name.toUpperCase(), +uuid.toLowerCase(), +name.toLowerCase(), +uuid.toUpperCase(), +name.toUpperCase(), ]; describe("Crafatar", function() { @@ -101,7 +101,7 @@ describe("Crafatar", function() { }); }); - describe("Avatar", function() { +describe("Avatar", function() { // profile "Alex" - hoping it'll never have a skin var alex_uuid = "ec561538f3fd461daff5086b22154bce"; // profile "Steven" (Steve doesn't exist) - hoping it'll never have a skin @@ -125,54 +125,132 @@ describe("Crafatar", function() { done(); }); }); - describe("Errors", function() { - it("should time out on uuid info download", function(done) { - var original_timeout = config.http_timeout; - config.http_timeout = 1; - networking.get_profile(rid, "069a79f444e94726a5befca90e38aaf5", function(err, profile) { - assert.strictEqual(err.code, "ETIMEDOUT"); - config.http_timeout = original_timeout; - done(); - }); +describe("Errors", function() { + it("should time out on uuid info download", function(done) { + var original_timeout = config.http_timeout; + config.http_timeout = 1; + networking.get_profile(rid, "069a79f444e94726a5befca90e38aaf5", function(err, profile) { + assert.strictEqual(err.code, "ETIMEDOUT"); + config.http_timeout = original_timeout; + done(); }); - it("should time out on username info download", function(done) { - var original_timeout = config.http_timeout; - config.http_timeout = 1; - networking.get_username_url(rid, "jomo", 0, function(err, url) { - assert.strictEqual(err.code, "ETIMEDOUT"); - config.http_timeout = original_timeout; - done(); - }); + }); + it("should time out on username info download", function(done) { + var original_timeout = config.http_timeout; + config.http_timeout = 1; + networking.get_username_url(rid, "jomo", 0, function(err, url) { + assert.strictEqual(err.code, "ETIMEDOUT"); + config.http_timeout = original_timeout; + done(); }); - it("should time out on skin download", function(done) { - var original_timeout = config.http_timeout; - config.http_timeout = 1; - networking.get_from(rid, "http://textures.minecraft.net/texture/477be35554684c28bdeee4cf11c591d3c88afb77e0b98da893fd7bc318c65184", function(body, res, error) { - assert.strictEqual(error.code, "ETIMEDOUT"); - config.http_timeout = original_timeout; - done(); - }); + }); + it("should time out on skin download", function(done) { + var original_timeout = config.http_timeout; + config.http_timeout = 1; + networking.get_from(rid, "http://textures.minecraft.net/texture/477be35554684c28bdeee4cf11c591d3c88afb77e0b98da893fd7bc318c65184", function(body, res, error) { + assert.strictEqual(error.code, "ETIMEDOUT"); + config.http_timeout = original_timeout; + done(); }); - it("should not find the skin", function(done) { - assert.doesNotThrow(function() { - networking.get_from(rid, "http://textures.minecraft.net/texture/this-does-not-exist", function(img, response, err) { + }); + it("should not find the skin", function(done) { + assert.doesNotThrow(function() { + networking.get_from(rid, "http://textures.minecraft.net/texture/this-does-not-exist", function(img, response, err) { assert.strictEqual(err, null); // no error here, but it shouldn't throw exceptions done(); }); - }); }); - it("should ignore file updates on invalid files", function(done) { - assert.doesNotThrow(function() { - cache.update_timestamp(rid, "0123456789abcdef0123456789abcdef", "invalid-file.png"); - }); + }); + it("should ignore file updates on invalid files", function(done) { + assert.doesNotThrow(function() { + cache.update_timestamp(rid, "0123456789abcdef0123456789abcdef", "invalid-file.png"); + }); + done(); + }); + it("should not find the file", function(done) { + skins.open_skin(rid, 'non/existant/path', function(err, img) { + assert.notStrictEqual(err, null); done(); }); - it("should not find the file", function(done) { - skins.open_skin(rid, 'non/existant/path', function(err, img) { - assert.notStrictEqual(err, null); + }); +}); + +describe("Server", function() { + before(function(done) { + server.boot(function() { + done(); + }); + }); + + // Test the home page + it("should return a 200", function(done) { + request.get('http://localhost:3000', function(error, res, body) { + assert.equal(200, res.statusCode); done(); }); }); + + // invalid method, we only allow GET and HEAD requests + it("should return a 405", function(done) { + request.post('http://localhost:3000/avatars/Jake0oo0', function(error, res, body) { + assert.equal(405, res.statusCode); + done(); + }); + }); + + it("should return a 422 (invalid size)", function(done) { + var size = config.max_size + 1; + request.get('http://localhost:3000/avatars/Jake0oo0?size=' + size, function(error, res, body) { + assert.equal(422, res.statusCode); + done(); + }); + }); + + var locations = ["avatars", "capes", "skins", "renders/head"] + for (var l in locations) { + var location = locations[l]; + it("should return a 422 (invalid uuid " + location + ")", function(done) { + request.get('http://localhost:3000/' + location + '/thisisaninvaliduuid', function(error, res, body) { + assert.equal(422, res.statusCode); + done(); + }); + }); + } + + it("should return a 422 (invalid scale)", function(done) { + var scale = config.max_scale + 1; + request.get('http://localhost:3000/renders/head/Jake0oo0?scale=' + scale, function(error, res, body) { + assert.equal(422, res.statusCode); + done(); + }); + }); + + it("should return a 404 (default steve image)", function(done) { + request.get('http://localhost:3000/avatars/invalidjsvns?default=steve', function(error, res, body) { + assert.equal(404, res.statusCode); + done(); + }); + }); + + it("should return a 200 (default external image)", function(done) { + request.get('http://localhost:3000/avatars/invalidjsvns?default=https%3A%2F%2Fi.imgur.com%2FocJVWAc.png', function(error, res, body) { + assert.equal(200, res.statusCode); + done(); + }); + }); + + it("should return a 404 (no cape)", function(done) { + request.get('http://localhost:3000/capes/Jake0oo0', function(error, res, body) { + assert.equal(404, res.statusCode); + done(); + }); + }); + + after(function(done) { + server.close(function() { + done(); + }) + }); }); // we have to make sure that we test both a 32x64 and 64x64 skin @@ -273,120 +351,61 @@ describe("Crafatar", function() { } }); - describe("Networking: Skin", function() { - it("should not fail (uuid)", function(done) { - helpers.get_skin(rid, id, function(err, hash, img) { - assert.strictEqual(err, null); - done(); - }); - }); - }); - - describe("Networking: Render", function() { - it("should not fail (full body)", function(done) { - helpers.get_render(rid, id, 6, true, true, function(err, hash, img) { - assert.strictEqual(err, null); - done(); - }); - }); - it("should not fail (only head)", function(done) { - helpers.get_render(rid, id, 6, true, false, function(err, hash, img) { - assert.strictEqual(err, null); - done(); - }); - }); - }); - - describe("Networking: Cape", function() { - it("should not fail (possible cape)", function(done) { - helpers.get_cape(rid, id, function(err, hash, img) { - assert.strictEqual(err, null); - done(); - }); - }); - }); - - - describe("Errors", function() { - before(function() { - cache.get_redis().flushall(); - }); - - if (id_type == "uuid") { - it("uuid should be rate limited", function(done) { - networking.get_profile(rid, id, function(err, profile) { - assert.strictEqual(profile.error, "TooManyRequestsException"); - done(); - }); - }); - } else { - it("username should NOT be rate limited (username)", function(done) { - helpers.get_avatar(rid, id, false, 160, function(err, status, image) { - assert.strictEqual(err, null); - done(); - }); - }); - } - }); - })(id, id_type); - } - describe("Server", function() { - before(function(done) { - server.boot(function() { - done(); - }); - }); - - // Test the home page - it("should return a 200", function(done) { - request.get('http://localhost:3000', function(error, res, body) { - assert.equal(200, res.statusCode); - done(); - }); - }); - - // invalid method, we only allow GET and HEAD requests - it("should return a 405", function(done) { - request.post('http://localhost:3000/avatars/Jake0oo0', function(error, res, body) { - assert.equal(405, res.statusCode); - done(); - }); - }); - - it("should return a 422 (invalid scale)", function(done) { - var scale = config.max_scale + 1; - request.get('http://localhost:3000/avatars/Jake0oo0?scale=' + scale, function(error, res, body) { - assert.equal(422, res.statusCode); - done(); - }); - }); - - it("should return a 422 (invalid uuid)", function(done) { - request.get('http://localhost:3000/avatars/thisisaninvaliduuid', function(error, res, body) { - assert.equal(422, res.statusCode); - done(); - }); - }); - - it("should return a 422 (invalid size)", function(done) { - var size = config.max_size + 1; - request.get('http://localhost:3000/renders/Jake0oo0?size=' + size, function(error, res, body) { - assert.equal(422, res.statusCode); - done(); - }); - }); - - it("should return a 301 (default image)", function(done) { - request.get('http://localhost:3000/renders/invalidjsvns?def=steve', function(error, res, body) { - assert.equal(301, res.statusCode); - done(); - }); - }); - - after(function(done) { - server.close(function() { - done(); - }) +describe("Networking: Skin", function() { + it("should not fail (uuid)", function(done) { + helpers.get_skin(rid, id, function(err, hash, img) { + assert.strictEqual(err, null); + done(); }); }); +}); + +describe("Networking: Render", function() { + it("should not fail (full body)", function(done) { + helpers.get_render(rid, id, 6, true, true, function(err, hash, img) { + assert.strictEqual(err, null); + done(); + }); + }); + it("should not fail (only head)", function(done) { + helpers.get_render(rid, id, 6, true, false, function(err, hash, img) { + assert.strictEqual(err, null); + done(); + }); + }); +}); + +describe("Networking: Cape", function() { + it("should not fail (possible cape)", function(done) { + helpers.get_cape(rid, id, function(err, hash, img) { + assert.strictEqual(err, null); + done(); + }); + }); +}); + + +describe("Errors", function() { + before(function() { + cache.get_redis().flushall(); + }); + + if (id_type == "uuid") { + it("uuid should be rate limited", function(done) { + networking.get_profile(rid, id, function(err, profile) { + assert.strictEqual(profile.error, "TooManyRequestsException"); + done(); + }); + }); + } else { + it("username should NOT be rate limited (username)", function(done) { + helpers.get_avatar(rid, id, false, 160, function(err, status, image) { + assert.strictEqual(err, null); + done(); + }); + }); + } +}); +})(id, id_type); +} }); \ No newline at end of file From 2d0af06122d276d995e77feddda5fbe633a8025d Mon Sep 17 00:00:00 2001 From: Jake Date: Mon, 9 Feb 2015 22:12:33 -0600 Subject: [PATCH 05/17] Test default images on all paths --- test/test.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/test/test.js b/test/test.js index a451bcd..47bb959 100644 --- a/test/test.js +++ b/test/test.js @@ -225,19 +225,23 @@ describe("Server", function() { }); }); - it("should return a 404 (default steve image)", function(done) { - request.get('http://localhost:3000/avatars/invalidjsvns?default=steve', function(error, res, body) { - assert.equal(404, res.statusCode); - done(); + locations = ["avatars", "capes", "skins"] + for (var l in locations) { + var location = locations[l]; + it("should return a 404 (default steve image " + location + ")", function(done) { + request.get('http://localhost:3000/' + location + '/invalidjsvns?default=steve', function(error, res, body) { + assert.equal(404, res.statusCode); + done(); + }); }); - }); - it("should return a 200 (default external image)", function(done) { - request.get('http://localhost:3000/avatars/invalidjsvns?default=https%3A%2F%2Fi.imgur.com%2FocJVWAc.png', function(error, res, body) { - assert.equal(200, res.statusCode); - done(); + it("should return a 200 (default external image " + location + ")", function(done) { + request.get('http://localhost:3000/' + location + '/invalidjsvns?default=https%3A%2F%2Fi.imgur.com%2FocJVWAc.png', function(error, res, body) { + assert.equal(200, res.statusCode); + done(); + }); }); - }); + } it("should return a 404 (no cape)", function(done) { request.get('http://localhost:3000/capes/Jake0oo0', function(error, res, body) { From 84701567b53ac4a1eb5f30b7b88e743fdb52dbcc Mon Sep 17 00:00:00 2001 From: Jake Date: Mon, 9 Feb 2015 22:16:44 -0600 Subject: [PATCH 06/17] Clean up tests, add some more --- test/test.js | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/test/test.js b/test/test.js index 47bb959..df2b5b1 100644 --- a/test/test.js +++ b/test/test.js @@ -168,7 +168,7 @@ describe("Errors", function() { done(); }); it("should not find the file", function(done) { - skins.open_skin(rid, 'non/existant/path', function(err, img) { + skins.open_skin(rid, "non/existant/path", function(err, img) { assert.notStrictEqual(err, null); done(); }); @@ -184,7 +184,7 @@ describe("Server", function() { // Test the home page it("should return a 200", function(done) { - request.get('http://localhost:3000', function(error, res, body) { + request.get("http://localhost:3000", function(error, res, body) { assert.equal(200, res.statusCode); done(); }); @@ -192,7 +192,7 @@ describe("Server", function() { // invalid method, we only allow GET and HEAD requests it("should return a 405", function(done) { - request.post('http://localhost:3000/avatars/Jake0oo0', function(error, res, body) { + request.post("http://localhost:3000", function(error, res, body) { assert.equal(405, res.statusCode); done(); }); @@ -200,56 +200,59 @@ describe("Server", function() { it("should return a 422 (invalid size)", function(done) { var size = config.max_size + 1; - request.get('http://localhost:3000/avatars/Jake0oo0?size=' + size, function(error, res, body) { + request.get("http://localhost:3000/avatars/Jake0oo0?size=" + size, function(error, res, body) { assert.equal(422, res.statusCode); done(); }); }); + it("should return a 422 (invalid scale)", function(done) { + var scale = config.max_scale + 1; + request.get("http://localhost:3000/renders/head/Jake0oo0?scale=" + scale, function(error, res, body) { + assert.equal(422, res.statusCode); + done(); + }); + }); + + // no default images for capes, should 404 + it("should return a 404 (no cape)", function(done) { + request.get("http://localhost:3000/capes/Jake0oo0", function(error, res, body) { + assert.equal(404, res.statusCode); + done(); + }); + }); + + // testing all paths for invalid id formats var locations = ["avatars", "capes", "skins", "renders/head"] for (var l in locations) { var location = locations[l]; - it("should return a 422 (invalid uuid " + location + ")", function(done) { - request.get('http://localhost:3000/' + location + '/thisisaninvaliduuid', function(error, res, body) { + it("should return a 422 (invalid id " + location + ")", function(done) { + request.get("http://localhost:3000/" + location + "/thisisaninvaliduuid", function(error, res, body) { assert.equal(422, res.statusCode); done(); }); }); } - it("should return a 422 (invalid scale)", function(done) { - var scale = config.max_scale + 1; - request.get('http://localhost:3000/renders/head/Jake0oo0?scale=' + scale, function(error, res, body) { - assert.equal(422, res.statusCode); - done(); - }); - }); - + // testing all paths for default images locations = ["avatars", "capes", "skins"] for (var l in locations) { var location = locations[l]; it("should return a 404 (default steve image " + location + ")", function(done) { - request.get('http://localhost:3000/' + location + '/invalidjsvns?default=steve', function(error, res, body) { + request.get("http://localhost:3000/" + location + "/invalidjsvns?default=steve", function(error, res, body) { assert.equal(404, res.statusCode); done(); }); }); it("should return a 200 (default external image " + location + ")", function(done) { - request.get('http://localhost:3000/' + location + '/invalidjsvns?default=https%3A%2F%2Fi.imgur.com%2FocJVWAc.png', function(error, res, body) { + request.get("http://localhost:3000/" + location + "/invalidjsvns?default=https%3A%2F%2Fi.imgur.com%2FocJVWAc.png", function(error, res, body) { assert.equal(200, res.statusCode); done(); }); }); } - it("should return a 404 (no cape)", function(done) { - request.get('http://localhost:3000/capes/Jake0oo0', function(error, res, body) { - assert.equal(404, res.statusCode); - done(); - }); - }); - after(function(done) { server.close(function() { done(); From cac316aeb36b1d7608e798a204bf5fb221a0843c Mon Sep 17 00:00:00 2001 From: Jake Date: Mon, 9 Feb 2015 22:33:43 -0600 Subject: [PATCH 07/17] Asset request, describe more tests --- test/test.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/test.js b/test/test.js index df2b5b1..89ad12b 100644 --- a/test/test.js +++ b/test/test.js @@ -183,15 +183,22 @@ describe("Server", function() { }); // Test the home page - it("should return a 200", function(done) { + it("should return a 200 (home page)", function(done) { request.get("http://localhost:3000", function(error, res, body) { assert.equal(200, res.statusCode); done(); }); }); + it("should return a 200 (asset request)", function(done) { + request.get("http://localhost:3000/stylesheets/style.css", function(error, res, body) { + assert.equal(200, res.statusCode); + done(); + }); + }); + // invalid method, we only allow GET and HEAD requests - it("should return a 405", function(done) { + it("should return a 405 (invalid method)", function(done) { request.post("http://localhost:3000", function(error, res, body) { assert.equal(405, res.statusCode); done(); From 9bebaff48ebe89ce822a7427e5c9a65837ed68d9 Mon Sep 17 00:00:00 2001 From: Jake Date: Tue, 10 Feb 2015 21:44:01 -0600 Subject: [PATCH 08/17] Test invalid render type --- test/test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/test.js b/test/test.js index 89ad12b..8e933ec 100644 --- a/test/test.js +++ b/test/test.js @@ -229,6 +229,13 @@ describe("Server", function() { }); }); + it("should return a 422 (invalid render type)", function(done) { + request.get("http://localhost:3000/renders/side/Jake0oo0", function(error, res, body) { + assert.equal(422, res.statusCode); + done(); + }); + }); + // testing all paths for invalid id formats var locations = ["avatars", "capes", "skins", "renders/head"] for (var l in locations) { From c925082f7ff599a128e8729dfad99dc1276f5d2d Mon Sep 17 00:00:00 2001 From: Jake Date: Tue, 10 Feb 2015 21:45:46 -0600 Subject: [PATCH 09/17] Test valid inputs for all paths --- server.js | 2 +- test/test.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index 325b9eb..c6c49bd 100644 --- a/server.js +++ b/server.js @@ -92,7 +92,7 @@ var exp = {}; exp.boot = function(callback) { var port = process.env.PORT || 3000; var bind_ip = process.env.BIND || "127.0.0.1"; - console.log("Server running on http://" + bind_ip + ":" + port + "/"); + logging.log("Server running on http://" + bind_ip + ":" + port + "/"); server = http.createServer(requestHandler).listen(port, bind_ip, function() { callback(); }); diff --git a/test/test.js b/test/test.js index 8e933ec..e057142 100644 --- a/test/test.js +++ b/test/test.js @@ -246,6 +246,13 @@ describe("Server", function() { done(); }); }); + + it("should return a 200 (valid input)", function(done) { + request.get("http://localhost:3000/" + location + "/Jake0oo0", function(error, res, body) { + assert.equal(200, res.statusCode); + done(); + }); + }); } // testing all paths for default images From ce34ae229126a1a8ea431e5abe0fc52d4426cf48 Mon Sep 17 00:00:00 2001 From: Jake Date: Tue, 10 Feb 2015 21:54:52 -0600 Subject: [PATCH 10/17] run cleaner --- test/test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test.js b/test/test.js index e057142..ebc0a58 100644 --- a/test/test.js +++ b/test/test.js @@ -9,6 +9,7 @@ var skins = require("../modules/skins"); var cache = require("../modules/cache"); var renders = require("../modules/renders"); var server = require("../server"); +var cleaner = require("../modules/cleaner"); var request = require("request"); // we don't want tests to fail because of slow internet @@ -43,6 +44,7 @@ describe("Crafatar", function() { before(function() { cache.get_redis().flushall(); + cleaner.run(); }); describe("UUID/username", function() { @@ -100,7 +102,6 @@ describe("Crafatar", function() { }); }); }); - describe("Avatar", function() { // profile "Alex" - hoping it'll never have a skin var alex_uuid = "ec561538f3fd461daff5086b22154bce"; From 2c1173b8a54f147e30b64ec6a4b9299a75ad8431 Mon Sep 17 00:00:00 2001 From: Jake Date: Tue, 10 Feb 2015 22:02:02 -0600 Subject: [PATCH 11/17] log location --- test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test.js b/test/test.js index ebc0a58..d1ad371 100644 --- a/test/test.js +++ b/test/test.js @@ -248,7 +248,7 @@ describe("Server", function() { }); }); - it("should return a 200 (valid input)", function(done) { + it("should return a 200 (valid input " + location + ")", function(done) { request.get("http://localhost:3000/" + location + "/Jake0oo0", function(error, res, body) { assert.equal(200, res.statusCode); done(); From 5a06e99643357312b4f52c96f7ff8b8c7b5cd848 Mon Sep 17 00:00:00 2001 From: Jake Date: Wed, 11 Feb 2015 18:25:56 -0600 Subject: [PATCH 12/17] Why does only one test seem to be processed --- routes/avatars.js | 5 ++ test/test.js | 219 +++++++++++++++++++++++----------------------- 2 files changed, 114 insertions(+), 110 deletions(-) diff --git a/routes/avatars.js b/routes/avatars.js index 09f0561..814580a 100644 --- a/routes/avatars.js +++ b/routes/avatars.js @@ -45,8 +45,12 @@ module.exports = function(req, res) { userId = userId.replace(/-/g, ""); logging.log(rid + "userid: " + userId); + console.log("THIS WAS CALLED") + try { + console.log("TRIED") helpers.get_avatar(rid, userId, helm, size, function(err, status, image, hash) { + console.log("I DID RUN COVERALLS!!") logging.log(rid + "storage type: " + human_status[status]); if (err) { logging.error(rid + err); @@ -72,6 +76,7 @@ module.exports = function(req, res) { } }); } catch(e) { + console.log("FAILED") logging.error(rid + "error: " + e.stack); handle_default(rid, 500, -1, userId); } diff --git a/test/test.js b/test/test.js index d1ad371..c632c1e 100644 --- a/test/test.js +++ b/test/test.js @@ -1,6 +1,5 @@ var assert = require("assert"); var fs = require("fs"); - var networking = require("../modules/networking"); var helpers = require("../modules/helpers"); var logging = require("../modules/logging"); @@ -32,10 +31,10 @@ function getRandomInt(min, max) { } var ids = [ -uuid.toLowerCase(), -name.toLowerCase(), -uuid.toUpperCase(), -name.toUpperCase(), + uuid.toLowerCase(), + name.toLowerCase(), + name.toUpperCase(), + uuid.toUpperCase(), ]; describe("Crafatar", function() { @@ -102,7 +101,7 @@ describe("Crafatar", function() { }); }); }); -describe("Avatar", function() { + describe("Avatar", function() { // profile "Alex" - hoping it'll never have a skin var alex_uuid = "ec561538f3fd461daff5086b22154bce"; // profile "Steven" (Steve doesn't exist) - hoping it'll never have a skin @@ -126,62 +125,62 @@ describe("Avatar", function() { done(); }); }); -describe("Errors", function() { - it("should time out on uuid info download", function(done) { - var original_timeout = config.http_timeout; - config.http_timeout = 1; - networking.get_profile(rid, "069a79f444e94726a5befca90e38aaf5", function(err, profile) { - assert.strictEqual(err.code, "ETIMEDOUT"); - config.http_timeout = original_timeout; - done(); + describe("Errors", function() { + it("should time out on uuid info download", function(done) { + var original_timeout = config.http_timeout; + config.http_timeout = 1; + networking.get_profile(rid, "069a79f444e94726a5befca90e38aaf5", function(err, profile) { + assert.strictEqual(err.code, "ETIMEDOUT"); + config.http_timeout = original_timeout; + done(); + }); }); - }); - it("should time out on username info download", function(done) { - var original_timeout = config.http_timeout; - config.http_timeout = 1; - networking.get_username_url(rid, "jomo", 0, function(err, url) { - assert.strictEqual(err.code, "ETIMEDOUT"); - config.http_timeout = original_timeout; - done(); + it("should time out on username info download", function(done) { + var original_timeout = config.http_timeout; + config.http_timeout = 1; + networking.get_username_url(rid, "jomo", 0, function(err, url) { + assert.strictEqual(err.code, "ETIMEDOUT"); + config.http_timeout = original_timeout; + done(); + }); }); - }); - it("should time out on skin download", function(done) { - var original_timeout = config.http_timeout; - config.http_timeout = 1; - networking.get_from(rid, "http://textures.minecraft.net/texture/477be35554684c28bdeee4cf11c591d3c88afb77e0b98da893fd7bc318c65184", function(body, res, error) { - assert.strictEqual(error.code, "ETIMEDOUT"); - config.http_timeout = original_timeout; - done(); + it("should time out on skin download", function(done) { + var original_timeout = config.http_timeout; + config.http_timeout = 1; + networking.get_from(rid, "http://textures.minecraft.net/texture/477be35554684c28bdeee4cf11c591d3c88afb77e0b98da893fd7bc318c65184", function(body, res, error) { + assert.strictEqual(error.code, "ETIMEDOUT"); + config.http_timeout = original_timeout; + done(); + }); }); - }); - it("should not find the skin", function(done) { - assert.doesNotThrow(function() { - networking.get_from(rid, "http://textures.minecraft.net/texture/this-does-not-exist", function(img, response, err) { + it("should not find the skin", function(done) { + assert.doesNotThrow(function() { + networking.get_from(rid, "http://textures.minecraft.net/texture/this-does-not-exist", function(img, response, err) { assert.strictEqual(err, null); // no error here, but it shouldn't throw exceptions done(); }); + }); }); - }); - it("should ignore file updates on invalid files", function(done) { - assert.doesNotThrow(function() { - cache.update_timestamp(rid, "0123456789abcdef0123456789abcdef", "invalid-file.png"); - }); - done(); - }); - it("should not find the file", function(done) { - skins.open_skin(rid, "non/existant/path", function(err, img) { - assert.notStrictEqual(err, null); + it("should ignore file updates on invalid files", function(done) { + assert.doesNotThrow(function() { + cache.update_timestamp(rid, "0123456789abcdef0123456789abcdef", "invalid-file.png"); + }); done(); }); + it("should not find the file", function(done) { + skins.open_skin(rid, "non/existant/path", function(err, img) { + assert.notStrictEqual(err, null); + done(); + }); + }); }); -}); -describe("Server", function() { - before(function(done) { - server.boot(function() { - done(); + describe("Server", function() { + before(function(done) { + server.boot(function() { + done(); + }); }); - }); // Test the home page it("should return a 200 (home page)", function(done) { @@ -241,6 +240,12 @@ describe("Server", function() { var locations = ["avatars", "capes", "skins", "renders/head"] for (var l in locations) { var location = locations[l]; + it("should return a 200 (valid input " + location + ")", function(done) { + request.get("http://localhost:3000/" + location + "/Jake0oo0", function(error, res, body) { + assert.equal(200, res.statusCode); + done(); + }); + }); it("should return a 422 (invalid id " + location + ")", function(done) { request.get("http://localhost:3000/" + location + "/thisisaninvaliduuid", function(error, res, body) { assert.equal(422, res.statusCode); @@ -248,12 +253,6 @@ describe("Server", function() { }); }); - it("should return a 200 (valid input " + location + ")", function(done) { - request.get("http://localhost:3000/" + location + "/Jake0oo0", function(error, res, body) { - assert.equal(200, res.statusCode); - done(); - }); - }); } // testing all paths for default images @@ -380,61 +379,61 @@ describe("Server", function() { } }); -describe("Networking: Skin", function() { - it("should not fail (uuid)", function(done) { - helpers.get_skin(rid, id, function(err, hash, img) { - assert.strictEqual(err, null); - done(); - }); - }); -}); - -describe("Networking: Render", function() { - it("should not fail (full body)", function(done) { - helpers.get_render(rid, id, 6, true, true, function(err, hash, img) { - assert.strictEqual(err, null); - done(); - }); - }); - it("should not fail (only head)", function(done) { - helpers.get_render(rid, id, 6, true, false, function(err, hash, img) { - assert.strictEqual(err, null); - done(); - }); - }); -}); - -describe("Networking: Cape", function() { - it("should not fail (possible cape)", function(done) { - helpers.get_cape(rid, id, function(err, hash, img) { - assert.strictEqual(err, null); - done(); - }); - }); -}); - - -describe("Errors", function() { - before(function() { - cache.get_redis().flushall(); - }); - - if (id_type == "uuid") { - it("uuid should be rate limited", function(done) { - networking.get_profile(rid, id, function(err, profile) { - assert.strictEqual(profile.error, "TooManyRequestsException"); - done(); + describe("Networking: Skin", function() { + it("should not fail (uuid)", function(done) { + helpers.get_skin(rid, id, function(err, hash, img) { + assert.strictEqual(err, null); + done(); + }); + }); }); - }); - } else { - it("username should NOT be rate limited (username)", function(done) { - helpers.get_avatar(rid, id, false, 160, function(err, status, image) { - assert.strictEqual(err, null); - done(); + + describe("Networking: Render", function() { + it("should not fail (full body)", function(done) { + helpers.get_render(rid, id, 6, true, true, function(err, hash, img) { + assert.strictEqual(err, null); + done(); + }); + }); + it("should not fail (only head)", function(done) { + helpers.get_render(rid, id, 6, true, false, function(err, hash, img) { + assert.strictEqual(err, null); + done(); + }); + }); }); - }); + + describe("Networking: Cape", function() { + it("should not fail (possible cape)", function(done) { + helpers.get_cape(rid, id, function(err, hash, img) { + assert.strictEqual(err, null); + done(); + }); + }); + }); + + + describe("Errors", function() { + before(function() { + cache.get_redis().flushall(); + }); + + if (id_type == "uuid") { + it("uuid should be rate limited", function(done) { + networking.get_profile(rid, id, function(err, profile) { + assert.strictEqual(profile.error, "TooManyRequestsException"); + done(); + }); + }); + } else { + it("username should NOT be rate limited (username)", function(done) { + helpers.get_avatar(rid, id, false, 160, function(err, status, image) { + assert.strictEqual(err, null); + done(); + }); + }); + } + }); + })(id, id_type); } -}); -})(id, id_type); -} }); \ No newline at end of file From 20d8b281bdd2c95aa78633d95b8bb4ac16f63352 Mon Sep 17 00:00:00 2001 From: Jake Date: Wed, 11 Feb 2015 19:31:05 -0600 Subject: [PATCH 13/17] welp..fix --- .travis.yml | 1 - routes/avatars.js | 4 - test/test.js | 266 +++++++++++++++++++++++----------------------- 3 files changed, 135 insertions(+), 136 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9ea3bea..2ff2b7f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: node_js node_js: - "0.10" - - "0.12" before_script: - cp "modules/config.example.js" "modules/config.js" before_install: diff --git a/routes/avatars.js b/routes/avatars.js index 814580a..edb76c7 100644 --- a/routes/avatars.js +++ b/routes/avatars.js @@ -45,12 +45,9 @@ module.exports = function(req, res) { userId = userId.replace(/-/g, ""); logging.log(rid + "userid: " + userId); - console.log("THIS WAS CALLED") try { - console.log("TRIED") helpers.get_avatar(rid, userId, helm, size, function(err, status, image, hash) { - console.log("I DID RUN COVERALLS!!") logging.log(rid + "storage type: " + human_status[status]); if (err) { logging.error(rid + err); @@ -76,7 +73,6 @@ module.exports = function(req, res) { } }); } catch(e) { - console.log("FAILED") logging.error(rid + "error: " + e.stack); handle_default(rid, 500, -1, userId); } diff --git a/test/test.js b/test/test.js index c632c1e..a57cbaf 100644 --- a/test/test.js +++ b/test/test.js @@ -31,10 +31,10 @@ function getRandomInt(min, max) { } var ids = [ - uuid.toLowerCase(), - name.toLowerCase(), - name.toUpperCase(), - uuid.toUpperCase(), +uuid.toLowerCase(), +name.toLowerCase(), +name.toUpperCase(), +uuid.toUpperCase(), ]; describe("Crafatar", function() { @@ -101,7 +101,7 @@ describe("Crafatar", function() { }); }); }); - describe("Avatar", function() { +describe("Avatar", function() { // profile "Alex" - hoping it'll never have a skin var alex_uuid = "ec561538f3fd461daff5086b22154bce"; // profile "Steven" (Steve doesn't exist) - hoping it'll never have a skin @@ -125,62 +125,62 @@ describe("Crafatar", function() { done(); }); }); - describe("Errors", function() { - it("should time out on uuid info download", function(done) { - var original_timeout = config.http_timeout; - config.http_timeout = 1; - networking.get_profile(rid, "069a79f444e94726a5befca90e38aaf5", function(err, profile) { - assert.strictEqual(err.code, "ETIMEDOUT"); - config.http_timeout = original_timeout; - done(); - }); +describe("Errors", function() { + it("should time out on uuid info download", function(done) { + var original_timeout = config.http_timeout; + config.http_timeout = 1; + networking.get_profile(rid, "069a79f444e94726a5befca90e38aaf5", function(err, profile) { + assert.strictEqual(err.code, "ETIMEDOUT"); + config.http_timeout = original_timeout; + done(); }); - it("should time out on username info download", function(done) { - var original_timeout = config.http_timeout; - config.http_timeout = 1; - networking.get_username_url(rid, "jomo", 0, function(err, url) { - assert.strictEqual(err.code, "ETIMEDOUT"); - config.http_timeout = original_timeout; - done(); - }); + }); + it("should time out on username info download", function(done) { + var original_timeout = config.http_timeout; + config.http_timeout = 1; + networking.get_username_url(rid, "jomo", 0, function(err, url) { + assert.strictEqual(err.code, "ETIMEDOUT"); + config.http_timeout = original_timeout; + done(); }); - it("should time out on skin download", function(done) { - var original_timeout = config.http_timeout; - config.http_timeout = 1; - networking.get_from(rid, "http://textures.minecraft.net/texture/477be35554684c28bdeee4cf11c591d3c88afb77e0b98da893fd7bc318c65184", function(body, res, error) { - assert.strictEqual(error.code, "ETIMEDOUT"); - config.http_timeout = original_timeout; - done(); - }); + }); + it("should time out on skin download", function(done) { + var original_timeout = config.http_timeout; + config.http_timeout = 1; + networking.get_from(rid, "http://textures.minecraft.net/texture/477be35554684c28bdeee4cf11c591d3c88afb77e0b98da893fd7bc318c65184", function(body, res, error) { + assert.strictEqual(error.code, "ETIMEDOUT"); + config.http_timeout = original_timeout; + done(); }); - it("should not find the skin", function(done) { - assert.doesNotThrow(function() { - networking.get_from(rid, "http://textures.minecraft.net/texture/this-does-not-exist", function(img, response, err) { + }); + it("should not find the skin", function(done) { + assert.doesNotThrow(function() { + networking.get_from(rid, "http://textures.minecraft.net/texture/this-does-not-exist", function(img, response, err) { assert.strictEqual(err, null); // no error here, but it shouldn't throw exceptions done(); }); - }); - }); - it("should ignore file updates on invalid files", function(done) { - assert.doesNotThrow(function() { - cache.update_timestamp(rid, "0123456789abcdef0123456789abcdef", "invalid-file.png"); - }); - done(); - }); - it("should not find the file", function(done) { - skins.open_skin(rid, "non/existant/path", function(err, img) { - assert.notStrictEqual(err, null); - done(); - }); }); }); - - describe("Server", function() { - before(function(done) { - server.boot(function() { - done(); - }); + it("should ignore file updates on invalid files", function(done) { + assert.doesNotThrow(function() { + cache.update_timestamp(rid, "0123456789abcdef0123456789abcdef", "invalid-file.png"); }); + done(); + }); + it("should not find the file", function(done) { + skins.open_skin(rid, "non/existant/path", function(err, img) { + assert.notStrictEqual(err, null); + done(); + }); + }); +}); + +describe("Server", function() { + before(function(done) { + server.boot(function() { + done(); + }); + }); // Test the home page it("should return a 200 (home page)", function(done) { @@ -240,38 +240,42 @@ describe("Crafatar", function() { var locations = ["avatars", "capes", "skins", "renders/head"] for (var l in locations) { var location = locations[l]; - it("should return a 200 (valid input " + location + ")", function(done) { - request.get("http://localhost:3000/" + location + "/Jake0oo0", function(error, res, body) { - assert.equal(200, res.statusCode); - done(); + (function(location) { + if (location !== "capes") { + it("should return a 200 (valid input " + location + ")", function(done) { + request.get("http://localhost:3000/" + location + "/Jake0oo0", function(error, res, body) { + assert.equal(200, res.statusCode); + done(); + }); + }) + } + it("should return a 422 (invalid id " + location + ")", function(done) { + request.get("http://localhost:3000/" + location + "/thisisaninvaliduuid", function(error, res, body) { + assert.equal(422, res.statusCode); + done(); + }); }); - }); - it("should return a 422 (invalid id " + location + ")", function(done) { - request.get("http://localhost:3000/" + location + "/thisisaninvaliduuid", function(error, res, body) { - assert.equal(422, res.statusCode); - done(); - }); - }); - + })(location); } - // testing all paths for default images - locations = ["avatars", "capes", "skins"] + //testing all paths for default images + locations = ["avatars", "skins"] for (var l in locations) { var location = locations[l]; - it("should return a 404 (default steve image " + location + ")", function(done) { - request.get("http://localhost:3000/" + location + "/invalidjsvns?default=steve", function(error, res, body) { - assert.equal(404, res.statusCode); - done(); + (function(location) { + it("should return a 404 (default steve image " + location + ")", function(done) { + request.get("http://localhost:3000/" + location + "/invalidjsvns?default=steve", function(error, res, body) { + assert.equal(404, res.statusCode); + done(); + }); }); - }); - - it("should return a 200 (default external image " + location + ")", function(done) { - request.get("http://localhost:3000/" + location + "/invalidjsvns?default=https%3A%2F%2Fi.imgur.com%2FocJVWAc.png", function(error, res, body) { - assert.equal(200, res.statusCode); - done(); + it("should return a 200 (default external image " + location + ")", function(done) { + request.get("http://localhost:3000/" + location + "/invalidjsvns?default=https%3A%2F%2Fi.imgur.com%2FocJVWAc.png", function(error, res, body) { + assert.equal(200, res.statusCode); + done(); + }); }); - }); + })(location); } after(function(done) { @@ -379,61 +383,61 @@ describe("Crafatar", function() { } }); - describe("Networking: Skin", function() { - it("should not fail (uuid)", function(done) { - helpers.get_skin(rid, id, function(err, hash, img) { - assert.strictEqual(err, null); - done(); - }); - }); +describe("Networking: Skin", function() { + it("should not fail (uuid)", function(done) { + helpers.get_skin(rid, id, function(err, hash, img) { + assert.strictEqual(err, null); + done(); + }); + }); +}); + +describe("Networking: Render", function() { + it("should not fail (full body)", function(done) { + helpers.get_render(rid, id, 6, true, true, function(err, hash, img) { + assert.strictEqual(err, null); + done(); + }); + }); + it("should not fail (only head)", function(done) { + helpers.get_render(rid, id, 6, true, false, function(err, hash, img) { + assert.strictEqual(err, null); + done(); + }); + }); +}); + +describe("Networking: Cape", function() { + it("should not fail (possible cape)", function(done) { + helpers.get_cape(rid, id, function(err, hash, img) { + assert.strictEqual(err, null); + done(); + }); + }); +}); + + +describe("Errors", function() { + before(function() { + cache.get_redis().flushall(); + }); + + if (id_type == "uuid") { + it("uuid should be rate limited", function(done) { + networking.get_profile(rid, id, function(err, profile) { + assert.strictEqual(profile.error, "TooManyRequestsException"); + done(); }); - - describe("Networking: Render", function() { - it("should not fail (full body)", function(done) { - helpers.get_render(rid, id, 6, true, true, function(err, hash, img) { - assert.strictEqual(err, null); - done(); - }); - }); - it("should not fail (only head)", function(done) { - helpers.get_render(rid, id, 6, true, false, function(err, hash, img) { - assert.strictEqual(err, null); - done(); - }); - }); + }); + } else { + it("username should NOT be rate limited (username)", function(done) { + helpers.get_avatar(rid, id, false, 160, function(err, status, image) { + assert.strictEqual(err, null); + done(); }); - - describe("Networking: Cape", function() { - it("should not fail (possible cape)", function(done) { - helpers.get_cape(rid, id, function(err, hash, img) { - assert.strictEqual(err, null); - done(); - }); - }); - }); - - - describe("Errors", function() { - before(function() { - cache.get_redis().flushall(); - }); - - if (id_type == "uuid") { - it("uuid should be rate limited", function(done) { - networking.get_profile(rid, id, function(err, profile) { - assert.strictEqual(profile.error, "TooManyRequestsException"); - done(); - }); - }); - } else { - it("username should NOT be rate limited (username)", function(done) { - helpers.get_avatar(rid, id, false, 160, function(err, status, image) { - assert.strictEqual(err, null); - done(); - }); - }); - } - }); - })(id, id_type); + }); } +}); +})(id, id_type); +} }); \ No newline at end of file From 7e890adf621721aa15f9ac1ecaebbd6aa49e4518 Mon Sep 17 00:00:00 2001 From: Jake Date: Wed, 11 Feb 2015 20:00:18 -0600 Subject: [PATCH 14/17] test default images for renders --- test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test.js b/test/test.js index a57cbaf..32115d1 100644 --- a/test/test.js +++ b/test/test.js @@ -259,7 +259,7 @@ describe("Server", function() { } //testing all paths for default images - locations = ["avatars", "skins"] + locations = ["avatars", "skins", "renders/head"] for (var l in locations) { var location = locations[l]; (function(location) { From c062348f40b421dcf54eb1f678c232da6321e603 Mon Sep 17 00:00:00 2001 From: Jake Date: Wed, 11 Feb 2015 20:16:55 -0600 Subject: [PATCH 15/17] Separate some test loops --- test/test.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/test/test.js b/test/test.js index 32115d1..2716f28 100644 --- a/test/test.js +++ b/test/test.js @@ -236,19 +236,31 @@ describe("Server", function() { }); }); + // testing all paths for valid inputs + var locations = ["avatars", "skins", "renders/head"] + for (var l in locations) { + var location = locations[l]; + (function(location) { + it("should return a 200 (valid input " + location + ")", function(done) { + request.get("http://localhost:3000/" + location + "/Jake0oo0", function(error, res, body) { + assert.equal(200, res.statusCode); + done(); + }); + }) + it("should return a 422 (invalid id " + location + ")", function(done) { + request.get("http://localhost:3000/" + location + "/thisisaninvaliduuid", function(error, res, body) { + assert.equal(422, res.statusCode); + done(); + }); + }); + })(location); + } + // testing all paths for invalid id formats var locations = ["avatars", "capes", "skins", "renders/head"] for (var l in locations) { var location = locations[l]; (function(location) { - if (location !== "capes") { - it("should return a 200 (valid input " + location + ")", function(done) { - request.get("http://localhost:3000/" + location + "/Jake0oo0", function(error, res, body) { - assert.equal(200, res.statusCode); - done(); - }); - }) - } it("should return a 422 (invalid id " + location + ")", function(done) { request.get("http://localhost:3000/" + location + "/thisisaninvaliduuid", function(error, res, body) { assert.equal(422, res.statusCode); From 5a4306db6a447d1345bc5a6780779957732aa96c Mon Sep 17 00:00:00 2001 From: Jake Date: Wed, 11 Feb 2015 20:26:29 -0600 Subject: [PATCH 16/17] force the cleaner to run, better coverage --- test/test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/test.js b/test/test.js index 2716f28..0ece3c1 100644 --- a/test/test.js +++ b/test/test.js @@ -43,6 +43,10 @@ describe("Crafatar", function() { before(function() { cache.get_redis().flushall(); + // largest possible integers, cause I don't know + // how big hard drives are these days + config.cleaning_disk_limit = Math.pow(2,32) - 1;; + config.cleaning_redis_limit = Math.pow(2,32) - 1;; cleaner.run(); }); @@ -175,6 +179,10 @@ describe("Errors", function() { }); }); +describe("Cleaner", function() { + +}); + describe("Server", function() { before(function(done) { server.boot(function() { From 242ea2df511bea617bda7be9c5285370d6de4c7a Mon Sep 17 00:00:00 2001 From: Jake Date: Wed, 11 Feb 2015 20:29:22 -0600 Subject: [PATCH 17/17] Format --- test/test.js | 216 +++++++++++++++++++++++++-------------------------- 1 file changed, 106 insertions(+), 110 deletions(-) diff --git a/test/test.js b/test/test.js index 0ece3c1..d910ddc 100644 --- a/test/test.js +++ b/test/test.js @@ -31,10 +31,10 @@ function getRandomInt(min, max) { } var ids = [ -uuid.toLowerCase(), -name.toLowerCase(), -name.toUpperCase(), -uuid.toUpperCase(), + uuid.toLowerCase(), + name.toLowerCase(), + name.toUpperCase(), + uuid.toUpperCase(), ]; describe("Crafatar", function() { @@ -45,8 +45,8 @@ describe("Crafatar", function() { cache.get_redis().flushall(); // largest possible integers, cause I don't know // how big hard drives are these days - config.cleaning_disk_limit = Math.pow(2,32) - 1;; - config.cleaning_redis_limit = Math.pow(2,32) - 1;; + config.cleaning_disk_limit = Math.pow(2, 32) - 1;; + config.cleaning_redis_limit = Math.pow(2, 32) - 1;; cleaner.run(); }); @@ -105,7 +105,7 @@ describe("Crafatar", function() { }); }); }); -describe("Avatar", function() { + describe("Avatar", function() { // profile "Alex" - hoping it'll never have a skin var alex_uuid = "ec561538f3fd461daff5086b22154bce"; // profile "Steven" (Steve doesn't exist) - hoping it'll never have a skin @@ -129,67 +129,63 @@ describe("Avatar", function() { done(); }); }); -describe("Errors", function() { - it("should time out on uuid info download", function(done) { - var original_timeout = config.http_timeout; - config.http_timeout = 1; - networking.get_profile(rid, "069a79f444e94726a5befca90e38aaf5", function(err, profile) { - assert.strictEqual(err.code, "ETIMEDOUT"); - config.http_timeout = original_timeout; - done(); + describe("Errors", function() { + it("should time out on uuid info download", function(done) { + var original_timeout = config.http_timeout; + config.http_timeout = 1; + networking.get_profile(rid, "069a79f444e94726a5befca90e38aaf5", function(err, profile) { + assert.strictEqual(err.code, "ETIMEDOUT"); + config.http_timeout = original_timeout; + done(); + }); }); - }); - it("should time out on username info download", function(done) { - var original_timeout = config.http_timeout; - config.http_timeout = 1; - networking.get_username_url(rid, "jomo", 0, function(err, url) { - assert.strictEqual(err.code, "ETIMEDOUT"); - config.http_timeout = original_timeout; - done(); + it("should time out on username info download", function(done) { + var original_timeout = config.http_timeout; + config.http_timeout = 1; + networking.get_username_url(rid, "jomo", 0, function(err, url) { + assert.strictEqual(err.code, "ETIMEDOUT"); + config.http_timeout = original_timeout; + done(); + }); }); - }); - it("should time out on skin download", function(done) { - var original_timeout = config.http_timeout; - config.http_timeout = 1; - networking.get_from(rid, "http://textures.minecraft.net/texture/477be35554684c28bdeee4cf11c591d3c88afb77e0b98da893fd7bc318c65184", function(body, res, error) { - assert.strictEqual(error.code, "ETIMEDOUT"); - config.http_timeout = original_timeout; - done(); + it("should time out on skin download", function(done) { + var original_timeout = config.http_timeout; + config.http_timeout = 1; + networking.get_from(rid, "http://textures.minecraft.net/texture/477be35554684c28bdeee4cf11c591d3c88afb77e0b98da893fd7bc318c65184", function(body, res, error) { + assert.strictEqual(error.code, "ETIMEDOUT"); + config.http_timeout = original_timeout; + done(); + }); }); - }); - it("should not find the skin", function(done) { - assert.doesNotThrow(function() { - networking.get_from(rid, "http://textures.minecraft.net/texture/this-does-not-exist", function(img, response, err) { + it("should not find the skin", function(done) { + assert.doesNotThrow(function() { + networking.get_from(rid, "http://textures.minecraft.net/texture/this-does-not-exist", function(img, response, err) { assert.strictEqual(err, null); // no error here, but it shouldn't throw exceptions done(); }); + }); }); - }); - it("should ignore file updates on invalid files", function(done) { - assert.doesNotThrow(function() { - cache.update_timestamp(rid, "0123456789abcdef0123456789abcdef", "invalid-file.png"); - }); - done(); - }); - it("should not find the file", function(done) { - skins.open_skin(rid, "non/existant/path", function(err, img) { - assert.notStrictEqual(err, null); + it("should ignore file updates on invalid files", function(done) { + assert.doesNotThrow(function() { + cache.update_timestamp(rid, "0123456789abcdef0123456789abcdef", "invalid-file.png"); + }); done(); }); - }); -}); - -describe("Cleaner", function() { - -}); - -describe("Server", function() { - before(function(done) { - server.boot(function() { - done(); + it("should not find the file", function(done) { + skins.open_skin(rid, "non/existant/path", function(err, img) { + assert.notStrictEqual(err, null); + done(); + }); }); }); + describe("Server", function() { + before(function(done) { + server.boot(function() { + done(); + }); + }); + // Test the home page it("should return a 200 (home page)", function(done) { request.get("http://localhost:3000", function(error, res, body) { @@ -403,61 +399,61 @@ describe("Server", function() { } }); -describe("Networking: Skin", function() { - it("should not fail (uuid)", function(done) { - helpers.get_skin(rid, id, function(err, hash, img) { - assert.strictEqual(err, null); - done(); - }); - }); -}); - -describe("Networking: Render", function() { - it("should not fail (full body)", function(done) { - helpers.get_render(rid, id, 6, true, true, function(err, hash, img) { - assert.strictEqual(err, null); - done(); - }); - }); - it("should not fail (only head)", function(done) { - helpers.get_render(rid, id, 6, true, false, function(err, hash, img) { - assert.strictEqual(err, null); - done(); - }); - }); -}); - -describe("Networking: Cape", function() { - it("should not fail (possible cape)", function(done) { - helpers.get_cape(rid, id, function(err, hash, img) { - assert.strictEqual(err, null); - done(); - }); - }); -}); - - -describe("Errors", function() { - before(function() { - cache.get_redis().flushall(); - }); - - if (id_type == "uuid") { - it("uuid should be rate limited", function(done) { - networking.get_profile(rid, id, function(err, profile) { - assert.strictEqual(profile.error, "TooManyRequestsException"); - done(); + describe("Networking: Skin", function() { + it("should not fail (uuid)", function(done) { + helpers.get_skin(rid, id, function(err, hash, img) { + assert.strictEqual(err, null); + done(); + }); + }); }); - }); - } else { - it("username should NOT be rate limited (username)", function(done) { - helpers.get_avatar(rid, id, false, 160, function(err, status, image) { - assert.strictEqual(err, null); - done(); + + describe("Networking: Render", function() { + it("should not fail (full body)", function(done) { + helpers.get_render(rid, id, 6, true, true, function(err, hash, img) { + assert.strictEqual(err, null); + done(); + }); + }); + it("should not fail (only head)", function(done) { + helpers.get_render(rid, id, 6, true, false, function(err, hash, img) { + assert.strictEqual(err, null); + done(); + }); + }); }); - }); + + describe("Networking: Cape", function() { + it("should not fail (possible cape)", function(done) { + helpers.get_cape(rid, id, function(err, hash, img) { + assert.strictEqual(err, null); + done(); + }); + }); + }); + + + describe("Errors", function() { + before(function() { + cache.get_redis().flushall(); + }); + + if (id_type == "uuid") { + it("uuid should be rate limited", function(done) { + networking.get_profile(rid, id, function(err, profile) { + assert.strictEqual(profile.error, "TooManyRequestsException"); + done(); + }); + }); + } else { + it("username should NOT be rate limited (username)", function(done) { + helpers.get_avatar(rid, id, false, 160, function(err, status, image) { + assert.strictEqual(err, null); + done(); + }); + }); + } + }); + })(id, id_type); } -}); -})(id, id_type); -} }); \ No newline at end of file