Skip to content

Commit

Permalink
feat: handle CONNECT requests for http destinations (#50)
Browse files Browse the repository at this point in the history
* handle clients which send a connect request for http destinations

* if verbose is set for act, then set verbose for ForwardProxy as well

* fixed tests to actually test mocking via ForwardProxy. added test for http connect requests

* updated package.json and package-lock.json files

* updated docs

* fix tests by passing parents env variables to child so that node is accessible
  • Loading branch information
shubhbapna authored Aug 15, 2023
1 parent 19e8d9c commit bb09768
Show file tree
Hide file tree
Showing 7 changed files with 548 additions and 104 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,12 @@ let result = await act.runEventAndJob("pull_request", "jobId");

#### Mocking apis during the run

You can use [Mockapi](#mockapi) and [Moctokit](https://github.com/kiegroup/mock-github#moctokit) to mock any kind of HTTP and HTTPS requests during your workflow run provided that the client being used honours HTTP_PROXY and HTTPS_PROXY env variables. Depending on the client, for HTTPS they might issue a CONNECT request to open a secure TCP tunnel. In this case `Act` won't be able to mock the HTTPS request.
(Note - For Octokit, you can mock HTTPS requests because it does not issues a CONNECT request)
You can use [Mockapi](#mockapi) and [Moctokit](https://github.com/kiegroup/mock-github#moctokit) to mock any kind of HTTP and HTTPS requests during your workflow run provided that the client being used honors HTTP_PROXY and HTTPS_PROXY env variables. Depending on the client, for HTTPS they might issue a CONNECT request to open a secure TCP tunnel. In this case `Act` won't be able to mock the HTTPS request.

```typescript
import { Moctokit } from "@kie/mock-github";
import { Mockapi } from "@kie/act-js";
const moctokit = new Moctokit();
const moctokit = new Moctokit("http://api.github.com");
const mockapi = new Mockapi({
customApi: {
baseUrl: "http://custom-api.com",
Expand Down Expand Up @@ -326,6 +325,12 @@ let result = await act.runEvent("pull_request", {
});
```

For testing actions which use `Octokit`, you will need to make sure that `Octokit` instance is configured to use proxies. You can do so by using [ProxyAgent](https://github.com/octokit/octokit.js#proxy-servers-nodejs-only) or using the hydrated `Octokit` instance from [@actions/github](https://github.com/actions/toolkit/tree/main/packages/github).

Examples to help you get started:
- [Using ProxyAgent with Octokit](https://github.com/shubhbapna/mock-github-act-js-examples/tree/main/custom-actions/javascript)
- [Testing @actions/github-script which uses @actions/github internally](https://github.com/shubhbapna/mock-github-act-js-examples/tree/main/workflow/github-script)

#### Mocking steps

There are cases where some of the steps have to be directly skipped or mocked because it is not feasible to execute them in a test env and might even be redundant to test them (npm publish for instance), so `mockSteps` mechanism is provided to overcome those cases.
Expand Down
Loading

0 comments on commit bb09768

Please sign in to comment.