fix rate-limiting tests

Mojang is now rate-limiting calls to their sessionserver case-insensitive.

This fix skips network-based tests for an upper-cased UUID which are previously
run with the same lower-cased UUID
This commit is contained in:
jomo 2016-11-03 21:51:43 +01:00
parent f0b73b34d1
commit f7b8fd4e8c

View File

@ -933,84 +933,92 @@ describe("Crafatar", function() {
var iid = ids[i]; var iid = ids[i];
var iid_type = iid.length > 16 ? "uuid" : "name"; var iid_type = iid.length > 16 ? "uuid" : "name";
// needs an anonymous function because id and id_type aren't constant // needs an anonymous function because id and id_type aren't constant
(function(id, id_type) { (function(n, id, id_type) {
describe("Networking: Avatar", function() { // Mojang's UUID rate limiting is case-insensitive
before(function() { // so we don't run UUID tests twice
cache.get_redis().flushall(); if(n < 3) {
console.log("\n\nRunning tests with " + id_type + " '" + id + "'\n\n"); describe("Networking: Avatar", function() {
}); before(function() {
cache.get_redis().flushall();
it("should be downloaded", function(done) { console.log("\n\nRunning tests with " + id_type + " '" + id + "'\n\n");
helpers.get_avatar(rid(), id, false, 160, function(err, status, image) {
assert.ifError(err);
assert.strictEqual(status, 2);
done();
}); });
}); it("should be downloaded", function(done) {
it("should be cached", function(done) {
helpers.get_avatar(rid(), id, false, 160, function(err, status, image) {
assert.ifError(err);
assert.strictEqual(status === 0 || status === 1, true);
done();
});
});
if (id.length > 16) {
// can't run 'checked' test due to Mojang's rate limits :(
} else {
it("should be checked", function(done) {
var original_cache_time = config.caching.local;
config.caching.local = 0;
helpers.get_avatar(rid(), id, false, 160, function(err, status, image) { helpers.get_avatar(rid(), id, false, 160, function(err, status, image) {
assert.ifError(err); assert.ifError(err);
assert.strictEqual(status, 3); assert.strictEqual(status, 2);
config.caching.local = original_cache_time;
done(); done();
}); });
}); });
} it("should be cached", function(done) {
}); helpers.get_avatar(rid(), id, false, 160, function(err, status, image) {
assert.ifError(err);
assert.strictEqual(status === 0 || status === 1, true);
done();
});
});
if (id.length > 16) {
// can't run 'checked' test due to Mojang's rate limits :(
} else {
it("should be checked", function(done) {
var original_cache_time = config.caching.local;
config.caching.local = 0;
helpers.get_avatar(rid(), id, false, 160, function(err, status, image) {
assert.ifError(err);
assert.strictEqual(status, 3);
config.caching.local = original_cache_time;
done();
});
});
}
});
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, status, img) { helpers.get_skin(rid(), id, function(err, hash, status, 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.ifError(err); assert.ifError(err);
done(); done();
});
});
it("should not fail (only head)", function(done) {
helpers.get_render(rid(), id, 6, true, false, function(err, hash, img) {
assert.ifError(err);
done();
});
}); });
}); });
it("should not fail (only head)", function(done) {
helpers.get_render(rid(), id, 6, true, false, function(err, hash, img) {
assert.ifError(err);
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, status, img) { helpers.get_cape(rid(), id, function(err, hash, status, img) {
assert.ifError(err); assert.ifError(err);
done(); done();
});
}); });
}); });
}); }
describe("Errors", function() { describe("Errors", function() {
before(function() { before(function() {
if(n >= 3) {
// Notice for tests skipped above
console.log("\n\nSkipping tests with " + id_type + " '" + id + "' due to case-insensitive rate-limiting\n\n");
}
cache.get_redis().flushall(); cache.get_redis().flushall();
}); });
if (id_type === "uuid") { if (id_type === "uuid") {
it("uuid should be rate limited", function(done) { // just making sure ...
it("uuid SHOULD be rate limited", function(done) {
networking.get_profile(rid(), id, function() { networking.get_profile(rid(), id, function() {
networking.get_profile(rid(), id, function(err, profile) { networking.get_profile(rid(), id, function(err, profile) {
assert.strictEqual(err.toString(), "HTTP: 429"); assert.strictEqual(err.toString(), "HTTP: 429");
@ -1030,6 +1038,6 @@ describe("Crafatar", function() {
}); });
} }
}); });
}(iid, iid_type)); }(i, iid, iid_type));
} }
}); });