diff --git a/src/services/link/index.js b/src/services/link/index.js index 137ada9b61d..38e78a10a5a 100644 --- a/src/services/link/index.js +++ b/src/services/link/index.js @@ -27,7 +27,8 @@ module.exports = function setup() { function redirectToTarget(req, res, next) { if (req.method === 'GET' && !req.query.target) { // capture these requests and issue a redirect - const linkId = req.params.__feathersId; + // const linkId = req.params.__feathersId; + const linkId = req.lookup.params.__id; linkService .get(linkId) .then((data) => { @@ -137,7 +138,7 @@ module.exports = function setup() { const { teamId } = data; if (email) { - const { data: userData } = await app.service('users').find({ query: { email: email } }); + const { data: userData } = await app.service('users').find({ query: { email } }); if (userData && userData[0] && userData[0].importHash) { linkInfo.hash = userData[0].importHash; } else { diff --git a/src/services/school/index.js b/src/services/school/index.js index d963a56a1b9..24e626af831 100644 --- a/src/services/school/index.js +++ b/src/services/school/index.js @@ -15,19 +15,19 @@ module.exports = function schoolServices() { const app = this; app.use('/schools/api', staticContent(path.join(__dirname, '/docs/openapi.yaml'))); - - const options = { - Model: schoolModels.schoolModel, - paginate: { - default: 5, - max: 100, // this is the max currently used in the SHD - }, - lean: { - virtuals: true, - }, - }; - - app.use('/schools', service(options)); + app.use( + '/schools', + service({ + Model: schoolModels.schoolModel, + paginate: { + default: 5, + max: 100, // this is the max currently used in the SHD + }, + lean: { + virtuals: true, + }, + }) + ); const schoolService = app.service('/schools'); schoolService.hooks(hooks); diff --git a/test/services/account/services/jwtTimerService.test.js b/test/services/account/services/jwtTimerService.test.js index 8996a518fcb..50a9b083b39 100644 --- a/test/services/account/services/jwtTimerService.test.js +++ b/test/services/account/services/jwtTimerService.test.js @@ -45,6 +45,7 @@ describe('jwtTimer service', () => { /* eslint-disable global-require */ redisHelper = require('../../../../src/utils/redis'); const { jwtTimerServiceSetup } = require('../../../../src/services/account/services/jwtTimerService'); + app.unuse('/accounts/jwtTimer'); app.configure(jwtTimerServiceSetup); /* eslint-enable global-require */ @@ -105,6 +106,7 @@ describe('jwtTimer service', () => { /* eslint-disable global-require */ redisHelper = require('../../../../src/utils/redis'); const { jwtTimerServiceSetup } = require('../../../../src/services/account/services/jwtTimerService'); + app.unuse('/accounts/jwtTimer'); app.configure(jwtTimerServiceSetup); /* eslint-enable global-require */ diff --git a/test/services/content/material.test.js b/test/services/content/material.test.js index b846f5418eb..3d1faa798e3 100644 --- a/test/services/content/material.test.js +++ b/test/services/content/material.test.js @@ -14,8 +14,8 @@ describe('material service', () => { before(async () => { app = await appPromise(); - server = await app.listen(0); nestServices = await setupNestServices(app); + server = await app.listen(0); }); after(async () => { @@ -41,10 +41,6 @@ describe('material service', () => { let materialA; let materialB; - before((done) => { - server = app.listen(0, done); - }); - before(async () => { [materialA, materialB] = await Promise.all([ Material.create({ diff --git a/test/services/datasources/datasourceRuns.test.js b/test/services/datasources/datasourceRuns.test.js index b169e92e4dd..06601b206d2 100644 --- a/test/services/datasources/datasourceRuns.test.js +++ b/test/services/datasources/datasourceRuns.test.js @@ -53,6 +53,9 @@ describe('datasourceRuns service', () => { }); mockery.registerMock('./strategies', [MockSyncer, MockSyncerWithData]); datasourceRunsService = app.service('datasourceRuns'); + + app.unuse('/sync/userAccount'); + app.unuse('/sync'); // eslint-disable-next-line global-require const sync = require('../../../src/services/sync'); app.configure(sync); diff --git a/test/services/helpdesk/index.test.js b/test/services/helpdesk/index.test.js index 4b515c6816c..f344cec0df9 100644 --- a/test/services/helpdesk/index.test.js +++ b/test/services/helpdesk/index.test.js @@ -2,8 +2,8 @@ const assert = require('assert'); const { expect } = require('chai'); const sinon = require('sinon'); -const appPromise = require('../../../src/app'); const { Configuration } = require('@hpi-schul-cloud/commons'); +const appPromise = require('../../../src/app'); describe('helpdesk service', function test() { this.timeout(10000); @@ -36,6 +36,7 @@ describe('helpdesk service', function test() { }); after((done) => { + app.unuse('/mails'); app.use('/mails', originalMailService); helpdeskService .remove(testProblem) @@ -115,6 +116,7 @@ describe('helpdesk service', function test() { problemDescription: 'Dies ist die Problembeschreibung 1', replyEmail: 'test@mail.de', }; + app.unuse('/mails'); const mailService = new MockMailService(); app.use('/mails', mailService); await helpdeskService.create(postBody, { account: { userId: '0000d213816abba584714c0a' } }); @@ -129,6 +131,7 @@ describe('helpdesk service', function test() { problemDescription: 'Dies ist die Problembeschreibung 1', replyEmail: 'test@mail.de', }; + app.unuse('/mails'); const mailService = new MockMailService(); app.use('/mails', mailService); const tempScTheme = Configuration.get('SUPPORT_PROBLEM_EMAIL_ADDRESS'); @@ -146,6 +149,7 @@ describe('helpdesk service', function test() { problemDescription: 'Dies ist die Problembeschreibung 1', replyEmail: 'test@mail.de', }; + app.unuse('/mails'); const mailService = new MockMailService(); app.use('/mails', mailService); await helpdeskService.create(postBody, { account: { userId: '0000d213816abba584714c0a' } }); @@ -161,6 +165,7 @@ describe('helpdesk service', function test() { problemDescription: 'Dies ist die Problembeschreibung 2', replyEmail: 'test@mail.de', }; + app.unuse('/mails'); const mailService = new MockMailService(); app.use('/mails', mailService); const tempScTheme = Configuration.get('SUPPORT_WISH_EMAIL_ADDRESS'); diff --git a/test/services/ldap-config/service.integration.test.js b/test/services/ldap-config/service.integration.test.js index 8fc6c455bef..914b22b9b92 100644 --- a/test/services/ldap-config/service.integration.test.js +++ b/test/services/ldap-config/service.integration.test.js @@ -150,25 +150,28 @@ describe('LdapConfigService', () => { function MockLdapService() { return { setup: () => {}, + get: () => {}, getUsers: sinon.fake.resolves(fakeUsers), getClasses: sinon.fake.resolves(fakeClasses), disconnect: sinon.fake.resolves(), }; } - beforeEach(() => { - ldapServiceMock = new MockLdapService(); - app.use('ldap', ldapServiceMock); - }); - before(() => { originalLdapService = app.service('ldap'); }); after(() => { + app.unuse('ldap'); app.use('ldap', originalLdapService); }); + beforeEach(() => { + app.unuse('/ldap'); + ldapServiceMock = new MockLdapService(); + app.use('ldap', ldapServiceMock); + }); + beforeEach(async () => { school = await testObjects.createTestSchool({ systems: [], @@ -223,6 +226,7 @@ describe('LdapConfigService', () => { }); it('should catch common errors', async () => { + app.unuse('ldap'); ldapServiceMock.getUsers = sinon.fake.rejects(new LDAPConnectionError()); app.use('ldap', ldapServiceMock); @@ -287,25 +291,28 @@ describe('LdapConfigService', () => { function MockLdapService() { return { setup: () => {}, + get: () => {}, getUsers: sinon.fake.resolves(fakeUsers), getClasses: sinon.fake.resolves(fakeClasses), disconnect: sinon.fake.resolves(), }; } - beforeEach(() => { - ldapServiceMock = new MockLdapService(); - app.use('ldap', ldapServiceMock); - }); - before(() => { originalLdapService = app.service('ldap'); }); after(() => { + app.unuse('ldap'); app.use('ldap', originalLdapService); }); + beforeEach(() => { + app.unuse('/ldap'); + ldapServiceMock = new MockLdapService(); + app.use('/ldap', ldapServiceMock); + }); + beforeEach(async () => { system = await testObjects.createTestSystem({ type: 'ldap', diff --git a/test/services/ldap/strategies/general.test.js b/test/services/ldap/strategies/general.test.js index 1cc530d626f..b938717cfad 100644 --- a/test/services/ldap/strategies/general.test.js +++ b/test/services/ldap/strategies/general.test.js @@ -66,6 +66,7 @@ describe('GeneralLDAPStrategy', () => { }); after(() => { + app.unuse('/ldap'); app.use('/ldap', originalLdapService); }); diff --git a/test/services/ldap/strategies/iserv-idm.test.js b/test/services/ldap/strategies/iserv-idm.test.js index 2aadaf1ea90..adb089e396c 100644 --- a/test/services/ldap/strategies/iserv-idm.test.js +++ b/test/services/ldap/strategies/iserv-idm.test.js @@ -22,6 +22,7 @@ describe('IservIdmLDAPStrategy', () => { }); after(() => { + app.unuse('/ldap'); app.use('/ldap', originalLdapService); }); @@ -29,6 +30,7 @@ describe('IservIdmLDAPStrategy', () => { function MockLdapService() { return { setup: () => {}, + get: () => {}, searchCollection: sinon.fake.returns([ { dn: 'o=Testschule,dc=de', o: 'Testschule' }, { dn: 'o=hvk,dc=schule', description: 'Heinrich-von-Kleist-Schule', o: 'hvk' }, @@ -37,6 +39,7 @@ describe('IservIdmLDAPStrategy', () => { } beforeEach(() => { + app.unuse('/ldap'); ldapServiceMock = new MockLdapService(); app.use('/ldap', ldapServiceMock); }); @@ -86,6 +89,7 @@ describe('IservIdmLDAPStrategy', () => { function MockLdapService() { return { setup: () => {}, + get: () => {}, searchCollection: sinon.fake.returns([ { dn: 'cn=student1,ou=users,o=Testschule,dc=de', @@ -153,6 +157,7 @@ describe('IservIdmLDAPStrategy', () => { } beforeEach(() => { + app.unuse('/ldap'); ldapServiceMock = new MockLdapService(); app.use('/ldap', ldapServiceMock); }); @@ -206,6 +211,7 @@ describe('IservIdmLDAPStrategy', () => { function MockLdapService() { return { setup: () => {}, + get: () => {}, searchCollection: sinon.fake.returns([ { dn: 'cn=klasse9a,ou=groups,o=Testschule,dc=de', @@ -228,6 +234,7 @@ describe('IservIdmLDAPStrategy', () => { } beforeEach(() => { + app.unuse('/ldap'); ldapServiceMock = new MockLdapService(); app.use('/ldap', ldapServiceMock); }); diff --git a/test/services/ldap/strategies/univention.test.js b/test/services/ldap/strategies/univention.test.js index cf6a1dad178..0451e389cd6 100644 --- a/test/services/ldap/strategies/univention.test.js +++ b/test/services/ldap/strategies/univention.test.js @@ -27,6 +27,7 @@ describe('UniventionLDAPStrategy', () => { }); after(() => { + app.unuse('/ldap'); app.use('/ldap', originalLdapService); }); @@ -39,11 +40,13 @@ describe('UniventionLDAPStrategy', () => { function MockLdapService() { return { setup: () => {}, + get: () => {}, searchCollection: sinon.fake.resolves(ldapFakeSchoolSearchResult), }; } beforeEach(() => { + app.unuse('/ldap'); ldapServiceMock = new MockLdapService(); app.use('/ldap', ldapServiceMock); }); @@ -122,6 +125,7 @@ describe('UniventionLDAPStrategy', () => { function MockLdapService() { return { setup: () => {}, + get: () => {}, searchCollection: sinon.fake.resolves([ { dn: 'uid=max1,cn=schueler,cn=users,ou=1,dc=training,dc=ucs', @@ -165,6 +169,7 @@ describe('UniventionLDAPStrategy', () => { } beforeEach(() => { + app.unuse('/ldap'); ldapServiceMock = new MockLdapService(); app.use('/ldap', ldapServiceMock); }); @@ -241,11 +246,13 @@ describe('UniventionLDAPStrategy', () => { function MockLdapService() { return { setup: () => {}, + get: () => {}, searchCollection: sinon.fake.resolves(ldapFakeClassSearchResult), }; } beforeEach(() => { + app.unuse('/ldap'); ldapServiceMock = new MockLdapService(); app.use('/ldap', ldapServiceMock); }); diff --git a/test/services/news/index.test.js b/test/services/news/index.test.js index 3e22ba4e0cc..1110b057dc0 100644 --- a/test/services/news/index.test.js +++ b/test/services/news/index.test.js @@ -4,18 +4,22 @@ const sleep = require('util').promisify(setTimeout); const appPromise = require('../../../src/app'); const { newsModel: News } = require('../../../src/services/news/model'); +const { setupNestServices, closeNestServices } = require('../../utils/setup.nest.services'); describe('news service', () => { let app; - let newsService; + let server; + let nestServices; before(async () => { app = await appPromise(); - newsService = app.service('news'); + nestServices = await setupNestServices(app); + server = await app.listen(0); }); - it('public service has been disabled', () => { - expect(newsService, 'use v3 instead').to.equal(undefined); + after(async () => { + await server.close(); + await closeNestServices(nestServices); }); describe('event handlers', () => { diff --git a/test/services/oauth2/mock.js b/test/services/oauth2/mock.js index f375128705a..b3457fd25de 100644 --- a/test/services/oauth2/mock.js +++ b/test/services/oauth2/mock.js @@ -2,6 +2,8 @@ const assert = require('assert'); const chai = require('chai'); const chaiHttp = require('chai-http'); +const { Configuration } = require('@hpi-schul-cloud/commons'); + // proxyserver const oauth2Server = require('./oauth2MockServer'); const oauth2 = require('../../../src/services/oauth2'); @@ -58,10 +60,18 @@ describe('oauth2 service mock', function oauthTest() { introspectService = app.service('oauth2/introspect'); consentService = app.service('oauth2/auth/sessions/consent'); - beforeHydraUri = app.settings.services.hydra; + beforeHydraUri = Configuration.get('HYDRA_URI'); const o2mock = await oauth2Server({}); - app.settings.services.hydra = o2mock.url; + Configuration.set('HYDRA_URI', o2mock.url); + + app.unuse('oauth2/baseUrl'); + app.unuse('oauth2/clients'); + app.unuse('oauth2/loginRequest'); + app.unuse('oauth2/logoutRequest'); + app.unuse('oauth2/consentRequest'); + app.unuse('oauth2/introspect'); + app.unuse('oauth2/auth/sessions/consent'); app.configure(oauth2); server = await app.listen(); @@ -70,7 +80,7 @@ describe('oauth2 service mock', function oauthTest() { after(async () => { // sets uri back to original uri - app.settings.services.hydra = beforeHydraUri; + Configuration.set('HYDRA_URI', beforeHydraUri); await server.close(); await closeNestServices(nestServices); }); diff --git a/test/services/rocketChat/index.test.js b/test/services/rocketChat/index.test.js index 0cb90fdd9f6..78caf281737 100644 --- a/test/services/rocketChat/index.test.js +++ b/test/services/rocketChat/index.test.js @@ -24,7 +24,9 @@ describe('rocket.chat user service', () => { app = await appPromise(); // const rcMock = await rcMockServer({}); const rocketChatService = { - getUserList: () => ({ users: [{ _id: 'someId', username: 'someUsername' }] }), + getUserList: () => { + return { users: [{ _id: 'someId', username: 'someUsername' }] }; + }, }; mockery.enable({ warnOnUnregistered: false, @@ -39,7 +41,13 @@ describe('rocket.chat user service', () => { delete require.cache[require.resolve('../../../src/services/rocketChat/helpers.js')]; delete require.cache[require.resolve('../../../src/services/rocketChat/index.js')]; const rocketChat = require('../../../src/services/rocketChat'); + app = await appPromise(); + + app.unuse('/rocketChat/channel'); + app.unuse('/rocketChat/user'); + app.unuse('/rocketChat/login'); + app.unuse('/rocketChat/logout'); app.configure(rocketChat); rocketChatUserService = app.service('/rocketChat/user'); @@ -92,6 +100,10 @@ class NestRocketChatServiceMock { this.app = app; } + get() { + return undefined; + } + async logoutUser(authToken, rcId) { return { authToken, rcId }; } @@ -132,6 +144,10 @@ class RocketChatUserServiceMock { } } + get() { + return undefined; + } + async getOrCreateRocketChatAccount(userId, params) { const rocktChatUserData = { authToken: 'rocketChatToken123', @@ -165,7 +181,9 @@ describe('rocket.chat login service', async () => { }); const setupServices = async (RCNestMock, RCUserMock) => { + app.unuse('/nest-rocket-chat'); app.use('/nest-rocket-chat', RCNestMock || new NestRocketChatServiceMock()); + app.unuse('/rocketChat/user'); app.use('/rocketChat/user', RCUserMock || new RocketChatUserServiceMock()); const setupData = await testObjects.setupUser(); return setupData; @@ -235,7 +253,9 @@ describe('rocket.chat logout service', async () => { }); const setupServices = async (RCNestMock, RCUserMock) => { + app.unuse('/nest-rocket-chat'); app.use('/nest-rocket-chat', RCNestMock || new NestRocketChatServiceMock()); + app.unuse('/rocketChat/user'); app.use('/rocketChat/user', RCUserMock || new RocketChatUserServiceMock()); const setupData = await testObjects.setupUser(); diff --git a/test/services/sync/strategies/CSVSyncer/CSVSyncer.integration.test.js b/test/services/sync/strategies/CSVSyncer/CSVSyncer.integration.test.js index 4c5830ddb84..44d52e13220 100644 --- a/test/services/sync/strategies/CSVSyncer/CSVSyncer.integration.test.js +++ b/test/services/sync/strategies/CSVSyncer/CSVSyncer.integration.test.js @@ -472,6 +472,7 @@ describe('CSVSyncer Integration', () => { it('should import five teachers into three existing classes', async () => { const emails = []; + app.unuse('/mails'); app.use( '/mails', new MockEmailService((email) => { @@ -726,6 +727,7 @@ describe('CSVSyncer Integration', () => { }); it('should not be able to send emails', async () => { + app.unuse('/mails'); app.use( '/mails', new MockEmailService(() => { @@ -791,6 +793,7 @@ describe('CSVSyncer Integration', () => { it('should import one user report two failures', async () => { const emails = []; + app.unuse('/mails'); app.use( '/mails', new MockEmailService((email) => { diff --git a/test/services/teams/hooks/helpers.test.js b/test/services/teams/hooks/helpers.test.js index 3b8293d7cb5..8a5caf39571 100644 --- a/test/services/teams/hooks/helpers.test.js +++ b/test/services/teams/hooks/helpers.test.js @@ -22,8 +22,8 @@ describe('hook helpers', () => { before(async () => { app = await appPromise(); - server = await app.listen(0); nestServices = await setupNestServices(app); + server = await app.listen(0); }); after(async () => { diff --git a/test/services/teams/hooks/index.test.js b/test/services/teams/hooks/index.test.js index 947c2a44380..b1d8ffbfd5c 100644 --- a/test/services/teams/hooks/index.test.js +++ b/test/services/teams/hooks/index.test.js @@ -20,8 +20,8 @@ describe('Team service hook tests.', () => { before(async () => { app = await appPromise(); - server = await app.listen(0); nestServices = await setupNestServices(app); + server = await app.listen(0); }); after(async () => { diff --git a/test/services/user/services/QrRegistrationLinks.test.js b/test/services/user/services/QrRegistrationLinks.test.js index 15b02d3445b..a409da20319 100644 --- a/test/services/user/services/QrRegistrationLinks.test.js +++ b/test/services/user/services/QrRegistrationLinks.test.js @@ -167,6 +167,7 @@ describe('qrRegistrationLinks service tests', () => { } catch (err) { expect(err.code).to.equal(400); expect(err.name).to.equal('BadRequest'); + // TODO something changed in the logic of errors? expect(err.message).to.equal('Can not generate QR registration links'); expect(err.errors.message).to.equal('The given role is not supported'); }