You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+48-15Lines changed: 48 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,39 +5,47 @@ A nimble **http** and **echo** server to test arbitrary http requests and REST A
5
5
`erised [options]`
6
6
```text
7
7
Parameters:
8
+
-cert string
9
+
path to a valid X.509 certificate file
10
+
-https
11
+
use HTTPS instead of HTTP. A valid X.509 certificate and private key are required
8
12
-idle int
9
13
maximum time in seconds to wait for the next request when keep-alive is enabled (default 120)
10
14
-json
11
15
use JSON log format
16
+
-key string
17
+
path to a valid private key file
12
18
-level string
13
19
one of debug/info/warn/error/off (default "info")
14
20
-path string
15
-
path to search recursively for X-Erised-Response-File (path is restricted to the directory or subdirectories where the program is invoked)
21
+
path to search recursively for X-Erised-Response-File
16
22
-port int
17
-
port to listen (default 8080)
23
+
port to listen. Default is 8080 for HTTP and 8443 for HTTPS
24
+
-profile string
25
+
profile this session. A valid file name is required
18
26
-read int
19
27
maximum duration in seconds for reading the entire request (default 5)
20
28
-write int
21
29
maximum duration in seconds before timing out response writes (default 10)
22
30
```
23
31
24
-
For help type **erised -h**
32
+
For help type `erised -h`
25
33
26
-
When executing **erised** with no parameters, the server will listen on port **8080** for incoming http requests.
34
+
When executing _erised_ with no parameters, the server will listen on port _8080_ for incoming http requests.
27
35
28
-
If you're using the _-path_ option, please **EXERCISE GREAT CAUTION** when setting the path to search. See **Known Issues** for more information. For security reasons, path is restricted to the directory or subdirectories where the program was invoked.
36
+
If you're using the _-path_ option, please **EXERCISE GREAT CAUTION** when setting the path to search. See **Known Issues** for more information. For security reasons, _path_ is restricted to the directory or subdirectories where the program was invoked.
29
37
30
38
The latest version is also available as a Docker image at [edaddario/erised](https://hub.docker.com/r/edaddario/erised).
31
39
32
40
To start the server in a docker container, with defaults values, execute the following command:
33
41
34
42
```sh
35
-
docker run --rm -p 8080:8080 --name erised edaddario/erised [options]
43
+
docker run --rm -p 8080:8080 --name erised edaddario/erised
36
44
```
37
45
38
46
If you would like to return file based responses (_X-Erised-Response-File_ set) when using the docker image, you'll need to map the directory containing your local files and set the _-path_ option accordingly.
39
47
40
-
The following example maps the **/local_directory/response_files** directory in your local machine to **/files** in the docker image, and then sets the **-path** option:
48
+
The following example maps the _/local_directory/response_files_ directory in your local machine to _/files_ in the docker image, and then sets the _-path_ option:
@@ -52,7 +60,7 @@ URL routes, HTTP methods (e.g. GET, POST, PATCH, etc.), query strings and body a
52
60
| erised/ip | GET | Returns the client IP |
53
61
| erised/shutdown | POST | Shutdowns the server |
54
62
55
-
The `erised/echoserver` path will ignore any additional segments after `/echoserver`, including HTTP methods, query strings and body, and it will return a webpage displaying server information and the request's parameters.
63
+
The _erised/echoserver_ path will ignore any additional segments after _/echoserver_, including HTTP methods, query strings and body, and it will return a webpage displaying server information and the request's parameters.
@@ -110,6 +118,7 @@ NetworkAuthenticationRequired or 511
110
118
Any other value will resolve to 200 (OK)
111
119
112
120
# Release History
121
+
* v0.11.2 - Add HTTPS capability, add test certificates, add program execution timing, add profiling option, refactor variable names for readability, and replace panics with more user-friendly fatal logs
113
122
* v0.9.7 - Refactor error handling
114
123
* v0.9.6 - Rename _erised/webpage_ to _erised/echoserver_ and add headers and server environment information
115
124
* v0.8.3 - Add _erised/webpage_ path, add multi-architecture docker images, minor refactoring, and minor cosmetic changes
@@ -128,23 +137,47 @@ Any other value will resolve to 200 (OK)
128
137
* v0.0.2 - Add HTTP redirection status codes (300's), startup configuration parameters and request's logging
129
138
* v0.0.1 - Initial release
130
139
140
+
# Enabling HTTPS
141
+
In order to enable HTTPS support, _erised_ requires a valid X.509 certificate signed by a trusted [Certification Authority](https://en.wikipedia.org/wiki/Certificate_authority) (CA) like [IdenTrust](https://www.identrust.com/), [DigiCert](https://www.digicert.com/) or [Let's Encrypt](https://letsencrypt.org/).
142
+
143
+
If you don't have one, or would prefer to use a local version, you'll find the necessary certificate ([localCA.pem](./cmd/erised/certs/localCA.pem)) to setup a Root CA in the [/certs](./cmd/erised/certs) folder, which will allow your computer to verify the included test certificate and key. The process to install the CA certificate is beyond the objective of this README, but [Google](https://www.google.com/search?q=how+to+install+trusted+root+certificate) or your favourite AI can help. Once the certificate is installed, it will show as **Erised Test CA**. Please ensure it is marked as **_trusted_**.
144
+
145
+
You should now be able to run _erised_ in HTTPS mode by executing `erised -https -cert erised.crt -key erised.key` where _erised.crt_ is the "site's" (your computer) X.509 certificate and _erised.key_ is the private key.
146
+
147
+
### A word of caution about trusting certificates with unclear provenance:
148
+
As mentioned before, covering the intricacies of establishing cryptographically secure digital identities and documenting the process to generate the relevant keys and certificates is well beyond the scope of this README, but it is important to at least call out some of the risks incurred when trusting a digital certificate because, in addition to validate identity and secure the communication between parties, they are also used to "sign" code (programs and libraries) that can run with privileged permissions.
149
+
150
+
I hope the message is clear: **when dealing with anything security related it always pays to be very careful and when in doubt, the best option is just not to.**
151
+
152
+
The [Secure Sockets Layer (SSL)](https://www.digicert.com/what-is-ssl-tls-and-https) certificates included with _erised_ are linked to _localhost_ and can only be used to enable TLS/SSL communication within your own computer.
153
+
154
+
For transparency, the (high level) steps to create them are:
155
+
156
+
1. Create a private key (_localCA.key_) to sign the Root CA certificate
157
+
2. Generate a Root CA certificate (_localCA.pem_) signed with the above key
158
+
3. Create a "site" private key (_erised.key_)
159
+
4. Generate an intermediate Certificate Signing Request certificate (_erised.csr_) signed with site's private key
160
+
5. Create an X.509 V3 certificate extension config file (_erised.ext_) to link the final certificate to _localhost_
161
+
6. Generate the site's final certificate (_erised.crt_) using the Root CA certificate, the CA private key, the intermediate CSR certificate, and the certificate extension config file
162
+
163
+
Please note that neither of the private keys are password protected. This is definitely not something that you would normally do, but decided to simplify the process in case you'd want to tinker with the provided certs.
164
+
131
165
# Known Issues
132
-
**erised** may be full of bugs. Poeple "_... have wasted away before it, not knowing if what they have seen is real, or even possible..._" so, use it with caution for it gives no knowledge or truth.
166
+
_erised_ may be full of bugs. Poeple "_... have wasted away before it, not knowing if what they have seen is real, or even possible..._" so, use it with caution for it gives no knowledge or truth.
133
167
134
168
Of all of its deficiencies, the most notable is:
135
-
* Using the _-path_ option could lead to significant security risks. When the _X-Erised-Response-File_ header is set it will search recursively for a matching filename in the current directory or **all** subdirectories underneath, returning the contents of the first match. For security reasons, path is restricted to the directory or subdirectories where the program was invoked.
136
-
* https protocol is not yet supported
169
+
* Using the _-path_ option could lead to significant security risks. When the _X-Erised-Response-File_ header is set, it will search recursively for a matching filename in the current directory or **all** subdirectories underneath it, returning the contents of the first match. For security reasons, path is restricted to the directory or subdirectories where the program was invoked.
137
170
138
-
I may or may not address these issues in a future release. Caveat Emptor
171
+
I may or may not address this or any other issues in a future release. [**Caveat Emptor**](./LICENSE)
139
172
140
173
# Motivation
141
174
When developing and testing REST API clients, sooner or later I'd come across situations where I needed a quick and easy way to dynamically test endpoint's responses under different scenarios. Although there are many excellent frameworks and mock servers available, the time and effort required to configure them is sometimes not justified, specially if the application under test exposes many routes, so after some brief and unsuccessful googling I decided to create my own.
142
175
143
-
**erised** was inspired by [Kenneth Reitz's](https://kennethreitz.org/) HTTP Request & Response Service [httpbin.io](https://httpbin.org/) and it may offer similar functionality in future releases.
176
+
_erised_ was partially inspired by [Kenneth Reitz's](https://kennethreitz.org/) HTTP Request & Response Service [httpbin.io](https://httpbin.org/) and later on by Marchandise Rudy's [Echo-Server](https://github.com/Ealenn/Echo-Server).
144
177
145
178
The typical use case is to get a response to an arbitrary http request when your ability to control the server's behaviour is limited or non-existent.
146
179
147
-
Imagine you're developing some client for [api.chucknorris.io](https://api.chucknorris.io/) and want to test the **/jokes/random** path. You could certainly make live calls against the server:
180
+
Imagine you're developing some client for [api.chucknorris.io](https://api.chucknorris.io/) and want to test the _/jokes/random_ path. You could certainly make live calls against the server:
0 commit comments