move addon config db code to addonconfigs.js
This commit is contained in:
80
src/test/addonconfigs-test.js
Normal file
80
src/test/addonconfigs-test.js
Normal file
@@ -0,0 +1,80 @@
|
||||
/* global it:false */
|
||||
/* global describe:false */
|
||||
/* global before:false */
|
||||
/* global after:false */
|
||||
|
||||
'use strict';
|
||||
|
||||
const addonConfigs = require('../addonconfigs.js'),
|
||||
common = require('./common.js'),
|
||||
expect = require('expect.js');
|
||||
|
||||
describe('Addon config', function () {
|
||||
const { setup, cleanup, app } = common;
|
||||
|
||||
before(setup);
|
||||
after(cleanup);
|
||||
|
||||
it('returns empty addon config array for invalid app', async function () {
|
||||
const results = await addonConfigs.getByAppId('randomid');
|
||||
expect(results).to.eql([ ]);
|
||||
});
|
||||
|
||||
it('set succeeds', async function () {
|
||||
await addonConfigs.set(app.id, 'addonid1', [ { name: 'ENV1', value: 'env' }, { name: 'ENV2', value: 'env2' } ]);
|
||||
await addonConfigs.set(app.id, 'addonid2', [ { name: 'ENV3', value: 'env' } ]);
|
||||
});
|
||||
|
||||
it('get succeeds', async function () {
|
||||
const results = await addonConfigs.get(app.id, 'addonid1');
|
||||
expect(results).to.eql([ { name: 'ENV1', value: 'env' }, { name: 'ENV2', value: 'env2' } ]);
|
||||
});
|
||||
|
||||
it('getByAppId succeeds', async function () {
|
||||
const results = await addonConfigs.getByAppId(app.id);
|
||||
expect(results).to.eql([ { name: 'ENV1', value: 'env' }, { name: 'ENV2', value: 'env2' }, { name: 'ENV3', value: 'env' } ]);
|
||||
});
|
||||
|
||||
it('getByName succeeds', async function () {
|
||||
const value = await addonConfigs.getByName(app.id, 'addonid1', 'ENV2');
|
||||
expect(value).to.be('env2');
|
||||
});
|
||||
|
||||
it('getByName of unknown value succeeds', async function () {
|
||||
const value = await addonConfigs.getByName(app.id, 'addonid1', 'ENVRANDOM');
|
||||
expect(value).to.be(null);
|
||||
});
|
||||
|
||||
it('getAppIdByValue succeeds', async function () {
|
||||
const appId = await addonConfigs.getAppIdByValue('addonid1', 'ENV1', 'env');
|
||||
expect(appId).to.be(app.id);
|
||||
});
|
||||
|
||||
it('getAppIdByValue pattern succeeds', async function () {
|
||||
const appId = await addonConfigs.getAppIdByValue('addonid1', '%ENV1', 'env');
|
||||
expect(appId).to.be(app.id);
|
||||
});
|
||||
|
||||
it('getAppIdByValue pattern of unknown succeeds', async function () {
|
||||
const appId = await addonConfigs.getAppIdByValue('addonid1', '%ENV1', 'envx');
|
||||
expect(appId).to.be(null);
|
||||
});
|
||||
|
||||
it('unset succeeds', async function () {
|
||||
await addonConfigs.unset(app.id, 'addonid1');
|
||||
});
|
||||
|
||||
it('unsetAddonConfig did remove configs', async function () {
|
||||
const results = await addonConfigs.getByAppId(app.id);
|
||||
expect(results).to.eql([ { name: 'ENV3', value: 'env' }]);
|
||||
});
|
||||
|
||||
it('unsetByAppId succeeds', async function () {
|
||||
await addonConfigs.unsetByAppId(app.id);
|
||||
});
|
||||
|
||||
it('unsetByAppId did remove configs', async function () {
|
||||
const results = await addonConfigs.getByAppId(app.id);
|
||||
expect(results).to.eql([ ]);
|
||||
});
|
||||
});
|
||||
@@ -309,89 +309,6 @@ describe('database', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('return empty addon config array for invalid app', function (done) {
|
||||
appdb.getAddonConfigByAppId('randomid', function (error, results) {
|
||||
expect(error).to.be(null);
|
||||
expect(results).to.eql([ ]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('setAddonConfig succeeds', function (done) {
|
||||
appdb.setAddonConfig(APP_1.id, 'addonid1', [ { name: 'ENV1', value: 'env' }, { name: 'ENV2', value: 'env2' } ], function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('setAddonConfig succeeds', function (done) {
|
||||
appdb.setAddonConfig(APP_1.id, 'addonid2', [ { name: 'ENV3', value: 'env' } ], function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('getAddonConfig succeeds', function (done) {
|
||||
appdb.getAddonConfig(APP_1.id, 'addonid1', function (error, results) {
|
||||
expect(error).to.be(null);
|
||||
expect(results).to.eql([ { name: 'ENV1', value: 'env' }, { name: 'ENV2', value: 'env2' } ]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('getAddonConfigByAppId succeeds', function (done) {
|
||||
appdb.getAddonConfigByAppId(APP_1.id, function (error, results) {
|
||||
expect(error).to.be(null);
|
||||
expect(results).to.eql([ { name: 'ENV1', value: 'env' }, { name: 'ENV2', value: 'env2' }, { name: 'ENV3', value: 'env' } ]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('getAddonConfigByName succeeds', function (done) {
|
||||
appdb.getAddonConfigByName(APP_1.id, 'addonid1', 'ENV2', function (error, value) {
|
||||
expect(error).to.be(null);
|
||||
expect(value).to.be('env2');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('getAddonConfigByName of unknown value succeeds', function (done) {
|
||||
appdb.getAddonConfigByName(APP_1.id, 'addonid1', 'NOPE', function (error) {
|
||||
expect(error.reason).to.be(BoxError.NOT_FOUND);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('unsetAddonConfig succeeds', function (done) {
|
||||
appdb.unsetAddonConfig(APP_1.id, 'addonid1', function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('unsetAddonConfig did remove configs', function (done) {
|
||||
appdb.getAddonConfigByAppId(APP_1.id, function (error, results) {
|
||||
expect(error).to.be(null);
|
||||
expect(results).to.eql([ { name: 'ENV3', value: 'env' }]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('unsetAddonConfigByAppId succeeds', function (done) {
|
||||
appdb.unsetAddonConfigByAppId(APP_1.id, function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('unsetAddonConfigByAppId did remove configs', function (done) {
|
||||
appdb.getAddonConfigByAppId(APP_1.id, function (error, results) {
|
||||
expect(error).to.be(null);
|
||||
expect(results).to.eql([ ]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('importFromFile', function () {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const appdb = require('../appdb.js'),
|
||||
const addonConfigs = require('../addonconfigs.js'),
|
||||
async = require('async'),
|
||||
common = require('./common.js'),
|
||||
constants = require('../constants.js'),
|
||||
@@ -15,8 +15,7 @@ const appdb = require('../appdb.js'),
|
||||
ldap = require('ldapjs'),
|
||||
ldapServer = require('../ldap.js'),
|
||||
mail = require('../mail.js'),
|
||||
safe = require('safetydance'),
|
||||
util = require('util');
|
||||
safe = require('safetydance');
|
||||
|
||||
async function ldapBind(dn, password) {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -417,9 +416,7 @@ describe('Ldap', function () {
|
||||
});
|
||||
|
||||
it('allows with valid password', async function () {
|
||||
const setAddonConfig = util.promisify(appdb.setAddonConfig);
|
||||
|
||||
await setAddonConfig(app.id, 'sendmail', [{ name: 'MAIL_SMTP_USERNAME', value : `${app.location}.app@${domain.domain}` }, { name: 'MAIL_SMTP_PASSWORD', value : 'sendmailpassword' }]),
|
||||
await addonConfigs.set(app.id, 'sendmail', [{ name: 'MAIL_SMTP_USERNAME', value : `${app.location}.app@${domain.domain}` }, { name: 'MAIL_SMTP_PASSWORD', value : 'sendmailpassword' }]),
|
||||
|
||||
await ldapBind(`cn=${app.location}.app@${domain.domain},ou=sendmail,dc=cloudron`, 'sendmailpassword');
|
||||
});
|
||||
@@ -469,8 +466,7 @@ describe('Ldap', function () {
|
||||
});
|
||||
|
||||
it('allows with valid password', async function () {
|
||||
const setAddonConfig = util.promisify(appdb.setAddonConfig);
|
||||
await setAddonConfig(app.id, 'recvmail', [{ name: 'MAIL_IMAP_USERNAME', value : `${app.location}.app@${domain.domain}` }, { name: 'MAIL_IMAP_PASSWORD', value : 'recvmailpassword' }]),
|
||||
await addonConfigs.set(app.id, 'recvmail', [{ name: 'MAIL_IMAP_USERNAME', value : `${app.location}.app@${domain.domain}` }, { name: 'MAIL_IMAP_PASSWORD', value : 'recvmailpassword' }]),
|
||||
await ldapBind(`cn=${app.location}.app@${domain.domain},ou=recvmail,dc=cloudron`, 'recvmailpassword');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user