| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719 | 
							- /* globals describe, it, before, after */
 
- /* eslint no-loop-func:0 guard-for-in:0 */
 
- // no spam
 
- var logging = require("../lib/logging");
 
- if (process.env.VERBOSE_TEST !== "true") {
 
-   logging.log = logging.debug = logging.warn = logging.error = function() {};
 
- }
 
- var networking = require("../lib/networking");
 
- var helpers = require("../lib/helpers");
 
- var request = require("request");
 
- var config = require("../config");
 
- var server = require("../lib/server");
 
- var assert = require("assert");
 
- var skins = require("../lib/skins");
 
- var cache = require("../lib/cache");
 
- var crc = require("crc").crc32;
 
- var fs = require("fs");
 
- // we don't want tests to fail because of slow internet
 
- config.server.http_timeout *= 3;
 
- var uuids = fs.readFileSync("test/uuids.txt").toString().split(/\r?\n/);
 
- // Get a random UUIDto prevent rate limiting
 
- var uuid = uuids[Math.round(Math.random() * (uuids.length - 1))];
 
- // Let's hope these will never be assigned
 
- var steve_ids = [
 
-   "fffffff0" + "fffffff0" + "fffffff0" + "fffffff0",
 
-   "fffffff0" + "fffffff0" + "fffffff1" + "fffffff1",
 
-   "fffffff0" + "fffffff1" + "fffffff0" + "fffffff1",
 
-   "fffffff0" + "fffffff1" + "fffffff1" + "fffffff0",
 
-   "fffffff1" + "fffffff0" + "fffffff0" + "fffffff1",
 
-   "fffffff1" + "fffffff0" + "fffffff1" + "fffffff0",
 
-   "fffffff1" + "fffffff1" + "fffffff0" + "fffffff0",
 
-   "fffffff1" + "fffffff1" + "fffffff1" + "fffffff1",
 
- ];
 
- // Let's hope these will never be assigned
 
- var alex_ids = [
 
-   "fffffff0" + "fffffff0" + "fffffff0" + "fffffff1",
 
-   "fffffff0" + "fffffff0" + "fffffff1" + "fffffff0",
 
-   "fffffff0" + "fffffff1" + "fffffff0" + "fffffff0",
 
-   "fffffff0" + "fffffff1" + "fffffff1" + "fffffff1",
 
-   "fffffff1" + "fffffff0" + "fffffff0" + "fffffff0",
 
-   "fffffff1" + "fffffff0" + "fffffff1" + "fffffff1",
 
-   "fffffff1" + "fffffff1" + "fffffff0" + "fffffff1",
 
-   "fffffff1" + "fffffff1" + "fffffff1" + "fffffff0",
 
- ];
 
- // generates a 12 character random string
 
- function rid() {
 
-   return Math.random().toString(36).substring(2, 14);
 
- }
 
- function getRandomInt(min, max) {
 
-   return Math.floor(Math.random() * (max - min + 1)) + min;
 
- }
 
