From a4a5ac1fbd3438e056bbcf83f67ce20d3dc752ef Mon Sep 17 00:00:00 2001 From: Jake Date: Sat, 1 Nov 2014 19:02:38 -0500 Subject: [PATCH 01/11] Fix Jeb's face --- views/index.jade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/index.jade b/views/index.jade index bd4b714..96c959a 100644 --- a/views/index.jade +++ b/views/index.jade @@ -48,7 +48,7 @@ block content img(src="#{domain}/avatars/853c80ef3c3749fdaa49938b674adae6?size=64") .well.code <img src="#{domain}/avatars/853c80ef3c3749fdaa49938b674adae6?size=64"> p Get jeb_'s helmet avatar, 64 × 64 pixels - img(src="#{domain}/avatars/853c80ef3c3749fdaa49938b674adae6?size=64&helm") + img(src="#{domain}/avatars/853c80ef3c3749fdaa49938b674adae6?size=64&helm") .well.code <img src="#{domain}/avatars/853c80ef3c3749fdaa49938b674adae6?size=64&helm"> p Get jeb_'s avatar, 64 × 64 pixels, or fall back to steve if his avatar is not found img(src="#{domain}/avatars/00000000000000000000000000000000?default=steve&size=64") From 054d77c7faa84db9ef8ef949b3bf7045758a80b8 Mon Sep 17 00:00:00 2001 From: Jake Date: Sat, 1 Nov 2014 19:13:22 -0500 Subject: [PATCH 02/11] package.json info --- package.json | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 5e43530..96a2610 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,23 @@ { "name": "crafatar", - "version": "0.0.0", + "version": "0.0.1", "private": true, + "author": "Jake0oo0", + "description": "A NodeJS application to server Minecraft avatars.", + "contributors": [{ + "name": "Jomo" + }], + "repository": { + "type": "git", + "url": "https://github.com/Jake0oo0/crafatar" + }, + "issues": { + "url": "https://github.com/Jake0oo0/crafatar/issues" + }, + "keywords": [ + "minecraft", + "avatar" + ], "scripts": { "start": "node server.js" }, From 7bfb0a7095e5465d2c17efab8e077f9ee346c372 Mon Sep 17 00:00:00 2001 From: Jake Date: Sat, 1 Nov 2014 21:31:20 -0500 Subject: [PATCH 03/11] Add testing support --- package.json | 5 ++- skins/faces/.gitkeep | 0 skins/helms/.gitkeep | 0 test/test.js | 93 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 1 deletion(-) delete mode 100644 skins/faces/.gitkeep delete mode 100644 skins/helms/.gitkeep create mode 100644 test/test.js diff --git a/package.json b/package.json index 96a2610..4356156 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,9 @@ "debug": "~2.0.0", "jade": "~1.6.0", "lwip": "0.0.5", - "request": "2.45.0" + "request": "2.45.0", + "mocha": "2.0.1", + "supertest": "0.14.0", + "should": "4.1.0" } } \ No newline at end of file diff --git a/skins/faces/.gitkeep b/skins/faces/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/skins/helms/.gitkeep b/skins/helms/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/test/test.js b/test/test.js new file mode 100644 index 0000000..92fcf6a --- /dev/null +++ b/test/test.js @@ -0,0 +1,93 @@ +var request = require('supertest'); +var asset = require('assert'); +var should = require('should'); +var fs = require('fs') +var uuids = fs.readFileSync('uuids.txt').toString().split("\n"); +// Get a random UUID in order to prevent rate limiting +var uuid = uuids[Math.floor((Math.random() * 200) + 1)]; + +// Only deletes files, doesn't delete directory. +var deleteFolderRecursive = function(path) { + if( fs.existsSync(path) ) { + fs.readdirSync(path).forEach(function(file,index){ + var curPath = path + "/" + file; + if(fs.lstatSync(curPath).isDirectory()) { + deleteFolderRecursive(curPath); + } else { + fs.unlinkSync(curPath); + } + }); + } +}; + +describe('Avatar Serving', function(){ + before(function() { + deleteFolderRecursive('../skins/'); + }) + describe('UUID', function(){ + it("should respond with a 422", function(done){ + request('http://localhost:3000') + .get('/avatars/invaliduuid') + .expect(422) + .end(function(err,res) { + if (err) throw err; + res.statusCode.should.eql(422); + done(); + }); + }); + it("should respond with a 404", function(done){ + request('http://localhost:3000') + .get('/avatars/2d5aa9cdaeb049189930461fc9b91dd5') + .expect(404) + .end(function(err,res) { + if (err) throw err; + res.statusCode.should.eql(404); + done(); + }); + }); + it("should be downloaded", function(done){ + request('http://localhost:3000') + .get('/avatars/' + uuid) + .expect(200) + .expect('X-Storage-Type', "downloaded") + .end(function(err,res) { + if (err) throw err; + res.statusCode.should.eql(200); + done(); + }); + }); + it("should respond with a valid avatar", function(done){ + request('http://localhost:3000') + .get('/avatars/' + uuid) + .expect(200) + .expect('Content-Type', "image/png") + .end(function(err,res) { + if (err) throw err; + res.statusCode.should.eql(200); + done(); + }); + }); + it("should should be locally saved", function(done){ + request('http://localhost:3000') + .get('/avatars/' + uuid) + .expect(200) + .expect('X-Storage-Type', "local") + .end(function(err,res) { + if (err) throw err; + res.statusCode.should.eql(200); + done(); + }); + }); + it("should should be rate limited", function(done){ + deleteFolderRecursive('../skins/'); + request('http://localhost:3000') + .get('/avatars/' + uuid) + .expect(404) + .end(function(err,res) { + if (err) throw err; + res.statusCode.should.eql(404); + done(); + }); + }); + }); +}); \ No newline at end of file From 8e3d37868e69e0d23c10952dc10aafb8c9b886db Mon Sep 17 00:00:00 2001 From: Jake Date: Sat, 1 Nov 2014 21:35:01 -0500 Subject: [PATCH 04/11] Implement travis support, needs testing --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b1a780b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +node_js: + - "0.10" +script: npm start && mocha \ No newline at end of file From 7b06652b6dad847fddd0b3768506f468f5cfdc14 Mon Sep 17 00:00:00 2001 From: Jake Date: Sat, 1 Nov 2014 21:37:35 -0500 Subject: [PATCH 05/11] Syntax? --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b1a780b..7d05e78 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ language: node_js node_js: - "0.10" -script: npm start && mocha \ No newline at end of file +script: "npm start && mocha" \ No newline at end of file From a1052b7cbe42e9a191a0d1e1df9f0585e9c26800 Mon Sep 17 00:00:00 2001 From: Jake Date: Sat, 1 Nov 2014 21:44:24 -0500 Subject: [PATCH 06/11] Try before_script --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7d05e78..bed2c78 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,6 @@ language: node_js node_js: - "0.10" -script: "npm start && mocha" \ No newline at end of file +before_script: + - npm start +script: mocha \ No newline at end of file From 7e0d0fff68e86c6a609d21f5c4e85977a32ff5e6 Mon Sep 17 00:00:00 2001 From: Jake Date: Sat, 1 Nov 2014 23:00:03 -0500 Subject: [PATCH 07/11] Rewrite tests --- package.json | 3 +- test/test.js | 104 +++++++++++++++++++-------------------------------- 2 files changed, 41 insertions(+), 66 deletions(-) diff --git a/package.json b/package.json index 4356156..3a3bf92 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "avatar" ], "scripts": { - "start": "node server.js" + "start": "node server.js", + "test": "node_modules/.bin/mocha -w" }, "dependencies": { "express": "~4.9.0", diff --git a/test/test.js b/test/test.js index 92fcf6a..f4998e4 100644 --- a/test/test.js +++ b/test/test.js @@ -1,10 +1,15 @@ -var request = require('supertest'); -var asset = require('assert'); -var should = require('should'); +var assert = require('assert'); var fs = require('fs') -var uuids = fs.readFileSync('uuids.txt').toString().split("\n"); +var should = require('should') + +var networking = require('../modules/networking'); +var helpers = require('../modules/helpers'); +var config = require('../modules/config'); +var skins = require('../modules/skins'); + +var uuids = fs.readFileSync('test/uuids.txt').toString().split("\r\n"); // Get a random UUID in order to prevent rate limiting -var uuid = uuids[Math.floor((Math.random() * 200) + 1)]; +var uuid = uuids[Math.floor((Math.random() * 200) + 1)] // Only deletes files, doesn't delete directory. var deleteFolderRecursive = function(path) { @@ -22,72 +27,41 @@ var deleteFolderRecursive = function(path) { describe('Avatar Serving', function(){ before(function() { - deleteFolderRecursive('../skins/'); + deleteFolderRecursive('skins/'); }) describe('UUID', function(){ - it("should respond with a 422", function(done){ - request('http://localhost:3000') - .get('/avatars/invaliduuid') - .expect(422) - .end(function(err,res) { - if (err) throw err; - res.statusCode.should.eql(422); + it("should be an invalid uuid", function(done){ + assert.equal(helpers.uuid_valid("invaliduuid"), false); + done(); + }); + it("should be a valid uuid", function(done){ + assert.equal(helpers.uuid_valid("0098cb60fa8e427cb299793cbd302c9a"), true); + done(); + }); + }); + describe('Avatar', function(){ + it("should be downloaded", function(done) { + helpers.get_avatar(uuid, false, 180, function(err, status, image) { + assert.equal(status, 2); done(); }); }); - it("should respond with a 404", function(done){ - request('http://localhost:3000') - .get('/avatars/2d5aa9cdaeb049189930461fc9b91dd5') - .expect(404) - .end(function(err,res) { - if (err) throw err; - res.statusCode.should.eql(404); - done(); - }); - }); - it("should be downloaded", function(done){ - request('http://localhost:3000') - .get('/avatars/' + uuid) - .expect(200) - .expect('X-Storage-Type', "downloaded") - .end(function(err,res) { - if (err) throw err; - res.statusCode.should.eql(200); - done(); - }); - }); - it("should respond with a valid avatar", function(done){ - request('http://localhost:3000') - .get('/avatars/' + uuid) - .expect(200) - .expect('Content-Type', "image/png") - .end(function(err,res) { - if (err) throw err; - res.statusCode.should.eql(200); - done(); - }); - }); - it("should should be locally saved", function(done){ - request('http://localhost:3000') - .get('/avatars/' + uuid) - .expect(200) - .expect('X-Storage-Type', "local") - .end(function(err,res) { - if (err) throw err; - res.statusCode.should.eql(200); - done(); - }); - }); - it("should should be rate limited", function(done){ - deleteFolderRecursive('../skins/'); - request('http://localhost:3000') - .get('/avatars/' + uuid) - .expect(404) - .end(function(err,res) { - if (err) throw err; - res.statusCode.should.eql(404); + it("should be local", function(done) { + helpers.get_avatar(uuid, false, 180, function(err, status, image) { + assert.equal(status, 1); done(); }); }); }); -}); \ No newline at end of file + describe('Mojang Errors', function(){ + before(function() { + deleteFolderRecursive('skins/'); + }) + it("should be rate limited", function(done) { + helpers.get_avatar(uuid, false, 180, function(err, status, image) { + assert.equal(err, null); + done(); + }); + }); + }); +}); From 11888176c29da3b8c7dcca07e1dac6570528b68a Mon Sep 17 00:00:00 2001 From: Jake Date: Sat, 1 Nov 2014 23:00:16 -0500 Subject: [PATCH 08/11] Fix travis --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index bed2c78..e87330b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,4 @@ language: node_js node_js: - "0.10" -before_script: - - npm start script: mocha \ No newline at end of file From b023c84298809e97460eb42db5918d8f7b07d970 Mon Sep 17 00:00:00 2001 From: Jake Date: Sat, 1 Nov 2014 23:01:16 -0500 Subject: [PATCH 09/11] Remove unnecessary dependencies --- package.json | 2 -- test/test.js | 1 - 2 files changed, 3 deletions(-) diff --git a/package.json b/package.json index 3a3bf92..34281e4 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,5 @@ "lwip": "0.0.5", "request": "2.45.0", "mocha": "2.0.1", - "supertest": "0.14.0", - "should": "4.1.0" } } \ No newline at end of file diff --git a/test/test.js b/test/test.js index f4998e4..1a03d5b 100644 --- a/test/test.js +++ b/test/test.js @@ -1,6 +1,5 @@ var assert = require('assert'); var fs = require('fs') -var should = require('should') var networking = require('../modules/networking'); var helpers = require('../modules/helpers'); From bc0fb8c5ec4ae9943bab96f10b389e83356cafaf Mon Sep 17 00:00:00 2001 From: Jake Date: Sat, 1 Nov 2014 23:02:05 -0500 Subject: [PATCH 10/11] Json error --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 34281e4..264b2fb 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,6 @@ "jade": "~1.6.0", "lwip": "0.0.5", "request": "2.45.0", - "mocha": "2.0.1", + "mocha": "2.0.1" } } \ No newline at end of file From e2126580e8087022a92fda45ee225b07503c915f Mon Sep 17 00:00:00 2001 From: Jake Date: Sat, 1 Nov 2014 23:07:26 -0500 Subject: [PATCH 11/11] Remove test command, see what travis does --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e87330b..b705b2a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: node_js node_js: - "0.10" -script: mocha \ No newline at end of file +notifications: + irc: "irc.esper.net#spongy" \ No newline at end of file