Skip to content

Commit f9b9299

Browse files
authored
Merge pull request #118 from filiphric/108-cannot-hide-credentials-in-query-parameter
108 cannot hide credentials in query parameter
2 parents 0b74d57 + 87f8837 commit f9b9299

File tree

7 files changed

+47
-4
lines changed

7 files changed

+47
-4
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [2.11.0](https://github.com/filiphric/cypress-plugin-api/compare/v2.10.5...v2.11.0) (2023-03-17)
6+
7+
8+
### Features
9+
10+
* add support for hiding query parameters ([9122abc](https://github.com/filiphric/cypress-plugin-api/commits/9122abcb68e683b5e2d8da6d35e703de593b8e73))
11+
512
### [2.10.5](https://github.com/filiphric/cypress-plugin-api/compare/v2.10.4...v2.10.5) (2023-03-17)
613

714

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ it('my secret test', {
100100
hideCredentialsOptions: {
101101
headers: ['authorization'],
102102
auth: ['pass'],
103-
body: ['username']
103+
body: ['username'],
104+
query: ['password']
104105
}
105106
}
106107
}, () => {
@@ -115,6 +116,9 @@ it('my secret test', {
115116
},
116117
body: {
117118
username: Cypress.env('myUser') // hidden
119+
},
120+
qs: {
121+
password: Cypress.env('password') // hidden
118122
}
119123
})
120124

cypress/e2e/authorization.cy.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,29 @@ describe('Hiding credentials by defining them', () => {
130130

131131
});
132132

133+
it('hides credentials in query', {
134+
env: {
135+
hideCredentials: true,
136+
hideCredentialsOptions: {
137+
qs: ['password']
138+
}
139+
}
140+
}, () => {
141+
142+
cy.api({
143+
method: 'POST',
144+
url: '/',
145+
qs: {
146+
password: 'secret'
147+
}
148+
})
149+
150+
cy.get('[data-cy="query"]')
151+
.should('contain', '******')
152+
.should('contain', 'password')
153+
154+
});
155+
133156
});
134157

135158
describe('Showing credentials', () => {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "Filip Hric (https://filiphric.com/)",
33
"license": "ISC",
44
"name": "cypress-plugin-api",
5-
"version": "2.10.5",
5+
"version": "2.11.0",
66
"keywords": [
77
"cypress",
88
"api",

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export interface HideCredentialsOptions {
109109
auth?: string[]
110110
headers?: string[]
111111
body?: string[]
112+
qs?: string[]
112113
}
113114

114115
export interface ApiRequestOptions extends Cypress.RequestOptions {

src/utils/anonymize.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const anonymize = (options: RequestProps) => {
88
auth: [],
99
body: [],
1010
headers: [],
11+
qs: [],
1112
...Cypress.env('hideCredentialsOptions')
1213
}
1314

@@ -37,5 +38,12 @@ export const anonymize = (options: RequestProps) => {
3738
}
3839
})
3940

41+
anonymizeOptions.qs?.forEach(k => {
42+
if (options.query.body && options.query.body[k as keyof Cypress.RequestBody]) {
43+
// @ts-ignore until I figure out how to fix this
44+
options.query.body[k] = options?.query.body[k].replace(/./g, '*')
45+
}
46+
})
47+
4048
return options
4149
}

0 commit comments

Comments
 (0)