Skip to content

Commit

Permalink
Add configuration for disabling/enabling spoofing
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mjgiarlo committed Mar 15, 2019
1 parent ca0d7c7 commit ce1d330
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
9 changes: 9 additions & 0 deletions __tests__/Config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
Expand Down Expand Up @@ -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'
Expand All @@ -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')
})
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ services:
editor:
build:
context: .
environment:
SPOOF_SINOPIA_SERVER: true
ports:
- 8000:8000
depends_on:
Expand Down
11 changes: 11 additions & 0 deletions src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down

0 comments on commit ce1d330

Please sign in to comment.