- describe("Crafatar", function() {
 
-   // we might have to make 2 HTTP requests
 
-   this.timeout(config.server.http_timeout * 2 + 50);
 
-   before(function(done) {
 
-     console.log("Flushing and waiting for redis ...");
 
-     cache.get_redis().flushall(function() {
 
-       console.log("Redis flushed!");
 
-       done();
 
-     });
 
-   });
 
-   describe("UUID/username", function() {
 
-     it("non-hex uuid is invalid", function(done) {
 
-       assert.strictEqual(helpers.id_valid("g098cb60fa8e427cb299793cbd302c9a"), false);
 
-       done();
 
-     });
 
-     it("empty id is invalid", function(done) {
 
-       assert.strictEqual(helpers.id_valid(""), false);
 
-       done();
 
-     });
 
-     it("lowercase uuid is valid", function(done) {
 
-       assert.strictEqual(helpers.id_valid("0098cb60fa8e427cb299793cbd302c9a"), true);
 
-       done();
 
-     });
 
-     it("uppercase uuid is valid", function(done) {
 
-       assert.strictEqual(helpers.id_valid("1DCEF164FF0A47F2B9A691385C774EE7"), true);
 
-       done();
 
-     });
 
-     it("dashed uuid is valid", function(done) {
 
-       assert.strictEqual(helpers.id_valid("0098cb60-fa8e-427c-b299-793cbd302c9a"), true);
 
-       done();
 
-     });
 
-     it("username is invalid", function(done) {
 
-       assert.strictEqual(helpers.id_valid("__niceUs3rname__"), false);
 
-       done();
 
-     });
 
-     it("username alex is invalid", function(done) {
 
-       assert.strictEqual(helpers.id_valid("alex"), false);
 
-       done();
 
-     });
 
-     it("username mhf_alex is invalid", function(done) {
 
-       assert.strictEqual(helpers.id_valid("mhf_alex"), false);
 
-       done();
 
-     });
 
-     it("username steve is invalid", function(done) {
 
-       assert.strictEqual(helpers.id_valid("steve"), false);
 
-       done();
 
-     });
 
-     it("username mhf_steve is invalid", function(done) {
 
-       assert.strictEqual(helpers.id_valid("mhf_steve"), false);
 
-       done();
 
-     });
 
-     it(">16 length username is invalid", function(done) {
 
-       assert.strictEqual(helpers.id_valid("ThisNameIsTooLong"), false);
 
-       done();
 
-     });
 
-     it("should not exist (uuid)", function(done) {
 
-       var number = getRandomInt(0, 9).toString();
 
-       networking.get_profile(rid(), Array(33).join(number), function(err, profile) {
 
-         assert.ifError(err);
 
-         assert.strictEqual(profile, null);
 
-         done();
 
-       });
 
-     });
 
-   });
 
-   describe("Avatar", function() {
 
-     for (var a in alex_ids) {
 
-       var alexid = alex_ids[a];
 
-       (function(alex_id) {
 
-         it("UUID " + alex_id + " should default to MHF_Alex", function(done) {
 
-           assert.strictEqual(skins.default_skin(alex_id), "mhf_alex");
 
-           done();
 
-         });
 
-       }(alexid));
 
-     }
 
-     for (var s in steve_ids) {
 
-       var steveid = steve_ids[s];
 
-       (function(steve_id) {
 
-         it("UUID " + steve_id + " should default to MHF_Steve", function(done) {
 
-           assert.strictEqual(skins.default_skin(steve_id), "mhf_steve");
 
-           done();
 
-         });
 
-       }(steveid));
 
-     }
 
-   });
 
-   describe("Errors", function() {
 
-     it("should time out on uuid info download", function(done) {
 
-       var original_timeout = config.server.http_timeout;
 
-       config.server.http_timeout = 1;
 
-       networking.get_profile(rid(), "069a79f444e94726a5befca90e38aaf5", function(err, profile) {
 
-         assert.notStrictEqual(["ETIMEDOUT", "ESOCKETTIMEDOUT"].indexOf(err.code), -1);
 
-         config.server.http_timeout = original_timeout;
 
-         done();
 
-       });
 
-     });
 
-     it("should time out on skin download", function(done) {
 
-       var original_timeout = config.http_timeout;
 
-       config.server.http_timeout = 1;
 
-       networking.get_from(rid(), "http://textures.minecraft.net/texture/477be35554684c28bdeee4cf11c591d3c88afb77e0b98da893fd7bc318c65184", function(body, res, error) {
 
-         assert.notStrictEqual(["ETIMEDOUT", "ESOCKETTIMEDOUT"].indexOf(error.code), -1);
 
-         config.server.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) {
 
-           assert.strictEqual(err, null); // no error here, but it shouldn't throw exceptions
 
-           done();
 
-         });
 
-       });
 
-     });
 
-     it("should not find the file", function(done) {
 
-       skins.open_skin(rid(), "non/existent/path", function(err, img) {
 
-         assert(err);
 
-         done();
 
-       });
 
-     });
 
-   });
 
