From 22cdc5fbad4ac44485ce6815edbdc223145e69c2 Mon Sep 17 00:00:00 2001 From: virgilchiriac Date: Tue, 28 Nov 2023 13:01:59 +0100 Subject: [PATCH] undo hydra url config config adjustment --- config/default.json | 3 +++ config/production.json | 5 ++++- src/services/oauth2/hooks/index.js | 5 ++--- src/services/oauth2/index.js | 8 ++------ test/services/oauth2/mock.js | 10 ++++------ 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/config/default.json b/config/default.json index bd8d6b19c5d..05499b0fc0e 100644 --- a/config/default.json +++ b/config/default.json @@ -3,6 +3,9 @@ "host": "localhost", "port": 3030, "public": "./public/", + "services": { + "hydra": "http://localhost:9001" + }, "I18N": { "AVAILABLE_LANGUAGES": "de,en,es,uk", "DEFAULT_LANGUAGE": "de", diff --git a/config/production.json b/config/production.json index a2c3c3302c9..dbe5a3eddfd 100644 --- a/config/production.json +++ b/config/production.json @@ -3,5 +3,8 @@ "host": "localhost", "port": "PORT", "mongodb": "MONGO_URI", - "public": "./public/" + "public": "./public/", + "services": { + "hydra": "HYDRA_URI" + } } diff --git a/src/services/oauth2/hooks/index.js b/src/services/oauth2/hooks/index.js index a8ce4090953..c4a0cac7916 100644 --- a/src/services/oauth2/hooks/index.js +++ b/src/services/oauth2/hooks/index.js @@ -7,7 +7,6 @@ const { Forbidden, MethodNotAllowed } = require('../../../errors'); const globalHooks = require('../../../hooks'); const Hydra = require('../hydra'); -const hydraUri = Configuration.get('HYDRA_URI'); const webUri = Configuration.get('HOST'); const properties = 'title="username" style="height: 26px; width: 180px; border: none;"'; @@ -106,7 +105,7 @@ const setIdToken = (hook) => { }; const injectLoginRequest = (hook) => - Hydra(hydraUri) + Hydra(hook.app.settings.services.hydra) .getLoginRequest(hook.id) .then((loginRequest) => { hook.params.loginRequest = loginRequest; @@ -114,7 +113,7 @@ const injectLoginRequest = (hook) => }); const injectConsentRequest = (hook) => - Hydra(hydraUri) + Hydra(hook.app.settings.services.hydra) .getConsentRequest(hook.id) .then((consentRequest) => { hook.params.consentRequest = consentRequest; diff --git a/src/services/oauth2/index.js b/src/services/oauth2/index.js index d459b239624..4725e73e922 100644 --- a/src/services/oauth2/index.js +++ b/src/services/oauth2/index.js @@ -1,13 +1,9 @@ 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'); -const hydraUri = Configuration.get('HYDRA_URI'); - const setClientDefaults = (data) => { data.scope = data.scope || 'openid offline'; data.grant_types = data.grant_types || ['authorization_code', 'refresh_token']; @@ -18,7 +14,7 @@ const setClientDefaults = (data) => { module.exports = function oauth2() { const app = this; - const hydraAdmin = Hydra(hydraUri); + const hydraAdmin = Hydra(app.settings.services.hydra); // hydra.isInstanceAlive() // .then(res => { logger.log('info', 'Hydra status is: ' + res.statusText) }) @@ -28,7 +24,7 @@ module.exports = function oauth2() { app.use('/oauth2/baseUrl', { find() { - return Promise.resolve(hydraUri); + return Promise.resolve(app.settings.services.hydra); }, }); diff --git a/test/services/oauth2/mock.js b/test/services/oauth2/mock.js index d7d0a296c91..deacdcb7b17 100644 --- a/test/services/oauth2/mock.js +++ b/test/services/oauth2/mock.js @@ -2,8 +2,6 @@ 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'); @@ -16,7 +14,7 @@ chai.use(chaiHttp); const { expect } = chai; -describe.skip('oauth2 service mock', function oauthTest() { +describe('oauth2 service mock', function oauthTest() { let app; let baseUrlService; let clientsService; @@ -60,10 +58,10 @@ describe.skip('oauth2 service mock', function oauthTest() { introspectService = app.service('oauth2/introspect'); consentService = app.service('oauth2/auth/sessions/consent'); - beforeHydraUri = Configuration.get('HYDRA_URI'); + beforeHydraUri = app.settings.services.hydra; const o2mock = await oauth2Server({}); - Configuration.set('HYDRA_URI', o2mock.url); + app.settings.services.hydra = o2mock.url; app.unuse('oauth2/baseUrl'); app.unuse('oauth2/clients'); @@ -80,7 +78,7 @@ describe.skip('oauth2 service mock', function oauthTest() { after(async () => { // sets uri back to original uri - Configuration.set('HYDRA_URI', beforeHydraUri); + app.settings.services.hydra = beforeHydraUri; await server.close(); await closeNestServices(nestServices); });