Skip to content

Commit bfb4685

Browse files
committed
CDS 9.3 & IAS auth
1 parent 138eb3a commit bfb4685

File tree

8 files changed

+426
-412
lines changed

8 files changed

+426
-412
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8-
## Version 1.7.3 - 2025-09-xx
8+
## Version 1.7.3 - 2025-09-08
99

1010
### Fixed
1111

12-
- tbd
12+
- Fix `ias` auth strategy, set `req.hostname`
1313

1414
## Version 1.7.2 - 2025-08-04
1515

package-lock.json

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

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@
5151
"devDependencies": {
5252
"@cap-js-community/websocket": "./",
5353
"@cap-js/cds-test": "^0.4.0",
54-
"@eslint/js": "^9.32.0",
55-
"@sap/cds": "^9.2.0",
56-
"@sap/cds-dk": "^9.2.0",
54+
"@eslint/js": "^9.35.0",
55+
"@sap/cds": "^9.3.1",
56+
"@sap/cds-dk": "^9.3.0",
5757
"@socket.io/redis-adapter": "^8.3.0",
5858
"@socket.io/redis-streams-adapter": "^0.2.2",
59-
"eslint": "^9.32.0",
59+
"eslint": "^9.35.0",
6060
"eslint-config-prettier": "^10.1.8",
6161
"eslint-plugin-jest": "^29.0.1",
6262
"eslint-plugin-n": "^17.21.3",
6363
"express": "^4.21.2",
6464
"globals": "^16.3.0",
65-
"jest": "^30.0.5",
65+
"jest": "^30.1.3",
6666
"prettier": "^3.6.2"
6767
},
6868
"license": "Apache-2.0",

src/socket/base.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ class SocketServer {
246246
* @returns {[function]} Returns a list of middleware functions
247247
*/
248248
beforeMiddlewares() {
249-
return [this.mockResponse.bind(this), this.applyAuthCookie.bind(this)];
249+
return [this.enhanceRequest.bind(this), this.applyAuthCookie.bind(this)];
250250
}
251251

252252
/**
@@ -310,14 +310,16 @@ class SocketServer {
310310
}
311311

312312
/**
313-
* Mock the HTTP response object and make available at req.res
313+
* Enhance the request object. Mock the HTTP response object and make available at req.res
314314
* @param {Object} socket Server socket
315315
* @param {Function} next Call next
316316
*/
317-
mockResponse(socket, next) {
317+
enhanceRequest(socket, next) {
318318
const req = socket.request;
319319
req.baseUrl ??= req.url;
320320
req.originalUrl ??= req.url;
321+
req.hostname ??= req.headers?.["x-forwarded-host"] ?? req.headers?.host ?? "";
322+
req.host = req.hostname;
321323
let error;
322324
try {
323325
// Mock response (not available in websocket, CDS middlewares need it)

test/_env/srv/handlers/cloudevent.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"use strict";
22

33
module.exports = (srv) => {
4+
srv.on("wsContext", async () => {});
5+
46
srv.on(["sendCloudEventModel", "sendCloudEventMap"], async (req) => {
57
const appinfoA = (req.data.appinfoA ?? req.data.data?.appinfoA ?? "abc") + "d";
68
const appinfoB = (req.data.appinfoB ?? req.data.data?.appinfoB ?? 123) + 1111;

test/_env/srv/handlers/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
module.exports = (srv) => {
44
const { Header } = srv.entities();
55

6+
srv.on("wsContext", async () => {});
7+
68
srv.before("CREATE", Header, async (req) => {
79
req.data.description += `- ${req.headers.test}`;
810
});

test/base/base.test.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,29 @@ describe("Base", () => {
7070
expect(baseFormat.compose("test", {})).toBeUndefined();
7171
});
7272

73-
test("Mock Response", async () => {
73+
test("Enhance Request - Host", async () => {
74+
const next = jest.fn();
75+
const socketServer = new SocketServer();
76+
let req = { headers: { host: "localhost:4711" } };
77+
socketServer.enhanceRequest({ request: req }, next);
78+
expect(req.baseUrl).toBe(req.url);
79+
expect(req.originalUrl).toBe(req.url);
80+
expect(req.hostname).toBe("localhost:4711");
81+
expect(req.host).toBe("localhost:4711");
82+
83+
req = { headers: { host: "localhost:4711", "x-forwarded-host": "localhost:4712" } };
84+
socketServer.enhanceRequest({ request: req }, next);
85+
expect(req.baseUrl).toBe(req.url);
86+
expect(req.originalUrl).toBe(req.url);
87+
expect(req.hostname).toBe("localhost:4712");
88+
expect(req.host).toBe("localhost:4712");
89+
});
90+
91+
test("Enhance Request - Mock Response", async () => {
7492
const socketServer = new SocketServer();
7593
const req = {};
7694
const next = jest.fn();
77-
socketServer.mockResponse({ request: req }, next);
95+
socketServer.enhanceRequest({ request: req }, next);
7896
expect(req.res).toBeDefined();
7997
expect(req.res.headers).toEqual({});
8098
expect(req.res.set("A", "B")).toBe(req.res);

test/ws/__snapshots__/main_ws.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`Main CRUD entity 1`] = `
44
{

0 commit comments

Comments
 (0)