mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-22 07:51:17 +01:00
Test invalid UUIDs on all routes
This commit is contained in:
parent
df56c38d03
commit
04cd39ae9f
169
test/test.js
169
test/test.js
@ -31,10 +31,10 @@ function getRandomInt(min, max) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var ids = [
|
var ids = [
|
||||||
uuid.toLowerCase(),
|
uuid.toLowerCase(),
|
||||||
name.toLowerCase(),
|
name.toLowerCase(),
|
||||||
uuid.toUpperCase(),
|
uuid.toUpperCase(),
|
||||||
name.toUpperCase(),
|
name.toUpperCase(),
|
||||||
];
|
];
|
||||||
|
|
||||||
describe("Crafatar", function() {
|
describe("Crafatar", function() {
|
||||||
@ -101,7 +101,7 @@ describe("Crafatar", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Avatar", function() {
|
describe("Avatar", function() {
|
||||||
// profile "Alex" - hoping it'll never have a skin
|
// profile "Alex" - hoping it'll never have a skin
|
||||||
var alex_uuid = "ec561538f3fd461daff5086b22154bce";
|
var alex_uuid = "ec561538f3fd461daff5086b22154bce";
|
||||||
// profile "Steven" (Steve doesn't exist) - hoping it'll never have a skin
|
// profile "Steven" (Steve doesn't exist) - hoping it'll never have a skin
|
||||||
@ -125,7 +125,7 @@ describe("Crafatar", function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("Errors", function() {
|
describe("Errors", function() {
|
||||||
it("should time out on uuid info download", function(done) {
|
it("should time out on uuid info download", function(done) {
|
||||||
var original_timeout = config.http_timeout;
|
var original_timeout = config.http_timeout;
|
||||||
config.http_timeout = 1;
|
config.http_timeout = 1;
|
||||||
@ -173,6 +173,84 @@ describe("Crafatar", function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
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
|
||||||
@ -273,16 +351,16 @@ describe("Crafatar", function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Networking: Skin", function() {
|
describe("Networking: Skin", function() {
|
||||||
it("should not fail (uuid)", function(done) {
|
it("should not fail (uuid)", function(done) {
|
||||||
helpers.get_skin(rid, id, function(err, hash, img) {
|
helpers.get_skin(rid, id, function(err, hash, img) {
|
||||||
assert.strictEqual(err, null);
|
assert.strictEqual(err, null);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Networking: Render", function() {
|
describe("Networking: Render", function() {
|
||||||
it("should not fail (full body)", function(done) {
|
it("should not fail (full body)", function(done) {
|
||||||
helpers.get_render(rid, id, 6, true, true, function(err, hash, img) {
|
helpers.get_render(rid, id, 6, true, true, function(err, hash, img) {
|
||||||
assert.strictEqual(err, null);
|
assert.strictEqual(err, null);
|
||||||
@ -295,19 +373,19 @@ describe("Crafatar", function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Networking: Cape", function() {
|
describe("Networking: Cape", function() {
|
||||||
it("should not fail (possible cape)", function(done) {
|
it("should not fail (possible cape)", function(done) {
|
||||||
helpers.get_cape(rid, id, function(err, hash, img) {
|
helpers.get_cape(rid, id, function(err, hash, img) {
|
||||||
assert.strictEqual(err, null);
|
assert.strictEqual(err, null);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe("Errors", function() {
|
describe("Errors", function() {
|
||||||
before(function() {
|
before(function() {
|
||||||
cache.get_redis().flushall();
|
cache.get_redis().flushall();
|
||||||
});
|
});
|
||||||
@ -327,66 +405,7 @@ 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();
|
|
||||||
})
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user