Skip to content

Commit edb5a2a

Browse files
sjvansheikowitteborghm23
authored
chore: housekeeping re cds^9 (#30)
- [x] make 9 jobs required for merge --------- Co-authored-by: heikowitteborg <[email protected]> Co-authored-by: d049904 <[email protected]>
1 parent a778f61 commit edb5a2a

File tree

8 files changed

+59
-38
lines changed

8 files changed

+59
-38
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
name: CI
2+
permissions:
3+
contents: read
24

35
on:
46
workflow_dispatch:
@@ -8,20 +10,27 @@ on:
810
branches: [main]
911

1012
jobs:
11-
build:
13+
lint:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- run: npm i
18+
- run: npm run lint
19+
test:
1220
runs-on: ubuntu-latest
1321
strategy:
1422
fail-fast: false
1523
matrix:
1624
node-version: [22.x, 20.x]
25+
cds-version: [9, 8]
1726
steps:
1827
- uses: actions/checkout@v2
1928
- name: Use Node.js ${{ matrix.node-version }}
2029
uses: actions/setup-node@v2
2130
with:
2231
node-version: ${{ matrix.node-version }}
23-
- run: npm i -g @sap/cds-dk
32+
- run: npm i -g @sap/cds-dk@${{ matrix.cds-version }}
2433
- run: npm i
34+
- run: if [ ${{ matrix.cds-version }} -eq 8 ]; then npm i -f @sap/cds@8 @cap-js/sqlite@1; fi
2535
- run: cds v
26-
- run: npm run lint
2736
- run: npm run test

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# macOS
2+
.DS_Store
3+
14
# Logs
25
logs
36
*.log

jest.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
transform: {},
3+
moduleNameMapper: {
4+
'^@sap/xssec$': '<rootDir>/test/__mocks__/xssec.js'
5+
}
6+
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
},
2323
"devDependencies": {
2424
"@cap-js/event-broker": "file:.",
25+
"@cap-js/cds-test": ">=0",
26+
"@cap-js/sqlite": ">=1",
2527
"@sap-cloud-sdk/resilience": "^4.0.0",
2628
"@sap/xssec": "^4.2.4"
2729
},

test/__mocks__/xssec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class IdentityService {
2+
constructor(credentials, config) {
3+
this.credentials = credentials
4+
this.config = config
5+
}
6+
}
7+
8+
class ValidationError extends Error {
9+
constructor(message = 'Invalid token') {
10+
super(message)
11+
this.name = 'ValidationError'
12+
}
13+
}
14+
15+
module.exports = {
16+
v3: 'dummy',
17+
createSecurityContext(_, contextConfig) {
18+
contextConfig.jwt ??= contextConfig.req?.headers?.authorization?.split(' ')[1]
19+
if (contextConfig.jwt !== 'dummyToken') throw new ValidationError()
20+
const tokenInfoObj = { sub: 'eb-client-id', azp: 'eb-client-id' }
21+
const dummyTokenInfo = {
22+
getPayload: () => tokenInfoObj,
23+
getClientId: () => 'eb-client-id',
24+
getZoneId: () => 'dummyZoneId',
25+
...tokenInfoObj
26+
}
27+
return { token: dummyTokenInfo }
28+
},
29+
IdentityService,
30+
errors: { ValidationError }
31+
}

test/event-broker-ias-multitenant/event-broker.test.js

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,6 @@ const DATA = { key1: 1, value1: 1 }
44
const HEADERS = { keyHeader1: 1, valueHeader1: 1 }
55
let messaging, ownSrv, extSrv
66

7-
jest.mock('@sap/xssec', () => ({
8-
createSecurityContext(token, _credentials, id, cb) {
9-
if (token !== 'dummyToken') return cb(null, null, null)
10-
const dummyContext = {}
11-
const tokenInfoObj = { sub: 'eb-client-id', azp: 'eb-client-id' }
12-
const dummyTokenInfo = {
13-
getPayload: () => tokenInfoObj,
14-
getClientId: () => 'eb-client-id',
15-
getZoneId: () => 'dummyZoneId',
16-
...tokenInfoObj
17-
}
18-
return cb(null, dummyContext, dummyTokenInfo)
19-
}
20-
}))
21-
227
const mockHttps = {
238
handleHttpReq: () => {
249
throw new Error('must be implemented by test')
@@ -120,14 +105,14 @@ describe('event-broker service with ias auth', () => {
120105
test('request without JWT token', async () => {
121106
await expect(POST(`/-/cds/event-broker/webhook`)).rejects.toHaveProperty(
122107
'message',
123-
'Request failed with status code 401'
108+
expect.stringMatching('Request failed with status code 401')
124109
)
125110
})
126111

127112
test('request with invalid JWT token', async () => {
128113
await expect(
129114
POST(`/-/cds/event-broker/webhook`, { some: 'data' }, { headers: { Authorization: 'Bearer invalidtoken' } })
130-
).rejects.toHaveProperty('message', 'Request failed with status code 401')
115+
).rejects.toHaveProperty('message', expect.stringMatching('Request failed with status code 401'))
131116
})
132117

133118
test('Event broker mock event - messaging service ', done => {

test/event-broker-ias-single-tenant/event-broker.test.js

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,6 @@ const DATA = { key1: 1, value1: 1 }
44
const HEADERS = { keyHeader1: 1, valueHeader1: 1 }
55
let messaging, ownSrv, extSrv, credentials
66

7-
jest.mock('@sap/xssec', () => ({
8-
createSecurityContext(token, _credentials, id, cb) {
9-
if (token !== 'dummyToken') return cb(null, null, null)
10-
const dummyContext = {}
11-
const tokenInfoObj = { sub: 'eb-client-id', azp: 'eb-client-id' }
12-
const dummyTokenInfo = {
13-
getPayload: () => tokenInfoObj,
14-
getClientId: () => 'eb-client-id',
15-
getZoneId: () => 'dummyZoneId',
16-
...tokenInfoObj
17-
}
18-
return cb(null, dummyContext, dummyTokenInfo)
19-
}
20-
}))
21-
227
const mockHttps = {
238
handleHttpReq: () => {
249
throw new Error('must be implemented by test')
@@ -89,14 +74,14 @@ describe('event-broker service with ias auth for single tenant scenario', () =>
8974
test('request without JWT token', async () => {
9075
await expect(POST(`/-/cds/event-broker/webhook`)).rejects.toHaveProperty(
9176
'message',
92-
'Request failed with status code 401'
77+
expect.stringMatching('Request failed with status code 401')
9378
)
9479
})
9580

9681
test('request with invalid JWT token', async () => {
9782
await expect(
9883
POST(`/-/cds/event-broker/webhook`, { some: 'data' }, { headers: { Authorization: 'Bearer invalidtoken' } })
99-
).rejects.toHaveProperty('message', 'Request failed with status code 401')
84+
).rejects.toHaveProperty('message', expect.stringMatching('Request failed with status code 401'))
10085
})
10186

10287
test('Event broker mock event - messaging service ', done => {

test/event-broker-x509-multitenant/event-broker.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe('event-broker service', () => {
102102
test('request without client cert', async () => {
103103
await expect(POST(`/-/cds/event-broker/webhook`)).rejects.toHaveProperty(
104104
'message',
105-
'Request failed with status code 401'
105+
expect.stringMatching('Request failed with status code 401')
106106
)
107107
})
108108

0 commit comments

Comments
 (0)