-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugin): allow to transform entries before saving a HAR (#182)
You can modify the entries before saving the HAR by using the `transform` option. This option should be set to a path to a module that exports a function, similar to the filter option, to change the Entry object as desired. ```js cy.recordHar({ transform: '../support/remove-sensitive-data.ts' }); ``` Here's a simple example of what the `remove-sensitive-data.ts` module might look like: ```ts import { Entry } from 'har-format'; const PASSWORD_REGEXP = /("password":\s*")\w+("\s*)/; export default async (entry: Entry) => { try { // Remove sensitive information from the request body if (entry.request.postData?.text) { entry.request.postData.text = entry.request.postData.text.replace( PASSWORD_REGEXP, '$1***$2' ); } return entry; } catch { return entry; } }; ``` In this example, the transform function will replace any instances of password with `***` in both the request and response bodies of each entry. closes #174
- Loading branch information
Showing
21 changed files
with
345 additions
and
71 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
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
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
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module.exports = async entry => { | ||
try { | ||
if (entry.response.content?.text) { | ||
entry.response.content = { | ||
...entry.response.content, | ||
text: entry.response.content.text.replace( | ||
/"products":\s*(.+)/g, | ||
`"items":$1` | ||
) | ||
}; | ||
} | ||
|
||
return entry; | ||
} catch { | ||
return entry; | ||
} | ||
}; | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = async entry => { | ||
try { | ||
if (entry.response.content?.text) { | ||
entry.response.content = { | ||
...entry.response.content, | ||
text: entry.response.content.text.replace( | ||
/"products":\s*(.+)/g, | ||
`"items":$1` | ||
) | ||
}; | ||
} | ||
|
||
return entry; | ||
} catch { | ||
return entry; | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export async entry => { | ||
try { | ||
if (entry.response.content?.text) { | ||
entry.response.content = { | ||
...entry.response.content, | ||
text: entry.response.content.text.replace( | ||
/"products":\s*(.+)/g, | ||
`"items":$1` | ||
) | ||
}; | ||
} | ||
|
||
return entry; | ||
} catch { | ||
return entry; | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Entry } from 'har-format'; | ||
|
||
export default async (entry: Entry) => { | ||
try { | ||
if (entry.response.content?.text) { | ||
entry.response.content = { | ||
...entry.response.content, | ||
text: entry.response.content.text.replace( | ||
/"products":\s*(.+)/g, | ||
`"items":$1` | ||
) | ||
}; | ||
} | ||
|
||
return entry; | ||
} catch { | ||
return entry; | ||
} | ||
}; |
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
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
Oops, something went wrong.