Skip to content

Commit d6f2610

Browse files
Merge remote-tracking branch 'origin/master' into feat/asset-scan-status-sanity-tests
# Conflicts: # test/sanity-check/api/asset-test.js
2 parents 9150bde + c13a012 commit d6f2610

3 files changed

Lines changed: 122 additions & 141 deletions

File tree

.github/workflows/issues-jira.yml

Lines changed: 0 additions & 118 deletions
This file was deleted.

test/sanity-check/api/asset-test.js

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -987,65 +987,78 @@ describe('Asset API Tests', () => {
987987
// ==========================================================================
988988

989989
describe('Asset Scan Status', () => {
990-
let scanAssetUid
990+
let assetUid
991991

992992
before(async function () {
993993
this.timeout(30000)
994-
// Reuse the image asset uploaded earlier — avoids a redundant upload
995-
if (testData.assets && testData.assets.image && testData.assets.image.uid) {
996-
scanAssetUid = testData.assets.image.uid
994+
// Reuse an asset created by the Asset Upload block to avoid an extra upload.
995+
// Fall back to creating a fresh one only if that block didn't succeed.
996+
if (testData.assets.image && testData.assets.image.uid) {
997+
assetUid = testData.assets.image.uid
997998
return
998999
}
999-
// Fallback: create a fresh asset if the upload block didn't run
10001000
try {
10011001
const asset = await stack.asset().create({
10021002
upload: assetPath,
1003-
title: `Scan Status Asset ${Date.now()}`,
1004-
description: 'Fallback asset for scan-status tests'
1003+
title: `Scan Status Test Asset ${Date.now()}`,
1004+
description: 'Asset for scan status testing'
10051005
})
1006-
scanAssetUid = asset.uid
1006+
assetUid = asset.uid
10071007
} catch (err) {
1008-
// Individual tests will self-skip when scanAssetUid is unset
1008+
// Asset creation failed — individual tests will skip themselves.
10091009
}
10101010
})
10111011

10121012
it('should accept include_asset_scan_status param on single asset fetch', async function () {
1013-
this.timeout(15000)
1014-
if (!scanAssetUid) return this.skip()
1015-
1016-
const asset = await stack.asset(scanAssetUid).fetch({ include_asset_scan_status: true })
1013+
if (!assetUid) return this.skip()
1014+
const asset = await stack.asset(assetUid).fetch({ include_asset_scan_status: true })
10171015

10181016
expect(asset).to.be.an('object')
1019-
expect(asset.uid).to.equal(scanAssetUid)
1020-
// _asset_scan_status is opt-in: present only when asset scanning is enabled for the stack.
1021-
// Possible values: 'pending' | 'clean' | 'quarantined' | 'not_scanned'
1017+
expect(asset.uid).to.equal(assetUid)
1018+
// _asset_scan_status is opt-in. When scanning is enabled: pending | clean | quarantined.
1019+
// When scanning is not enabled for the stack, the API returns 'not_scanned'.
10221020
if ('_asset_scan_status' in asset) {
10231021
expect(asset._asset_scan_status).to.be.a('string')
10241022
expect(['pending', 'clean', 'quarantined', 'not_scanned']).to.include(asset._asset_scan_status)
10251023
}
10261024
})
10271025

10281026
it('should accept include_asset_scan_status param on asset list query', async function () {
1029-
this.timeout(15000)
1030-
10311027
const response = await stack.asset().query({ include_asset_scan_status: true }).find()
10321028

10331029
expect(response).to.be.an('object')
10341030
expect(response.items).to.be.an('array')
1031+
// pending | clean | quarantined when scanning is enabled; not_scanned otherwise.
10351032
if (response.items.length > 0 && '_asset_scan_status' in response.items[0]) {
10361033
expect(response.items[0]._asset_scan_status).to.be.a('string')
10371034
expect(['pending', 'clean', 'quarantined', 'not_scanned']).to.include(response.items[0]._asset_scan_status)
10381035
}
10391036
})
10401037

1041-
it('should NOT return _asset_scan_status when param is omitted', async function () {
1042-
this.timeout(15000)
1043-
if (!scanAssetUid) return this.skip()
1044-
1045-
const asset = await stack.asset(scanAssetUid).fetch()
1038+
it('should not return _asset_scan_status when param is omitted', async function () {
1039+
if (!assetUid) return this.skip()
1040+
const asset = await stack.asset(assetUid).fetch()
10461041

10471042
expect(asset).to.be.an('object')
10481043
expect(asset).to.not.have.property('_asset_scan_status')
10491044
})
1045+
1046+
it('should accept include_asset_scan_status param on asset upload', async function () {
1047+
this.timeout(30000)
1048+
const asset = await stack.asset().create(
1049+
{
1050+
upload: assetPath,
1051+
title: `Scan Status Upload Test ${Date.now()}`
1052+
},
1053+
{ include_asset_scan_status: true }
1054+
)
1055+
1056+
expect(asset).to.be.an('object')
1057+
expect(asset.uid).to.be.a('string')
1058+
// pending when scanning is enabled; not_scanned when scanning is not enabled for the stack.
1059+
if ('_asset_scan_status' in asset) {
1060+
expect(['pending', 'not_scanned']).to.include(asset._asset_scan_status)
1061+
}
1062+
})
10501063
})
10511064
})

test/unit/asset-test.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,92 @@ describe('Contentstack Asset test', () => {
463463
})
464464
.catch(done)
465465
})
466+
467+
// Asset Scanning tests
468+
it('Asset fetch sends include_asset_scan_status as query param and returns _asset_scan_status', done => {
469+
var mock = new MockAdapter(Axios)
470+
mock.onGet('/assets/UID').reply((config) => {
471+
expect(config.params.include_asset_scan_status).to.equal(true)
472+
return [200, {
473+
asset: {
474+
...assetMock,
475+
_asset_scan_status: 'clean'
476+
}
477+
}]
478+
})
479+
makeAsset({
480+
asset: { ...systemUidMock },
481+
stackHeaders: stackHeadersMock
482+
})
483+
.fetch({ include_asset_scan_status: true })
484+
.then((asset) => {
485+
checkAsset(asset)
486+
expect(asset._asset_scan_status).to.equal('clean')
487+
done()
488+
})
489+
.catch(done)
490+
})
491+
492+
it('Asset query sends include_asset_scan_status as query param and returns _asset_scan_status', done => {
493+
var mock = new MockAdapter(Axios)
494+
mock.onGet('/assets').reply((config) => {
495+
expect(config.params.include_asset_scan_status).to.equal(true)
496+
return [200, {
497+
assets: [{
498+
...assetMock,
499+
_asset_scan_status: 'clean'
500+
}]
501+
}]
502+
})
503+
makeAsset()
504+
.query({ include_asset_scan_status: true })
505+
.find()
506+
.then((collection) => {
507+
expect(collection.items[0]._asset_scan_status).to.equal('clean')
508+
done()
509+
})
510+
.catch(done)
511+
})
512+
513+
it('Asset create sends include_asset_scan_status as query param and returns pending scan status', done => {
514+
var mock = new MockAdapter(Axios)
515+
mock.onPost('/assets').reply((config) => {
516+
expect(config.params.include_asset_scan_status).to.equal(true)
517+
return [200, {
518+
asset: {
519+
...assetMock,
520+
_asset_scan_status: 'pending'
521+
}
522+
}]
523+
})
524+
makeAsset()
525+
.create(
526+
{ upload: path.join(__dirname, '../sanity-check/mock/customUpload.html') },
527+
{ include_asset_scan_status: true }
528+
)
529+
.then((asset) => {
530+
expect(asset._asset_scan_status).to.equal('pending')
531+
done()
532+
})
533+
.catch(done)
534+
})
535+
536+
it('Asset fetch without include_asset_scan_status does not return _asset_scan_status', done => {
537+
var mock = new MockAdapter(Axios)
538+
mock.onGet('/assets/UID').reply(200, {
539+
asset: { ...assetMock }
540+
})
541+
makeAsset({
542+
asset: { ...systemUidMock },
543+
stackHeaders: stackHeadersMock
544+
})
545+
.fetch()
546+
.then((asset) => {
547+
expect(asset._asset_scan_status).to.equal(undefined)
548+
done()
549+
})
550+
.catch(done)
551+
})
466552
})
467553

468554
function makeAsset (data) {

0 commit comments

Comments
 (0)