Download the PHP package allejo/php-vcr-sanitizer without Composer

On this page you can find all versions of the php package allejo/php-vcr-sanitizer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-vcr-sanitizer

php-vcr-sanitizer

Packagist Tested with php-vcr v1.4+ Unit Tests GitHub license

php-vcr is a tool for recording and replaying outgoing requests, however it has had "Privacy aware" marked as "soon" for quite some time now. Whenever I test my APIs, there will often be some sensitive information such as keys or passwords in the recordings. Up until now, I've had a separate script to always remove sensitive data before getting checked into version control.

I got tired of having to always sanitize the data, so this is a quick and dirty solution until php-vcr officially supports "private" recordings.

Table of Contents

Installation

Install the package through Composer.

Usage

After your VCR instance has been turned on, call VCRCleaner::enable() and pass whatever URL parameters or headers you don't want to be recorded in your fixtures.

Configuration

This library allows your sanitize both the Request and Response sections of your recordings so only non-sensitive data is written to your cassettes. You define the behavior for this sanitizer via an array with configuration options explained below.

Sanitizing Requests

Sanitizing Responses

The php-vcr library does not officially support modifying its responses so this library uses reflection to modify the contents of responses. While this feature is officially supported by this project, bear with us if this feature were to break due to the php-vcr changing its internals.

Disabling the Sanitizer

Why is there no VCRCleaner::disable()? There's no simple and non-hackish way to restore the VCR to its original state. It's probably easier to just configure your VCR differently for a certain batch of unit tests anyways.

How Sanitizing Works

When VCR is looking for recordings to playback, VCRCleaner uses modified "matchers" to check everything except for the fields you've marked as sensitive.

Hostnames

If the hostname of the URL endpoint you're hitting is sensitive and shouldn't be recorded, you can have the sanitizer ignore hostnames and they'll be replaced in the url field with a [] instead and the host header will be set to null.

Headers

Let's say you set the X-Api-Key header to SuperToast. In your recording, the header you specified will be saved as null.

URL Parameters

Notice how apiKey=yourSecretApiKey is stripped away in your recording. During your VCR playback, it'll look for matching requests without the apiKey parameter.

Body Content

Unlike ignoring headers or URL parameters, scrubbing information from both request and response bodies makes use of an array of callbacks. The result of each function is passed on to the next function.

Notice how password=hunter2 has been stripped away from the request body. The callbacks take the body as a string parameter, the modified result has to be returned.

Post Field Content

When making POST requests, your VCR will sometimes record the data inside of a post_fields parameter rather than the body; e.g. when CURLOPT_POSTFIELDS is used in cURL and you do not set CURLOPT_POST to true. In those cases, this option can be used to sanitize sensitive content. Note that unlike the body field, post_fields is an array:

License

MIT


All versions of php-vcr-sanitizer with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1.3
php-vcr/php-vcr Version ^1.4
symfony/event-dispatcher Version ^4.0|^5.0|^6.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package allejo/php-vcr-sanitizer contains the following files

Loading the files please wait ....