Add tests for proxy app upstreamUri
This commit is contained in:
@@ -9,6 +9,7 @@ const apps = require('../apps.js'),
|
||||
AuditSource = require('../auditsource.js'),
|
||||
BoxError = require('../boxerror.js'),
|
||||
common = require('./common.js'),
|
||||
constants = require('../constants.js'),
|
||||
expect = require('expect.js'),
|
||||
safe = require('safetydance');
|
||||
|
||||
@@ -72,6 +73,40 @@ describe('Apps', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('validateUpstreamUri', function () {
|
||||
it('does not allow empty URI', function () {
|
||||
expect(apps._validateUpstreamUri('')).to.be.an(Error);
|
||||
});
|
||||
|
||||
it('does not allow invalid URI scheme', function () {
|
||||
expect(apps._validateUpstreamUri('bla:blub')).to.be.an(Error);
|
||||
});
|
||||
|
||||
it('does not allow unsupported scheme', function () {
|
||||
expect(apps._validateUpstreamUri('ftp://foobar.com')).to.be.an(Error);
|
||||
});
|
||||
|
||||
it('does not allow trailing URI paths ', function () {
|
||||
expect(apps._validateUpstreamUri('https://foobar.com/extra/path')).to.be.an(Error);
|
||||
});
|
||||
|
||||
it('allows IP', function () {
|
||||
expect(apps._validateUpstreamUri('http://1.2.3.4')).to.eql(null);
|
||||
});
|
||||
|
||||
it('allows IP with port', function () {
|
||||
expect(apps._validateUpstreamUri('http://1.2.3.4:80')).to.eql(null);
|
||||
});
|
||||
|
||||
it('allows domain', function () {
|
||||
expect(apps._validateUpstreamUri('https://www.cloudron.io')).to.eql(null);
|
||||
});
|
||||
|
||||
it('allows domain with port', function () {
|
||||
expect(apps._validateUpstreamUri('https://www.cloudron.io:443')).to.eql(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('canAccess', function () {
|
||||
const someuser = { id: 'someuser', groupIds: [], role: 'user' };
|
||||
const adminuser = { id: 'adminuser', groupIds: [ 'groupie' ], role: 'admin' };
|
||||
@@ -269,6 +304,27 @@ describe('Apps', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('proxy app', function () {
|
||||
const app = require('./common.js').proxyApp;
|
||||
const newUpstreamUri = 'https://foobar.com:443';
|
||||
|
||||
before(async function () {
|
||||
await apps.add(app.id, app.appStoreId, app.manifest, app.subdomain, app.domain, app.portBindings, app);
|
||||
});
|
||||
|
||||
it('cannot set invalid upstream uri', async function () {
|
||||
const [error] = await safe(apps.setUpstreamUri(app, 'foo:bar:80', AuditSource.PLATFORM));
|
||||
expect(error.reason).to.be(BoxError.BAD_FIELD);
|
||||
});
|
||||
|
||||
it('can set upstream uri', async function () {
|
||||
await apps.setUpstreamUri(app, newUpstreamUri, AuditSource.PLATFORM);
|
||||
const result = await apps.get(app.id);
|
||||
|
||||
expect(result.upstreamUri).to.equal(newUpstreamUri);
|
||||
});
|
||||
});
|
||||
|
||||
describe('configureInstalledApps', function () {
|
||||
const app1 = Object.assign({}, app, { id: 'id1', installationState: apps.ISTATE_ERROR, subdomain: 'loc1' });
|
||||
const app2 = Object.assign({}, app, { id: 'id2', installationState: apps.ISTATE_INSTALLED, subdomain: 'loc2' });
|
||||
|
||||
Reference in New Issue
Block a user