Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@W-12582733: Adding env-var endpoint for Manager's smoke tests #1178

Draft
wants to merge 3 commits into
base: v2-archive-20230512
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 20 additions & 1 deletion packages/template-mrt-reference-app/app/ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,21 @@ const ENVS_TO_EXPOSE = [
'aws_lambda_log_stream_name',
'aws_region',
'bundle_id',
// These "customer" defined environment variables are set and expected
// by the MRT smoke test suite
'customer_defined_array',
'customer_defined_boolean',
'customer_defined_float',
'customer_defined_integer',
'customer_defined_json',
'customer_defined_null',
'customer_defined_string',
'deploy_id',
'deploy_target',
'external_domain_name',
'mobify_property_id',
'node_env',
'tz'
'tz',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this fails the lint check in CI, fixable with npm run lint:fix after running npm ci from pwa-kit root

]

const HEADERS_TO_REDACT = ['x-api-key', 'x-apigateway-context', 'x-apigateway-event']
Expand Down Expand Up @@ -163,6 +172,15 @@ const tlsVersionTest = async (_, res) => {
res.send(JSON.stringify({'tls1.1': response11, 'tls1.2': response12}, null, 4))
}

/**
* Express handler that returns all the environment variables set
*/
const envVarsEndpoint = async (_, res) => {
res.header('Content-Type', 'application/json')
const exposed = filterAndSortObjectKeys(process.env, ENVS_TO_EXPOSE)
res.send(JSON.stringify(exposed, null, 4))
}

/**
* Logging middleware; logs request and response headers (and response status).
*/
Expand Down Expand Up @@ -218,6 +236,7 @@ const {handler, app, server} = runtime.createHandler(options, (app) => {
// Configure routes
app.all('/exception', exception)
app.get('/tls', tlsVersionTest)
app.get('/env-vars', envVarsEndpoint)

// Add a /auth/logout path that will always send a 401 (to allow clearing
// of browser credentials)
Expand Down
3 changes: 2 additions & 1 deletion packages/template-mrt-reference-app/app/ssr.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ describe('server', () => {
test.each([
['/', 200, 'application/json; charset=utf-8'],
['/tls', 200, 'application/json; charset=utf-8'],
['/exception', 500, 'text/html; charset=utf-8']
['/exception', 500, 'text/html; charset=utf-8'],
['/env-vars', 200, 'application/json; charset=utf-8']
])('Path %p should render correctly', (path, expectedStatus, expectedContentType) => {
return request(app)
.get(path)
Expand Down