test.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. var assert = require('assert');
  2. var fs = require('fs');
  3. var networking = require('../modules/networking');
  4. var helpers = require('../modules/helpers');
  5. var config = require('../modules/config');
  6. var skins = require('../modules/skins');
  7. var cache = require("../modules/cache");
  8. // we don't want tests to fail because of slow internet
  9. config.http_timeout = 3000;
  10. var uuids = fs.readFileSync('test/uuids.txt').toString().split("\n");
  11. var usernames = fs.readFileSync('test/usernames.txt').toString().split("\n");
  12. // Get a random UUID + username in order to prevent rate limiting
  13. var uuid = uuids[Math.round(Math.random() * (uuids.length - 1))];
  14. var username = usernames[Math.round(Math.random() * (usernames.length - 1))];
  15. describe('Avatar Serving', function(){
  16. before(function() {
  17. cache.get_redis().flushall();
  18. });
  19. describe('UUID', function(){
  20. it("should be an invalid uuid", function(done){
  21. assert.strictEqual(helpers.uuid_valid("g098cb60fa8e427cb299793cbd302c9a"), false);
  22. done();
  23. });
  24. it("should be an invalid uuid", function(done){
  25. assert.strictEqual(helpers.uuid_valid(""), false);
  26. done();
  27. });
  28. it("should be an invalid uuid", function(done){
  29. assert.strictEqual(helpers.uuid_valid("0098cb60-fa8e-427c-b299-793cbd302c9a"), false);
  30. done();
  31. });
  32. it("should be an invalid username", function(done){
  33. assert.strictEqual(helpers.uuid_valid("usernäme"), false);
  34. done();
  35. });
  36. it("should be an invalid username", function(done){
  37. assert.strictEqual(helpers.uuid_valid("user-name"), false);
  38. done();
  39. });
  40. it("should be an invalid username", function(done){
  41. assert.strictEqual(helpers.uuid_valid("ThisNameIsTooLong"), false);
  42. done();
  43. });
  44. it("should be a valid uuid", function(done){
  45. assert.strictEqual(helpers.uuid_valid("0098cb60fa8e427cb299793cbd302c9a"), true);
  46. done();
  47. });
  48. it("should be a valid username", function(done){
  49. assert.strictEqual(helpers.uuid_valid("__niceUs3rname__"), true);
  50. done();
  51. });
  52. it("should not exist", function(done){
  53. networking.get_profile("00000000000000000000000000000000", function(err, profile) {
  54. assert.strictEqual(err, 0);
  55. done();
  56. });
  57. });
  58. it("should exist without skin", function(done) {
  59. // profile 'Alex'
  60. helpers.get_avatar("ec561538f3fd461daff5086b22154bce", false, 160, function(err, status, image) {
  61. assert.strictEqual(status, 3);
  62. done();
  63. });
  64. });
  65. });
  66. describe('Avatar', function(){
  67. it("should be downloaded (uuid)", function(done) {
  68. helpers.get_avatar(uuid, false, 160, function(err, status, image) {
  69. assert.strictEqual(status, 2);
  70. done();
  71. });
  72. });
  73. it("should be local (uuid)", function(done) {
  74. helpers.get_avatar(uuid, false, 160, function(err, status, image) {
  75. assert.strictEqual(status, 1);
  76. done();
  77. });
  78. });
  79. it("should be downloaded (username)", function(done) {
  80. helpers.get_avatar(username, false, 160, function(err, status, image) {
  81. assert.strictEqual(status, 2);
  82. done();
  83. });
  84. });
  85. it("should be local (username)", function(done) {
  86. helpers.get_avatar(username, false, 160, function(err, status, image) {
  87. assert.strictEqual(status, 1);
  88. done();
  89. });
  90. });
  91. });
  92. describe('Mojang Errors', function(){
  93. before(function() {
  94. cache.get_redis().flushall();
  95. });
  96. it("should be rate limited", function(done) {
  97. helpers.get_avatar(uuid, false, 160, function(err, status, image) {
  98. assert.strictEqual(err, null);
  99. done();
  100. });
  101. });
  102. });
  103. });