Filter sensitive data
Note: this config option is also available as define_cassette_placeholder
to reflect the fact that it is useful for more than just sensitive data.
The filter_sensitive_data
configuration option can be used to prevent sensitive data from being written to your cassette files. This may be important if you commit your cassettes files to source control and do not want your sensitive data exposed. Pass the following arguments to filter_sensitive_data
:
When the interactions are replayed, the sensitive text will replace the substitution string so that the interaction will be identical to what was originally recorded.
Warning, the data you're filtering may have been escaped or encoded. Thus you may need to escape the sensitive text. For example, if "some&password" is in your cassette within a context which is html escaped, you will need to filter "some&password" or CGI::escapeHTML('some&password')
. Similarly if it's escaped in a query string, then you will need to filter "some%26password" or CGI::escape('some&password')
You can specify as many filterings as you want.
Multiple filterings
Given a file named "filtering.rb" with:
When I run ruby filtering.rb --with-server
Then the output should contain "Response: Hello World"
And the file "cassettes/filtering.yml" should contain " "
And the file "cassettes/filtering.yml" should not contain "Hello"
And the file "cassettes/filtering.yml" should not contain "World"
When I run ruby filtering.rb
Then the output should contain "Hello World".
Filter tagged cassettes
Given a file named "tagged_filtering.rb" with:
When I run ruby tagged_filtering.rb --with-server
Then the output should contain each of the following:
| Tagged Response: Hello World 1 | | Untagged Response: Hello World 2 |
And the file "cassettes/tagged.yml" should contain "Hello 1"
And the file "cassettes/untagged.yml" should contain "Hello World 2"
When I run ruby tagged_filtering.rb
Then the output should contain each of the following:
| Tagged Response: Hello World 1 | | Untagged Response: Hello World 2 |
Filter dynamic data based on yielded HTTP interaction
Given a file named "dynamic_filtering.rb" with:
When I run ruby dynamic_filtering.rb --with-server
Then the output should contain "john.doe/monkey"
And the file "cassettes/example.yml" should contain "john.doe/"
And the file "cassettes/example.yml" should contain a YAML fragment like:
When I run ruby dynamic_filtering.rb
Then the output should contain "john.doe/monkey".
Last updated