Skip to content

Commit c92fd23

Browse files
author
Your Name
committed
handled assets in not scanned status
2 parents 5789088 + a35b929 commit c92fd23

14 files changed

Lines changed: 687 additions & 580 deletions

File tree

.talismanrc

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
fileignoreconfig:
22

33
- filename: pnpm-lock.yaml
4-
checksum: 31e333d6769adbaae042c92ea0930fab168a0e06fc1bda406d49fd1042a7a9c7
5-
- filename: packages/contentstack-audit/src/audit-base-command.ts
6-
checksum: 14275f241e4a194cfd1fb33d277df194011eba4458ccaab7e0d0bd3a1c9ccfe7
7-
- filename: packages/contentstack-audit/src/modules/entries.ts
8-
checksum: b0fa5f7b390ef2d64bd4834a5b848780b902373e2c644833842b42c6b767d54e
9-
- filename: packages/contentstack-audit/test/unit/modules/entries.test.ts
10-
checksum: ff448c79d436d5e8b141efcc76f19892bfe96039ea9a60fae4e995b5ccbc2960
4+
checksum: 423213f918d2052ec37ad421d23057e159c8633d200bfa688d34bbcb73a19285
115
version: '1.0'

packages/contentstack-audit/src/config/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ const config = {
5555
name: 'assets',
5656
dirName: 'assets',
5757
fileName: 'assets.json',
58+
// Asset scan statuses that must block import/reference; any other value (including
59+
// 'not_scanned', 'clean', or the field being absent) is treated as safe.
60+
blockingScanStatuses: ['pending', 'quarantined'],
5861
},
5962
environments: {
6063
name: 'environments',

packages/contentstack-audit/src/modules/assets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export default class Assets {
187187
log.debug(`Processing asset: ${assetUid}`, this.config.auditContext);
188188

189189
const scanStatus = this.assets[assetUid]?._asset_scan_status;
190-
if (scanStatus && scanStatus !== 'clean') {
190+
if (this.config.moduleConfig.assets.blockingScanStatuses.includes(scanStatus)) {
191191
log.debug(`Asset ${assetUid} has a non-clean scan status: ${scanStatus}`, this.config.auditContext);
192192
cliux.print($t(auditMsg.SCAN_ASSET_QUARANTINE_MSG, { uid: assetUid, status: scanStatus }), {
193193
color: 'yellow',

packages/contentstack-audit/src/modules/entries.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -929,16 +929,17 @@ export default class Entries {
929929

930930
/**
931931
* Returns true when the given asset uid should be treated as unusable — either it doesn't
932-
* exist in the exported assets.json at all, or it exists but its scan status is present and
933-
* not 'clean' (e.g. 'pending'/'quarantined'). Returns false (never flag) when asset metadata
932+
* exist in the exported assets.json at all, or it exists but its scan status is one of
933+
* config.moduleConfig.assets.blockingScanStatuses (e.g. 'pending'/'quarantined'). Any other
934+
* status — including 'clean', 'not_scanned' (org has asset scanning disabled), or the field
935+
* being absent — is not a blocking condition. Returns false (never flag) when asset metadata
934936
* wasn't available at all, since we can't validate what we don't have data for.
935937
*/
936938
isAssetBad(uid?: string): boolean {
937939
if (!this.assetsDataAvailable || !uid) return false;
938940
const assetRecord = this.assetMetaData[uid];
939941
if (!assetRecord) return true;
940-
const scanStatus = assetRecord._asset_scan_status;
941-
return Boolean(scanStatus) && scanStatus !== 'clean';
942+
return this.config.moduleConfig.assets.blockingScanStatuses.includes(assetRecord._asset_scan_status ?? '');
942943
}
943944

944945
/**

packages/contentstack-audit/test/unit/mock/contents/assets/chunk1-assets.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,13 @@
2929
"url": "https://images.contentstack.io/v3/assets/blt/blt-no-status-asset/no-status.png",
3030
"_version": 1,
3131
"publish_details": []
32+
},
33+
"blt-not-scanned-asset": {
34+
"uid": "blt-not-scanned-asset",
35+
"filename": "not-scanned.png",
36+
"url": "https://images.contentstack.io/v3/assets/blt/blt-not-scanned-asset/not-scanned.png",
37+
"_version": 1,
38+
"_asset_scan_status": "not_scanned",
39+
"publish_details": []
3240
}
3341
}

packages/contentstack-audit/test/unit/modules/assets.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ describe('Assets module', () => {
4848
});
4949
expect(assetsInstance.missingScanStatusAssets).to.not.have.property('blt-clean-asset');
5050
expect(assetsInstance.missingScanStatusAssets).to.not.have.property('blt-no-status-asset');
51+
expect(assetsInstance.missingScanStatusAssets).to.not.have.property('blt-not-scanned-asset');
5152
});
5253

5354
fancy
@@ -69,6 +70,7 @@ describe('Assets module', () => {
6970
expect(writtenContent).to.not.have.property('blt-quarantined-asset');
7071
expect(writtenContent).to.have.property('blt-clean-asset');
7172
expect(writtenContent).to.have.property('blt-no-status-asset');
73+
expect(writtenContent).to.have.property('blt-not-scanned-asset');
7274
});
7375
});
7476
});

packages/contentstack-audit/test/unit/modules/entries.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,10 @@ describe('Entries module', () => {
15571557
uid: 'blt-pending-asset',
15581558
_asset_scan_status: 'pending',
15591559
});
1560+
expect(ctInstance.assetMetaData['blt-not-scanned-asset']).to.deep.include({
1561+
uid: 'blt-not-scanned-asset',
1562+
_asset_scan_status: 'not_scanned',
1563+
});
15601564
});
15611565

15621566
fancy
@@ -1611,6 +1615,17 @@ describe('Entries module', () => {
16111615
expect(ctInstance.isAssetBad('blt-clean')).to.be.false;
16121616
expect(ctInstance.isAssetBad('blt-legacy')).to.be.false;
16131617
});
1618+
1619+
fancy
1620+
.stdout({ print: process.env.PRINT === 'true' || false })
1621+
.it('returns false when the asset scan status is not_scanned (org has asset scanning disabled)', () => {
1622+
const ctInstance = new Entries(constructorParam);
1623+
(ctInstance as any).assetsDataAvailable = true;
1624+
(ctInstance as any).assetMetaData = {
1625+
'blt-not-scanned': { uid: 'blt-not-scanned', _asset_scan_status: 'not_scanned' },
1626+
};
1627+
expect(ctInstance.isAssetBad('blt-not-scanned')).to.be.false;
1628+
});
16141629
});
16151630

16161631
describe('validateFileField method', () => {

packages/contentstack-export/src/config/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ const config: DefaultConfig = {
118118
displayExecutionTime: false,
119119
enableDownloadStatus: false,
120120
includeVersionedAssets: false,
121+
// Asset scan statuses that must block download; any other value (including 'not_scanned',
122+
// 'clean', or the field being absent) is treated as safe to download.
123+
blockingScanStatuses: ['pending', 'quarantined'],
121124
},
122125
content_types: {
123126
dirName: 'content_types',

packages/contentstack-export/src/export/modules/assets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ export default class ExportAssets extends BaseClass {
337337
listOfAssets = uniqBy(listOfAssets, 'url');
338338
log.debug(`Total unique assets to download: ${listOfAssets.length}`, this.exportConfig.context);
339339

340-
const isNotClean = (asset: any) => asset._asset_scan_status && asset._asset_scan_status !== 'clean';
340+
const isNotClean = (asset: any) => this.assetConfig.blockingScanStatuses.includes(asset._asset_scan_status);
341341
const skippedAssets = filter(listOfAssets, isNotClean);
342342
listOfAssets = filter(listOfAssets, (asset: any) => !isNotClean(asset));
343343

packages/contentstack-export/src/types/default-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export default interface DefaultConfig {
102102
displayExecutionTime: boolean;
103103
enableDownloadStatus: boolean;
104104
includeVersionedAssets: boolean;
105+
blockingScanStatuses: string[];
105106
dependencies?: Modules[];
106107
};
107108
content_types: {

0 commit comments

Comments
 (0)