Skip to content

Commit

Permalink
🐛 api: whitelist filtering must not be case sensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
Steph0 committed Oct 8, 2024
1 parent 173621e commit 72dda8f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ export const findSCOV2Centers = async function ({ cursorId, size = DEFAULT_PAGIN
.where({ isV3Pilot: false, type: CERTIFICATION_CENTER_TYPES.SCO })
.andWhere((queryBuilder) => {
queryBuilder
.whereNotIn('certification-centers.externalId', _getWhitelist())
.orWhereNull('certification-centers.externalId');
.whereRaw('UPPER(TRIM("certification-centers"."externalId")) NOT IN (?)', _getWhitelist())
.orWhereNull('certification-centers.externalId')
.orWhereRaw('TRIM("certification-centers"."externalId") = \'\'');
})
.orderBy('certification-centers.id', 'ASC')
.limit(size);
Expand All @@ -35,7 +36,7 @@ export const findSCOV2Centers = async function ({ cursorId, size = DEFAULT_PAGIN
const _getWhitelist = () => {
const whitelist = config.features.pixCertifScoBlockedAccessWhitelist;
logger.debug('SCO Whitelist:[%o]', whitelist);
return whitelist;
return whitelist.join(',');
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,31 @@ describe('Certification | Configuration | Integration | Repository | center-repo
// then
expect(results).to.deep.equal([notInWhitelistId]);
});

it('should not be case sensitive on externalId', async function () {
// given
const externalIdOfCenter = 'uAi123';
// Note : @see config.js : config is already trimmed and uppercased
const externalIdInConfig = 'UAI123';
const notInWhitelistId = databaseBuilder.factory.buildCertificationCenter({
isV3Pilot: false,
type: CERTIFICATION_CENTER_TYPES.SCO,
}).id;
databaseBuilder.factory.buildCertificationCenter({
isV3Pilot: false,
type: CERTIFICATION_CENTER_TYPES.SCO,
externalId: externalIdOfCenter,
}).id;
await databaseBuilder.commit();

config.features.pixCertifScoBlockedAccessWhitelist = [externalIdInConfig];

// when
const results = await centerRepository.findSCOV2Centers();

// then
expect(results).to.deep.equal([notInWhitelistId]);
});
});

context('when center has no externalId', function () {
Expand All @@ -132,13 +157,18 @@ describe('Certification | Configuration | Integration | Repository | center-repo
type: CERTIFICATION_CENTER_TYPES.SCO,
externalId: '',
}).id;
const expectedThree = databaseBuilder.factory.buildCertificationCenter({
isV3Pilot: false,
type: CERTIFICATION_CENTER_TYPES.SCO,
externalId: ' ',
}).id;
await databaseBuilder.commit();

// when
const results = await centerRepository.findSCOV2Centers();

// then
expect(results).to.deep.equal([expectedOne, expectedTwo]);
expect(results).to.deep.equal([expectedOne, expectedTwo, expectedThree]);
});
});
});
Expand Down

0 comments on commit 72dda8f

Please sign in to comment.