From 827052f375a5fb9ad3f22f0fca48305729c384c6 Mon Sep 17 00:00:00 2001 From: virgilchiriac <17074330+virgilchiriac@users.noreply.github.com> Date: Tue, 12 Dec 2023 08:08:05 +0100 Subject: [PATCH] BC-6011 - try bettermarks uri config (#4628) --------- Co-authored-by: SevenWaysDP --- .../templates/configmap_file_init.yml.j2 | 8 ++++---- src/services/oauth2/hooks/index.js | 4 ++-- src/services/oauth2/index.js | 7 +++++-- test/services/oauth2/mock.js | 15 ++++++++------- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/ansible/roles/schulcloud-server-init/templates/configmap_file_init.yml.j2 b/ansible/roles/schulcloud-server-init/templates/configmap_file_init.yml.j2 index 654d4152b95..6825b0bafec 100644 --- a/ansible/roles/schulcloud-server-init/templates/configmap_file_init.yml.j2 +++ b/ansible/roles/schulcloud-server-init/templates/configmap_file_init.yml.j2 @@ -333,7 +333,7 @@ data: # Perform the final Bettermarks config data init if client secret and URL has been properly set. if [ -n "$BETTERMARKS_CLIENT_SECRET" ] && [ -n "$BETTERMARKS_URL" ]; then # Add document to the 'ltitools' collection with Bettermarks tool configuration. - mongosh $DATABASE__URL --eval 'db.ltitools.replaceOne( + mongosh $DATABASE__URL --eval 'db.getCollection("ltitools").replaceOne( { "name": "bettermarks", "isTemplate": true @@ -391,7 +391,7 @@ data: # Add Bettermarks' tools configuration as an external tool # (stored in the 'external-tools' collection) that uses OAuth. - mongosh $DATABASE__URL --eval 'db.external-tools.replaceOne( + mongosh $DATABASE__URL --eval 'db.getCollection("external-tools").replaceOne( { "name": "bettermarks", "config_type": "oauth2" @@ -428,7 +428,7 @@ data: if [ -n "$NEXTCLOUD_CLIENT_SECRET" ] && [ -n "$NEXTCLOUD_SOCIALLOGIN_OIDC_INTERNAL_NAME" ]; then echo "Inserting nextcloud to ltitools..." # Add document to the 'ltitools' collection - mongosh $DATABASE__URL --eval 'db.ltitools.update( + mongosh $DATABASE__URL --eval 'db.getCollection("ltitools").update( { "name": "'$NEXTCLOUD_SOCIALLOGIN_OIDC_INTERNAL_NAME'", "isTemplate": true @@ -488,7 +488,7 @@ data: # Add Nextcloud' tools configuration as an external tool # (stored in the 'external-tools' collection) that uses OAuth. echo "Inserting nextcloud to external-tools..." - mongosh $DATABASE__URL --eval 'db.external-tools.update( + mongosh $DATABASE__URL --eval 'db.getCollection("external-tools").update( { "name": "nextcloud", "config_type": "oauth2" diff --git a/src/services/oauth2/hooks/index.js b/src/services/oauth2/hooks/index.js index c4a0cac7916..35e5653b7d3 100644 --- a/src/services/oauth2/hooks/index.js +++ b/src/services/oauth2/hooks/index.js @@ -105,7 +105,7 @@ const setIdToken = (hook) => { }; const injectLoginRequest = (hook) => - Hydra(hook.app.settings.services.hydra) + Hydra(Configuration.get('HYDRA_URI')) .getLoginRequest(hook.id) .then((loginRequest) => { hook.params.loginRequest = loginRequest; @@ -113,7 +113,7 @@ const injectLoginRequest = (hook) => }); const injectConsentRequest = (hook) => - Hydra(hook.app.settings.services.hydra) + Hydra(Configuration.get('HYDRA_URI')) .getConsentRequest(hook.id) .then((consentRequest) => { hook.params.consentRequest = consentRequest; diff --git a/src/services/oauth2/index.js b/src/services/oauth2/index.js index 4725e73e922..34deb09c83d 100644 --- a/src/services/oauth2/index.js +++ b/src/services/oauth2/index.js @@ -1,5 +1,6 @@ const { static: staticContent } = require('@feathersjs/express'); const path = require('path'); +const { Configuration } = require('@hpi-schul-cloud/commons'); const hooks = require('./hooks'); const Hydra = require('./hydra.js'); @@ -13,8 +14,10 @@ const setClientDefaults = (data) => { }; module.exports = function oauth2() { + const hydraUri = Configuration.get('HYDRA_URI'); + const app = this; - const hydraAdmin = Hydra(app.settings.services.hydra); + const hydraAdmin = Hydra(hydraUri); // hydra.isInstanceAlive() // .then(res => { logger.log('info', 'Hydra status is: ' + res.statusText) }) @@ -24,7 +27,7 @@ module.exports = function oauth2() { app.use('/oauth2/baseUrl', { find() { - return Promise.resolve(app.settings.services.hydra); + return Promise.resolve(hydraUri); }, }); diff --git a/test/services/oauth2/mock.js b/test/services/oauth2/mock.js index deacdcb7b17..e20e3c61182 100644 --- a/test/services/oauth2/mock.js +++ b/test/services/oauth2/mock.js @@ -1,7 +1,7 @@ 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'); @@ -50,6 +50,12 @@ describe('oauth2 service mock', function oauthTest() { let beforeHydraUri; before(async function before() { this.timeout(10000); + + beforeHydraUri = Configuration.get('HYDRA_URI'); + + const o2mock = await oauth2Server({}); + Configuration.set('HYDRA_URI', o2mock.url); + app = await appPromise(); baseUrlService = app.service('oauth2/baseUrl'); @@ -58,11 +64,6 @@ describe('oauth2 service mock', function oauthTest() { introspectService = app.service('oauth2/introspect'); consentService = app.service('oauth2/auth/sessions/consent'); - beforeHydraUri = app.settings.services.hydra; - - const o2mock = await oauth2Server({}); - app.settings.services.hydra = o2mock.url; - app.unuse('oauth2/baseUrl'); app.unuse('oauth2/clients'); app.unuse('oauth2/loginRequest'); @@ -78,7 +79,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); });