简体   繁体   English

在 git 推送上加密/屏蔽敏感数据(在远程仓库上加密/屏蔽显示)

[英]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我有一个 Cypress 代码,其中包含敏感的 header,我希望对其进行屏蔽/解密

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.我想不出什么可以通过 git 推送/获取自动加密和解密值。 That's probably not the direction you want to go anyway.无论如何,这可能不是您想要的方向 go。

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.使用 Cypress,有多种方法可以将环境变量放入测试中,但一种简单的方法是使用cypress.env.json文件。 This file would be listed inside your.gitignore.该文件将列在 your.gitignore 中。

The env file would look like the following: env 文件如下所示:

// 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/ https://glebbahmutov.com/blog/keep-passwords-secret-in-e2e-tests/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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