test.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. var uuids = fs.readFileSync('test/uuids.txt').toString().split("\n");
  9. // Get a random UUID in order to prevent rate limiting
  10. var uuid = uuids[Math.floor((Math.random() * 200) + 1)];
  11. describe('Avatar Serving', function(){
  12. before(function() {
  13. cache.get_redis().flushall();
  14. });
  15. describe('UUID', function(){
  16. it("should be an invalid uuid", function(done){
  17. assert.strictEqual(helpers.uuid_valid("g098cb60fa8e427cb299793cbd302c9a"), false);
  18. done();
  19. });
  20. it("should be an invalid uuid", function(done){
  21. assert.strictEqual(helpers.uuid_valid(""), false);
  22. done();
  23. });
  24. it("should be an invalid uuid", function(done){
  25. assert.strictEqual(helpers.uuid_valid("0098cb60-fa8e-427c-b299-793cbd302c9a"), false);
  26. done();
  27. });
  28. it("should be an invalid username", function(done){
  29. assert.strictEqual(helpers.uuid_valid("usernäme"), false);
  30. done();
  31. });
  32. it("should be an invalid username", function(done){
  33. assert.strictEqual(helpers.uuid_valid("user-name"), false);
  34. done();
  35. });
  36. it("should be an invalid username", function(done){
  37. assert.strictEqual(helpers.uuid_valid("ThisNameIsTooLong"), false);
  38. done();
  39. });
  40. it("should be a valid uuid", function(done){
  41. assert.strictEqual(helpers.uuid_valid("0098cb60fa8e427cb299793cbd302c9a"), true);
  42. done();
  43. });
  44. it("should be a valid username", function(done){
  45. assert.strictEqual(helpers.uuid_valid("__niceUs3rname__"), true);
  46. done();
  47. });
  48. it("should not exist", function(done){
  49. networking.get_profile("00000000000000000000000000000000", function(err, profile) {
  50. assert.strictEqual(err, 0);
  51. done();
  52. });
  53. });
  54. it("should exist without skin", function(done) {
  55. // profile 'Alex'
  56. helpers.get_avatar("ec561538f3fd461daff5086b22154bce", false, 160, function(err, status, image) {
  57. assert.strictEqual(status, 3);
  58. done();
  59. });
  60. });
  61. });
  62. describe('Avatar', function(){
  63. it("should be downloaded", function(done) {
  64. helpers.get_avatar(uuid, false, 160, function(err, status, image) {
  65. assert.strictEqual(status, 2);
  66. done();
  67. });
  68. });
  69. it("should be local", function(done) {
  70. helpers.get_avatar(uuid, false, 160, function(err, status, image) {
  71. assert.strictEqual(status, 1);
  72. done();
  73. });
  74. });
  75. });
  76. describe('Mojang Errors', function(){
  77. before(function() {
  78. cache.get_redis().flushall();
  79. });
  80. it("should be rate limited", function(done) {
  81. helpers.get_avatar(uuid, false, 160, function(err, status, image) {
  82. assert.strictEqual(err, null);
  83. done();
  84. });
  85. });
  86. });
  87. });