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