diff --git a/services/web/app/src/Features/Compile/ClsiCookieManager.js b/services/web/app/src/Features/Compile/ClsiCookieManager.js index 458c99d96b..4eac9b1adc 100644 --- a/services/web/app/src/Features/Compile/ClsiCookieManager.js +++ b/services/web/app/src/Features/Compile/ClsiCookieManager.js @@ -224,12 +224,15 @@ const ClsiCookieManagerFactory = function (backendGroup) { ) } - async function clearServerId(projectId, userId) { + async function clearServerId(projectId, userId, compileBackendClass) { if (!clsiCookiesEnabled) { return } try { - await rclient.del(buildKey(projectId, userId)) + await rclient.del( + buildKey(projectId, userId, compileBackendClass), + buildOldKey(projectId, userId) + ) } catch (err) { // redis errors need wrapping as the instance may be shared throw new OError( diff --git a/services/web/app/src/Features/Compile/ClsiManager.mjs b/services/web/app/src/Features/Compile/ClsiManager.mjs index 3f33b6e6bf..6ac2de7969 100644 --- a/services/web/app/src/Features/Compile/ClsiManager.mjs +++ b/services/web/app/src/Features/Compile/ClsiManager.mjs @@ -81,7 +81,8 @@ async function clearClsiServerId(projectId, userId, compileBackendClass) { jobs.push( NewBackendCloudClsiCookieManager.promises.clearServerId( projectId, - userId + userId, + newCompileBackendClass ) ) } diff --git a/services/web/test/unit/src/Compile/ClsiCookieManagerTests.js b/services/web/test/unit/src/Compile/ClsiCookieManagerTests.js index e1991257c1..6198300111 100644 --- a/services/web/test/unit/src/Compile/ClsiCookieManagerTests.js +++ b/services/web/test/unit/src/Compile/ClsiCookieManagerTests.js @@ -7,6 +7,7 @@ describe('ClsiCookieManager', function () { beforeEach(function () { this.redis = { auth() {}, + del: sinon.stub(), get: sinon.stub(), setex: sinon.stub().resolves(), } @@ -181,6 +182,20 @@ describe('ClsiCookieManager', function () { }) }) + describe('clearServerId', function () { + it('should clear both keys', async function () { + await this.ClsiCookieManager.promises.clearServerId( + this.project_id, + this.user_id, + 'n2d' + ) + this.redis.del.should.have.been.calledWith( + `clsiserver:n2d:${this.project_id}:${this.user_id}`, + `clsiserver:${this.project_id}:${this.user_id}` + ) + }) + }) + describe('setServerId', function () { beforeEach(function () { this.clsiServerId = 'server-id' diff --git a/services/web/test/unit/src/Compile/ClsiManager.test.mjs b/services/web/test/unit/src/Compile/ClsiManager.test.mjs index edf3903932..e01aac593c 100644 --- a/services/web/test/unit/src/Compile/ClsiManager.test.mjs +++ b/services/web/test/unit/src/Compile/ClsiManager.test.mjs @@ -798,7 +798,7 @@ describe('ClsiManager', function () { ctx.result = await ctx.ClsiManager.promises.sendRequest( ctx.project._id, ctx.user_id, - {} + { compileBackendClass: 'n2d' } ) }) @@ -823,7 +823,7 @@ describe('ClsiManager', function () { it('should clear the CLSI server id cookie', function (ctx) { expect( ctx.ClsiCookieManager.promises.clearServerId - ).to.have.been.calledWith(ctx.project._id, ctx.user_id) + ).to.have.been.calledWith(ctx.project._id, ctx.user_id, 'n2d') }) it('should return a success status', function (ctx) { @@ -1039,7 +1039,7 @@ describe('ClsiManager', function () { it('should clear the clsi persistance', function (ctx) { ctx.ClsiCookieManager.promises.clearServerId - .calledWith(ctx.project._id, ctx.user_id) + .calledWith(ctx.project._id, ctx.user_id, 'n2d') .should.equal(true) }) @@ -1062,6 +1062,15 @@ describe('ClsiManager', function () { await setTimeout(0) }) + it('should clear both cookies', function (ctx) { + expect( + ctx.ClsiCookieManager.promises.clearServerId + ).to.have.been.calledWith(ctx.project._id, ctx.user_id, 'c2d') + expect( + ctx.ClsiCookieManager.promises.clearServerId + ).to.have.been.calledWith(ctx.project._id, ctx.user_id, 'n4') + }) + it('should forward delete request', function (ctx) { expect(ctx.FetchUtils.fetchString).to.have.been.calledWith( sinon.match(