mirror of
https://github.com/azures04/crafatar.git
synced 2026-05-06 11:00:39 +02:00
Network rewrite/major cleanup, major caching changes, etc
Work on implementing capes Update to no-express Add more render tests Add capes express route Add documentation Add undefined images to .gitignore Fix no-express server again Cleanup config a bit General cleanup Add CodeClimate badge Test on Heroku Speed optimizations Fix tests Code cleanup
This commit is contained in:
@@ -14,4 +14,8 @@ for uuid in `cat "$dir/uuids.txt"`; do
|
||||
helm="&helm"
|
||||
fi
|
||||
curl -sSL -o /dev/null -w "%{url_effective} %{http_code} %{time_total}s\\n" "http://$host/avatars/$uuid?size=$size$helm"
|
||||
done
|
||||
<<<<<<< HEAD
|
||||
done
|
||||
=======
|
||||
done
|
||||
>>>>>>> Network rewrite/major cleanup, major caching changes, etc
|
||||
|
||||
84
test/test.js
84
test/test.js
@@ -8,6 +8,7 @@ var config = require("../modules/config");
|
||||
var skins = require("../modules/skins");
|
||||
var cache = require("../modules/cache");
|
||||
var renders = require("../modules/renders");
|
||||
var cleaner = require("../modules/cleaner")
|
||||
|
||||
// we don't want tests to fail because of slow internet
|
||||
config.http_timeout *= 3;
|
||||
@@ -22,6 +23,10 @@ var names = fs.readFileSync("test/usernames.txt").toString().split(/\r?\n/);
|
||||
var uuid = uuids[Math.round(Math.random() * (uuids.length - 1))];
|
||||
var name = names[Math.round(Math.random() * (names.length - 1))];
|
||||
|
||||
function getRandomInt(min, max) {
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
}
|
||||
|
||||
var ids = [
|
||||
uuid.toLowerCase(),
|
||||
uuid.toUpperCase(),
|
||||
@@ -35,6 +40,7 @@ describe("Crafatar", function() {
|
||||
|
||||
before(function() {
|
||||
cache.get_redis().flushall();
|
||||
cleaner.run();
|
||||
});
|
||||
|
||||
describe("UUID/username", function() {
|
||||
@@ -79,13 +85,14 @@ describe("Crafatar", function() {
|
||||
done();
|
||||
});
|
||||
it("should not exist (uuid)", function(done) {
|
||||
networking.get_skin_url("00000000000000000000000000000000", function(err, profile) {
|
||||
assert.strictEqual(err, null);
|
||||
var number = getRandomInt(0, 9).toString();
|
||||
networking.get_profile(Array(33).join(number), function(err, profile) {
|
||||
assert.strictEqual(profile, null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("should not exist (username)", function(done) {
|
||||
networking.get_skin_url("Steve", function(err, profile) {
|
||||
networking.get_username_url("Steve", 1, function(err, profile) {
|
||||
assert.strictEqual(err, null);
|
||||
done();
|
||||
});
|
||||
@@ -99,10 +106,13 @@ describe("Crafatar", function() {
|
||||
var steven_uuid = "b8ffc3d37dbf48278f69475f6690aabd";
|
||||
|
||||
it("uuid's account should exist, but skin should not", function(done) {
|
||||
helpers.get_avatar(alex_uuid, false, 160, function(err, status, image) {
|
||||
assert.strictEqual(status, 2);
|
||||
done();
|
||||
});
|
||||
networking.get_profile(alex_uuid, function(err, profile) {
|
||||
assert.notStrictEqual(profile, null);
|
||||
networking.get_uuid_url(profile, 1, function(url) {
|
||||
assert.strictEqual(url, null);
|
||||
done();
|
||||
});
|
||||
})
|
||||
});
|
||||
it("odd UUID should default to Alex", function(done) {
|
||||
assert.strictEqual(skins.default_skin(alex_uuid), "alex");
|
||||
@@ -117,7 +127,7 @@ describe("Crafatar", function() {
|
||||
it("should time out on uuid info download", function(done) {
|
||||
var original_timeout = config.http_timeout;
|
||||
config.http_timeout = 1;
|
||||
networking.get_skin_url("069a79f444e94726a5befca90e38aaf5", function(err, skin_url) {
|
||||
networking.get_profile("069a79f444e94726a5befca90e38aaf5", function(err, profile) {
|
||||
assert.strictEqual(err.code, "ETIMEDOUT");
|
||||
config.http_timeout = original_timeout;
|
||||
done();
|
||||
@@ -126,7 +136,7 @@ describe("Crafatar", function() {
|
||||
it("should time out on username info download", function(done) {
|
||||
var original_timeout = config.http_timeout;
|
||||
config.http_timeout = 1;
|
||||
networking.get_skin_url("redstone_sheep", function(err, skin_url) {
|
||||
networking.get_username_url("redstone_sheep", 1, function(err, url) {
|
||||
assert.strictEqual(err.code, "ETIMEDOUT");
|
||||
config.http_timeout = original_timeout;
|
||||
done();
|
||||
@@ -135,7 +145,11 @@ describe("Crafatar", function() {
|
||||
it("should time out on skin download", function(done) {
|
||||
var original_timeout = config.http_timeout;
|
||||
config.http_timeout = 1;
|
||||
<<<<<<< HEAD
|
||||
networking.get_skin("http://textures.minecraft.net/texture/477be35554684c28bdeee4cf11c591d3c88afb77e0b98da893fd7bc318c65184", uuid, function(err, img) {
|
||||
=======
|
||||
networking.get_from("http://textures.minecraft.net/texture/477be35554684c28bdeee4cf11c591d3c88afb77e0b98da893fd7bc318c65184", function(img, response, err) {
|
||||
>>>>>>> Network rewrite/major cleanup, major caching changes, etc
|
||||
assert.strictEqual(err.code, "ETIMEDOUT");
|
||||
config.http_timeout = original_timeout;
|
||||
done();
|
||||
@@ -143,7 +157,11 @@ describe("Crafatar", function() {
|
||||
});
|
||||
it("should not find the skin", function(done) {
|
||||
assert.doesNotThrow(function() {
|
||||
<<<<<<< HEAD
|
||||
networking.get_skin("http://textures.minecraft.net/texture/this-does-not-exist", uuid, function(err, img) {
|
||||
=======
|
||||
networking.get_from("http://textures.minecraft.net/texture/this-does-not-exist", function(img, response, err) {
|
||||
>>>>>>> Network rewrite/major cleanup, major caching changes, etc
|
||||
assert.strictEqual(err, null); // no error here, but it shouldn't throw exceptions
|
||||
done();
|
||||
});
|
||||
@@ -157,6 +175,32 @@ describe("Crafatar", function() {
|
||||
});
|
||||
});
|
||||
|
||||
// we have to make sure that we test both a 32x64 and 64x64 skin
|
||||
describe("Networking: Render", function() {
|
||||
it("should not fail (username, 32x64 skin)", function(done) {
|
||||
helpers.get_render("md_5", 6, true, true, function(err, hash, img) {
|
||||
assert.strictEqual(err, null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("should not fail (username, 64x64 skin)", function(done) {
|
||||
helpers.get_render("Jake0oo0", 6, true, true, function(err, hash, img) {
|
||||
assert.strictEqual(err, null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Networking: Cape", function() {
|
||||
it("should not fail (guaranteed cape)", function(done) {
|
||||
helpers.get_cape("Dinnerbone", function(err, hash, img) {
|
||||
assert.strictEqual(err, null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// DRY with uuid and username tests
|
||||
for (var i in ids) {
|
||||
var id = ids[i];
|
||||
@@ -177,6 +221,7 @@ describe("Crafatar", function() {
|
||||
});
|
||||
it("should be cached", function(done) {
|
||||
helpers.get_avatar(id, false, 160, function(err, status, image) {
|
||||
console.log("STATUS: " + status)
|
||||
assert.strictEqual(status === 0 || status === 1, true);
|
||||
done();
|
||||
});
|
||||
@@ -206,17 +251,23 @@ describe("Crafatar", function() {
|
||||
});
|
||||
|
||||
describe("Networking: Render", function() {
|
||||
it("should not fail (username, 64x64 skin)", function(done) {
|
||||
helpers.get_render("Jake0oo0", 6, true, true, function(err, hash, img) {
|
||||
it("should not fail (full body)", function(done) {
|
||||
helpers.get_render(id, 6, true, true, function(err, hash, img) {
|
||||
assert.strictEqual(err, null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("should not fail (only head)", function(done) {
|
||||
helpers.get_render(id, 6, true, false, function(err, hash, img) {
|
||||
assert.strictEqual(err, null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Networking: Render", function() {
|
||||
it("should not fail (username, 32x64 skin)", function(done) {
|
||||
helpers.get_render("md_5", 6, true, true, function(err, hash, img) {
|
||||
describe("Networking: Cape", function() {
|
||||
it("should not fail (possible cape)", function(done) {
|
||||
helpers.get_cape(id, function(err, hash, img) {
|
||||
assert.strictEqual(err, null);
|
||||
done();
|
||||
});
|
||||
@@ -231,8 +282,9 @@ describe("Crafatar", function() {
|
||||
|
||||
if (id_type == "uuid") {
|
||||
it("uuid should be rate limited", function(done) {
|
||||
helpers.get_avatar(id, false, 160, function(err, status, image) {
|
||||
assert.strictEqual(JSON.parse(err).error, "TooManyRequestsException");
|
||||
networking.get_profile(id, function(err, profile) {
|
||||
console.log("THIS THING:: " + err)
|
||||
assert.strictEqual(profile.error, "TooManyRequestsException");
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user