Merge pull request #15687 from overleaf/jel-token-v1-mismatch

[web] Test for v1 project URL fragment in link sharing hash check

GitOrigin-RevId: 10cb2efe60f4613e3a39a5199bd653376c06ad3b
This commit is contained in:
Jessica Lawshe
2023-11-17 09:03:05 +00:00
committed by Copybot
parent 7db5d761ea
commit 11ce29197b
2 changed files with 83 additions and 7 deletions
@@ -661,7 +661,7 @@ describe('TokenAccessHandler', function () {
`#${prefix}`,
'readOnly',
userId,
projectId
{ projectId }
)
expect(this.Metrics.inc).to.have.been.calledWith(
@@ -707,7 +707,7 @@ describe('TokenAccessHandler', function () {
undefined,
'readOnly',
userId,
projectId
{ projectId }
)
expect(this.Metrics.inc).to.have.been.calledWith(
@@ -724,7 +724,7 @@ describe('TokenAccessHandler', function () {
'#',
'readOnly',
userId,
projectId
{ projectId }
)
expect(this.Metrics.inc).to.have.been.calledWith(
@@ -735,7 +735,7 @@ describe('TokenAccessHandler', function () {
}
)
})
it('it handles encoded hashtags', function () {
it('handles encoded hashtags', function () {
const token = 'zxpxjrwdtsgd'
const prefix = this.TokenAccessHandler.createTokenHashPrefix(token)
@@ -744,7 +744,7 @@ describe('TokenAccessHandler', function () {
`%23${prefix}`,
'readOnly',
userId,
projectId
{ projectId }
)
expect(this.Metrics.inc).to.have.been.calledWith(
@@ -755,5 +755,67 @@ describe('TokenAccessHandler', function () {
}
)
})
it('sends "mismatch-v1-format" for suspected v1 URLs with 7 numbers in URL fragment', function () {
const token = '4112142489ddsbkrdzhxrq'
const prefix = '%2F1234567%2F'
this.TokenAccessHandler.checkTokenHashPrefix(
token,
`#${prefix}`,
'readAndWrite',
userId,
{ projectId }
)
expect(this.Metrics.inc).to.have.been.calledWith(
'link-sharing.hash-check',
{
path: 'readAndWrite',
status: 'mismatch-v1-format',
}
)
expect(this.logger.info).to.have.been.calledWith(
{
tokenHashPrefix: prefix,
hashPrefixStatus: 'mismatch-v1-format',
userId,
projectId,
type: 'readAndWrite',
},
'mismatched token hash prefix'
)
})
it('sends "mismatch-v1-format" for suspected v1 URLs with 8 numbers in URL fragment', function () {
const token = '4112142489ddsbkrdzhxrq'
const prefix = '%2F12345678%2F'
this.TokenAccessHandler.checkTokenHashPrefix(
token,
`#${prefix}`,
'readAndWrite',
userId,
{ projectId }
)
expect(this.Metrics.inc).to.have.been.calledWith(
'link-sharing.hash-check',
{
path: 'readAndWrite',
status: 'mismatch-v1-format',
}
)
expect(this.logger.info).to.have.been.calledWith(
{
tokenHashPrefix: prefix,
hashPrefixStatus: 'mismatch-v1-format',
userId,
projectId,
type: 'readAndWrite',
},
'mismatched token hash prefix'
)
})
})
})