Skip to content

Commit

Permalink
update code and cypress test so that failure is expected against depl…
Browse files Browse the repository at this point in the history
…oyed environments
  • Loading branch information
pearl-truss committed Feb 7, 2024
1 parent fd77f65 commit b9c8501
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion services/app-api/src/authn/thirdPartyAuthn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function userFromThirdPartyAuthorizer(
const ipAddressIsValid = allowedIpAddresses.includes(ipAddress)
if (!ipAddressIsValid) {
const errMsg = new Error(
`IP address: ${ipAddress} is not in the allowed list`
`IP address: ${ipAddress}, this IP address is not in the allowed list`
)
return err(errMsg)
}
Expand Down
4 changes: 3 additions & 1 deletion services/app-api/src/handlers/apollo_gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ function contextForRequestForFetcher(userFetcher: userFromAuthProvider): ({
}
} catch (err) {
console.error('Error attempting to fetch user: ', err)
throw new Error('Log: placing user in gql context failed')
throw new Error(
`Log: placing user in gql context failed, ${err}`
)
}
} else {
throw new Error('Log: no AuthProvider from an internal API user.')
Expand Down
1 change: 0 additions & 1 deletion services/cypress/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ module.exports = defineConfig({
newConfig.env.COGNITO_REGION = process.env.COGNITO_REGION
newConfig.env.COGNITO_IDENTITY_POOL_ID = process.env.COGNITO_IDENTITY_POOL_ID
newConfig.env.COGNITO_USER_POOL_WEB_CLIENT_ID = process.env.COGNITO_USER_POOL_WEB_CLIENT_ID

on('before:browser:launch', (browser, launchOptions) => {
prepareAudit(launchOptions)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('thirdPartyAPIAccess', () => {
})
})

it('works with a valid key', () => {
it('expect server error when called from deployed cypress, otherwise success on local', () => {

// get the API URL!
const url = Cypress.env('API_URL')
Expand Down Expand Up @@ -69,7 +69,12 @@ describe('thirdPartyAPIAccess', () => {
body: '{"query":"query IndexRates { indexRates { totalCount edges { node { id } } } }"}',
failOnStatusCode: false,
}).then(res => {
expect(res.status).to.equal(200)
if (Cypress.config().baseUrl === 'http://localhost:3000') {
expect(res.status).to.equal(200) // okay
} else {
expect(res.body.errors[0].message).to.contain('this IP address is not in the allowed list')
expect(res.status).to.equal(500) // server error
}
})

})
Expand Down

0 comments on commit b9c8501

Please sign in to comment.