-   describe("Server", function() {
 
-     // throws Exception when default headers are not in res.headers
 
-     function assert_headers(res) {
 
-       assert(res.headers["content-type"]);
 
-       assert("" + res.headers["response-time"]);
 
-       assert(res.headers["x-request-id"]);
 
-       assert.equal(res.headers["access-control-allow-origin"], "*");
 
-       assert.equal(res.headers["cache-control"], "max-age=" + config.caching.browser);
 
-     }
 
-     // throws Exception when +url+ is requested with +etag+
 
-     // and it does not return 304 without a body
 
-     function assert_cache(url, etag, callback) {
 
-       request.get(url, {
 
-         headers: {
 
-           "If-None-Match": etag,
 
-         },
 
-       }, function(error, res, body) {
 
-         assert.ifError(error);
 
-         assert.strictEqual(body, '');
 
-         assert.equal(res.statusCode, 304);
 
-         assert_headers(res);
 
-         callback();
 
-       });
 
-     }
 
-     before(function(done) {
 
-       server.boot(function() {
 
-         done();
 
-       });
 
-     });
 
-     it("should return 405 Method Not Allowed for POST", function(done) {
 
-       request.post("http://localhost:3000", function(error, res, body) {
 
-         assert.ifError(error);
 
-         assert.strictEqual(res.statusCode, 405);
 
-         done();
 
-       });
 
-     });
 
-     it("should return correct HTTP response for home page", function(done) {
 
-       var url = "http://localhost:3000";
 
-       request.get(url, function(error, res, body) {
 
-         assert.ifError(error);
 
-         assert.strictEqual(res.statusCode, 200);
 
-         assert_headers(res);
 
-         assert(res.headers.etag);
 
-         assert.strictEqual(res.headers["content-type"], "text/html; charset=utf-8");
 
-         assert.strictEqual(res.headers.etag, '"' + crc(body) + '"');
 
-         assert(body);
 
-         assert_cache(url, res.headers.etag, function() {
 
-           done();
 
-         });
 
-       });
 
-     });
 
-     it("should return correct HTTP response for assets", function(done) {
 
-       var url = "http://localhost:3000/stylesheets/style.css";
 
-       request.get(url, function(error, res, body) {
 
-         assert.ifError(error);
 
-         assert.strictEqual(res.statusCode, 200);
 
-         assert_headers(res);
 
-         assert(res.headers.etag);
 
-         assert.strictEqual(res.headers["content-type"], "text/css");
 
-         assert.strictEqual(res.headers.etag, '"' + crc(body) + '"');
 
-         assert(body);
 
-         assert_cache(url, res.headers.etag, function() {
 
-           done();
 
-         });
 
-       });
 
-     });
 
-     it("should return correct HTTP response for URL encoded URLs", function(done) {
 
-       var url = "http://localhost:3000/%61%76%61%74%61%72%73/%61%65%37%39%35%61%61%38%36%33%32%37%34%30%38%65%39%32%61%62%32%35%63%38%61%35%39%66%33%62%61%31"; // avatars/ae795aa86327408e92ab25c8a59f3ba1
 
-       request.get(url, function(error, res, body) {
 
-         assert.ifError(error);
 
-         assert.strictEqual(res.statusCode, 200);
 
-         assert_headers(res);
 
-         assert(res.headers.etag);
 
-         assert.strictEqual(res.headers["content-type"], "image/png");
 
-         assert(body);
 
-         done();
 
-       });
 
-     });
 
-     it("should not fail on simultaneous requests", function(done) {
 
-       var url = "http://localhost:3000/avatars/696a82ce41f44b51aa31b8709b8686f0";
 
-       // 10 requests at once
 
-       var requests = 10;
 
-       var finished = 0;
 
-       function partDone() {
 
-         finished++;
 
-         if (requests === finished) {
 
-           done();
 
-         }
 
-       }
 
-       function req() {
 
-         request.get(url, function(error, res, body) {
 
-           assert.ifError(error);
 
-           assert.strictEqual(res.statusCode, 200);
 
-           assert_headers(res);
 
-           assert(res.headers.etag);
 
-           assert.strictEqual(res.headers["content-type"], "image/png");
 
-           assert(body);
 
-           partDone();
 
-         });
 
-       }
 
-       // make simultanous requests
 
-       for (var k = 0; k < requests; k++) {
 
-         req(k);
 
-       }
 
-   });
 
-     var server_tests = {
 
-       "avatar with existing uuid": {
 
-         url: "http://localhost:3000/avatars/853c80ef3c3749fdaa49938b674adae6?size=16",
 
-         crc32: [4264176600],
 
-       },
 
-       "avatar with non-existent uuid": {
 
-         url: "http://localhost:3000/avatars/00000000000000000000000000000000?size=16",
 
-         crc32: [3348154329],
 
-       },
 
-       "avatar with non-existent uuid defaulting to mhf_alex": {
 
-         url: "http://localhost:3000/avatars/00000000000000000000000000000000?size=16&default=mhf_alex",
 
-         crc32: [73899130],
 
-       },
 
-       "avatar with non-existent uuid defaulting to uuid": {
 
-         url: "http://localhost:3000/avatars/00000000000000000000000000000000?size=16&default=853c80ef3c3749fdaa49938b674adae6",
 
-         crc32: [0],
 
-         redirect: "/avatars/853c80ef3c3749fdaa49938b674adae6?size=16",
 
-       },
 
-       "avatar with non-existent uuid defaulting to url": {
 
-         url: "http://localhost:3000/avatars/00000000000000000000000000000000?size=16&default=http%3A%2F%2Fexample.com%2FCaseSensitive",
 
-         crc32: [0],
 
-         redirect: "http://example.com/CaseSensitive",
 
-       },
 
-       "overlay avatar with existing uuid": {
 
-         url: "http://localhost:3000/avatars/853c80ef3c3749fdaa49938b674adae6?size=16&overlay",
 
-         crc32: [575355728],
 
-       },
 
-       "overlay avatar with non-existent uuid": {
 
-         url: "http://localhost:3000/avatars/00000000000000000000000000000000?size=16&overlay",
 
-         crc32: [3348154329],
 
-       },
 
-       "overlay avatar with non-existent uuid defaulting to mhf_alex": {
 
-         url: "http://localhost:3000/avatars/00000000000000000000000000000000?size=16&overlay&default=mhf_alex",
 
-         crc32: [73899130],
 
-       },
 
-       "overlay avatar with non-existent uuid defaulting to uuid": {
 
-         url: "http://localhost:3000/avatars/00000000000000000000000000000000?size=16&default=853c80ef3c3749fdaa49938b674adae6",
 
-         crc32: [0],
 
-         redirect: "/avatars/853c80ef3c3749fdaa49938b674adae6?size=16",
 
-       },
 
-       "overlay avatar with non-existent uuid defaulting to url": {
 
-         url: "http://localhost:3000/avatars/00000000000000000000000000000000?size=16&overlay&default=http%3A%2F%2Fexample.com%2FCaseSensitive",
 
-         crc32: [0],
 
-         redirect: "http://example.com/CaseSensitive",
 
-       },
 
-       "cape with existing uuid": {
 
-         url: "http://localhost:3000/capes/853c80ef3c3749fdaa49938b674adae6",
 
-         crc32: [985789174],
 
-       },
 
-       "cape with non-existent uuid": {
 
-         url: "http://localhost:3000/capes/00000000000000000000000000000000",
 
-         crc32: [0],
 
-       },
 
-       "cape with non-existent uuid defaulting to url": {
 
-         url: "http://localhost:3000/capes/00000000000000000000000000000000?default=http%3A%2F%2Fexample.com%2FCaseSensitive",
 
-         crc32: [0],
 
-         redirect: "http://example.com/CaseSensitive",
 
-       },
 
-       "skin with existing uuid": {
 
-         url: "http://localhost:3000/skins/853c80ef3c3749fdaa49938b674adae6",
 
-         crc32: [1759176487],
 
-       },
 
-       "skin with non-existent uuid": {
 
-         url: "http://localhost:3000/skins/00000000000000000000000000000000",
 
-         crc32: [1853029228],
 
-       },
 
-       "skin with non-existent uuid defaulting to mhf_alex": {
 
-         url: "http://localhost:3000/skins/00000000000000000000000000000000?default=mhf_alex",
 
-         crc32: [427506205],
 
-       },
 
-       "skin with non-existent uuid defaulting to uuid": {
 
-         url: "http://localhost:3000/skins/00000000000000000000000000000000?size=16&default=853c80ef3c3749fdaa49938b674adae6",
 
-         crc32: [0],
 
-         redirect: "/skins/853c80ef3c3749fdaa49938b674adae6?size=16",
 
-       },
 
-       "skin with non-existent uuid defaulting to url": {
 
-         url: "http://localhost:3000/skins/00000000000000000000000000000000?default=http%3A%2F%2Fexample.com%2FCaseSensitive",
 
-         crc32: [0],
 
-         redirect: "http://example.com/CaseSensitive",
 
-       },
 
-       "head render with existing uuid": {
 
-         url: "http://localhost:3000/renders/head/853c80ef3c3749fdaa49938b674adae6?scale=2",
 
-         crc32: [1168786201],
 
-       },
 
-       "head render with non-existent uuid": {
 
-         url: "http://localhost:3000/renders/head/00000000000000000000000000000000?scale=2",
 
-         crc32: [3800926063],
 
-       },
 
-       "head render with non-existent uuid defaulting to mhf_alex": {
 
-         url: "http://localhost:3000/renders/head/00000000000000000000000000000000?scale=2&default=mhf_alex",
 
-         crc32: [4027858557],
 
-       },
 
-       "head render with non-existent uuid defaulting to uuid": {
 
-         url: "http://localhost:3000/renders/head/00000000000000000000000000000000?scale=2&default=853c80ef3c3749fdaa49938b674adae6",
 
-         crc32: [0],
 
-         redirect: "/renders/head/853c80ef3c3749fdaa49938b674adae6?scale=2",
 
-       },
 
-       "head render with non-existent uuid defaulting to url": {
 
-         url: "http://localhost:3000/renders/head/00000000000000000000000000000000?scale=2&default=http%3A%2F%2Fexample.com%2FCaseSensitive",
 
-         crc32: [0],
 
-         redirect: "http://example.com/CaseSensitive",
 
-       },
 
-       "overlay head render with existing uuid": {
 
-         url: "http://localhost:3000/renders/head/853c80ef3c3749fdaa49938b674adae6?scale=2&overlay",
 
-         crc32: [2880579826],
 
-       },
 
-       "overlay head render with non-existent uuid": {
 
-         url: "http://localhost:3000/renders/head/00000000000000000000000000000000?scale=2&overlay",
 
-         crc32: [3800926063],
 
-       },
 
-       "overlay head render with non-existent uuid defaulting to mhf_alex": {
 
-         url: "http://localhost:3000/renders/head/00000000000000000000000000000000?scale=2&overlay&default=mhf_alex",
 
-         crc32: [4027858557],
 
-       },
 
-       "overlay head with non-existent uuid defaulting to uuid": {
 
-         url: "http://localhost:3000/renders/head/00000000000000000000000000000000?scale=2&overlay&default=853c80ef3c3749fdaa49938b674adae6",
 
-         crc32: [0],
 
-         redirect: "/renders/head/853c80ef3c3749fdaa49938b674adae6?scale=2&overlay=",
 
-       },
 
-       "overlay head render with non-existent uuid defaulting to url": {
 
-         url: "http://localhost:3000/renders/head/00000000000000000000000000000000?scale=2&overlay&default=http%3A%2F%2Fexample.com%2FCaseSensitive",
 
-         crc32: [0],
 
-         redirect: "http://example.com/CaseSensitive",
 
-       },
 
-       "body render with existing uuid": {
 
-         url: "http://localhost:3000/renders/body/853c80ef3c3749fdaa49938b674adae6?scale=2",
 
-         crc32: [1144887125],
 
-       },
 
-       "body render with non-existent uuid": {
 
-         url: "http://localhost:3000/renders/body/00000000000000000000000000000000?scale=2",
 
-         crc32: [996962526],
 
-       },
 
-       "body render with non-existent uuid defaulting to mhf_alex": {
 
-         url: "http://localhost:3000/renders/body/00000000000000000000000000000000?scale=2&default=mhf_alex",
 
-         crc32: [4280894468],
 
-       },
 
-       "body render with non-existent uuid defaulting to uuid": {
 
-         url: "http://localhost:3000/renders/body/00000000000000000000000000000000?scale=2&default=853c80ef3c3749fdaa49938b674adae6",
 
-         crc32: [0],
 
-         redirect: "/renders/body/853c80ef3c3749fdaa49938b674adae6?scale=2",
 
-       },
 
-       "body render with non-existent uuid defaulting to url": {
 
-         url: "http://localhost:3000/renders/body/00000000000000000000000000000000?scale=2&default=http%3A%2F%2Fexample.com%2FCaseSensitive",
 
-         crc32: [0],
 
-         redirect: "http://example.com/CaseSensitive",
 
-       },
 
-       "overlay body render with existing uuid": {
 
-         url: "http://localhost:3000/renders/body/853c80ef3c3749fdaa49938b674adae6?scale=2&overlay",
 
-         crc32: [1107696668],
 
-       },
 
-       "overlay body render with non-existent uuid": {
 
-         url: "http://localhost:3000/renders/body/00000000000000000000000000000000?scale=2&overlay",
 
-         crc32: [996962526],
 
-       },
 
-       "overlay body render with non-existent uuid defaulting to mhf_alex": {
 
-         url: "http://localhost:3000/renders/body/00000000000000000000000000000000?scale=2&overlay&default=mhf_alex",
 
-         crc32: [4280894468],
 
-       },
 
-       "overlay body render with non-existent uuid defaulting to url": {
 
-         url: "http://localhost:3000/renders/body/00000000000000000000000000000000?scale=2&overlay&default=http%3A%2F%2Fexample.com%2FCaseSensitive",
 
-         crc32: [0],
 
-         redirect: "http://example.com/CaseSensitive",
 
-       },
 
-     };
 
-     for (var description in server_tests) {
 
-       var loc = server_tests[description];
 
-       (function(location) {
 
-         it("should return correct HTTP response for " + description, function(done) {
 
-           request.get(location.url, {followRedirect: false, encoding: null}, function(error, res, body) {
 
-             assert.ifError(error);
 
-             assert_headers(res);
 
-             assert(res.headers["x-storage-type"]);
 
-             var hash = crc(body);
 
-             var matches = false;
 
-             for (var c = 0; c < location.crc32.length; c++) {
 
-               if (location.crc32[c] === hash) {
 
-                 matches = true;
 
-                 break;
 
-               }
 
-             }
 
-             try {
 
-               assert(matches);
 
-             } catch(e) {
 
-               throw new Error(hash + " != " + location.crc32 + " | " + body.toString("base64"));
 
-             }
 
-             assert.strictEqual(res.headers.location, location.redirect);
 
-             if (location.crc32[0] === 0) {
 
-               assert.strictEqual(res.statusCode, location.redirect ? 307 : 404);
 
-               assert.ifError(res.headers.etag); // etag must not be present on non-200
 
-               assert.strictEqual(res.headers["content-type"], "text/plain");
 
-               done();
 
-             } else {
 
-               assert.strictEqual(res.headers["content-type"], "image/png");
 
-               assert.strictEqual(res.statusCode, 200);
 
-               assert(res.headers.etag);
 
-               assert.strictEqual(res.headers.etag, '"' + hash + '"');
 
-               assert_cache(location.url, res.headers.etag, function() {
 
-                 done();
 
-               });
 
-             }
 
-           });
 
-         });
 
-       }(loc));
 
-     }
 
-     it("should return 304 on server error", function(done) {
 
-       var original_debug = config.server.debug_enabled;
 
-       var original_timeout = config.server.http_timeout;
 
-       config.server.debug_enabled = false;
 
-       config.server.http_timeout = 1;
 
-       request.get({url: "http://localhost:3000/avatars/0000000000000000000000000000000f", headers: {"If-None-Match": '"some-etag"'}}, function(error, res, body) {
 
-         assert.ifError(error);
 
-         assert.strictEqual(body, '');
 
-         assert.strictEqual(res.statusCode, 304);
 
-         config.server.debug_enabled = original_debug;
 
-         config.server.http_timeout = original_timeout;
 
-         done();
 
-       });
 
-     });
 
-     it("should return a 422 (invalid size)", function(done) {
 
-       var size = config.avatars.max_size + 1;
 
-       request.get("http://localhost:3000/avatars/2d5aa9cdaeb049189930461fc9b91cc5?size=" + size, function(error, res, body) {
 
-         assert.ifError(error);
 
-         assert.strictEqual(res.statusCode, 422);
 
-         done();
 
-       });
 
-     });
 
-     it("should return a 422 (invalid scale)", function(done) {
 
-       var scale = config.renders.max_scale + 1;
 
-       request.get("http://localhost:3000/renders/head/2d5aa9cdaeb049189930461fc9b91cc5?scale=" + scale, function(error, res, body) {
 
-         assert.ifError(error);
 
-         assert.strictEqual(res.statusCode, 422);
 
-         done();
 
-       });
 
-     });
 
-     it("should return a 422 (invalid render type)", function(done) {
 
-       request.get("http://localhost:3000/renders/invalid/2d5aa9cdaeb049189930461fc9b91cc5", function(error, res, body) {
 
-         assert.ifError(error);
 
-         assert.strictEqual(res.statusCode, 422);
 
-         done();
 
-       });
 
-     });
 
-     // testing all paths for Invalid UUID
 
-     var locations = ["avatars", "skins", "capes", "renders/body", "renders/head"];
 
-     for (var l in locations) {
 
-       loc = locations[l];
 
-       (function(location) {
 
-         it("should return a 422 (invalid uuid " + location + ")", function(done) {
 
-           request.get("http://localhost:3000/" + location + "/thisisaninvaliduuid", function(error, res, body) {
 
-             assert.ifError(error);
 
-             assert.strictEqual(res.statusCode, 422);
 
-             done();
 
-           });
 
-         });
 
-         it("should return a 404 (invalid path " + location + ")", function(done) {
 
-           request.get("http://localhost:3000/" + location + "/853c80ef3c3749fdaa49938b674adae6/invalid", function(error, res, body) {
 
-             assert.ifError(error);
 
-             assert.strictEqual(res.statusCode, 404);
 
-             done();
 
-           });
 
-         });
 
-       }(loc));
 
-     }
 
-   });
 
