test.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. var networking = require("../lib/networking");
  2. var helpers = require("../lib/helpers");
  3. var logging = require("../lib/logging");
  4. var cleaner = require("../lib/cleaner");
  5. var request = require("request");
  6. var config = require("../lib/config");
  7. var server = require("../lib/server");
  8. var assert = require("assert");
  9. var skins = require("../lib/skins");
  10. var cache = require("../lib/cache");
  11. var crc = require("crc").crc32;
  12. var fs = require("fs");
  13. // we don't want tests to fail because of slow internet
  14. config.http_timeout *= 3;
  15. // no spam
  16. if (process.env.VERBOSE_TEST !== "true") {
  17. logging.log = logging.debug = logging.warn = logging.error = function() {};
  18. }
  19. var uuids = fs.readFileSync("test/uuids.txt").toString().split(/\r?\n/);
  20. var names = fs.readFileSync("test/usernames.txt").toString().split(/\r?\n/);
  21. // Get a random UUID + name in order to prevent rate limiting
  22. var uuid = uuids[Math.round(Math.random() * (uuids.length - 1))];
  23. var name = names[Math.round(Math.random() * (names.length - 1))];
  24. // Let's hope these will never be assigned
  25. var steve_ids = [
  26. "fffffff0" + "fffffff0" + "fffffff0" + "fffffff0",
  27. "fffffff0" + "fffffff0" + "fffffff1" + "fffffff1",
  28. "fffffff0" + "fffffff1" + "fffffff0" + "fffffff1",
  29. "fffffff0" + "fffffff1" + "fffffff1" + "fffffff0",
  30. "fffffff1" + "fffffff0" + "fffffff0" + "fffffff1",
  31. "fffffff1" + "fffffff0" + "fffffff1" + "fffffff0",
  32. "fffffff1" + "fffffff1" + "fffffff0" + "fffffff0",
  33. "fffffff1" + "fffffff1" + "fffffff1" + "fffffff1",
  34. ];
  35. // Let's hope these will never be assigned
  36. var alex_ids = [
  37. "fffffff0" + "fffffff0" + "fffffff0" + "fffffff1",
  38. "fffffff0" + "fffffff0" + "fffffff1" + "fffffff0",
  39. "fffffff0" + "fffffff1" + "fffffff0" + "fffffff0",
  40. "fffffff0" + "fffffff1" + "fffffff1" + "fffffff1",
  41. "fffffff1" + "fffffff0" + "fffffff0" + "fffffff0",
  42. "fffffff1" + "fffffff0" + "fffffff1" + "fffffff1",
  43. "fffffff1" + "fffffff1" + "fffffff0" + "fffffff1",
  44. "fffffff1" + "fffffff1" + "fffffff1" + "fffffff0",
  45. ];
  46. var rid = "TestReqID: ";
  47. function getRandomInt(min, max) {
  48. return Math.floor(Math.random() * (max - min + 1)) + min;
  49. }
  50. var ids = [
  51. uuid.toLowerCase(),
  52. name.toLowerCase(),
  53. name.toUpperCase(),
  54. uuid.toUpperCase(),
  55. ];
  56. describe("Crafatar", function() {
  57. // we might have to make 2 HTTP requests
  58. this.timeout(config.http_timeout * 2 + 50);
  59. before(function() {
  60. cache.get_redis().flushall();
  61. // cause I don't know how big hard drives are these days
  62. config.cleaning_disk_limit = Infinity;
  63. config.cleaning_redis_limit = Infinity;
  64. cleaner.run();
  65. });
  66. describe("UUID/username", function() {
  67. it("non-hex uuid is invalid", function(done) {
  68. assert.strictEqual(helpers.id_valid("g098cb60fa8e427cb299793cbd302c9a"), false);
  69. done();
  70. });
  71. it("empty id is invalid", function(done) {
  72. assert.strictEqual(helpers.id_valid(""), false);
  73. done();
  74. });
  75. it("non-alphanumeric username is invalid", function(done) {
  76. assert.strictEqual(helpers.id_valid("usernäme"), false);
  77. done();
  78. });
  79. it("dashed username is invalid", function(done) {
  80. assert.strictEqual(helpers.id_valid("user-name"), false);
  81. done();
  82. });
  83. it(">16 length username is invalid", function(done) {
  84. assert.strictEqual(helpers.id_valid("ThisNameIsTooLong"), false);
  85. done();
  86. });
  87. it("lowercase uuid is valid", function(done) {
  88. assert.strictEqual(helpers.id_valid("0098cb60fa8e427cb299793cbd302c9a"), true);
  89. done();
  90. });
  91. it("uppercase uuid is valid", function(done) {
  92. assert.strictEqual(helpers.id_valid("1DCEF164FF0A47F2B9A691385C774EE7"), true);
  93. done();
  94. });
  95. it("dashed uuid is valid", function(done) {
  96. assert.strictEqual(helpers.id_valid("0098cb60-fa8e-427c-b299-793cbd302c9a"), true);
  97. done();
  98. });
  99. it("16 chars, underscored, capital, numbered username is valid", function(done) {
  100. assert.strictEqual(helpers.id_valid("__niceUs3rname__"), true);
  101. done();
  102. });
  103. it("1 char username is valid", function(done) {
  104. assert.strictEqual(helpers.id_valid("a"), true);
  105. done();
  106. });
  107. it("should not exist (uuid)", function(done) {
  108. var number = getRandomInt(0, 9).toString();
  109. networking.get_profile(rid, Array(33).join(number), function(err, profile) {
  110. assert.strictEqual(profile, null);
  111. done();
  112. });
  113. });
  114. it("should not exist (username)", function(done) {
  115. networking.get_username_url(rid, "Steve", 0, function(err, profile) {
  116. assert.strictEqual(err, null);
  117. done();
  118. });
  119. });
  120. });
  121. describe("Avatar", function() {
  122. it("uuid's account should exist, but skin should not", function(done) {
  123. // profile "Alex" - hoping it'll never have a skin
  124. networking.get_profile(rid, "ec561538f3fd461daff5086b22154bce", function(err, profile) {
  125. assert.notStrictEqual(profile, null);
  126. networking.get_uuid_url(profile, 1, function(url) {
  127. assert.strictEqual(url, null);
  128. done();
  129. });
  130. });
  131. });
  132. it("Username should default to Steve", function(done) {
  133. assert.strictEqual(skins.default_skin("TestUser"), "steve");
  134. done();
  135. });
  136. for (var a in alex_ids) {
  137. var alex_id = alex_ids[a];
  138. (function(alex_id) {
  139. it("UUID " + alex_id + " should default to Alex", function(done) {
  140. assert.strictEqual(skins.default_skin(alex_id), "alex");
  141. done();
  142. });
  143. })(alex_id);
  144. }
  145. for (var s in steve_ids) {
  146. var steve_id = steve_ids[s];
  147. (function(steve_id) {
  148. it("UUID " + steve_id + " should default to Steve", function(done) {
  149. assert.strictEqual(skins.default_skin(steve_id), "steve");
  150. done();
  151. });
  152. })(steve_id);
  153. }
  154. });
  155. describe("Errors", function() {
  156. it("should time out on uuid info download", function(done) {
  157. var original_timeout = config.http_timeout;
  158. config.http_timeout = 1;
  159. networking.get_profile(rid, "069a79f444e94726a5befca90e38aaf5", function(err, profile) {
  160. assert.strictEqual(err.code, "ETIMEDOUT");
  161. config.http_timeout = original_timeout;
  162. done();
  163. });
  164. });
  165. it("should time out on username info download", function(done) {
  166. var original_timeout = config.http_timeout;
  167. config.http_timeout = 1;
  168. networking.get_username_url(rid, "jomo", 0, function(err, url) {
  169. assert.strictEqual(err.code, "ETIMEDOUT");
  170. config.http_timeout = original_timeout;
  171. done();
  172. });
  173. });
  174. it("should time out on skin download", function(done) {
  175. var original_timeout = config.http_timeout;
  176. config.http_timeout = 1;
  177. networking.get_from(rid, "http://textures.minecraft.net/texture/477be35554684c28bdeee4cf11c591d3c88afb77e0b98da893fd7bc318c65184", function(body, res, error) {
  178. assert.strictEqual(error.code, "ETIMEDOUT");
  179. config.http_timeout = original_timeout;
  180. done();
  181. });
  182. });
  183. it("should not find the skin", function(done) {
  184. assert.doesNotThrow(function() {
  185. networking.get_from(rid, "http://textures.minecraft.net/texture/this-does-not-exist", function(img, response, err) {
  186. assert.strictEqual(err, null); // no error here, but it shouldn't throw exceptions
  187. done();
  188. });
  189. });
  190. });
  191. it("should ignore file updates on invalid files", function(done) {
  192. assert.doesNotThrow(function() {
  193. cache.update_timestamp(rid, "0123456789abcdef0123456789abcdef", "invalid-file.png", false, function(err) {
  194. done();
  195. });
  196. });
  197. });
  198. it("should not find the file", function(done) {
  199. skins.open_skin(rid, "non/existent/path", function(err, img) {
  200. assert.notStrictEqual(err, null);
  201. done();
  202. });
  203. });
  204. });
  205. describe("Server", function() {
  206. // throws Exception when default headers are not in res.headers
  207. function assert_headers(res) {
  208. assert(res.headers["content-type"]);
  209. assert(res.headers["response-time"]);
  210. assert(res.headers["x-request-id"]);
  211. assert.equal(res.headers["access-control-allow-origin"], "*");
  212. assert.equal(res.headers["cache-control"], "max-age=" + config.browser_cache_time + ", public");
  213. }
  214. // throws Exception when +url+ is requested with +etag+
  215. // and it does not return 304 without a body
  216. function assert_cache(url, etag, callback) {
  217. request.get(url, {
  218. headers: {
  219. "If-None-Match": etag
  220. }
  221. }, function(error, res, body) {
  222. assert.ifError(error);
  223. assert.ifError(body);
  224. assert.equal(res.statusCode, 304);
  225. assert(res.headers["etag"]);
  226. assert_headers(res);
  227. callback();
  228. });
  229. }
  230. before(function(done) {
  231. server.boot(function() {
  232. done();
  233. });
  234. });
  235. it("should return 405 Method Not Allowed for POST", function(done) {
  236. request.post("http://localhost:3000", function(error, res, body) {
  237. assert.ifError(error);
  238. assert.strictEqual(res.statusCode, 405);
  239. done();
  240. });
  241. });
  242. it("should return correct HTTP response for home page", function(done) {
  243. var url = "http://localhost:3000";
  244. request.get(url, function(error, res, body) {
  245. assert.ifError(error);
  246. assert.strictEqual(res.statusCode, 200);
  247. assert_headers(res);
  248. assert(res.headers["etag"]);
  249. assert.strictEqual(res.headers["content-type"], "text/html; charset=utf-8");
  250. assert.strictEqual(res.headers["etag"], "\"" + crc(body) + "\"");
  251. assert(body);
  252. assert_cache(url, res.headers["etag"], function() {
  253. done();
  254. });
  255. });
  256. });
  257. it("should return correct HTTP response for assets", function(done) {
  258. var url = "http://localhost:3000/stylesheets/style.css";
  259. request.get(url, function(error, res, body) {
  260. assert.ifError(error);
  261. assert.strictEqual(res.statusCode, 200);
  262. assert_headers(res);
  263. assert(res.headers["etag"]);
  264. assert.strictEqual(res.headers["content-type"], "text/css");
  265. assert.strictEqual(res.headers["etag"], "\"" + crc(body) + "\"");
  266. assert(body);
  267. assert_cache(url, res.headers["etag"], function() {
  268. done();
  269. });
  270. });
  271. });
  272. var locations = {
  273. "avatar with existing username": {
  274. url: "http://localhost:3000/avatars/jeb_?size=16",
  275. etag: '"a846b82963"',
  276. crc32: 3898010414
  277. },
  278. "avatar with not existing username": {
  279. url: "http://localhost:3000/avatars/0?size=16",
  280. etag: '"steve"',
  281. crc32: 2172290550
  282. },
  283. "helm avatar with existing username": {
  284. url: "http://localhost:3000/avatars/jeb_?size=16&helm",
  285. etag: '"a846b82963"',
  286. crc32: 2775605405
  287. },
  288. "helm avatar with not existing username": {
  289. url: "http://localhost:3000/avatars/0?size=16&helm",
  290. etag: '"steve"',
  291. crc32: 2172290550
  292. },
  293. "avatar with existing uuid": {
  294. url: "http://localhost:3000/avatars/853c80ef3c3749fdaa49938b674adae6?size=16",
  295. etag: '"a846b82963"',
  296. crc32: 3898010414
  297. },
  298. "avatar with not existing uuid": {
  299. url: "http://localhost:3000/avatars/00000000000000000000000000000000?size=16",
  300. etag: '"steve"',
  301. crc32: 2172290550
  302. },
  303. "helm avatar with existing uuid": {
  304. url: "http://localhost:3000/avatars/853c80ef3c3749fdaa49938b674adae6?size=16&helm",
  305. etag: '"a846b82963"',
  306. crc32: 2775605405
  307. },
  308. "helm avatar with not existing uuid": {
  309. url: "http://localhost:3000/avatars/00000000000000000000000000000000?size=16&helm",
  310. etag: '"steve"',
  311. crc32: 2172290550
  312. },
  313. "cape with existing username": {
  314. url: "http://localhost:3000/capes/jeb_",
  315. etag: '"3f688e0e69"',
  316. crc32: 3151059445
  317. },
  318. "cape with not existing username": {
  319. url: "http://localhost:3000/capes/0",
  320. etag: undefined,
  321. crc32: 0
  322. },
  323. "cape with existing uuid": {
  324. url: "http://localhost:3000/capes/853c80ef3c3749fdaa49938b674adae6",
  325. etag: '"3f688e0e69"',
  326. crc32: 3151059445
  327. },
  328. "cape with not existing uuid": {
  329. url: "http://localhost:3000/capes/00000000000000000000000000000000",
  330. etag: undefined,
  331. crc32: 0
  332. },
  333. "skin with existing username": {
  334. url: "http://localhost:3000/skins/jeb_",
  335. etag: '"a846b82963"',
  336. crc32: 2804046136
  337. },
  338. "skin with not existing username": {
  339. url: "http://localhost:3000/skins/0",
  340. etag: '"steve"',
  341. crc32: 3033070999
  342. },
  343. "skin with existing uuid": {
  344. url: "http://localhost:3000/skins/853c80ef3c3749fdaa49938b674adae6",
  345. etag: '"a846b82963"',
  346. crc32: 2804046136
  347. },
  348. "skin with not existing uuid": {
  349. url: "http://localhost:3000/skins/00000000000000000000000000000000",
  350. etag: '"steve"',
  351. crc32: 3033070999
  352. },
  353. "head render with existing username": {
  354. url: "http://localhost:3000/renders/head/jeb_?scale=2",
  355. etag: '"a846b82963"',
  356. crc32: 4068337011
  357. },
  358. "head render with not existing username": {
  359. url: "http://localhost:3000/renders/head/0?scale=2",
  360. etag: '"steve"',
  361. crc32: 3356822684
  362. },
  363. "helm head render with existing username": {
  364. url: "http://localhost:3000/renders/head/jeb_?scale=2&helm",
  365. etag: '"a846b82963"',
  366. crc32: 4150827424
  367. },
  368. "helm head render with not existing username": {
  369. url: "http://localhost:3000/renders/head/0?scale=2&helm",
  370. etag: '"steve"',
  371. crc32: 349655416
  372. },
  373. "head render with existing uuid": {
  374. url: "http://localhost:3000/renders/head/853c80ef3c3749fdaa49938b674adae6?scale=2",
  375. etag: '"a846b82963"',
  376. crc32: 4068337011
  377. },
  378. "head render with not existing uuid": {
  379. url: "http://localhost:3000/renders/head/00000000000000000000000000000000?scale=2",
  380. etag: '"steve"',
  381. crc32: 3356822684
  382. },
  383. "helm head render with existing uuid": {
  384. url: "http://localhost:3000/renders/head/853c80ef3c3749fdaa49938b674adae6?scale=2&helm",
  385. etag: '"a846b82963"',
  386. crc32: 4150827424
  387. },
  388. "helm head render with not existing uuid": {
  389. url: "http://localhost:3000/avatars/00000000000000000000000000000000?scale=2&helm",
  390. etag: '"steve"',
  391. crc32: 1255390784
  392. },
  393. "body render with existing username": {
  394. url: "http://localhost:3000/renders/body/jeb_?scale=2",
  395. etag: '"a846b82963"',
  396. crc32: 2118588728
  397. },
  398. "body render with not existing username": {
  399. url: "http://localhost:3000/renders/body/0?scale=2",
  400. etag: '"steve"',
  401. crc32: 216470159
  402. },
  403. "helm body render with existing username": {
  404. url: "http://localhost:3000/renders/body/jeb_?scale=2&helm",
  405. etag: '"a846b82963"',
  406. crc32: 2280652919
  407. },
  408. "helm body render with not existing username": {
  409. url: "http://localhost:3000/renders/body/0?scale=2&helm",
  410. etag: '"steve"',
  411. crc32: 1991273336
  412. },
  413. "body render with existing uuid": {
  414. url: "http://localhost:3000/renders/body/853c80ef3c3749fdaa49938b674adae6?scale=2",
  415. etag: '"a846b82963"',
  416. crc32: 2118588728
  417. },
  418. "body render with not existing uuid": {
  419. url: "http://localhost:3000/renders/body/00000000000000000000000000000000?scale=2",
  420. etag: '"steve"',
  421. crc32: 216470159
  422. },
  423. "helm body render with existing uuid": {
  424. url: "http://localhost:3000/renders/body/853c80ef3c3749fdaa49938b674adae6?scale=2&helm",
  425. etag: '"a846b82963"',
  426. crc32: 2280652919
  427. },
  428. "helm body render with not existing uuid": {
  429. url: "http://localhost:3000/renders/body/00000000000000000000000000000000?scale=2&helm",
  430. etag: '"steve"',
  431. crc32: 1991273336
  432. },
  433. };
  434. for (var description in locations) {
  435. var location = locations[description];
  436. (function(location) {
  437. it("should return correct HTTP response for " + description, function(done) {
  438. request.get(location.url, function(error, res, body) {
  439. assert.ifError(error);
  440. assert_headers(res);
  441. assert(res.headers["x-storage-type"]);
  442. assert.strictEqual(res.headers["etag"], location.etag);
  443. assert.strictEqual(crc(body), location.crc32);
  444. if (location.etag === undefined) {
  445. assert.strictEqual(res.statusCode, 404);
  446. assert.strictEqual(res.headers["content-type"], "text/plain");
  447. done();
  448. } else {
  449. assert(res.headers["etag"]);
  450. assert.strictEqual(res.headers["content-type"], "image/png");
  451. assert.strictEqual(res.statusCode, 200);
  452. assert_cache(location.url, res.headers["etag"], function() {
  453. done();
  454. });
  455. }
  456. });
  457. });
  458. }(location));
  459. }
  460. after(function(done) {
  461. server.close(function() {
  462. done();
  463. });
  464. });
  465. });
  466. // we have to make sure that we test both a 32x64 and 64x64 skin
  467. describe("Networking: Render", function() {
  468. it("should not fail (username, 32x64 skin)", function(done) {
  469. helpers.get_render(rid, "md_5", 6, true, true, function(err, hash, img) {
  470. assert.strictEqual(err, null);
  471. done();
  472. });
  473. });
  474. it("should not fail (username, 64x64 skin)", function(done) {
  475. helpers.get_render(rid, "Jake_0", 6, true, true, function(err, hash, img) {
  476. assert.strictEqual(err, null);
  477. done();
  478. });
  479. });
  480. });
  481. describe("Networking: Cape", function() {
  482. it("should not fail (guaranteed cape)", function(done) {
  483. helpers.get_cape(rid, "Dinnerbone", function(err, hash, status, img) {
  484. assert.strictEqual(err, null);
  485. done();
  486. });
  487. });
  488. it("should already exist", function(done) {
  489. before(function() {
  490. cache.get_redis().flushall();
  491. });
  492. helpers.get_cape(rid, "Dinnerbone", function(err, hash, status, img) {
  493. assert.strictEqual(err, null);
  494. done();
  495. });
  496. });
  497. it("should not be found", function(done) {
  498. helpers.get_cape(rid, "Jake_0", function(err, hash, status, img) {
  499. assert.strictEqual(img, null);
  500. done();
  501. });
  502. });
  503. });
  504. describe("Networking: Skin", function() {
  505. it("should not fail", function(done) {
  506. helpers.get_cape(rid, "Jake_0", function(err, hash, status, img) {
  507. assert.strictEqual(err, null);
  508. done();
  509. });
  510. });
  511. it("should already exist", function(done) {
  512. before(function() {
  513. cache.get_redis().flushall();
  514. });
  515. helpers.get_cape(rid, "Jake_0", function(err, hash, status, img) {
  516. assert.strictEqual(err, null);
  517. done();
  518. });
  519. });
  520. });
  521. // DRY with uuid and username tests
  522. for (var i in ids) {
  523. var id = ids[i];
  524. var id_type = id.length > 16 ? "uuid" : "name";
  525. // needs an anonymous function because id and id_type aren't constant
  526. (function(id, id_type) {
  527. describe("Networking: Avatar", function() {
  528. before(function() {
  529. cache.get_redis().flushall();
  530. console.log("\n\nRunning tests with " + id_type + " '" + id + "'\n\n");
  531. });
  532. it("should be downloaded", function(done) {
  533. helpers.get_avatar(rid, id, false, 160, function(err, status, image) {
  534. assert.strictEqual(status, 2);
  535. done();
  536. });
  537. });
  538. it("should be cached", function(done) {
  539. helpers.get_avatar(rid, id, false, 160, function(err, status, image) {
  540. assert.strictEqual(status === 0 || status === 1, true);
  541. done();
  542. });
  543. });
  544. if (id.length > 16) {
  545. console.log("can't run 'checked' test due to Mojang's rate limits :(");
  546. } else {
  547. it("should be checked", function(done) {
  548. var original_cache_time = config.local_cache_time;
  549. config.local_cache_time = 0;
  550. helpers.get_avatar(rid, id, false, 160, function(err, status, image) {
  551. assert.strictEqual(status, 3);
  552. config.local_cache_time = original_cache_time;
  553. done();
  554. });
  555. });
  556. }
  557. });
  558. describe("Networking: Skin", function() {
  559. it("should not fail (uuid)", function(done) {
  560. helpers.get_skin(rid, id, function(err, hash, status, img) {
  561. assert.strictEqual(err, null);
  562. done();
  563. });
  564. });
  565. });
  566. describe("Networking: Render", function() {
  567. it("should not fail (full body)", function(done) {
  568. helpers.get_render(rid, id, 6, true, true, function(err, hash, img) {
  569. assert.strictEqual(err, null);
  570. done();
  571. });
  572. });
  573. it("should not fail (only head)", function(done) {
  574. helpers.get_render(rid, id, 6, true, false, function(err, hash, img) {
  575. assert.strictEqual(err, null);
  576. done();
  577. });
  578. });
  579. });
  580. describe("Networking: Cape", function() {
  581. it("should not fail (possible cape)", function(done) {
  582. helpers.get_cape(rid, id, function(err, hash, status, img) {
  583. assert.strictEqual(err, null);
  584. done();
  585. });
  586. });
  587. });
  588. describe("Errors", function() {
  589. before(function() {
  590. cache.get_redis().flushall();
  591. });
  592. if (id_type == "uuid") {
  593. it("uuid should be rate limited", function(done) {
  594. networking.get_profile(rid, id, function(err, profile) {
  595. assert.strictEqual(profile.error, "TooManyRequestsException");
  596. done();
  597. });
  598. });
  599. } else {
  600. it("username should NOT be rate limited (username)", function(done) {
  601. helpers.get_avatar(rid, id, false, 160, function(err, status, image) {
  602. assert.strictEqual(err, null);
  603. done();
  604. });
  605. });
  606. }
  607. });
  608. })(id, id_type);
  609. }
  610. });