Skip to content

Commit 75b6af5

Browse files
authored
Enable https simulations (#24)
* Provide script to consumers for https simulations The script installs and trusts the Hoverfly default certificate[1], which allows https calls to be simulated by Hoverfly[2]. [1] https://docs.hoverfly.io/en/latest/pages/tutorials/advanced/configuressl/configuressl.html [2] https://docs.hoverfly.io/en/latest/pages/tutorials/basic/https/https.html * Test that https calls can be simulated * Update README with HTTPS instructions
1 parent 009a06b commit 75b6af5

File tree

5 files changed

+93
-3
lines changed

5 files changed

+93
-3
lines changed

.github/workflows/tests.yml

+43
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ env:
55
ASSERT_VERSION: "| grep -q $HOVERFLY_VERSION"
66
ASSERT_HOVERFLY_NOT_INSTALLED: "! hoverfly -version"
77
ASSERT_HOVERCTL_NOT_INSTALLED: "! hoverctl version"
8+
ASSERT_ERROR: "!"
9+
EXAMPLE_HTTPS_PROXY_REQUEST: "curl --proxy localhost:8500 https://example.com"
810

911
jobs:
1012

@@ -88,3 +90,44 @@ jobs:
8890
run: |
8991
${{ env.ASSERT_HOVERFLY_NOT_INSTALLED }}
9092
${{ env.ASSERT_HOVERCTL_NOT_INSTALLED }}
93+
94+
95+
use_script_to_enable_https_simulations:
96+
name: Enable https simulations
97+
runs-on: ubuntu-latest
98+
steps:
99+
- uses: actions/checkout@v2
100+
- name: Install Hoverfly
101+
uses: ./
102+
with:
103+
runner_github_workspace_path: ${{ github.workspace }}
104+
- name: Enable https calls to be simulated by Hoverfly
105+
run: install-and-trust-hoverfly-default-cert.sh
106+
- name: Verify that https calls can be simulated
107+
run: |
108+
hoverctl start
109+
hoverctl mode capture
110+
${{ env.EXAMPLE_HTTPS_PROXY_REQUEST }}
111+
hoverctl mode simulate
112+
${{ env.EXAMPLE_HTTPS_PROXY_REQUEST }}
113+
hoverctl stop
114+
115+
116+
https_simulations_do_not_work_without_https_script:
117+
name: Verify https simulations will not work without script
118+
runs-on: ubuntu-latest
119+
steps:
120+
- uses: actions/checkout@v2
121+
- name: Install Hoverfly
122+
uses: ./
123+
with:
124+
runner_github_workspace_path: ${{ github.workspace }}
125+
# Commenting out the script, to verify https simulations fail without it
126+
# - name: Enable https calls to be simulated by Hoverfly
127+
# run: install-and-trust-hoverfly-default-cert.sh
128+
- name: Verify that https calls cannot be simulated
129+
run: |
130+
hoverctl start
131+
hoverctl mode capture
132+
${{env.ASSERT_ERROR }} ${{ env.EXAMPLE_HTTPS_PROXY_REQUEST }}
133+
hoverctl stop

Dockerfile

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
FROM alpine:3.10
22

3-
COPY LICENSE README.md /
4-
5-
COPY entrypoint.sh /entrypoint.sh
3+
COPY LICENSE README.md entrypoint.sh install-and-trust-hoverfly-default-cert.sh /
64

75
ENTRYPOINT ["/entrypoint.sh"]

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,36 @@ The Hoverfly binaries are installed at `${{ github.workspace }}/bin`
100100

101101
(The [GitHub workspace directory is persistent throughout the GitHub Action workflow](https://docs.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners#filesystems-on-github-hosted-runners), which means that the binaries are available to any subsequent workflow steps.)
102102

103+
104+
## Enabling HTTPS Hoverfly simulations
105+
106+
To enable [HTTPS Hoverfly simulations](https://docs.hoverfly.io/en/latest/pages/tutorials/basic/https/https.html), follow this example:
107+
108+
```
109+
steps:
110+
- name: Install Hoverfly
111+
uses: agilepathway/hoverfly-github-action@main
112+
with:
113+
version: v1.3.0
114+
runner_github_workspace_path: ${{ github.workspace }}
115+
- name: Enable https calls to be simulated by Hoverfly
116+
run: install-and-trust-hoverfly-default-cert.sh
117+
```
118+
119+
This script
120+
[installs and trusts the default Hoverfly certificate](https://docs.hoverfly.io/en/latest/pages/tutorials/advanced/configuressl/configuressl.html),
121+
after which you can go ahead and simulate HTTPS calls (see
122+
[this example](https://github.com/agilepathway/hoverfly-github-action/blob/a0a08dae5c28d0980205c7997ce4accc20d1fc48/.github/workflows/tests.yml#L95-L113)
123+
in the [end-to-end tests](.github/workflows/tests.yml)).
124+
125+
Our Hoverfly GitHub Action automatically makes this https cert
126+
[install script](./install-and-trust-hoverfly-default-cert.sh) available to you
127+
(in the same `${{ github.workspace }}/bin` directory which we add to the path and which the
128+
Hoverfly binaries are located in too).
129+
130+
131+
132+
103133
## Tests / examples
104134

105135
The [tests](.github/workflows/tests.yml) contain further configuration examples.

entrypoint.sh

+6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ export HOVERFLY_VERSION=$INPUT_VERSION
88
export HOVERFLY_BUNDLE=hoverfly_bundle_$HOVERFLY_PLATFORM
99
export HOVERFLY_DOWNLOAD_URL=https://github.com/SpectoLabs/hoverfly/releases/download/
1010

11+
1112
mkdir -p "$CONTAINER_HOVERFLY_INSTALL_PATH"
13+
14+
# make the script that enables https calls to be simulated accessible to the consumer
15+
install -m 755 /install-and-trust-hoverfly-default-cert.sh "$CONTAINER_HOVERFLY_INSTALL_PATH"
16+
17+
1218
mkdir -p /tmp/hoverfly
1319
cd /tmp/hoverfly || exit
1420

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
3+
# This script installs and trusts the default Hoverfly certificate[1],
4+
# after which you can go ahead and simulate HTTPS calls[2] (see this example[3] in the end-to-end tests[4]).
5+
#
6+
# [1] https://docs.hoverfly.io/en/latest/pages/tutorials/advanced/configuressl/configuressl.html
7+
# [2] https://docs.hoverfly.io/en/latest/pages/tutorials/basic/https/https.html
8+
# [3] https://github.com/agilepathway/hoverfly-github-action/blob/a0a08dae5c28d0980205c7997ce4accc20d1fc48/.github/workflows/tests.yml#L95-L113
9+
# [4] https://github.com/agilepathway/hoverfly-github-action/blob/main/.github/workflows/tests.yml
10+
11+
wget https://raw.githubusercontent.com/SpectoLabs/hoverfly/master/core/cert.pem
12+
sudo mv cert.pem /usr/local/share/ca-certificates/hoverfly.crt
13+
sudo update-ca-certificates

0 commit comments

Comments
 (0)