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

refactor(cypress): read creds from env instead of hardcoding the path #4430

Merged
merged 18 commits into from Apr 30, 2024

Conversation

pixincreate
Copy link
Member

@pixincreate pixincreate commented Apr 22, 2024

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

Usage

export DEBUG=cypress:cli
export CYPRESS_CONNECTOR="connector_name"
export CYPRESS_BASEURL="http://127.0.0.1:8080"
export CYPRESS_ADMINAPIKEY='some_api_key'

# Introduced change
export CYPRESS_CONNECTOR_AUTH_FILE_PATH='path/to/creds.json'

npm run cypress

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

There has been many occurrences where developers accidentally exposed the path to creds.json from their PC (although it is not too much of a security risk, it still poses a significant risk on surface level). To avoid that from happening again in future, this measure has been taken.

How did you test it?

Followed the Usage section mentioned above and ran the tests, they ran fine without any issues:

image

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible
  • I added a CHANGELOG entry if applicable

@pixincreate pixincreate added A-CI-CD Area: Continuous Integration/Deployment C-test Category: Tests labels Apr 22, 2024
@pixincreate pixincreate added this to the April 2024 milestone Apr 22, 2024
@pixincreate pixincreate self-assigned this Apr 22, 2024
@pixincreate pixincreate requested a review from a team as a code owner April 22, 2024 18:38
SanchithHegde
SanchithHegde previously approved these changes Apr 23, 2024
@pixincreate pixincreate changed the base branch from trustpay_collection_fix to main April 23, 2024 13:25
@pixincreate pixincreate dismissed SanchithHegde’s stale review April 23, 2024 13:25

The base branch was changed.

@pixincreate pixincreate changed the base branch from main to refactor-cypress-for-more-control April 23, 2024 13:26
SanchithHegde
SanchithHegde previously approved these changes Apr 23, 2024
Gnanasundari24 and others added 5 commits April 24, 2024 17:14
- auto-formatting
- remove hardcoded creds path for exporting them through env
- remove deplicated logger code for calling it through a functionQ
@pixincreate pixincreate changed the base branch from refactor-cypress-for-more-control to main April 25, 2024 07:50
@pixincreate pixincreate dismissed SanchithHegde’s stale review April 25, 2024 07:50

The base branch was changed.

Gnanasundari24 and others added 2 commits April 25, 2024 14:59
…to-env

* 'main' of github.com:juspay/hyperswitch:
  ci(postman): Fix Adyen postman collection (#4459)
  docs(cypress): Update Cypress README Documentation (#4380)
  Refactor(core): make save_payment_method as post_update_tracker trait function (#4307)
  refactor(connector): pass optional browser_info to stripe for increased trust (#4374)
Comment on lines 88 to 111
// readFile is used to read the contents of the file and it always returns a promise ([Object Object]) due to its asynchronous nature
// it is best to use then() to handle the response within the same block of code
cy.readFile(globalState.get("connectorAuthFilePath")).then((jsonContent) => {
const authDetails = getValueByKey(JSON.stringify(jsonContent), globalState.get("connectorId"));
createConnectorBody.connector_account_details = authDetails;
cy.request({
method: "POST",
url: `${globalState.get("baseUrl")}/account/${merchantId}/connectors`,
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"api-key": globalState.get("adminApiKey"),
},
body: createConnectorBody,
}).then((response) => {
logRequestId(response.headers['x-request-id']);

if (response.status === 200) {
expect(globalState.get("connectorId")).to.equal(response.body.connector_name);
} else {
cy.task('cli_log', "response status -> " + JSON.stringify(response.status));
cy.task('cli_log', "res body -> " + JSON.stringify(response.body));
}
});
Copy link
Member Author

Choose a reason for hiding this comment

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

ConnectorAuthDetails in line 29 reads the content from the file and stores within that variable.

getValueByKey() takes the content of the file and the key (the connector name) and returns the respective connector auth details.

Since we now read from the env, we do not have any method to store the content. Cypress natively supports cy.readFile which is again, asynchronous in nature, returns an Object (promise). We can only parse that Object within .then() and read it.

With that, it makes it necessary for us to move the entire flow within cy.readFile() [Docs: https://docs.cypress.io/api/commands/readfile]

@pixincreate pixincreate requested review from prasunna09 and removed request for a team April 25, 2024 11:40
…to-env

* 'main' of github.com:juspay/hyperswitch:
  feat: add an api for toggling extended card info feature (#4444)
@Gnanasundari24
Copy link
Contributor

@pixincreate Can you update the readme for this. So that contributors can know how to configure auth file.

@pixincreate
Copy link
Member Author

pixincreate commented Apr 30, 2024

@pixincreate Can you update the readme for this. So that contributors can know how to configure auth file.

Will take this as a separate PR.

Edit: #4505

@likhinbopanna likhinbopanna added this pull request to the merge queue Apr 30, 2024
Merged via the queue into main with commit 0c9ba1e Apr 30, 2024
10 of 12 checks passed
@likhinbopanna likhinbopanna deleted the move-creds-to-env branch April 30, 2024 09:58
pixincreate added a commit that referenced this pull request Apr 30, 2024
* 'main' of github.com:juspay/hyperswitch:
  refactor(cypress): read creds from env instead of hardcoding the path  (#4430)
  ci: fix paypal postman tests (#4501)
  Refactor(core): remove payment_method_id from RouterData struct (#4485)
  fix(euclid_wasm): connector config wasm metadata update (#4460)
  chore(version): 2024.04.30.0
  feat(user): add single purpose token and auth (#4470)
  feat: stripe connect integration for payouts (#2041)
  feat(router): handle authorization for frictionless flow in external 3ds flow (#4471)
  feat(FRM): Revise post FRM core flows (#4394)
  feat(router): send poll_config in next_action of confirm response for external 3ds flow (#4443)
  chore(version): 2024.04.29.0
  feat(connector): [CRYPTOPAY]  Report underpaid/overpaid amount in outgoing webhooks (#4468)
  feat(users): use cookie for auth (#4434)
  refactor(scheduler): join frequency and count in `RetryMapping` (#4313)
  refactor(required_fields): change required fields for billing address (#4258)
  refactor(access_token): use `merchant_connector_id` for storing access token (#4462)
  chore(version): 2024.04.26.0
  chore(postman): update Postman collection files
@pixincreate pixincreate removed the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-CI-CD Area: Continuous Integration/Deployment C-test Category: Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants