test.js 3.5 KB

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