Merge pull request #220 from gmetais/develop

v1.12.1
This commit is contained in:
Gaël Métais
2017-01-08 22:49:05 +08:00
committed by GitHub
8 changed files with 53 additions and 5 deletions
+2
View File
@@ -37,6 +37,8 @@ apiService.factory('API', ['$location', 'Runs', 'Results', function($location, R
}, function(response) {
if (response.status === 429) {
alert('Too many requests, you reached the max number of requests allowed in 24h');
} else if (response.status === 403) {
alert('This particular query was blocked due to spamming. If you think it\'s an error, please open an issue on GitHub.');
} else {
alert('An error occured...');
}
+1 -1
View File
@@ -253,7 +253,7 @@
}
.totalWeightPie {
max-width: 39em;
max-width: 20em;
margin: 2em auto 4em;
canvas {
+17
View File
@@ -23,6 +23,13 @@ var ApiController = function(app) {
req.body.url = 'http://' + req.body.url;
}
// Block requests to unwanted websites (=spam)
if (isBlocked(req.body.url)) {
console.error('Test blocked for URL: %s', req.body.url);
res.status(403).send('Forbidden');
return;
}
// Grab the test parameters and generate a random run ID
var run = {
runId: (Date.now()*1000 + Math.round(Math.random()*1000)).toString(36),
@@ -86,6 +93,7 @@ var ApiController = function(app) {
return ylt(run.params.url, runOptions);
})
// Phantomas completed, let's save the screenshot if any
.then(function(data) {
@@ -327,6 +335,15 @@ var ApiController = function(app) {
});
});
function isBlocked(url) {
if (!serverSettings.blockedUrls) {
return false;
}
return serverSettings.blockedUrls.some(function(blockedUrl) {
return (url.indexOf(blockedUrl) === 0);
});
}
};
module.exports = ApiController;
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "yellowlabtools",
"version": "1.12.0",
"version": "1.12.1",
"description": "Online tool to audit a webpage for performance and front-end quality issues",
"license": "GPL-2.0",
"author": {
+2 -1
View File
@@ -8,5 +8,6 @@
},
"maxAnonymousRunsPerDay": 99999999,
"maxAnonymousCallsPerDay": 99999999
"maxAnonymousCallsPerDay": 99999999,
"blockedUrls": []
}
+2 -1
View File
@@ -8,5 +8,6 @@
},
"maxAnonymousRunsPerDay": 99999999,
"maxAnonymousCallsPerDay": 99999999
"maxAnonymousCallsPerDay": 99999999,
"blockedUrls": []
}
+24
View File
@@ -687,4 +687,28 @@ describe('api', function() {
});
});
it('should refuse a query on a blocked Url', function(done) {
this.timeout(5000);
request({
method: 'POST',
url: serverUrl + '/api/runs',
body: {
url: 'http://www.test.com/something.html',
waitForResponse: false
},
json: true,
headers: {
'Content-Type': 'application/json',
'X-Api-Key': Object.keys(config.authorizedKeys)[0]
}
}, function(error, response, body) {
if (!error && response.statusCode === 403) {
done();
} else {
done(error || response.statusCode);
}
});
});
});
+4 -1
View File
@@ -8,5 +8,8 @@
"1234567890": "contact@gaelmetais.com"
},
"maxAnonymousRunsPerDay": 10,
"maxAnonymousCallsPerDay": 1000
"maxAnonymousCallsPerDay": 1000,
"blockedUrls": [
"http://www.test.com"
]
}