Getting started
This guide installs Decoy and starts it with api.stripe.com as an Intercepted Host. You answer a curl call to that host with a Rule you register, then read the call back from the Call Journal. No application code changes.
Decoy is part of SlopKit. The source is at gitlab.techtailors.net/slopkit/decoy.
Prerequisites
- Linux on x86-64
curlandjq- Free local ports 7411, 7412, 7413 and 5300, the defaults Decoy listens on
Install Decoy
Download the 0.1.0 release binary, a self-extracting file, and make it executable:
mkdir -p ~/.local/bin curl -fsSL -o ~/.local/bin/decoy "https://gitlab.techtailors.net/api/v4/projects/slopkit%2Fdecoy/packages/generic/decoy/0.1.0/decoy-linux-amd64" chmod +x ~/.local/bin/decoy
If ~/.local/bin is not on your PATH, add it for this shell, then check the install:
export PATH="$HOME/.local/bin:$PATH" decoy --version
decoy 0.1.0
The binary updates itself. Run decoy update later to move to the newest release on the stable channel. Today it prints:
decoy update
cram: decoy 0.1.0 is already up to date
Start Decoy and intercept a host
Start Decoy in the background and name the host to intercept
decoy serve --intercept api.stripe.com &
Decoy prints where it listens. The upstream resolver and your home directory will differ.
decoy: control API http://127.0.0.1:7411 decoy: DNS 127.0.0.1:5300 (udp+tcp), upstream 127.0.0.1:53 decoy: proxy http://127.0.0.1:7412 (HTTPS_PROXY / HTTP_PROXY) decoy: transparent tls://127.0.0.1:7413 decoy: CA /home/<you>/.local/state/decoy/ca.pem
Call the host with no Rule registered
decoy run starts a command with the proxy and the Decoy CA trust set up, so curl reaches Decoy instead of Stripe.
decoy run -- curl -s -w '\nHTTP %{http_code}\n' https://api.stripe.com/v1/payment_intents
Decoy answers 502 and says why. The host's Unmatched Policy is fail and nothing matches yet.
{
"error": "decoy: no Rule matched this request and the Unmatched Policy for this host is `fail`",
"hint": "register a Rule with POST /rules on the control API, or change the host's `unmatched` policy",
"host": "api.stripe.com",
"method": "GET",
"path": "/v1/payment_intents"
}
HTTP 502
Answer the call with a Rule
Register a Rule on the control API
It matches POST calls under /v1/payment_intents and answers with a declined card.
curl -s -X POST http://127.0.0.1:7411/rules -d '{
"label": "first-try", "host": "api.stripe.com", "method": "POST",
"path": {"prefix": "/v1/payment_intents"},
"respond": {"status": 402, "json": {"error": {"code": "card_declined"}}}
}' | jq -c '{id, label, host}'
{"id":"r1","label":"first-try","host":"api.stripe.com"}
Call the host again, this time with a POST
decoy run -- curl -s -w '\nHTTP %{http_code}\n' -X POST https://api.stripe.com/v1/payment_intents -d amount=1000
The Rule answers. This call never left your machine.
{"error":{"code":"card_declined"}}
HTTP 402
Read the Call Journal
It shows both calls and which one a Rule answered.
curl -s "http://127.0.0.1:7411/calls?host=api.stripe.com" | jq -c '.calls[] | {id, method, path, outcome, rule_id, status: .response.status}'
{"id":"c1","method":"GET","path":"/v1/payment_intents","outcome":"fail","rule_id":null,"status":502}
{"id":"c2","method":"POST","path":"/v1/payment_intents","outcome":"rule","rule_id":"r1","status":402}
Stop Decoy
kill %1
Decoy keeps Rules, hosts and the journal in memory, so they are gone now. Only the Decoy CA stays on disk.
Check the files Decoy wrote
ls ~/.local/state/decoy
ca-bundle.pem ca-key.pem ca.pem client-ca.pem
ca.pem is the Decoy CA. ca-bundle.pem holds the public roots plus the Decoy CA. decoy run points SSL_CERT_FILE at it.
Next steps
Open the reference for the control API, Rule fields, Handlers, Setup Helpers and the limits of what Decoy can intercept. It also shows how to install the @slopkit/decoy package for Handler types.