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
:
A substitution string. This is the string that will be written to
the cassettte file as a placeholder. It should be unique and you
may want to wrap it in special characters like
{ }
or< >
.A symbol specifying a tag (optional). If a tag is given, the
filtering will only be applied to cassettes with the given tag.
A block. The block should return the sensitive text that you want replaced with the substitution string. If your block accepts an argument, the HTTP interaction will be yielded so that you can dynamically specify the sensitive text based on the interaction (see the last scenario for an example of this).
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.
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