• Stars
    star
    1,218
  • Rank 38,490 (Top 0.8 %)
  • Language
    Python
  • License
    MIT License
  • Created about 11 years ago
  • Updated almost 8 years ago

Reviews

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

Repository Details

Malformed servers to test your HTTP client

Hamms

Hamms is designed to elicit failures in your HTTP Client. Connection failures, malformed response data, slow servers, fat headers, and more!

Installation

You can either install hamms via pip:

pip install hamms

Or clone this project:

git clone https://github.com/kevinburke/hamms.git

Usage

  1. Start hamms by running it from the command line:

     python -m hamms
    

    Or use the HammsServer class to start and stop the server on command.

    from hamms import HammsServer
    
    class MyTest(object):
        def setUp(self):
            self.hs = HammsServer()
            self.hs.start(beginning_port=5500)
    
        def tearDown(self):
            self.hs.stop()
  2. Make requests and test your client. See the reference below for a list of supported failure modes.

By default, Hamms uses ports 5500-5600. You can customize the port range by passing the beginning_port parameter to HammsServer.start().

Reference

Connection level errors

Connect to the ports listed below to enact the various failure modes.

  • 5500 - Nothing is listening on the port. Note, your machine will likely send back a TCP reset (closing the connection) immediately.

    To simulate a connection failure that just hangs forever (a connection timeout), connect to a bad host on a real server, for example www.google.com:81, or use a port in the 10.* range, for example 10.255.255.1.

  • 5501 - The port accepts traffic but never sends back data

  • 5502 - The port sends back an empty string immediately upon connection

  • 5503 - The port sends back an empty string after the client sends data

  • 5504 - The port sends back a malformed response ("foo bar") immediately upon connection

  • 5505 - The port sends back a malformed response ("foo bar") after the client sends data

  • 5506 - The client accepts the request, and sends back one byte every 5 seconds

  • 5507 - The client accepts the request, and sends back one byte every 30 seconds

  • 5508 - Send a request to localhost:5508?sleep=<float> to sleep for float number of seconds. If no value is provided, sleep for 5 seconds.

  • 5509 - Send a request to localhost:5509?status=<int> to return a response with HTTP status code status. If no value is provided, return status code 200.

  • 5510 - The server will send a response with a Content-Length: 3 header, however the response is actually 1 MB in size. This can break clients that reuse a socket.

  • 5511 - Send a request to localhost:5511?size=<int> to return a Cookie header that is n bytes long. By default, return a 63KB header. 1KB larger will break many popular clients (curl, requests, for example)

  • 5512 - Use this port to test retry logic in your client - to ensure that it retries on failure.

    The server maintains a counter for incoming requests. Each time a new request is made, a 500 error is served and the counter is decremented. When the counter reaches zero, a 200 response is served. This server accepts two query arguments:

    • key - Specify a key to create a new counter. Continue making requests with key=<key> to decrement that particular counter. If no key is provided, 'default' is used.
    • tries - Specify the number of tries before success, as an integer. If no number is provided, you will get a success on the 3rd try.

    The server will let you know the key and how many tries are remaining until you get a successful response. Example error response:

    HTTP/1.1 500 INTERNAL SERVER ERROR
    Content-Length: 116
    Content-Type: application/json
    Date: Wed, 19 Nov 2014 00:59:19 GMT
    Server: TwistedWeb/14.0.2
    
    {
        "error": "The server had an error. Try again 1 more time",
        "key": "foobar",
        "success": false,
        "tries_remaining": 1
    }

    Example usage:

    r = requests.get('http://localhost:5512?key=special-key')
    assert_equal(r.status_code, 500)
    r = requests.get('http://localhost:5512?key=special-key')
    assert_equal(r.status_code, 500)
    # Third time is the charm
    r = requests.get('http://localhost:5512?key=special-key')
    assert_equal(r.status_code, 200)
    
    # Set tries=1 to serve a 200 right away.
    r = requests.get('http://localhost:5512?key=my-key&tries=1')
    assert_equal(r.status_code, 200)

    You can see the status of all available counters by making a GET request to http://localhost:5512/counters, or reset a counter by making a POST request to http://localhost:5512/counters with the key you want to reset.

  • 5513 - Send a request to localhost:5513?failrate=<float>. The server will drop requests with a frequency of failrate.

  • 5514 - The server will try as hard as it can to return a content type that is not parseable by the Accept header provided by the request. Specify a Accept: application/json header in your request and the server will return data with the text/morse content type. The server will try these content-types in turn:

  • text/morse

  • application/json

  • text/html

  • text/csv

If your Accept header indicates it can accept all of these content-types, the server will return text/morse.

  • 5515 - The server will return a response with a content-type that matches the request, but it will be incomplete. The server will advertise an incorrect, too long Content-Length, and the response body will not be complete. The practical effect is that the server will hang halfway through the response download. The server can return partial responses with the following content-types:

  • application/json

  • text/html

  • text/plain

  • text/xml

