From ce1d330b33e56e460dd03327c66c0c04e063cc7d Mon Sep 17 00:00:00 2001 From: "Michael J. Giarlo" Date: Fri, 15 Mar 2019 11:57:19 -0700 Subject: [PATCH] Add configuration for disabling/enabling spoofing Set default value to enable spoofing and explicitly set this value in the editor service in docker-compose to retain current behavior connects to #309 --- __tests__/Config.test.js | 9 +++++++++ docker-compose.yml | 2 ++ src/Config.js | 11 +++++++++++ 3 files changed, 22 insertions(+) diff --git a/__tests__/Config.test.js b/__tests__/Config.test.js index b2485c8cf..16f83f83e 100644 --- a/__tests__/Config.test.js +++ b/__tests__/Config.test.js @@ -12,6 +12,10 @@ describe('Config', () => { expect(Config.sinopiaUrl).toEqual('https://sinopia.io') }) + it('spoof sinopia server has static value', () => { + expect(Config.spoofSinopiaServer).toEqual(true) + }) + it('aws client ID has static value', () => { expect(Config.awsClientID).toEqual('2u6s7pqkc1grq1qs464fsi82at') }) @@ -52,6 +56,7 @@ describe('Config', () => { beforeAll(() => { process.env = { + SPOOF_SINOPIA_SERVER: 'false', SINOPIA_URI: 'sinopia.foo', COGNITO_CLIENT_ID: '1a2b3c', AWS_COGNITO_DOMAIN: 'sinopia-foo.amazoncognito.com' @@ -62,6 +67,10 @@ describe('Config', () => { expect(Config.sinopiaUrl).toEqual('https://sinopia.foo') }) + it('spoof sinopia server has static value', () => { + expect(Config.spoofSinopiaServer).toEqual(false) + }) + it('aws client ID has static value', () => { expect(Config.awsClientID).toEqual('1a2b3c') }) diff --git a/docker-compose.yml b/docker-compose.yml index 317aeaa98..1ef2a6905 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,6 +3,8 @@ services: editor: build: context: . + environment: + SPOOF_SINOPIA_SERVER: true ports: - 8000:8000 depends_on: diff --git a/src/Config.js b/src/Config.js index b466d6d9b..9d7371739 100644 --- a/src/Config.js +++ b/src/Config.js @@ -7,6 +7,17 @@ class Config { return `https://${this.sinopiaDomainName}` } + static get spoofSinopiaServer() { + // There are two value types of `process.env` variables: + // 1. When undefined, `if` condition it not satisfied and default `true` is returned + // 2. When defined, will always be a string. + // a. When set to 'true' return `true` (use spoof) + // b. When set to 'false' or any other string, return `false` (don't use spoof) + if (process.env.SPOOF_SINOPIA_SERVER) + return process.env.SPOOF_SINOPIA_SERVER === 'true' + return true + } + static get awsClientID() { return process.env.COGNITO_CLIENT_ID || '2u6s7pqkc1grq1qs464fsi82at' }