Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
…o feature/cacheable-lookup
  • Loading branch information
10xLaCroixDrinker committed May 3, 2022
2 parents 172b245 + 7d2cc30 commit 452f7ad
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ jobs:
name: Docker Tag Version Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set env
id: set_tag_version
run: |
#Checks for when a valid tag is manually pushed
if [[ $GITHUB_REF != "" && "${{ github.event.client_payload.tagversion }}" == "" ]];
then
echo ::set-output name=tagversion::$(egrep -o '(v[0-9]+\.[0-9]+\.[0-9]+)(-\S*)?' <<< $GITHUB_REF)
echo ::set-output name=tagversion::$(egrep -o '^v([0-9]+\.[0-9]+\.[0-9]+)(-\S*)?' <<< $GITHUB_REF)
else
echo ::set-output name=tagversion::${{ github.event.client_payload.tagversion }}
fi
Expand All @@ -40,8 +39,13 @@ jobs:
- name: Docker tag version
id: set_docker_tag_version
run: |
tagversion=${{ steps.set_tag_version.outputs.tagversion}}
# trimmed off 'v' from tagversion
tagversion=${{ steps.set_tag_version.outputs.tagversion }}
echo ::set-output name=dockertag::$(sed 's/^v*//' <<< "$tagversion")
# ensure tag is available
- uses: actions/checkout@v2
with:
ref: "v${{ steps.set_docker_tag_version.outputs.dockertag }}"
- name: Trigger Production Image Publishing
uses: octokit/request-action@v2.x
id: dispatch_release-step-4_automatic_docker-prod-build-and-publish
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ jobs:
name: One App Production Image Build and Push
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Docker login
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login --username ${{ secrets.DOCKER_USER }} --password-stdin
- name: Build production docker image
run: docker build -t prod .
- name: Extract sem versions
id: get_sem_version
run: |
Expand All @@ -41,6 +36,13 @@ jobs:
echo ::set-output name=major_version::${MAJOR}
echo ::set-output name=minor_version::${MINOR}
fi
- uses: actions/checkout@v2
with:
ref: "v${{ steps.set_docker_version.outputs.docker_version }}"
- name: Docker login
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login --username ${{ secrets.DOCKER_USER }} --password-stdin
- name: Build production docker image
run: docker build -t prod .
- name: Tag Docker Images
run: |
docker tag prod ${{ secrets.DOCKER_USER }}/one-app:${{ steps.set_docker_version.outputs.major_version}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ jobs:
name: One App Development Image Build and Push
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Docker Image Versions
id: set_docker_version
run: |
Expand All @@ -31,7 +30,10 @@ jobs:
fi
- name: Print docker version
run: |
echo "tag: ${{ github.event.inputs.docker_tag_version }}"
echo "tag: ${{ steps.set_docker_version.outputs.docker_version }}"
- uses: actions/checkout@v2
with:
ref: "v${{ steps.set_docker_version.outputs.docker_version }}"
- name: Docker login
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login --username ${{ secrets.DOCKER_USER }} --password-stdin
- name: Build development docker image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ jobs:
name: One App Statics Publish to NPM
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v1
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
- name: Docker login
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login --username ${{ secrets.DOCKER_USER }} --password-stdin
- name: Tag Version
id: set_tag_version
run: |
Expand All @@ -29,6 +21,16 @@ jobs:
else
echo ::set-output name=tagversion::${{ github.event.inputs.tag_version }}
fi
- uses: actions/checkout@v2
with:
ref: "v${{ steps.set_tag_version.outputs.tagversion}}"
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v1
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
- name: Docker login
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login --username ${{ secrets.DOCKER_USER }} --password-stdin
- name: Extract and zip production statics
run: |
docker create --name prod ${{ secrets.DOCKER_USER }}/one-app:${{ steps.set_tag_version.outputs.tagversion}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`runTime HTTP_ONE_APP_DEV_CDN_PORT normalizes numeric input 1`] = `"env var HTTP_ONE_APP_DEV_CDN_PORT needs to be a valid integer, given \\"0002345a\\""`;

exports[`runTime HTTP_ONE_APP_DEV_PROXY_SERVER_PORT normalizes numeric input: env var HTTP_ONE_APP_DEV_PROXY_SERVER_PORT needs to be a valid integer, given "r00t" 1`] = `"env var HTTP_ONE_APP_DEV_PROXY_SERVER_PORT needs to be a valid integer, given \\"r00t\\""`;

exports[`runTime NODE_ENV only allows for values to be set to either development or production 1`] = `
Array [
"development",
"production",
]
`;

exports[`runTime ONE_CLIENT_ROOT_MODULE_NAME validates that environment value is defined 1`] = `"The \`ONE_CLIENT_ROOT_MODULE_NAME\` environment variable must be defined."`;
96 changes: 82 additions & 14 deletions __tests__/server/config/env/runTime.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ describe('runTime', () => {
'ONE_CLIENT_CDN_URL',
'ONE_CLIENT_LOCALE_FILENAME',
'ONE_CLIENT_ROOT_MODULE_NAME',
]
.forEach((name) => { origEnvVarVals[name] = process.env[name]; });
'ONE_ENABLE_POST_TO_MODULE_ROUTES',
'ONE_MAX_POST_REQUEST_PAYLOAD',
].forEach((name) => {
origEnvVarVals[name] = process.env[name];
});

function getEnvVarConfig(envVarName) {
const runTime = require('../../../../src/server/config/env/runTime').default;
Expand All @@ -70,6 +73,7 @@ describe('runTime', () => {
resetEnvVar('NODE_ENV');
resetEnvVar('ONE_DANGEROUSLY_DISABLE_CSP', 'false');
resetEnvVar('HTTP_ONE_APP_DEV_CDN_PORT');
resetEnvVar('ONE_ENABLE_POST_TO_MODULE_ROUTES');
jest.resetModules();
jest.resetAllMocks();
});
Expand All @@ -78,9 +82,7 @@ describe('runTime', () => {
// eslint-disable-next-line no-console
console.info = origConsoleInfo;
console.warn = origConsoleWarn;
Object
.keys(origEnvVarVals)
.forEach((name) => resetEnvVar(name, origEnvVarVals[name]));
Object.keys(origEnvVarVals).forEach((name) => resetEnvVar(name, origEnvVarVals[name]));
jest.resetAllMocks();
});

Expand Down Expand Up @@ -131,13 +133,17 @@ describe('runTime', () => {
const disableCspEnv = getEnvVarConfig('ONE_DANGEROUSLY_DISABLE_CSP');

it('throws error if ONE_DANGEROUSLY_DISABLE_CSP is set to true and NODE_ENV is not development', () => {
expect(() => disableCspEnv.validate('true')).toThrowError('If you are trying to bypass CSP requirement, NODE_ENV must also be set to development.');
expect(() => disableCspEnv.validate('true')).toThrowError(
'If you are trying to bypass CSP requirement, NODE_ENV must also be set to development.'
);
});

it('warns console if both ONE_DANGEROUSLY_DISABLE_CSP and NODE_ENV are set properly', () => {
process.env.NODE_ENV = 'development';
disableCspEnv.validate('true');
expect(console.warn).toHaveBeenCalledWith('ONE_DANGEROUSLY_DISABLE_CSP is true and NODE_ENV is set to development. Content-Security-Policy header will not be set.');
expect(console.warn).toHaveBeenCalledWith(
'ONE_DANGEROUSLY_DISABLE_CSP is true and NODE_ENV is set to development. Content-Security-Policy header will not be set.'
);
});

it('does not warn or throw if ONE_DANGEROUSLY_DISABLE_CSP is set to false', () => {
Expand Down Expand Up @@ -190,7 +196,9 @@ describe('runTime', () => {
'env var HTTP_ONE_APP_DEV_CDN_PORT needs to be a valid integer, given "r00t"'
);
expect(devCdnPort.normalize('0002345')).toEqual(2345);
expect(() => devCdnPort.normalize('0002345a')).toThrowErrorMatchingSnapshot();
expect(() => devCdnPort.normalize('0002345a')).toThrowErrorMatchingInlineSnapshot(
'"env var HTTP_ONE_APP_DEV_CDN_PORT needs to be a valid integer, given \\"0002345a\\""'
);
});

it('does not normalize if no value is given', () => {
Expand All @@ -215,8 +223,8 @@ describe('runTime', () => {

it('normalizes numeric input', () => {
expect(devProxyPort.normalize('1337')).toEqual(1337);
expect(() => devProxyPort.normalize('r00t')).toThrowErrorMatchingSnapshot(
'env var HTTP_ONE_APP_DEV_PROXY_SERVER_PORT needs to be a valid integer, given "r00t"'
expect(() => devProxyPort.normalize('r00t')).toThrowErrorMatchingInlineSnapshot(
'"env var HTTP_ONE_APP_DEV_PROXY_SERVER_PORT needs to be a valid integer, given \\"r00t\\""'
);
expect(devProxyPort.normalize('0002345')).toEqual(2345);
expect(() => devProxyPort.normalize('0002345a')).toThrow();
Expand Down Expand Up @@ -263,7 +271,9 @@ describe('runTime', () => {
process.env.NODE_ENV = 'development';
process.env.HTTP_ONE_APP_DEV_CDN_PORT = 3001;
expect(holocronModuleMapPath.defaultValue()).toBeDefined();
expect(holocronModuleMapPath.defaultValue()).toBe('http://localhost:3001/static/module-map.json');
expect(holocronModuleMapPath.defaultValue()).toBe(
'http://localhost:3001/static/module-map.json'
);
});

it('has no default value for production', () => {
Expand Down Expand Up @@ -293,13 +303,18 @@ describe('runTime', () => {
});

describe('HOLOCRON_SERVER_MAX_SIM_MODULES_FETCH', () => {
const holocronServerMaxSimModulesFetch = getEnvVarConfig('HOLOCRON_SERVER_MAX_SIM_MODULES_FETCH');
const holocronServerMaxSimModulesFetch = getEnvVarConfig(
'HOLOCRON_SERVER_MAX_SIM_MODULES_FETCH'
);

it('does not have a default value', () => {
expect(holocronServerMaxSimModulesFetch.defaultValue).toBe(undefined);
});

it('validates the value as a positive integer', positiveInteger(holocronServerMaxSimModulesFetch));
it(
'validates the value as a positive integer',
positiveInteger(holocronServerMaxSimModulesFetch)
);
});

describe('ONE_CLIENT_REPORTING_URL', () => {
Expand Down Expand Up @@ -390,7 +405,9 @@ describe('runTime', () => {
const clientRootModuleName = getEnvVarConfig('ONE_CLIENT_ROOT_MODULE_NAME');

it('validates that environment value is defined', () => {
expect(() => clientRootModuleName.validate()).toThrowErrorMatchingSnapshot();
expect(() => clientRootModuleName.validate()).toThrowErrorMatchingInlineSnapshot(
'"The `ONE_CLIENT_ROOT_MODULE_NAME` environment variable must be defined."'
);
expect(() => clientRootModuleName.validate('frank-lloyd-root')).not.toThrow();
});

Expand Down Expand Up @@ -432,4 +449,55 @@ describe('runTime', () => {
expect(oneServiceWorkerFeatureFlag.normalize('true')).toEqual(true);
});
});

describe('ONE_ENABLE_POST_TO_MODULE_ROUTES', () => {
const enablePostToModuleRoutes = getEnvVarConfig('ONE_ENABLE_POST_TO_MODULE_ROUTES');

it('should have a default value of "false"', () => {
expect(enablePostToModuleRoutes.defaultValue).toBe('false');
});

it('should normalize the value to lower case', () => {
expect(enablePostToModuleRoutes.normalize('Value')).toBe('value');
expect(enablePostToModuleRoutes.normalize('VALUE')).toBe('value');
});

it('should pass validation when value is "true" or "false"', () => {
expect(() => enablePostToModuleRoutes.validate('true')).not.toThrow();
expect(() => enablePostToModuleRoutes.validate('false')).not.toThrow();
});

it('should fail validation when value is not "true" or "false"', () => {
expect(() => enablePostToModuleRoutes.validate('bad value')
).toThrowErrorMatchingInlineSnapshot(
'"Expected \\"bad value\\" to be \\"true\\" or \\"false\\""'
);
});
});

describe('ONE_MAX_POST_REQUEST_PAYLOAD', () => {
const postRequestMaxPayload = getEnvVarConfig('ONE_MAX_POST_REQUEST_PAYLOAD');

it('should have a default value of "15kb"', () => {
expect(postRequestMaxPayload.defaultValue).toBe('15kb');
});

it('should fail validation when input is not parseable by bytes util', () => {
process.env.ONE_ENABLE_POST_TO_MODULE_ROUTES = true;
expect(() => postRequestMaxPayload.validate('bad value')).toThrowErrorMatchingInlineSnapshot(
'"Expected \\"bad value\\" to be parseable by bytes utility https://www.npmjs.com/package/bytes"'
);
});

it('should pass validation when input is parseable by bytes util', () => {
process.env.ONE_ENABLE_POST_TO_MODULE_ROUTES = true;
expect(() => postRequestMaxPayload.validate('20kb')).not.toThrow();
});

it('should fail validation when POSTing is not enabled', () => {
expect(() => postRequestMaxPayload.validate('20kb')).toThrowErrorMatchingInlineSnapshot(
'"ONE_ENABLE_POST_TO_MODULE_ROUTES must be \\"true\\" to configure max POST payload."'
);
});
});
});
9 changes: 6 additions & 3 deletions __tests__/server/ssrServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('ssrServer', () => {
jest.clearAllMocks();
process.env.NODE_ENV = 'development';
delete process.env.ONE_ENABLE_POST_TO_MODULE_ROUTES;
delete process.env.ONE_MAX_POST_REQUEST_PAYLOAD;
});

describe('middleware order', () => {
Expand Down Expand Up @@ -288,7 +289,7 @@ describe('ssrServer', () => {

describe('enablePostToModuleRoutes', () => {
beforeEach(() => {
process.env.ONE_ENABLE_POST_TO_MODULE_ROUTES = 'yes';
process.env.ONE_ENABLE_POST_TO_MODULE_ROUTES = 'true';
});

it('should check the state for a status code for all post calls', async () => {
Expand Down Expand Up @@ -331,10 +332,11 @@ describe('ssrServer', () => {
});

it('should configure json parsing with a maximum limit for render post calls', async () => {
process.env.ONE_MAX_POST_REQUEST_PAYLOAD = '100kb';
await request(loadServer())
.post('/route');
expect(json).toBeCalled();
expect(json.mock.calls[2][0]).toHaveProperty('limit', '15kb');
expect(json.mock.calls[2][0]).toHaveProperty('limit', '100kb');
});
it('should configure urlencoded parsing with a maximum limit for render post pre-flight options calls', async () => {
await request(loadServer())
Expand All @@ -344,10 +346,11 @@ describe('ssrServer', () => {
});

it('should configure json urlencoded with a maximum limit for render post calls', async () => {
process.env.ONE_MAX_POST_REQUEST_PAYLOAD = '25kb';
await request(loadServer())
.post('/route');
expect(urlencoded).toBeCalled();
expect(json.mock.calls[2][0]).toHaveProperty('limit', '15kb');
expect(json.mock.calls[2][0]).toHaveProperty('limit', '25kb');
});

describe('cors for render post calls', () => {
Expand Down
Loading

0 comments on commit 452f7ad

Please sign in to comment.