• Stars
    star
    164
  • Rank 230,032 (Top 5 %)
  • Language
    Go
  • License
    MIT License
  • Created over 9 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

httpUnit tests compliance of web and net servers with desired output.

httpUnit

httpUnit tests web and net servers for basic functionality.

The tool can open an http/https connection and verify that the expected status code is received. It can also verify that the resulting HTML output contains a string or regular expression. It can direct the request to a particular IP address, ignoring DNS (similar to curl --resolve). The tool can also open a TCP connection and verify that the connection was completed. For https connections it will output various TLS-related information.

Tests can be input three ways:

  • Command line: A single test can be listed on the command line. This is useful for interactive debugging.
  • TOML file: A list of tests, with a full range of features, can be listed in a TOML file. This is the recommended mode for tests done on a regular basis. The format is described below.
  • JSON/Hiera mode: A simple list tcp tests can be specified in JSON format. These are in the format of an iptables "set". This mode is highly specific to a local requirement.

When specifying a single test on the command line, the only tests performed are status code, and regex. If the URL does not contain a scheme ("https://", "http://"), "http://" is prefixed. The IP may be an empty string to indicate all IP addresses resolved to from the URL's hostname.

Usage:

httpUnit [flag] [-hiera="path/to/sets.json"] [-toml="/path/to/httpunit.toml"] [url] [ip] [code] [regex]

The flags are:

-filter=""
	if specified, only uses this IP address; may end with "." to
	filter by IPs that start with the filter
-no10=false
	no RFC1918 addresses
-timeout="3s"
	connection timeout
-tags=""
        if specified, only runs plans that are tagged with one of the
	tags specified. You can specify more than one tag, seperated by commas
-protos=""
	if specified, only runs plans where the URL contains the given
	protocol. Valid protocols are: http,https,tcp,tcp4,tcp6,udp,udp4,udp6,ip,ip4,ip6
	You can specify more than one protocol, seperated by commas
-header="X-Request-Guid"
	in more verbose mode, print this HTTP header
-v
	verbose output: show successes
-vv
	more verbose output: show -header, cert details

URLs

