Skip to content

Commit 4584412

Browse files
authored
Merge pull request #500 from bheesham/use-nodes-global-fetch
fetch is now built-in to node 18
2 parents 0b47b61 + 70b96ab commit 4584412

10 files changed

Lines changed: 10 additions & 147 deletions

package-lock.json

Lines changed: 1 addition & 67 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"c8": "^9.0.0",
2323
"eslint": "^9.22.0",
2424
"jest": "^29.7.0",
25-
"jest-fetch-mock": "^3.0.3",
2625
"prettier": "2.8.8",
2726
"lodash": "^4.17.21"
2827
},
@@ -31,8 +30,7 @@
3130
"aws-sdk": "^2.1646.0",
3231
"ipaddr.js": "^1.9.1",
3332
"js-yaml": "^4.1.0",
34-
"jsonwebtoken": "^9.0.2",
35-
"node-fetch": "^2.7.0"
33+
"jsonwebtoken": "^9.0.2"
3634
},
3735
"engines": {
3836
"node": ">=18.0.0 <23.0.0"

tf/actions.tf

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,6 @@ resource "auth0_action" "gheGroups" {
9999
version = "v3"
100100
}
101101

102-
dependencies {
103-
name = "node-fetch"
104-
version = "2.7.0"
105-
}
106-
107102
secrets {
108103
name = "personapi_audience"
109104
value = local.parsed_secrets["gheGroups_personapi_audience"]
@@ -173,11 +168,6 @@ resource "auth0_action" "accessRules" {
173168
version = "v3"
174169
}
175170

176-
dependencies {
177-
name = "node-fetch"
178-
version = "2.7.0"
179-
}
180-
181171
dependencies {
182172
name = "jsonwebtoken"
183173
version = "9.0.2"
@@ -326,11 +316,6 @@ resource "auth0_action" "activateNewUsersInCIS" {
326316
version = "v3"
327317
}
328318

329-
dependencies {
330-
name = "node-fetch"
331-
version = "2.7.0"
332-
}
333-
334319
dependencies {
335320
name = "jsonwebtoken"
336321
version = "9.0.2"

tf/actions/accessRules.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Required Libraries
2-
const fetch = require("node-fetch");
32
const YAML = require("js-yaml");
43
const jwt = require("jsonwebtoken");
54
const AWS = require("aws-sdk");

tf/actions/activateNewUsersInCIS.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const fetch = require("node-fetch");
21
const jwt = require("jsonwebtoken");
32
const AWS = require("aws-sdk");
43

tf/actions/gheGroups.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Required Libraries
2-
const fetch = require("node-fetch");
3-
41
exports.onExecutePostLogin = async (event, api) => {
52
console.log("Running action:", "gheGroups");
63

tf/tests/accessRules.test.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
const _ = require("lodash");
2-
const fetch = require("node-fetch");
32

43
const appsYaml = require("./modules/apps.yml.js").load();
54
const eventObj = require("./modules/event.json");
65
const decodeRedirect = require("./modules/decodePostErrorUrl.js");
76
const idTokenObj = require("./modules/idToken.json");
87
const { onExecutePostLogin } = require("../actions/accessRules.js");
98

10-
jest.mock("node-fetch");
11-
129
beforeEach(() => {
1310
_event = _.cloneDeep(eventObj);
1411
_event.user.aai = [];
@@ -20,10 +17,6 @@ beforeEach(() => {
2017

2118
_idToken = _.cloneDeep(idTokenObj);
2219

23-
fetch.mockResolvedValue({
24-
text: jest.fn().mockResolvedValue(appsYaml),
25-
});
26-
2720
// Mock auth0 api object
2821
api = {
2922
idToken: {
@@ -62,6 +55,9 @@ beforeEach(() => {
6255
consoleLogSpy = jest.spyOn(console, "log").mockImplementation(() => {});
6356
consoleWarnSpy = jest.spyOn(console, "warn").mockImplementation(() => {});
6457
consoleErrorSpy = jest.spyOn(console, "error").mockImplementation(() => {});
58+
fetchSpy = jest.spyOn(global, "fetch").mockResolvedValue({
59+
text: jest.fn().mockResolvedValue(appsYaml),
60+
});
6561
});
6662

6763
afterEach(() => {
@@ -70,6 +66,7 @@ afterEach(() => {
7066
consoleLogSpy.mockRestore();
7167
consoleWarnSpy.mockRestore();
7268
consoleErrorSpy.mockRestore();
69+
fetchSpy.mockRestore();
7370
});
7471

7572
// TODO: test whitelisted duo users

tf/tests/activateNewUsersInCIS.test.js

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
const _ = require("lodash");
2-
const fetch = require("node-fetch");
3-
42
const eventObj = require("./modules/event.json");
53
const { onExecutePostLogin } = require("../actions/activateNewUsersInCIS.js");
64

7-
// Mock the node-fetch module
8-
jest.mock("node-fetch");
9-
105
// Take all log enteries and combine them into a single array
116
const combineLog = (consoleLogs) => {
127
let combinedLog = [];
@@ -124,11 +119,13 @@ beforeEach(() => {
124119
});
125120
}
126121
};
122+
fetchSpy = jest.spyOn(global, "fetch").mockImplementation(fetchRespCallback);
127123
});
128124

129125
afterEach(() => {
130126
// Clean up after each test
131127
jest.clearAllMocks();
128+
fetchSpy.mockRestore();
132129
consoleLogSpy.mockRestore();
133130
consoleWarnSpy.mockRestore();
134131
consoleErrorSpy.mockRestore();
@@ -150,9 +147,6 @@ test("Expect onExecutePostLogin to be defined", async () => {
150147
});
151148

152149
test("When connection does not match, expect empty logs and workflow to continue", async () => {
153-
// Mock Fetch
154-
fetch.mockImplementation(fetchRespCallback);
155-
156150
// Set connection name to a connection other than WHITELISTED_CONNECTIONS
157151
_event.connection.name = "non_whitelisted_provider";
158152

@@ -175,9 +169,6 @@ test("When connection does not match, expect empty logs and workflow to continue
175169
});
176170

177171
test("When existsInCIS is already set, expect empty logs and workflow to continue", async () => {
178-
// Mock Fetch
179-
fetch.mockImplementation(fetchRespCallback);
180-
181172
// Set existsInCIS in user metadata
182173
_event.user.app_metadata = { existsInCIS: true };
183174

@@ -244,9 +235,6 @@ test("When failing to get beartoken, expect error logged and workflow to continu
244235
});
245236

246237
test("When failing to get profile, expect error logged and workflow to continue", async () => {
247-
// Mock Fetch
248-
fetch.mockImplementation(fetchRespCallback);
249-
250238
// Set token and person fetch responses
251239
tokenResp = { access_token: "fakefakefakefake" };
252240
personResponseStatusOk = false;
@@ -272,9 +260,6 @@ test("When failing to get profile, expect error logged and workflow to continue"
272260
});
273261

274262
test("When change API fails, expect error logged and workflow to continue", async () => {
275-
// Mock Fetch
276-
fetch.mockImplementation(fetchRespCallback);
277-
278263
// Set token, person and change responses
279264
tokenResp = { access_token: "fakefakefakefake" };
280265
personResp = {};
@@ -302,9 +287,6 @@ test("When change API fails, expect error logged and workflow to continue", asyn
302287
test.each(WHITELISTED_CONNECTIONS)(
303288
"When new user with %s connection is created, expect it logged and workflow to continue",
304289
async (connection) => {
305-
// Mock Fetch
306-
fetch.mockImplementation(fetchRespCallback);
307-
308290
// Set token, person and change responses
309291
tokenResp = { access_token: "fakefakefakefake" };
310292
personResp = {};
@@ -339,9 +321,6 @@ test.each(WHITELISTED_CONNECTIONS)(
339321
);
340322

341323
test("When person API profile exists, expect set existsInCIS", async () => {
342-
// Mock Fetch
343-
fetch.mockImplementation(fetchRespCallback);
344-
345324
// Set token and person fetch responses
346325
tokenResp = { access_token: "fakefakefakefake" };
347326
personResp = { usernames: { values: { "HACK#GITHUB": "jdoegithub" } } };

tf/tests/awsSaml.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ const _ = require("lodash");
33
const eventObj = require("./modules/event.json");
44
const { onExecutePostLogin } = require("../actions/awsSaml.js");
55

6-
jest.mock("node-fetch");
7-
86
const compileGroups = async (_event) => {
97
// Ensure we have the correct group data
108
const app_metadata_groups = _event.user.app_metadata.groups || [];

0 commit comments

Comments
 (0)