-   // we have to make sure that we test both a 32x64 and 64x64 skin
 
-   describe("Networking: Render", function() {
 
-     it("should not fail (uuid, 32x64 skin)", function(done) {
 
-       helpers.get_render(rid(), "af74a02d19cb445bb07f6866a861f783", 6, true, true, function(err, hash, img) {
 
-         assert.strictEqual(err, null);
 
-         done();
 
-       });
 
-     });
 
-     it("should not fail (uuid, 64x64 skin)", function(done) {
 
-       helpers.get_render(rid(), "2d5aa9cdaeb049189930461fc9b91cc5", 6, true, true, function(err, hash, img) {
 
-         assert.strictEqual(err, null);
 
-         done();
 
-       });
 
-     });
 
-   });
 
-   describe("Networking: Cape", function() {
 
-     it("should not fail (guaranteed cape)", function(done) {
 
-       helpers.get_cape(rid(), "61699b2ed3274a019f1e0ea8c3f06bc6", function(err, hash, status, img) {
 
-         assert.strictEqual(err, null);
 
-         done();
 
-       });
 
-     });
 
-     it("should already exist", function(done) {
 
-       before(function() {
 
-         cache.get_redis().flushall();
 
-       });
 
-       helpers.get_cape(rid(), "61699b2ed3274a019f1e0ea8c3f06bc6", function(err, hash, status, img) {
 
-         assert.strictEqual(err, null);
 
-         done();
 
-       });
 
-     });
 
-     it("should not be found", function(done) {
 
-       helpers.get_cape(rid(), "2d5aa9cdaeb049189930461fc9b91cc5", function(err, hash, status, img) {
 
-         assert.ifError(err);
 
-         assert.strictEqual(img, null);
 
-         done();
 
-       });
 
-     });
 
-   });
 
