adjust security unit tests
MODIFY
test/api/SecurityTest.ts
test/api/SecurityTest.ts
@@ -23,14 +23,18 @@ let initialTenant: Tenant;
* @param message
*/
function checkSensitiveDataIsObfuscated(message: any): void {
- if (typeof message === 'string') { // If the message is a string
+ // If the message is a string
+ if (typeof message === 'string') {
const dataParts: string[] = message.split('&');
// Check if it is a query string
if (dataParts.length > 1) {
- for (let i = 0; i < dataParts.length; i++) {
- const dataPart = dataParts[i];
+ for (const dataPart of dataParts) {
+ let queryParamKey = dataPart.split('=')[0];
+ const queryParamKeyParts = queryParamKey.split('?');
+ queryParamKey = queryParamKeyParts.length > 1 ? queryParamKeyParts[1] : queryParamKeyParts[0];
for (const sensitiveData of Constants.SENSITIVE_DATA) {
- if (dataPart.toLowerCase().startsWith(sensitiveData.toLocaleLowerCase())) { // Check each query string part anonymized
+ if (queryParamKey.toLowerCase().startsWith(sensitiveData.toLocaleLowerCase())) {
+ // Check each query string part anonymized
expect(dataPart).to.equal(dataPart.substring(0, sensitiveData.length + 1) + Constants.ANONYMIZED_VALUE);
break;
}
@@ -43,13 +47,17 @@ function checkSensitiveDataIsObfuscated(message:any): void {
break;
}
}
- } else if (Array.isArray(message)) { // In case of an array, check every item anonymized
+ }
+ // In case of an array, check every item anonymized
+ if (Array.isArray(message)) {
for (const item of message) {
checkSensitiveDataIsObfuscated(item);
}
- } else if (typeof message === 'object') { // In case of object
+ }
+ // In case of object
+ if (typeof message === 'object') {
for (const key of Object.keys(message)) {
- if (typeof message[key] === 'string' && Constants.SENSITIVE_DATA.filter((sensitiveData) => key.toLocaleLowerCase() === sensitiveData.toLocaleLowerCase()).length > 0) {
+ if (Constants.SENSITIVE_DATA.filter((sensitiveData) => key.toLowerCase() === sensitiveData.toLowerCase()).length > 0) {
// If the key indicates sensitive data and the value is a string, check value anonymized
expect(message[key]).to.equal(Constants.ANONYMIZED_VALUE);
} else { // Otherwise, apply the whole check to the value

adjust security unit tests