Merge pull request #5460 from overleaf/ab-skip-invalid-identify

Skip identify event when analyticsId is invalid

GitOrigin-RevId: 1fd9c54f59ad0b6196875f9826021e95752eddf0
This commit is contained in:
Alexandre Bourdin 2021-10-15 09:11:47 +02:00 committed by Copybot
parent 231ba305ed
commit 121ee4b72e
2 changed files with 9 additions and 9 deletions

View file

@ -14,8 +14,10 @@ const analyticsUserPropertiesQueue = Queues.getAnalyticsUserPropertiesQueue()
const ONE_MINUTE_MS = 60 * 1000
const UUID_REGEXP = /^[\w]{8}(-[\w]{4}){3}-[\w]{12}$/
function identifyUser(userId, analyticsId, isNewUser) {
if (!userId || !analyticsId || userId.toString() === analyticsId.toString()) {
if (!userId || !analyticsId || !analyticsId.toString().match(UUID_REGEXP)) {
return
}
if (_isAnalyticsDisabled() || _isSmokeTestUser(userId)) {

View file

@ -81,16 +81,14 @@ describe('AnalyticsManager', function () {
})
it('analyticsId is missing', function () {
this.AnalyticsManager.identifyUser(this.fakeUserId, undefined)
this.AnalyticsManager.identifyUser(
new ObjectID(this.fakeUserId),
undefined
)
sinon.assert.notCalled(this.analyticsEventsQueue.add)
})
it('userId equals analyticsId', function () {
this.AnalyticsManager.identifyUser(this.fakeUserId, this.fakeUserId)
sinon.assert.notCalled(this.analyticsEventsQueue.add)
})
it('Mongo userId equals string userId', function () {
it('analyticsId is not a valid UUID', function () {
this.AnalyticsManager.identifyUser(
new ObjectID(this.fakeUserId),
this.fakeUserId
@ -109,7 +107,7 @@ describe('AnalyticsManager', function () {
describe('queues the appropriate message for', function () {
it('identifyUser', function () {
const analyticsId = '456def'
const analyticsId = 'bd101c4c-722f-4204-9e2d-8303e5d9c120'
this.AnalyticsManager.identifyUser(this.fakeUserId, analyticsId)
sinon.assert.calledWithMatch(this.analyticsEventsQueue.add, 'identify', {
userId: this.fakeUserId,