Add env and debug mode tests

This commit is contained in:
Girish Ramakrishnan
2019-09-09 15:35:02 -07:00
parent 801ca7eda1
commit 5f9b2f1159
3 changed files with 156 additions and 4 deletions

View File

@@ -287,7 +287,7 @@ function setEnvironment(req, res, next) {
assert.strictEqual(typeof req.params.id, 'string');
if (!req.body.env || typeof req.body.env !== 'object') return next(new HttpError(400, 'env must be an object'));
if (Object.keys(req.body.env).some(function (key) { return typeof req.body.env[key] !== 'string'; })) return next(new HttpError(400, 'env must contain values as strings'));
if (Object.keys(req.body.env).some((key) => typeof req.body.env[key] !== 'string')) return next(new HttpError(400, 'env must contain values as strings'));
apps.setEnvironment(req.params.id, req.body.env, auditSource.fromRequest(req), function (error, result) {
if (error) return next(toHttpError(error));

View File

@@ -1122,6 +1122,159 @@ describe('App API', function () {
});
});
describe('configure debug mode', function () {
it('fails with missing mode', function (done) {
superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure/debug_mode')
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
done();
});
});
it('fails with bad debug mode', function (done) {
superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure/debug_mode')
.query({ access_token: token })
.send({ debugMode: 'sleep' })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
done();
});
});
it('can set debug mode', function (done) {
superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure/debug_mode')
.query({ access_token: token })
.send({ debugMode: { readonlyRootfs: false } })
.end(function (err, res) {
expect(res.statusCode).to.equal(202);
taskId = res.body.taskId;
done();
});
});
it('wait for task', function (done) {
waitForTask(taskId, done);
});
it('did change readonly rootfs', function (done) {
apps.get(APP_ID, function (error, app) {
if (error) return done(error);
docker.getContainer(app.containerId).inspect(function (error, data) {
expect(error).to.not.be.ok();
expect(data.HostConfig.ReadonlyRootfs).to.be(false);
done();
});
});
});
it('can reset debug mode', function (done) {
superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure/debug_mode')
.query({ access_token: token })
.send({ debugMode: null })
.end(function (err, res) {
expect(res.statusCode).to.equal(202);
taskId = res.body.taskId;
done();
});
});
it('wait for task', function (done) {
waitForTask(taskId, done);
});
it('did change readonly rootfs', function (done) {
apps.get(APP_ID, function (error, app) {
if (error) return done(error);
docker.getContainer(app.containerId).inspect(function (error, data) {
expect(error).to.not.be.ok();
expect(data.HostConfig.ReadonlyRootfs).to.be(true);
done();
});
});
});
});
describe('configure env', function () {
it('fails with missing env', function (done) {
superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure/env')
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
done();
});
});
it('fails with bad env mode', function (done) {
superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure/env')
.query({ access_token: token })
.send({ env: 'ok' })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
done();
});
});
it('can set env', function (done) {
superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure/env')
.query({ access_token: token })
.send({ env: { 'OPM': 'SAITAMA' } })
.end(function (err, res) {
expect(res.statusCode).to.equal(202);
taskId = res.body.taskId;
done();
});
});
it('wait for task', function (done) {
waitForTask(taskId, done);
});
it('did set env', function (done) {
apps.get(APP_ID, function (error, app) {
if (error) return done(error);
docker.getContainer(app.containerId).inspect(function (error, data) {
expect(error).to.not.be.ok();
expect(data.Config.Env).to.contain('OPM=SAITAMA');
done();
});
});
});
it('can reset env', function (done) {
superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure/env')
.query({ access_token: token })
.send({ env: {} })
.end(function (err, res) {
expect(res.statusCode).to.equal(202);
taskId = res.body.taskId;
done();
});
});
it('wait for task', function (done) {
waitForTask(taskId, done);
});
it('did reset env', function (done) {
apps.get(APP_ID, function (error, app) {
if (error) return done(error);
docker.getContainer(app.containerId).inspect(function (error, data) {
expect(error).to.not.be.ok();
expect(data.Config.Env).to.not.contain('OPM=SAITAMA');
done();
});
});
});
});
describe('start/stop', function () {
it('non admin cannot stop app', function (done) {
superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/stop')