[web] fix clearing of clsi persistence during migration to new key (#29172)

GitOrigin-RevId: 1d9e6eb87f8f27792fdc866e7dcc29b47e1b2547
This commit is contained in:
Jakob Ackermann
2025-10-16 16:22:22 +02:00
committed by Copybot
parent 706971ef41
commit ad3e8bd65d
4 changed files with 34 additions and 6 deletions
@@ -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(
@@ -81,7 +81,8 @@ async function clearClsiServerId(projectId, userId, compileBackendClass) {
jobs.push(
NewBackendCloudClsiCookieManager.promises.clearServerId(
projectId,
userId
userId,
newCompileBackendClass
)
)
}
@@ -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'
@@ -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(