mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-21 23:41:18 +01:00
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:
parent
f0b73b34d1
commit
f7b8fd4e8c
120
test/test.js
120
test/test.js
@ -933,84 +933,92 @@ describe("Crafatar", function() {
|
||||
var iid = ids[i];
|
||||
var iid_type = iid.length > 16 ? "uuid" : "name";
|
||||
// needs an anonymous function because id and id_type aren't constant
|
||||
(function(id, id_type) {
|
||||
describe("Networking: Avatar", function() {
|
||||
before(function() {
|
||||
cache.get_redis().flushall();
|
||||
console.log("\n\nRunning tests with " + id_type + " '" + id + "'\n\n");
|
||||
});
|
||||
|
||||
it("should be downloaded", function(done) {
|
||||
helpers.get_avatar(rid(), id, false, 160, function(err, status, image) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(status, 2);
|
||||
done();
|
||||
(function(n, id, id_type) {
|
||||
// Mojang's UUID rate limiting is case-insensitive
|
||||
// so we don't run UUID tests twice
|
||||
if(n < 3) {
|
||||
describe("Networking: Avatar", function() {
|
||||
before(function() {
|
||||
cache.get_redis().flushall();
|
||||
console.log("\n\nRunning tests with " + id_type + " '" + id + "'\n\n");
|
||||
});
|
||||
});
|
||||
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;
|
||||
it("should be downloaded", function(done) {
|
||||
helpers.get_avatar(rid(), id, false, 160, function(err, status, image) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(status, 3);
|
||||
config.caching.local = original_cache_time;
|
||||
assert.strictEqual(status, 2);
|
||||
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() {
|
||||
it("should not fail (uuid)", function(done) {
|
||||
helpers.get_skin(rid(), id, function(err, hash, status, img) {
|
||||
assert.strictEqual(err, null);
|
||||
done();
|
||||
describe("Networking: Skin", function() {
|
||||
it("should not fail (uuid)", function(done) {
|
||||
helpers.get_skin(rid(), id, function(err, hash, status, img) {
|
||||
assert.strictEqual(err, null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Networking: Render", function() {
|
||||
it("should not fail (full body)", function(done) {
|
||||
helpers.get_render(rid(), id, 6, true, true, function(err, hash, img) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
describe("Networking: Render", function() {
|
||||
it("should not fail (full body)", function(done) {
|
||||
helpers.get_render(rid(), id, 6, true, true, 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();
|
||||
});
|
||||
});
|
||||
});
|
||||
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() {
|
||||
it("should not fail (possible cape)", function(done) {
|
||||
helpers.get_cape(rid(), id, function(err, hash, status, img) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
describe("Networking: Cape", function() {
|
||||
it("should not fail (possible cape)", function(done) {
|
||||
helpers.get_cape(rid(), id, function(err, hash, status, img) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
describe("Errors", 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();
|
||||
});
|
||||
|
||||
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(err, profile) {
|
||||
assert.strictEqual(err.toString(), "HTTP: 429");
|
||||
@ -1030,6 +1038,6 @@ describe("Crafatar", function() {
|
||||
});
|
||||
}
|
||||
});
|
||||
}(iid, iid_type));
|
||||
}(i, iid, iid_type));
|
||||
}
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user