getHostType: consider APP_DOC_INTERNAL_URL as native (#715)

The getHostType() now returns "native" when the host corresponds to the value of APP_DOC_INTERNAL_URL. T
While trying to scale, with a different internal and public URL for doc workers, and having configured the org to be specified in the path (GRIST_ORG_IN_PATH=true), the APP_DOC_INTERNAL_URL parameter was not treated as internal which made the connection between home server and doc workers impossible.

---------
https://github.com/gristlabs/grist-core/pull/715
Co-authored-by: Florent FAYOLLE <florent.fayolle@beta.gouv.fr>
This commit is contained in:
Florent
2023-11-06 09:24:59 +01:00
committed by GitHub
parent c8eb1ad4a9
commit 10822d3b86
4 changed files with 67 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
import {decodeUrl, IGristUrlState, parseFirstUrlPart} from 'app/common/gristUrls';
import {decodeUrl, getHostType, IGristUrlState, parseFirstUrlPart} from 'app/common/gristUrls';
import {assert} from 'chai';
import * as testUtils from 'test/server/testUtils';
describe('gristUrls', function() {
@@ -76,4 +77,56 @@ describe('gristUrls', function() {
assert.deepEqual(parseFirstUrlPart('o', ''), {path: ''});
});
});
describe('getHostType', function() {
const defaultOptions = {
baseDomain: 'getgrist.com',
pluginUrl: 'https://plugin.getgrist.com',
};
let oldEnv: testUtils.EnvironmentSnapshot;
beforeEach(function () {
oldEnv = new testUtils.EnvironmentSnapshot();
});
afterEach(function () {
oldEnv.restore();
});
it('should interpret localhost as "native"', function() {
assert.equal(getHostType('localhost', defaultOptions), 'native');
assert.equal(getHostType('localhost:8080', defaultOptions), 'native');
});
it('should interpret base domain as "native"', function() {
assert.equal(getHostType('getgrist.com', defaultOptions), 'native');
assert.equal(getHostType('www.getgrist.com', defaultOptions), 'native');
assert.equal(getHostType('foo.getgrist.com', defaultOptions), 'native');
assert.equal(getHostType('foo.getgrist.com:8080', defaultOptions), 'native');
});
it('should interpret plugin domain as "plugin"', function() {
assert.equal(getHostType('plugin.getgrist.com', defaultOptions), 'plugin');
assert.equal(getHostType('PLUGIN.getgrist.com', { pluginUrl: 'https://pLuGin.getgrist.com' }), 'plugin');
});
it('should interpret other domains as "custom"', function() {
assert.equal(getHostType('foo.com', defaultOptions), 'custom');
assert.equal(getHostType('foo.bar.com', defaultOptions), 'custom');
});
it('should interpret doc internal url as "native"', function() {
process.env.APP_DOC_INTERNAL_URL = 'https://doc-worker-123.internal/path';
assert.equal(getHostType('doc-worker-123.internal', defaultOptions), 'native');
assert.equal(getHostType('doc-worker-123.internal:8080', defaultOptions), 'custom');
assert.equal(getHostType('doc-worker-124.internal', defaultOptions), 'custom');
process.env.APP_DOC_INTERNAL_URL = 'https://doc-worker-123.internal:8080/path';
assert.equal(getHostType('doc-worker-123.internal:8080', defaultOptions), 'native');
assert.equal(getHostType('doc-worker-123.internal', defaultOptions), 'custom');
assert.equal(getHostType('doc-worker-124.internal:8080', defaultOptions), 'custom');
assert.equal(getHostType('doc-worker-123.internal:8079', defaultOptions), 'custom');
});
});
});

View File

@@ -17,9 +17,10 @@ describe('DocApi2', function() {
let owner: UserAPI;
let wsId: number;
testUtils.setTmpLogLevel('error');
const oldEnv = new testUtils.EnvironmentSnapshot();
let oldEnv: testUtils.EnvironmentSnapshot;
before(async function() {
oldEnv = new testUtils.EnvironmentSnapshot();
const tmpDir = await createTmpDir();
process.env.GRIST_DATA_DIR = tmpDir;
process.env.STRIPE_ENDPOINT_SECRET = 'TEST_WITHOUT_ENDPOINT_SECRET';