From 703cf79e110b22ee6ac47ec69fea7410a36ca4e4 Mon Sep 17 00:00:00 2001 From: D045778 Date: Mon, 7 Apr 2025 20:46:36 +0200 Subject: [PATCH 1/6] chore: prep for service restrictions by default --- test/consuming-services.test.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/test/consuming-services.test.js b/test/consuming-services.test.js index 73f2c825..d151e76b 100644 --- a/test/consuming-services.test.js +++ b/test/consuming-services.test.js @@ -15,15 +15,15 @@ describe('cap/samples - Consuming Services locally', () => { const { Authors } = AdminService.entities expect (await SELECT.from(Authors)) // .to.eql(await SELECT.from('Authors')) - .to.eql(await AdminService.read(Authors)) - .to.eql(await AdminService.read('Authors')) - .to.eql(await AdminService.run(SELECT.from(Authors))) - .to.eql(await AdminService.run(SELECT.from('Authors'))) + .to.eql(await AdminService.tx({user: cds.User.privileged}, tx => tx.read(Authors))) + .to.eql(await AdminService.tx({user: cds.User.privileged}, tx => tx.read('Authors'))) + .to.eql(await AdminService.tx({user: cds.User.privileged}, tx => tx.run(SELECT.from(Authors)))) + .to.eql(await AdminService.tx({user: cds.User.privileged}, tx => tx.run(SELECT.from('Authors')))) }) it('allows reading from local services using cds.ql', async () => { const AdminService = await cds.connect.to('AdminService') - const authors = await AdminService.read (`Authors`, a => { + const authors = await AdminService.tx({user: cds.User.privileged}, tx => tx.read (`Authors`, a => { a.name, a.books((b) => { b.title, @@ -31,7 +31,7 @@ describe('cap/samples - Consuming Services locally', () => { c.name, c.symbol }) }) - }).where(`name like`, 'E%') + }).where(`name like`, 'E%')) expect(authors).to.containSubset([ { name: 'Emily Brontë', @@ -69,13 +69,14 @@ describe('cap/samples - Consuming Services locally', () => { } const query1 = SELECT.from(Authors, projection).where(`name like`, 'E%') const query2 = cds.read(Authors, projection).where(`name like`, 'E%') + // cds.context = {user: cds.User.privileged} expect(await cds.run(query1)) .to.eql(await db.run(query1)) - .to.eql(await srv.run(query1)) - .to.eql(await srv.read(Authors, projection).where(`name like`, 'E%')) + .to.eql(await srv.tx({user: cds.User.privileged}, tx => tx.run(query1))) + .to.eql(await srv.tx({user: cds.User.privileged}, tx => tx.read(Authors, projection).where(`name like`, 'E%'))) .to.eql(await cds.run(query2)) .to.eql(await db.run(query2)) - .to.eql(await srv.run(query2)) + .to.eql(await srv.tx({user: cds.User.privileged}, tx => tx.run(query2))) .to.eql(await db.read(Authors, projection).where(`name like`, 'E%')) }) }) From 439b768e3d94fa3691bedab6dd13721b368121bb Mon Sep 17 00:00:00 2001 From: D045778 Date: Tue, 15 Apr 2025 11:59:20 +0200 Subject: [PATCH 2/6] Revert "chore: prep for service restrictions by default" This reverts commit 703cf79e110b22ee6ac47ec69fea7410a36ca4e4. --- test/consuming-services.test.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/test/consuming-services.test.js b/test/consuming-services.test.js index d151e76b..73f2c825 100644 --- a/test/consuming-services.test.js +++ b/test/consuming-services.test.js @@ -15,15 +15,15 @@ describe('cap/samples - Consuming Services locally', () => { const { Authors } = AdminService.entities expect (await SELECT.from(Authors)) // .to.eql(await SELECT.from('Authors')) - .to.eql(await AdminService.tx({user: cds.User.privileged}, tx => tx.read(Authors))) - .to.eql(await AdminService.tx({user: cds.User.privileged}, tx => tx.read('Authors'))) - .to.eql(await AdminService.tx({user: cds.User.privileged}, tx => tx.run(SELECT.from(Authors)))) - .to.eql(await AdminService.tx({user: cds.User.privileged}, tx => tx.run(SELECT.from('Authors')))) + .to.eql(await AdminService.read(Authors)) + .to.eql(await AdminService.read('Authors')) + .to.eql(await AdminService.run(SELECT.from(Authors))) + .to.eql(await AdminService.run(SELECT.from('Authors'))) }) it('allows reading from local services using cds.ql', async () => { const AdminService = await cds.connect.to('AdminService') - const authors = await AdminService.tx({user: cds.User.privileged}, tx => tx.read (`Authors`, a => { + const authors = await AdminService.read (`Authors`, a => { a.name, a.books((b) => { b.title, @@ -31,7 +31,7 @@ describe('cap/samples - Consuming Services locally', () => { c.name, c.symbol }) }) - }).where(`name like`, 'E%')) + }).where(`name like`, 'E%') expect(authors).to.containSubset([ { name: 'Emily Brontë', @@ -69,14 +69,13 @@ describe('cap/samples - Consuming Services locally', () => { } const query1 = SELECT.from(Authors, projection).where(`name like`, 'E%') const query2 = cds.read(Authors, projection).where(`name like`, 'E%') - // cds.context = {user: cds.User.privileged} expect(await cds.run(query1)) .to.eql(await db.run(query1)) - .to.eql(await srv.tx({user: cds.User.privileged}, tx => tx.run(query1))) - .to.eql(await srv.tx({user: cds.User.privileged}, tx => tx.read(Authors, projection).where(`name like`, 'E%'))) + .to.eql(await srv.run(query1)) + .to.eql(await srv.read(Authors, projection).where(`name like`, 'E%')) .to.eql(await cds.run(query2)) .to.eql(await db.run(query2)) - .to.eql(await srv.tx({user: cds.User.privileged}, tx => tx.run(query2))) + .to.eql(await srv.run(query2)) .to.eql(await db.read(Authors, projection).where(`name like`, 'E%')) }) }) From e29a9791f54f41f388ef3845ec7a3a1a5ff697d9 Mon Sep 17 00:00:00 2001 From: D045778 Date: Tue, 15 Apr 2025 12:01:33 +0200 Subject: [PATCH 3/6] disable auth checks --- test/consuming-services.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/consuming-services.test.js b/test/consuming-services.test.js index 73f2c825..7bc97d7d 100644 --- a/test/consuming-services.test.js +++ b/test/consuming-services.test.js @@ -3,6 +3,8 @@ const { expect } = cds.test ('@capire/bookshop') describe('cap/samples - Consuming Services locally', () => { + before(() => (cds.User.default = cds.User.privileged)) // disable auth checks + it('bootstrapped the database successfully', ()=>{ const { AdminService } = cds.services const { Authors } = AdminService.entities From 1c8d7b1703d1e485c227eb579a8b9de9a174739b Mon Sep 17 00:00:00 2001 From: D045778 Date: Tue, 15 Apr 2025 13:43:37 +0200 Subject: [PATCH 4/6] without before hook --- test/consuming-services.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/consuming-services.test.js b/test/consuming-services.test.js index 7bc97d7d..562a4984 100644 --- a/test/consuming-services.test.js +++ b/test/consuming-services.test.js @@ -3,7 +3,7 @@ const { expect } = cds.test ('@capire/bookshop') describe('cap/samples - Consuming Services locally', () => { - before(() => (cds.User.default = cds.User.privileged)) // disable auth checks + cds.User.default = cds.User.privileged // disable auth checks it('bootstrapped the database successfully', ()=>{ const { AdminService } = cds.services From 5a68acc2abcf292b394b8ad5584525d6626ec2a1 Mon Sep 17 00:00:00 2001 From: D045778 Date: Tue, 15 Apr 2025 13:44:39 +0200 Subject: [PATCH 5/6] early as possible --- test/consuming-services.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/consuming-services.test.js b/test/consuming-services.test.js index 562a4984..9aedb5f1 100644 --- a/test/consuming-services.test.js +++ b/test/consuming-services.test.js @@ -1,9 +1,9 @@ const cds = require('@sap/cds') const { expect } = cds.test ('@capire/bookshop') +cds.User.default = cds.User.privileged // disable auth checks describe('cap/samples - Consuming Services locally', () => { - cds.User.default = cds.User.privileged // disable auth checks it('bootstrapped the database successfully', ()=>{ const { AdminService } = cds.services From c6fd86cc837da1a0d047fe2e88b19c9357ba210d Mon Sep 17 00:00:00 2001 From: D045778 Date: Tue, 15 Apr 2025 13:44:57 +0200 Subject: [PATCH 6/6] rm line --- test/consuming-services.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/consuming-services.test.js b/test/consuming-services.test.js index 9aedb5f1..6a7c8dbe 100644 --- a/test/consuming-services.test.js +++ b/test/consuming-services.test.js @@ -4,7 +4,6 @@ cds.User.default = cds.User.privileged // disable auth checks describe('cap/samples - Consuming Services locally', () => { - it('bootstrapped the database successfully', ()=>{ const { AdminService } = cds.services const { Authors } = AdminService.entities