<commit_before># Cybersourcery Testing

For Rails projects, supports feature/integration testing of the Cybersource Silent Order POST (SOP) service. It can be used with [the Cybersourcery gem](https://github.com/promptworks/cybersourcery) or as a stand-alone testing service. It uses a Sinatra proxy server and [VCR](https://github.com/vcr/vcr), to avoid the need for repeated requests to the Cybersource SOP test server.

## Features

Automated testing with Cybersource SOP is more difficult than typical 3rd party services. When a transaction is submitted, Cybersource dynamically generates a hidden form in the user's browser, which it then automatically submits to your site's response page for the transaction. Also, both your submission to Cybersource, and the response from Cybersource, require the verification of signatures that are unique to each transaction. The Cybersourcery Testing gem handles these complexities for you.

It includes:

* A proxy server to stand-in for the Cybersource SOP test server. It runs on Sinatra, and includes a middleware translating proxy which directs both requests to, and responses from, the Cybersource SOP test server to the Sinatra server.
* Detection and alerts for undocumented Cybersource SOP error conditions. Cybersource will return an unexplained server error if you attempt to pass arrays in form data, or pass values that exceed 700 characters in length. The proxy server will detect these conditions and raise exceptions that include clear explanations.
* VCR to record your test transactions, for re-use in future test runs. 
* The ability to define your own custom matchers, to detect variations in the data in test submissions. The gem comes with a check for changes in the credit card number. You can add checks for other fields as needed for your business requirements.

When a test is run that shows a change against any of the matchers you have defined, the proxy server will forward the transaction to the actual Cybersource SOP test server, and VCR will record the transaction. Subsequent runs of the same test will rely on the VCR recording. This means you can do repeated feature/integration testing without requiring ongoing contact with the Cybersource SOP test server.

## Installation

1. Add it to your Gemfile and run bundle:

  ```ruby
  gem 'cybersourcery_testing'
  bundle
  ```

2. Run the generator for creating a sample .env file, and update your .env file:

  ```console
  rails generate cybersourcery_testing:dotenv
  ```
  
  This generates a file in your Rails root directory named `.env.cybersourcery_testing_sample`. If you do not have a `.env` file already, rename it to `.env`. If you do have a `.env` file, copy the contents of the sample file and paste them to the end of your .env file. You can then delete the sample file.
  
3. Update your .env settings as needed:

  * CYBERSOURCERY_SOP_TEST_URL: the URL of the Cybersource Silent Order Post (SOP) test server. You should not need to change this.
  * CYBERSOURCERY_SOP_PROXY_URL: the base URL the Sinatra proxy will use.
  * CYBERSOURCERY_RESPONSE_PAGE_URL: this must match the "Customer Response Page" URL you have set in the Cybersource Business Center for the profile you will use when testing.
  * CYBERSOURCERY_LOCAL_RESPONSE_PAGE_PATH: the path to the local equivalent of the "Customer Response Page" (should be in URI path format, e.g. `/confirm`)
  * CYBERSOURCERY_USE_VCR_IN_TESTS: `true` or `false`. This should be `true` unless you have a special reason to change it. If you do not set this to `true` the Sinatra proxy will always forward all requests to the actual Cybersource SOP test server.
  * CYBERSOURCERY_VCR_CASSETTE_DIR: the relative path to where your VCR cassette file should be stored
<commit_msg>minor text update<commit_after># Cybersourcery Testing

For Rails projects, supports feature/integration testing of the Cybersource Silent Order POST (SOP) service. It can be used with [the Cybersourcery gem](https://github.com/promptworks/cybersourcery) or as a stand-alone testing service. It uses a Sinatra proxy server and [VCR](https://github.com/vcr/vcr), to avoid the need for repeated requests to the Cybersource SOP test server.

## Features

Automated testing with Cybersource SOP is more difficult than typical 3rd party services. When a transaction is submitted, Cybersource dynamically generates a hidden form in the user's browser, which it then automatically submits to your site's response page for the transaction. Also, both your submission to Cybersource, and the response from Cybersource, require the verification of signatures that are unique to each transaction. The Cybersourcery Testing gem handles these complexities for you.

It includes:

* A proxy server to stand-in for the Cybersource SOP test server. It runs on Sinatra, and includes a middleware translating proxy which directs both requests to, and responses from, the Cybersource SOP test server to the Sinatra server.
* Detection and alerts for undocumented Cybersource SOP error conditions, where Cybersource returns only a general server error message. The proxy server will detect these conditions and raise exceptions that include clear explanations.
* VCR to record your test transactions, for re-use in future test runs. 
* The ability to define your own custom matchers, to detect variations in the data in test submissions. The gem comes with a check for changes in the credit card number. You can add checks for other fields as needed for your business requirements.

When a test is run that shows a change against any of the matchers you have defined, the proxy server will forward the transaction to the actual Cybersource SOP test server, and VCR will record the transaction. Subsequent runs of the same test will rely on the VCR recording. This means you can do repeated feature/integration testing without requiring ongoing contact with the Cybersource SOP test server.

## Installation

1. Add it to your Gemfile and run bundle:

  ```ruby
  gem 'cybersourcery_testing'
  bundle
  ```

2. Run the generator for creating a sample .env file, and update your .env file:

  ```console
  rails generate cybersourcery_testing:dotenv
  ```
  
  This generates a file in your Rails root directory named `.env.cybersourcery_testing_sample`. If you do not have a `.env` file already, rename it to `.env`. If you do have a `.env` file, copy the contents of the sample file and paste them to the end of your .env file. You can then delete the sample file.
  
3. Update your .env settings as needed:

  * CYBERSOURCERY_SOP_TEST_URL: the URL of the Cybersource Silent Order Post (SOP) test server. You should not need to change this.
  * CYBERSOURCERY_SOP_PROXY_URL: the base URL the Sinatra proxy will use.
  * CYBERSOURCERY_RESPONSE_PAGE_URL: this must match the "Customer Response Page" URL you have set in the Cybersource Business Center for the profile you will use when testing.
  * CYBERSOURCERY_LOCAL_RESPONSE_PAGE_PATH: the path to the local equivalent of the "Customer Response Page" (should be in URI path format, e.g. `/confirm`)
  * CYBERSOURCERY_USE_VCR_IN_TESTS: `true` or `false`. This should be `true` unless you have a special reason to change it. If you do not set this to `true` the Sinatra proxy will always forward all requests to the actual Cybersource SOP test server.
  * CYBERSOURCERY_VCR_CASSETTE_DIR: the relative path to where your VCR cassette file should be stored

{'fraction_non_alphanumeric': 0.04336734693877551, 'fraction_numerical': 0.001476906552094522, 'mean_word_length': 4.558955223880597, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4834750', 'n_tokens_mistral': 1975, 'n_tokens_neox': 1893, 'n_words': 1098}