From 22c033970189f04b63542b23e9a70e9eb167ca3d Mon Sep 17 00:00:00 2001 From: d049904 Date: Tue, 16 Sep 2025 16:53:17 +0200 Subject: [PATCH] fix: Make localhost IP test compatible with CI environments Local environments use IPv6 (::1) while CI environments use IPv4-mapped IPv6 (::ffff:127.0.0.1). Updated test to accept both valid localhost representations. --- test/api/api.test.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/api/api.test.js b/test/api/api.test.js index b631435..9446e3a 100644 --- a/test/api/api.test.js +++ b/test/api/api.test.js @@ -13,6 +13,9 @@ cds.env.requires['audit-log'] = { const wait = require('node:timers/promises').setTimeout +// Matcher for localhost IPs (handles both IPv6 and IPv4-mapped IPv6) +const localhostIP = expect.stringMatching(/^(::1|::ffff:127\.0\.0\.1)$/) + describe('AuditLogService API', () => { let __log, _logs const _log = (...args) => { @@ -145,14 +148,14 @@ describe('AuditLogService API', () => { const response = await GET('/api/Books', { auth: BOB }) expect(response).toMatchObject({ status: 403 }) expect(_logs.length).toBe(1) - expect(_logs).toContainMatchObject({ user: 'bob', ip: '::1' }) + expect(_logs).toContainMatchObject({ user: 'bob', ip: localhostIP }) }) test('late reject', async () => { const response = await GET('/api/Books', { auth: ALICE }) expect(response).toMatchObject({ status: 403 }) expect(_logs.length).toBe(1) - expect(_logs).toContainMatchObject({ user: 'alice', ip: '::1' }) + expect(_logs).toContainMatchObject({ user: 'alice', ip: localhostIP }) }) test('early reject in batch', async () => { @@ -163,7 +166,7 @@ describe('AuditLogService API', () => { ) expect(response).toMatchObject({ status: 403 }) expect(_logs.length).toBeGreaterThan(0) //> coding in ./srv/server.js results in 2 logs on @sap/cds^7 - expect(_logs).toContainMatchObject({ user: 'bob', ip: '::1' }) + expect(_logs).toContainMatchObject({ user: 'bob', ip: localhostIP }) }) test('late reject in batch', async () => { @@ -175,7 +178,7 @@ describe('AuditLogService API', () => { expect(response).toMatchObject({ status: 200 }) expect(response.data.responses[0]).toMatchObject({ status: 403 }) expect(_logs.length).toBe(1) - expect(_logs).toContainMatchObject({ user: 'alice', ip: '::1' }) + expect(_logs).toContainMatchObject({ user: 'alice', ip: localhostIP }) }) }) })