-   describe("Networking: Skin", function() {
 
-     it("should not fail", function(done) {
 
-       helpers.get_cape(rid(), "2d5aa9cdaeb049189930461fc9b91cc5", function(err, hash, status, img) {
 
-         assert.strictEqual(err, null);
 
-         done();
 
-       });
 
-     });
 
-     it("should already exist", function(done) {
 
-       before(function() {
 
-         cache.get_redis().flushall();
 
-       });
 
-       helpers.get_cape(rid(), "2d5aa9cdaeb049189930461fc9b91cc5", function(err, hash, status, img) {
 
-         assert.strictEqual(err, null);
 
-         done();
 
-       });
 
-     });
 
-   });
 
-   describe("Networking: Avatar", function() {
 
-     before(function() {
 
-       cache.get_redis().flushall();
 
-     });
 
-     it("should be downloaded", function(done) {
 
-       helpers.get_avatar(rid(), uuid, false, 160, function(err, status, image) {
 
-         assert.ifError(err);
 
-         assert.strictEqual(status, 2);
 
-         done();
 
-       });
 
-     });
 
-     it("should be cached", function(done) {
 
-       helpers.get_avatar(rid(), uuid, false, 160, function(err, status, image) {
 
-         assert.ifError(err);
 
-         assert.strictEqual(status === 0 || status === 1, true);
 
-         done();
 
-       });
 
-     });
 
-   });
 