URLs may be specified with various protocols: http, https, tcp, udp, ip. "4" or "6" may be appended to tcp, udp, and ip (as per net/#Dial). tcp and udp must specify a port, or default to 0. http and https may specify a port to override the default.

TOML

The toml file has two sections: Plan is a list of test plans. IPs are a table of search and replace regexes.

Each [[plan]] lists:

  • label = A label for documentation purposes. It must be unique.
  • url = The URL to retrieve.
  • ips = For http/https, a list of IPs to send the URL to. Default is "use DNS". Otherwise the connection is made to the IP address listed, ignoring DNS.
  • code = For http/https, the expected status code, default 200.
  • string = For http/https, a string we expect to find in the result.
  • regex = For http/https, a regular expression we expect to match in the result.
  • timeout = An optional timeout for the test in seconds. Default is 3 seconds.
  • tags = An optional set of tags for the test. Used for when you want to only run a subset of tests with the -tags flag
  • insecureSkipVerify = true Will allow testing of untrusted or self-signed certificates.

The test plan is run once for each item in the ips list, or more if macros are in effect.

In the ips list, * will be substituted by all the A and AAAA records returned when DNS is performed on the hostname of the URL.

The [[IPs]] section is for defining macros. Here are some typical use-cases:

Specify a value n to mean "10.0.0.n". This may save you a lot of typing in a big configuration file:

'^(\d+)$' = ["10.0.0.$1"]

Similar to the previous example, but specify a base address:

BASEIP = ["10.0.0."]
'^(\d+)$' = ["BASEIP$1"]

Specify a value n to mean the 16th IP address in many CIDR bocks:

'^(\d+)$' = ["10.0.0.$1", "10.1.1.$1", "10.2.2.$1", "10.3.3.$1", "10.4.4.$1"]

Specify a value nINT to mean .n and .n+64, plus whatever DNS returns:

BASEIP = ["10.0.0."]
'^(\d+)$' = ["BASEIP$1", "BASEIP($1+64)", "*"]

Why we made this?

This tool makes it easy to do test-driven development on your web server.

Every request to our web server passes through three systems that are all complex and error prone: the firewall, the load balancer, and the web server itself. Even when running in a test environment with automated tools that generate the configurations we still needed a way to test our results.

Before this tool each change was followed by a few simple manual tests, often by manually typing curl commands. We missed a lot of errors.

With this tool, we now have hundreds of tests that we can run with a single command. The tests run in parallel therefore all the testing is done very quickly.

When we need to make a change we first add the test, then we proceed making the change until the test passes. This test-driven development has accumulated 200 tests that we run for any change, considerably more than we'd ever run manually. This improves confidence in our ability to make changes quickly.

While making unrelated changes we often run it in a loop to make sure we don't unintentionally break anything.

The command-line mode has been useful both in development of changes, and diagnosing outages.

A simple example file:

# Verify that this URL returns text that matches "some regex":
[[plan]]
  label = "api"
  url = "http://api.example.com/"
  text = "API for example.com"
  regex = "some regex"

# Verify that this URL returns a redirect. Send to both
# the IP address listed in DNS, plus 10.11.22.33 and 10.99.88.77.
[[plan]]
  label = "redirect"
  url = "https://example.com/redirect"
  ips = ["*", "10.11.22.33", "10.99.88.77"]
  code = 301

A more complex example file:

In this example we want an IP address to mean the IP address, but if we specify a single number (e.g. "16") we want that to expand to the .16 address of a few different CIDR blocks. We also want to be able to specify a number + INT (e.g. "16INT") to indicate a slightly different list.

[IPs]
  BASEIP = ["87.65.43."]
  '^(\d+)$' = ["*", "BASEIP$1", "BASEIP($1+64)", "1.2.3.$1"]
  '^(\d+)INT$' = ["10.0.1.$1", "10.0.2.$1", "BASEIP$1", "BASEIP($1+64)"]

[[plan]]
  label = "api"
  url = "http://api.example.com/"
  # This will generate the DNS A/AAAA records, 87.65.43.16, 87.65.43.80, 1.2.3.16 and 8.7.6.5:
  ips = ["16", "8.7.6.5"]
  text = "API for example.com"
  regex = "some regex"
  tags = ["apis","example.com"]

[[plan]]
  label = "redirect"
  url = "https://example.com/redirect"
  # This will generate the DNS A/AAAA records, 10.0.1.20, 10.0.2.20, 87.65.43.20, 87.65.43.84:
  ips = ["*", "20INT"]
  code = 301
  tags = ["redirect","example.com"]

[[plan]]
  label = "mail"
  url = "tcp://mail-host.com:25"

More Repositories

1

blackbox

Safely store secrets in Git/Mercurial/Subversion
Go
6,670
star
2

StackExchange.Redis

General purpose redis client
C#
5,889
star
3

dnscontrol

Infrastructure as code for DNS!
Go
3,043
star
4

NetGain

A high performance websocket server library powering Stack Overflow.
C#
933
star
5

Stacks

Stack Overflowโ€™s Design System
Less
610
star
6

wmi

WMI for Go
Go
433
star
7

pagedown

The Markdown editor and converter used on Stack Overflow and the other Stack Exchange sites
JavaScript
419
star
8

Stacks-Editor

Stack Overflow's Combination Rich Text / Markdown Editor
TypeScript
362
star
9

StackExchange.DataExplorer

Stack Exchange Data Explorer
JavaScript
353
star
10

MarkdownSharp

Open source C# implementation of Markdown processor, used by Stack Overflow.
C#
246
star
11

stack-blog

Stack Overflow Blog
HTML
238
star
12

StackExchange.Utils

Utility class packages used at Stack Exchange...but on NuGet!
C#
195
star
13

StackExchange.Precompilation

Roslyn based csc.exe and aspnet_compiler.exe replacement with metaprogramming hooks for ASP.NET MVC projects from the pre-DNX era
C#
154
star
14

StackExchange.Metrics

A .NET client to send metrics to a variety of metrics backends
C#
136
star
15

Stacks-Icons

Authoring tools for Stack Overflow's shared icon set.
TypeScript
35
star
16

NRediSearch

C#
31
star
17

stackegg

The core game logic of Stack Overflow's April 1st 2015 game, StackEgg.
C#
30
star
18

mayflower

A simple MS SQL Server database migrator using Node.js and TDS.
JavaScript
26
star
19

StackID

An OpenID provider implemented for the Stack Exchange network, built on top of dotNetOpenAuth.
C#
20
star
20

stackexchange.github.com

Source for stackexchange.github.com
HTML
19
star
21

apca-check

Axe rules to check against APCA bronze and silver+ conformance levels.
TypeScript
18
star
22

unikong

Stack Overflow's April 1, 2016 game
JavaScript
16
star
23

haproxy-kubefigurator

Dynamic haproxy configuration for Kubernetes services
Go
14
star
24

RyuJIT-TailCallBug

Tail Call Parameter Corruption Repro for .Net 4.6
C#
12
star
25

signalfx-powershell

This is a PowerShell wrapper around the SignalFx API
PowerShell
10
star
26

mof

Package mof parses and marshals Managed Object Format (MOF) structures
Go
9
star
27

pat

A wrapper for "puppet agent --test"
Go
9
star
28

stackexchange-superfirewall

A facade for firewall::firewall{} that adds enhanced functionality.
Puppet
7
star
29

browserslist-viewer

Static site to parse and display a browserslist string
TypeScript
6
star
30

stacks-utils

A monorepo containing a collection of Stacks config files and other utilities
JavaScript
6
star
31

Stacks-TagHelpers

A set of .Net Core Tag Helpers for use with Stacks
C#
5
star
32

DesignSprint

This repository was used for building a Stack Overflow Talent exploratory design sprint.
HTML
2
star
33

terraform-provider-stackoverflow

Terraform Provider for Stack Overflow
Go
2
star
34

sre-log-1

1
star
35

marketing-resources

1
star