简体   繁体   中英

Encrypt/Mask sensitive data on git push (Encryprted/masked display on remote repo)

I have a Cypress code that contains sensitive header that I wish to be masked/decrypted

cy.request({
    method: 'GET',
    url: 'https://sample-url',
    headers: {
        'key': 'value'
    }
})

Is there a way whenever we push on remote, my desired values gets encrypted (eg the headers on the above example).

There's nothing I can think of that will encrypt and decrypt values automatically via git push/fetch. That's probably not the direction you want to go anyway.

The more simple way dealing with sensitive values is by storing them in environment variables and to not commit these to version control.

With Cypress, there's several ways to get environment vars into tests , but one easy way is with a cypress.env.json file. This file would be listed inside your.gitignore.

The env file would look like the following:

// cypress.env.json
{
  "secretKey": "value"
}

And your code would call it like this

// Code
cy.request({
    method: 'GET',
    url: 'https://sample-url',
    headers: {
        'key': Cypress.env('secretKey');
    }
})

The only thing you need to make sure, if you run the tests in a pipeline, you have to set the environmet variables before running the tests.

Here's another link that I think could help

https://glebbahmutov.com/blog/keep-passwords-secret-in-e2e-tests/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM