-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #303 from snyk/fix/santize-cr-env
fix: sanitize CR env data in logs
- Loading branch information
Showing
2 changed files
with
17 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ describe('log', () => { | |
const azureReposToken = (process.env.AZURE_REPOS_TOKEN = 'AZURE_TOKEN'); | ||
const artifactoryUrl = (process.env.ARTIFACTORY_URL = | ||
'http://basic:[email protected]'); | ||
const crAgentUrl = (process.env.CR_AGENT_URL = | ||
'CONTAINER_REGISTRY_AGENT_URL'); | ||
const crCredentials = (process.env.CR_CREDENTIALS = 'CR_CREDS'); | ||
|
||
const log = require('../../lib/log'); | ||
|
||
|
@@ -25,12 +28,15 @@ describe('log', () => { | |
jiraUser, | ||
jiraPass, | ||
artifactoryUrl, | ||
crAgentUrl, | ||
crCredentials, | ||
].join(); | ||
const sanitizedTokens = | ||
'${BROKER_TOKEN},${GITHUB_TOKEN},${GITLAB_TOKEN},${AZURE_REPOS_TOKEN}'; | ||
const sanitizedBitBucket = '${BITBUCKET_USERNAME},${BITBUCKET_PASSWORD}'; | ||
const sanitizedJira = '${JIRA_USERNAME},${JIRA_PASSWORD}'; | ||
const sanitizedArtifactory = '${ARTIFACTORY_URL}'; | ||
const sanitizedCRData = '${CR_AGENT_URL},${CR_CREDENTIALS}'; | ||
|
||
// setup logger output capturing | ||
const logs: string[] = []; | ||
|
@@ -64,11 +70,14 @@ describe('log', () => { | |
expect(logged).not.toMatch(jiraPass); | ||
expect(logged).not.toMatch(azureReposToken); | ||
expect(logged).not.toMatch(artifactoryUrl); | ||
expect(logged).not.toMatch(crAgentUrl); | ||
expect(logged).not.toMatch(crCredentials); | ||
|
||
// assert sensitive data is masked | ||
expect(logged).toMatch(sanitizedBitBucket); | ||
expect(logged).toMatch(sanitizedTokens); | ||
expect(logged).toMatch(sanitizedJira); | ||
expect(logged).toMatch(sanitizedArtifactory); | ||
expect(logged).toMatch(sanitizedCRData); | ||
}); | ||
}); |