test.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. var assert = require('assert');
  2. var fs = require('fs')
  3. var should = require('should')
  4. var networking = require('../modules/networking');
  5. var helpers = require('../modules/helpers');
  6. var config = require('../modules/config');
  7. var skins = require('../modules/skins');
  8. var uuids = fs.readFileSync('test/uuids.txt').toString().split("\r\n");
  9. // Get a random UUID in order to prevent rate limiting
  10. var uuid = uuids[Math.floor((Math.random() * 200) + 1)]
  11. // Only deletes files, doesn't delete directory.
  12. var deleteFolderRecursive = function(path) {
  13. if( fs.existsSync(path) ) {
  14. fs.readdirSync(path).forEach(function(file,index){
  15. var curPath = path + "/" + file;
  16. if(fs.lstatSync(curPath).isDirectory()) {
  17. deleteFolderRecursive(curPath);
  18. } else {
  19. fs.unlinkSync(curPath);
  20. }
  21. });
  22. }
  23. };
  24. describe('Avatar Serving', function(){
  25. before(function() {
  26. deleteFolderRecursive('skins/');
  27. })
  28. describe('UUID', function(){
  29. it("should be an invalid uuid", function(done){
  30. assert.equal(helpers.uuid_valid("invaliduuid"), false);
  31. done();
  32. });
  33. it("should be a valid uuid", function(done){
  34. assert.equal(helpers.uuid_valid("0098cb60fa8e427cb299793cbd302c9a"), true);
  35. done();
  36. });
  37. });
  38. describe('Avatar', function(){
  39. it("should be downloaded", function(done) {
  40. helpers.get_avatar(uuid, false, 180, function(err, status, image) {
  41. assert.equal(status, 2);
  42. done();
  43. });
  44. });
  45. it("should be local", function(done) {
  46. helpers.get_avatar(uuid, false, 180, function(err, status, image) {
  47. assert.equal(status, 1);
  48. done();
  49. });
  50. });
  51. });
  52. describe('Mojang Errors', function(){
  53. before(function() {
  54. deleteFolderRecursive('skins/');
  55. })
  56. it("should be rate limited", function(done) {
  57. helpers.get_avatar(uuid, false, 180, function(err, status, image) {
  58. assert.equal(err, null);
  59. done();
  60. });
  61. });
  62. });
  63. });