-   describe("Networking: Skin", function() {
 
-     it("should not fail (uuid)", function(done) {
 
-       helpers.get_skin(rid(), uuid, function(err, hash, status, img) {
 
-         assert.strictEqual(err, null);
 
-         done();
 
-       });
 
-     });
 
-   });
 
-   describe("Networking: Render", function() {
 
-     it("should not fail (full body)", function(done) {
 
-       helpers.get_render(rid(), uuid, 6, true, true, function(err, hash, img) {
 
-         assert.ifError(err);
 
-         done();
 
-       });
 
-     });
 
-     it("should not fail (only head)", function(done) {
 
-       helpers.get_render(rid(), uuid, 6, true, false, function(err, hash, img) {
 
-         assert.ifError(err);
 
-         done();
 
-       });
 
-     });
 
-   });
 
-   describe("Networking: Cape", function() {
 
-     it("should not fail (possible cape)", function(done) {
 
-       helpers.get_cape(rid(), uuid, function(err, hash, status, img) {
 
-         assert.ifError(err);
 
-         done();
 
-       });
 
-     });
 
-   });
 
-   describe("Errors", function() {
 
-       before(function() {
 
-       cache.get_redis().flushall();
 
-     });
 
-     // Mojang has changed its rate limiting, so we no longer expect to hit the rate limit
 
-     // it("uuid SHOULD be rate limited", function(done) {
 
-     //   networking.get_profile(rid(), uuid, function() {
 
-     //     networking.get_profile(rid(), uuid, function(err, profile) {
 
-     //       assert.strictEqual(err.toString(), "HTTP: 429");
 
-     //       assert.strictEqual(profile, null);
 
-     //       done();
 
-     //     });
 
-     //   });
 
-     // });
 
-     it("CloudFront rate limit is handled", function(done) {
 
-       var original_rate_limit = config.server.sessions_rate_limit;
 
-       config.server.sessions_rate_limit = 1;
 
-       networking.get_profile(rid(), uuid, function() {
 
-         networking.get_profile(rid(), uuid, function(err, profile) {
 
-           assert.strictEqual(err.code, "RATELIMIT");
 
-           config.server.sessions_rate_limit = original_rate_limit;
 
-           done();
 
-         });
 
-       });
 
-     });
 
-   });
 
-   after(function(done) {
 
-     server.close(function() {
 
-       cache.get_redis().quit();
 
-       done();
 
-     });
 
-   });
 
- });
 
 
  |