Add robotsTxt tests

This commit is contained in:
Girish Ramakrishnan
2019-09-09 21:41:55 -07:00
parent 6f53723169
commit 79f9963792
3 changed files with 76 additions and 10 deletions

View File

@@ -1049,7 +1049,7 @@ function setAutomaticUpdate(appId, enable, auditSource, callback) {
function setRobotsTxt(appId, robotsTxt, auditSource, callback) {
assert.strictEqual(typeof appId, 'string');
assert(!robotsTxt || typeof robotsTxt === 'string');
assert(robotsTxt === null || typeof robotsTxt === 'string');
assert.strictEqual(typeof auditSource, 'object');
assert.strictEqual(typeof callback, 'function');
@@ -1059,14 +1059,17 @@ function setRobotsTxt(appId, robotsTxt, auditSource, callback) {
error = validateRobotsTxt(robotsTxt);
if (error) return callback(error);
appdb.update(appId, { robotsTxt: robotsTxt }, function (error) {
if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new AppsError(AppsError.NOT_FOUND, 'No such app'));
if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error));
reverseProxy.writeAppConfig(_.extend({}, app, { robotsTxt }), function (error) {
if (error) return callback(new AppsError(AppsError.EXTERNAL_ERROR, 'Error writing nginx config'));
// TODO: call reverseProxy config re-write here
eventlog.add(eventlog.ACTION_APP_CONFIGURE, auditSource, { appId: appId, app: app, robotsTxt: robotsTxt });
appdb.update(appId, { robotsTxt: robotsTxt }, function (error) {
if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new AppsError(AppsError.NOT_FOUND, 'No such app'));
if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error));
callback();
eventlog.add(eventlog.ACTION_APP_CONFIGURE, auditSource, { appId: appId, app: app, robotsTxt: robotsTxt });
callback();
});
});
});
}