Cucumber-style HTTP frontends testing
Perl Perl6
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
lib/Test
tests
INSTALL
README.pod

README.pod

NAME

http-cuke - Cucumber-style HTTP configuration testing for the masses

SYNOPSIS

Example of test scenario:

Feature: Front page responds correctly
In order to avoid problems with caching logic and/or frontend configuration
As an operations ninja
I want to check that front page is served correctly and the frontends configuration is correct

Scenario: HTTP to HTTPS redirects are in place
  When I go to "http://my.example.server.lan/"
  Then I should be redirected to "https://my.example.server.lan/"
  Then the final HTTP status code should be "200"

Put that text in a whatever.test file, and point http-cuke to the directory that contains it with:

http-cuke --test-dir ./some-tests

Or run just a single test file:

http-cuke --test ./single.test

Have a look at the tests directory where you will find this example:

Feature: Google front page allows me to search
In order not to be stuck without being able to google something
As a curious person
I want to be check that Google is available

Scenario: Google frontpage is available
  Given the HTTP request header "Accept-Language" is "en"
  When I go to "http://www.google.com/"
  Then the final HTTP status code should be "200"
  Then the page should contain "Google"

This is a test you can actually run with:

cd bin
./http-cuke --test ../tests/example.test

DESCRIPTION

Run cucumber style tests against any HTTP server.

If you are not familiar with cucumber, check it out at http://cukes.info/.

With this tool you can define set of tests (or features and scenarios in cucumber-speak) and run them.

The type of tests that http-cuke can help you with are those that involve checking a HTTP server configuration, behavior or plain responses.

You can check redirects, response headers, cookies, response bodies, inject custom HTTP headers in the requests, check Varnish responses, and more.

MOTIVATION: THE WHY

This tool is not meant to replace tools like WWW::Mechanize or similar ones. It is meant to perform automated testing for frontends configuration testing.

By frontend I mean Apache, Nginx, Varnish, and deadly combinations of the three. It can be a nightmare to make sure you have all the correct redirects in place, that pages are cached according to your own logic, etc...

Yes, but even then, after all, cucumber is pretty well established. So why?

Because of the dependencies mess. I don't want to depend on too many packages, and Perl already has all the tools I needed to do this. I just glued them together, and there you have a TAP-compliant cucumber-style HTTP testing that I can easily hook up to Jenkins.

The main advantage of this tool is that it opens up even complex HTTP testing to a broader audience, not necessarily programmers. That is, btw, the whole point of BDD testing, and that's Good(tm).

AVAILABLE TESTS

So what are the magic words that are available to build the test cases?

Here's a list:

Given a max of (\d+) redirects
Given a timeout of (\d+) seconds
Given a "(.+)" user agent
Given the HTTP request header "(.+)" is "(.*)"
Given the client sends a cookie "(.+)" with value "(.*)"
When I go to "(.+)"
When I send a ([A-Z]+) request to "([^"]+)"
When I send a ([A-Z]+) request to "([^"]+)" with body "(.*)"

A super-cheap hack, but it works for now. Examples:

When I send a GET request to "http://somedomain.lan/"
When I send a POST request to "http://somedomain.lan/" with body ""
When I send a PATCH request to "http://somedomain.lan/some-api" with body "{"hello":"there"}"
Then the page should be cached
Then the page should not be cached
Then I should be redirected to "(.+)"
Then the HTTP response header "(.+)" should match "(.*)"
Then the HTTP status code should be "(.+)"
Then the HTTP status line should match "(.+)"
Then the page should not contain "(.+)"
Then the server should send a CSRF token
Then the page should contain "(.+)"
Then the page MD5 checksum should be "(.+)"

AUTHOR

Cosimo Streppone, <cosimo@opera.com>

LICENSE AND COPYRIGHT

This code is offered under the Open Source BSD license.

Copyright (c) 2015, Opera Software. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  • Neither the name of Opera Software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

DISCLAIMER OF WARRANTY

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.