Test invalid UUIDs on all routes

This commit is contained in:
Jake 2015-02-09 22:09:34 -06:00
parent df56c38d03
commit 04cd39ae9f

View File

@ -175,6 +175,84 @@ describe("Crafatar", function() {
}); });
}); });
describe("Server", function() {
before(function(done) {
server.boot(function() {
done();
});
});
// Test the home page
it("should return a 200", function(done) {
request.get('http://localhost:3000', function(error, res, body) {
assert.equal(200, res.statusCode);
done();
});
});
// invalid method, we only allow GET and HEAD requests
it("should return a 405", function(done) {
request.post('http://localhost:3000/avatars/Jake0oo0', function(error, res, body) {
assert.equal(405, res.statusCode);
done();
});
});
it("should return a 422 (invalid size)", function(done) {
var size = config.max_size + 1;
request.get('http://localhost:3000/avatars/Jake0oo0?size=' + size, function(error, res, body) {
assert.equal(422, res.statusCode);
done();
});
});
var locations = ["avatars", "capes", "skins", "renders/head"]
for (var l in locations) {
var location = locations[l];
it("should return a 422 (invalid uuid " + location + ")", function(done) {
request.get('http://localhost:3000/' + location + '/thisisaninvaliduuid', function(error, res, body) {
assert.equal(422, res.statusCode);
done();
});
});
}
it("should return a 422 (invalid scale)", function(done) {
var scale = config.max_scale + 1;
request.get('http://localhost:3000/renders/head/Jake0oo0?scale=' + scale, function(error, res, body) {
assert.equal(422, res.statusCode);
done();
});
});
it("should return a 404 (default steve image)", function(done) {
request.get('http://localhost:3000/avatars/invalidjsvns?default=steve', function(error, res, body) {
assert.equal(404, res.statusCode);
done();
});
});
it("should return a 200 (default external image)", function(done) {
request.get('http://localhost:3000/avatars/invalidjsvns?default=https%3A%2F%2Fi.imgur.com%2FocJVWAc.png', function(error, res, body) {
assert.equal(200, res.statusCode);
done();
});
});
it("should return a 404 (no cape)", function(done) {
request.get('http://localhost:3000/capes/Jake0oo0', function(error, res, body) {
assert.equal(404, res.statusCode);
done();
});
});
after(function(done) {
server.close(function() {
done();
})
});
});
// we have to make sure that we test both a 32x64 and 64x64 skin // we have to make sure that we test both a 32x64 and 64x64 skin
describe("Networking: Render", function() { describe("Networking: Render", function() {
it("should not fail (username, 32x64 skin)", function(done) { it("should not fail (username, 32x64 skin)", function(done) {
@ -330,63 +408,4 @@ describe("Crafatar", function() {
}); });
})(id, id_type); })(id, id_type);
} }
describe("Server", function() {
before(function(done) {
server.boot(function() {
done();
});
});
// Test the home page
it("should return a 200", function(done) {
request.get('http://localhost:3000', function(error, res, body) {
assert.equal(200, res.statusCode);
done();
});
});
// invalid method, we only allow GET and HEAD requests
it("should return a 405", function(done) {
request.post('http://localhost:3000/avatars/Jake0oo0', function(error, res, body) {
assert.equal(405, res.statusCode);
done();
});
});
it("should return a 422 (invalid scale)", function(done) {
var scale = config.max_scale + 1;
request.get('http://localhost:3000/avatars/Jake0oo0?scale=' + scale, function(error, res, body) {
assert.equal(422, res.statusCode);
done();
});
});
it("should return a 422 (invalid uuid)", function(done) {
request.get('http://localhost:3000/avatars/thisisaninvaliduuid', function(error, res, body) {
assert.equal(422, res.statusCode);
done();
});
});
it("should return a 422 (invalid size)", function(done) {
var size = config.max_size + 1;
request.get('http://localhost:3000/renders/Jake0oo0?size=' + size, function(error, res, body) {
assert.equal(422, res.statusCode);
done();
});
});
it("should return a 301 (default image)", function(done) {
request.get('http://localhost:3000/renders/invalidjsvns?def=steve', function(error, res, body) {
assert.equal(301, res.statusCode);
done();
});
});
after(function(done) {
server.close(function() {
done();
})
});
});
}); });