Skip to content

Commit

Permalink
added follow-redirect and updated path to include url queries (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhbapna authored Mar 6, 2023
1 parent 0e7634c commit f15f749
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 17 deletions.
28 changes: 23 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kie/act-js",
"version": "2.0.3",
"version": "2.0.4",
"description": "nodejs wrapper for nektos/act",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
Expand Down Expand Up @@ -41,6 +41,7 @@
"devDependencies": {
"@octokit/rest": "^19.0.5",
"@types/express": "^4.17.13",
"@types/follow-redirects": "^1.14.1",
"@types/jest": "^28.1.3",
"@types/node": "^18.0.0",
"@typescript-eslint/eslint-plugin": "^5.48.2",
Expand All @@ -60,6 +61,7 @@
"@kie/mock-github": "^1.0.1",
"ajv": "^8.12.0",
"express": "^4.18.1",
"follow-redirects": "^1.15.2",
"yaml": "^2.1.3"
},
"jestSonar": {
Expand Down
2 changes: 1 addition & 1 deletion src/mockapi/request/request-mocker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MockapiResponseMocker } from "@aj/mockapi/response/response-mocker";

export class MockapiRequestMocker extends RequestMocker {
constructor(baseUrl: string, endpointDetails: EndpointDetails, allowUnmocked = false) {
super(baseUrl, endpointDetails);
super(baseUrl, endpointDetails, allowUnmocked);

// need to bind the instance context to the function. otherwise it is lost during method generation
this.request = this.request.bind(this);
Expand Down
8 changes: 4 additions & 4 deletions src/proxy/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import net from "net";
import express from "express";
import http from "http";
import { http } from "follow-redirects";
import { Server } from "http";
import { ResponseMocker } from "@kie/mock-github";
import { networkInterfaces } from "os";
import internal from "stream";

export class ForwardProxy {
private apis: ResponseMocker<unknown, number>[];
private app: express.Express;
private server: http.Server;
private server: Server;
private logger: (msg: string) => void;
private currentConnections: Record<number, internal.Duplex>;
private currentSocketId: number;
Expand Down Expand Up @@ -128,10 +129,9 @@ export class ForwardProxy {

// forward the intercepted api call
this.app.all("/*", function (req, res) {
logger(req.baseUrl + req.path);
const opts = {
host: req.hostname,
path: req.path,
path: req.path + new URL(req.url).search,
method: req.method,
headers: req.headers,
agent: false,
Expand Down
12 changes: 6 additions & 6 deletions test/unit/proxy/proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,17 @@ describe("http", () => {
const proxy = new ForwardProxy([
mockapi.mock.google.root
.get()
.setResponse({ status: 200, data: { msg: "mocked_response" } }),
.setResponse({ status: 400, data: { msg: "mocked_response" } }),
]);
const ip = await proxy.start();
process.env["http_proxy"] = `http://${ip}`;
process.env["https_proxy"] = `http://${ip}`;

await expect(
axios.get("http://redhat.com/", {
maxRedirects: 0,
})
).rejects.toThrowError("Request failed with status code 301");
const { status } = await axios.get("http://redhat.com/");

expect(
status
).toBe(200);
await proxy.stop();
});
});
Expand Down

0 comments on commit f15f749

Please sign in to comment.