If your server indicates an Accept header value of */*, or the server cannot find a matching content-type, the server will returnn an incomplete json response.

  • 5516 - Same semantics as port 5515, but the server will close the connection partway through, instead of hanging indefinitely.

Not implemented yet

  • The server sends back a response without a content-type
  • The server sends back a response with the wrong content-type
  • The server randomly drops bytes from a valid response.
  • Sending back byte data
SSL
  • Handshake timeout
  • Invalid certificate
  • TLS v1.0 and higher only
  • TLS v1.2 and higher only
  • Server closes connection

Donating

Donations free up time to make improvements to the library, and respond to bug reports. You can send donations via Paypal's "Send Money" feature to [email protected]. Donations are not tax deductible in the USA.

More Repositories

1

doony

UI Improvements for Jenkins
JavaScript
970
star
2

nacl

Pure Go implementation of the NaCL set of API's
Go
540
star
3

ssh_config

Go parser for ssh_config files
Go
386
star
4

go-bindata

A small utility which generates Go code from any file. Useful for embedding binary data in a Go program.
Go
330
star
5

hulk

In-browser JSON editor
JavaScript
312
star
6

sshpass

Mirror of http://sourceforge.net/projects/sshpass/
Shell
199
star
7

hostsfile

go tool for working with /etc/hosts files
Go
131
star
8

rct

Creating cool coasters for Roller Coaster Tycoon
Go
124
star
9

tecate

Figure out when your HTML is busted
JavaScript
110
star
10

customize-twitter-1.1

Add your own custom CSS to modify the Twitter Embeddable Widget
JavaScript
91
star
11

tss

Go port of moreutils/ts
Go
43
star
12

swish

Switch SSH settings between Github profiles
Go
38
star
13

travis

Command line client for interacting with Travis CI
Go
19
star
14

handlers

Useful HTTP middlewares
Go
19
star
15

gitopen

Open one of your remote URL's in your browser
Python
17
star
16

rest

Go REST helpers
Go
14
star
17

sll

Strip long lines from output
Go
14
star
18

multi-emailer

Send personalized email messages to multiple email accounts (e.g. City Council members)
Go
13
star
19

2013

Flat UI website redesign
HTML
12
star
20

differ

Go
12
star
21

read-mongo-logs

Tail Mongo database logs
Go
11
star
22

gitlab

Command line tool for waiting for Gitlab pipelines to complete
Go
11
star
23

ansible-go

Go
9
star
24

rct-rides

working with roller coaster tycoon saved ride format
Go
9
star
25

weirdfortune

the unix fortune program, now with weird twitter
Python
8
star
26

snapchat-friends

surprise, your friend network is public
Python
8
star
27

proto-make-example

Makefile
8
star
28

gobike

Go
6
star
29

ynab-go

YNAB Go Client, including a detailed age of money calculator
Go
6
star
30

write_mailmap

Easy generate an AUTHORS file from the Git commit history
Makefile
6
star
31

metrosolver

Finding optimal Mini Metro routes
6
star
32

google-oauth-handler

HTTP middleware for handling Google authentication
Go
5
star
33

targets

I am the next coming of John Carmack
C#
5
star
34

go-random-project-generator

Random project name generator (like Github or Heroku app names)
Go
5
star
35

twilio-jsonapi

A JSON convenience wrapper for the Twilio API
Python
4
star
36

godocdoc

Start godoc and open a HTTP server to the homepage
Go
4
star
37

isec2

Go library that reports whether you are running in EC2
Go
3
star
38

envdir

Go port of djb envdir
Go
3
star
39

vault-go

Better Hashicorp Vault client
Go
3
star
40

public-comments

I write letters to local governments and post them here
Go
3
star
41

clipper

API for retrieving Clipper Card data (and parsing Clipper Transactions)
Go
3
star
42

talks

Talks I give at conferences
3
star
43

goodmorningcmc

Python
2
star
44

circle-webhook

webhook server and JSON parser for circle ci webhooks
Go
2
star
45

gerrit-heroku

Attempting to run Gerrit on Heroku
Makefile
2
star
46

slides

Presentations
HTML
2
star
47

write_config_from_env

Pull env vars into a config file
Go
2
star
48

humanbench

Human-readable benchmark output
Go
2
star
49

tt

Better Node test runner
Go
2
star
50

jenkins

Open Jenkins urls from your command line
Python
2
star
51

haa

CA Housing Accountability Act Resources
2
star
52

stubhub-tickets

checking stubhub ticket prices
Python
2
star
53

tarbz2.com

Helping you remember which tar option to use.
ApacheConf
2
star
54

goose

Maintained fork of liamstask/goose that supports ALTER TYPE, CREATE INDEX CONCURRENTLY
Go
2
star
55

buildkite

Buildkite CLI tool
Go
2
star
56

chroma-markdown

Combined Markdown + syntax highlight HTML compiler
Go
2
star
57

gostdjs

The Go standard library, implemented in Javascript
JavaScript
1
star
58

old-county-road

JavaScript
1
star
59

generic-pool-timeout

JavaScript
1
star
60

oculus-rating-data

Working with Oculus rating data
Go
1
star
61

tarsnap-old-archives

Deleting old Tarsnap archives
Go
1
star
62

rustls-postgres

1
star
63

sample-html

sample html
1
star
64

local-servers

Making your local projects more browsable
Makefile
1
star
65

recompile

Concurrent recompilation of individual files (see README)
Go
1
star
66

Twilio-Python-quickstarts

Python quickstarts for Twilio
Python
1
star
67

flagr

Rearrange flags so the options come first
Go
1
star
68

delete-phone-numbers

Delete numbers from a Twilio account
Go
1
star
69

flot.selection.js

The Flot selection plugin, with draggable left/right edges
JavaScript
1
star
70

make

Go
1
star
71

javascript-ipython

ipython notebook for javascript
Shell
1
star
72

enable_pg_logs

Enable Postgres query logging
Go
1
star
73

ipv6-etc-hosts

Go
1
star
74

telapi-python

Tel API Python Helper Library
Python
1
star
75

lucifer

Hot, hot test reloading from Javascript
JavaScript
1
star
76

waterline-self-driving-car

1
star
77

newproject

1
star
78

bigtext

Go library to display text really big using Quicksilver on a Mac
Go
1
star
79

twilio_munischedule

Ruby
1
star