Skip to content

Commit 7e8450e

Browse files
committed
Init Node Tests
1 parent cfe0f8e commit 7e8450e

File tree

13 files changed

+408
-31
lines changed

13 files changed

+408
-31
lines changed

nodes/HttpForwardAuth/HttpForwardAuthTrigger.node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export class HttpForwardAuthTrigger implements INodeType {
114114
res.status(403).send('Error 403 - Forbidden').end();
115115
} else {
116116
deleteSessionTokenCookie(addResHeader);
117-
res.redirect(logoutRedirectURL);
117+
res.status(302).redirect(logoutRedirectURL);
118118
}
119119
}
120120
return {

nodes/HttpForwardAuth/transport.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { setupRedisClient } from './utils';
55

66
let instance: ConnectionPoolManager;
77

8-
// 2 hours
9-
const ttl = 2 * 60 * 60 * 1000;
8+
// ~2 hours
9+
const ttl = 2 * 60 * 60 * 1000 - 1;
1010

1111
// 30 minutes
1212
const cleanUpInterval = 30 * 60 * 1000;

nodes/HttpForwardAuth/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* c8 ignore start */
12
import type { createClient } from 'redis';
23

34
export type RedisCredential = {
@@ -19,3 +20,4 @@ export type Redis = {
1920
client: ReturnType<typeof createClient>;
2021
RATE_LIMIT_SHA: string;
2122
};
23+
/* c8 ignore stop */

nodes/HttpForwardAuth/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export function setSessionTokenCookie(
132132
): void {
133133
addResHeader(
134134
'Set-Cookie',
135-
`${SESSION_KEY}=${token}; HttpOnly; SameSite=Lax; Expires=${expiresAt.toUTCString()}; Path=/${enableHTTP ? '' : '; Secure;'}`,
135+
`${SESSION_KEY}=${token}; HttpOnly; SameSite=Lax; Expires=${expiresAt.toUTCString()}; Path=/${enableHTTP ? '' : '; Secure'}`,
136136
);
137137
}
138138

@@ -142,7 +142,7 @@ export function deleteSessionTokenCookie(
142142
): void {
143143
addResHeader(
144144
'Set-Cookie',
145-
`${SESSION_KEY}=; HttpOnly; SameSite=Lax; Max-Age=0; Path=/${enableHTTP ? '' : '; Secure;'}`,
145+
`${SESSION_KEY}=; HttpOnly; SameSite=Lax; Max-Age=0; Path=/${enableHTTP ? '' : '; Secure'}`,
146146
);
147147
}
148148

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"lint": "eslint nodes credentials package.json",
3131
"lintfix": "eslint nodes credentials package.json --fix",
3232
"prepublishOnly": "pnpm build && pnpm lint -c .eslintrc.prepublish.js nodes credentials package.json",
33-
"test": "jest",
33+
"test": "jest --silent=false",
3434
"test-watch": "jest --watch"
3535
},
3636
"files": [
@@ -45,6 +45,7 @@
4545
},
4646
"devDependencies": {
4747
"@scure/base": "^1.2.4",
48+
"@types/express": "^5.0.0",
4849
"@types/jest": "^29.5.14",
4950
"@types/node": "^22.13.1",
5051
"@typescript-eslint/parser": "^7.15.0",

pnpm-lock.yaml

Lines changed: 75 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/helpers.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { createClient } from 'redis';
2+
import { getPoolManagerInstance } from '../nodes/HttpForwardAuth/transport';
3+
import type { RedisCredential } from '../nodes/HttpForwardAuth/types';
4+
5+
export const setupRedis = (mockOverrides?: Record<string, unknown>) => {
6+
(createClient as jest.Mock).mockImplementation(() => ({
7+
connect: async () => 'CONNECTED',
8+
disconnect: async () => 'DISCONNECTED',
9+
scriptLoad: async () => 'RATE_LIMIT_SHA',
10+
ping: async () => 'PONG',
11+
get: async () => 'GET',
12+
set: async () => 'SET',
13+
del: async () => 'DEL',
14+
evalSha: async () => 'EVALSHA',
15+
...mockOverrides,
16+
}));
17+
};
18+
19+
export const resetRedis = async () => {
20+
const poolManager = getPoolManagerInstance();
21+
await poolManager.purgeConnections();
22+
};
23+
24+
export const resetJest = () => {
25+
jest.resetAllMocks();
26+
jest.useRealTimers();
27+
}
28+
29+
export const credentialsMock: RedisCredential = { host: 'redis', port: 6379, database: 0 };

test/libs/cookieParser.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const cookies = [
1010
'asd-asd-asd',
1111
];
1212

13-
describe('CookieParse', () => {
13+
describe('CookieParse Suite', () => {
1414
it('Should parse cookies correctly', () => {
1515
expect(cookieParse(cookies[0])['AAA-Aaaa-Aaaaaa']).toBe('00-Aaa-0000');
1616
expect(cookieParse(cookies[0]).DddDD).toBe('DD:DD:Ddd_Ddddddddd:33.33:-333.33:d3');

test/libs/oslojs.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
import { SHA256 } from '../../nodes/HttpForwardAuth/oslojs/sha2/sha256';
88
import { bigEndian, rotr32 } from '../../nodes/HttpForwardAuth/oslojs/binary';
99

10-
describe('Oslojs', () => {
10+
describe('Oslojs Suite', () => {
1111
it('Should encode to HexLowerCase', () => {
1212
const cases = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
1313
for (const length of cases) {

test/nodes/response.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { getRedisClient } from "../../nodes/HttpForwardAuth/transport";
2+
import { resetJest, resetRedis, setupRedis, credentialsMock } from "../helpers";
3+
4+
jest.mock('redis', () => ({
5+
__esModule: true,
6+
createClient: jest.fn(),
7+
}));
8+
9+
jest.useFakeTimers();
10+
11+
describe('Response Suite', () => {
12+
afterAll(resetJest);
13+
afterEach(resetRedis);
14+
15+
it('Test', async () => {
16+
setupRedis();
17+
await getRedisClient(credentialsMock);
18+
expect(true).toBe(true)
19+
})
20+
});

0 commit comments

Comments
 (0)