From a12a2e235bbce973c0f62e56e3e5641bac95ac55 Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Tue, 24 Nov 2026 16:05:27 +0530 Subject: [PATCH 1/2] test(asset): fix two order/data-dependent sanity test failures - AssetUnitTest.testPublishIncludesApiVersionHeader added api_version to the shared static Asset, leaking a third header into later tests, so testAssetGetByTypeVideo (asserts exactly 2 headers) failed in CI. Use a fresh Asset for the publish test. - AssetAPITest.testFindAssetsAllScanStatusesAreValid searched the whole list body for a status string, which fails when the first page only holds assets created before scanning was enabled (no _asset_scan_status field). Parse the list and validate the status only on assets that carry one. Co-Authored-By: Claude Sonnet 5.5 --- .../contentstack/cms/stack/AssetAPITest.java | 22 ++++++++++++------- .../contentstack/cms/stack/AssetUnitTest.java | 12 +++++++--- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/test/java/com/contentstack/cms/stack/AssetAPITest.java b/src/test/java/com/contentstack/cms/stack/AssetAPITest.java index 34da4a33..699c5040 100644 --- a/src/test/java/com/contentstack/cms/stack/AssetAPITest.java +++ b/src/test/java/com/contentstack/cms/stack/AssetAPITest.java @@ -377,7 +377,7 @@ void testFetchAssetWithScanStatus() throws IOException { @Test @Order(13) - void testFindAssetsAllScanStatusesAreValid() throws IOException { + void testFindAssetsAllScanStatusesAreValid() throws IOException, ParseException { Asset listAsset = client.stack(API_KEY, MANAGEMENT_TOKEN).asset(); listAsset.addParam("include_asset_scan_status", true); listAsset.addHeader("api_key", API_KEY); @@ -385,13 +385,19 @@ void testFindAssetsAllScanStatusesAreValid() throws IOException { Response response = listAsset.find().execute(); Assertions.assertTrue(response.isSuccessful(), "Expected 200"); Assertions.assertNotNull(response.body()); - String body = response.body().string(); - Assertions.assertTrue(body.contains("_asset_scan_status"), - "Response should include _asset_scan_status when param is set"); - boolean hasValidStatus = body.contains("\"pending\"") || body.contains("\"clean\"") - || body.contains("\"not_scanned\"") || body.contains("\"quarantined\""); - Assertions.assertTrue(hasValidStatus, - "Every _asset_scan_status value must be one of: pending, clean, not_scanned, quarantined"); + JSONObject json = (JSONObject) new JSONParser().parse(response.body().string()); + org.json.simple.JSONArray assets = (org.json.simple.JSONArray) json.get("assets"); + Assertions.assertNotNull(assets, "Response should contain an 'assets' array"); + java.util.List validStatuses = java.util.Arrays.asList("pending", "clean", "not_scanned", "quarantined"); + // Assets created before scanning was enabled may not carry the field, so only + // validate the status on assets that have one (the first page can be all legacy assets). + for (Object item : assets) { + Object status = ((JSONObject) item).get("_asset_scan_status"); + if (status != null) { + Assertions.assertTrue(validStatuses.contains(status), + "_asset_scan_status value '" + status + "' must be one of: pending, clean, not_scanned, quarantined"); + } + } } @Test diff --git a/src/test/java/com/contentstack/cms/stack/AssetUnitTest.java b/src/test/java/com/contentstack/cms/stack/AssetUnitTest.java index 0798745a..00b3fc46 100644 --- a/src/test/java/com/contentstack/cms/stack/AssetUnitTest.java +++ b/src/test/java/com/contentstack/cms/stack/AssetUnitTest.java @@ -563,10 +563,16 @@ void testScanStatusParamCoexistsWithOtherParams() { void testPublishIncludesApiVersionHeader() { // api_version: 3.2 is required for CDA-side scan validation on publish. // Without it, quarantined assets incorrectly appear as published in the UI. - asset.clearParams(); - asset.addHeader("api_version", "3.2"); + // Use a fresh Asset: adding api_version to the shared static `asset` leaks the header + // into later tests (e.g. testAssetGetByTypeVideo asserts exactly 2 headers). + HashMap headers = new HashMap<>(); + headers.put(Util.API_KEY, API_KEY); + headers.put(Util.AUTHORIZATION, MANAGEMENT_TOKEN); + Asset publishAsset = TestClient.getClient().stack(headers).asset(_uid); + publishAsset.clearParams(); + publishAsset.addHeader("api_version", "3.2"); JSONObject body = new JSONObject(); - Request resp = asset.publish(body).request(); + Request resp = publishAsset.publish(body).request(); Assertions.assertEquals("POST", resp.method()); Assertions.assertEquals("/v3/assets/" + _uid + "/publish", resp.url().encodedPath()); Assertions.assertEquals("3.2", resp.header("api_version")); From 896ff3ff660d3798762cc20ba77266bb55835fa4 Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Tue, 24 Nov 2026 16:16:41 +0530 Subject: [PATCH 2/2] test(asset): expect 2 headers in the 9 tests that relied on the leaked api_version Commit 61dd73b raised these assertions to 3 to match the api_version header leaked from testPublishIncludesApiVersionHeader through the shared static Asset. With the publish test isolated, a request carries only api_key and authorization, so assert 2 like the other AssetUnitTest cases. Co-Authored-By: Claude Sonnet 5.5 --- .../contentstack/cms/stack/AssetUnitTest.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/test/java/com/contentstack/cms/stack/AssetUnitTest.java b/src/test/java/com/contentstack/cms/stack/AssetUnitTest.java index 00b3fc46..f54c4bec 100644 --- a/src/test/java/com/contentstack/cms/stack/AssetUnitTest.java +++ b/src/test/java/com/contentstack/cms/stack/AssetUnitTest.java @@ -67,7 +67,7 @@ void testAssetSingle() { Request resp = asset.fetch().request(); Assertions.assertTrue(resp.isHttps()); Assertions.assertEquals("GET", resp.method()); - Assertions.assertEquals(3, resp.headers().size()); + Assertions.assertEquals(2, resp.headers().size()); Collection matcher = new ArrayList<>(); matcher.add("api_key"); matcher.add("authorization"); @@ -147,7 +147,7 @@ void testAssetReplace() { .request(); Assertions.assertTrue(resp.isHttps()); Assertions.assertEquals("PUT", resp.method()); - Assertions.assertEquals(3, resp.headers().size()); + Assertions.assertEquals(2, resp.headers().size()); Collection matcher = new ArrayList<>(); matcher.add("api_key"); matcher.add("authorization"); @@ -197,7 +197,7 @@ void testAssetDelete() { Request resp = asset.delete().request(); Assertions.assertTrue(resp.isHttps()); Assertions.assertEquals("DELETE", resp.method()); - Assertions.assertEquals(3, resp.headers().size()); + Assertions.assertEquals(2, resp.headers().size()); Collection matcher = new ArrayList<>(); matcher.add("api_key"); matcher.add("authorization"); @@ -211,7 +211,7 @@ void testAssetRteInformation() { Request resp = asset.rteInformation().request(); Assertions.assertTrue(resp.isHttps()); Assertions.assertEquals("GET", resp.method()); - Assertions.assertEquals(3, resp.headers().size()); + Assertions.assertEquals(2, resp.headers().size()); Collection matcher = new ArrayList<>(); matcher.add("api_key"); matcher.add("authorization"); @@ -229,7 +229,7 @@ void testAssetSetVersionName() { Request resp = asset.setVersionName(2, body).request(); Assertions.assertTrue(resp.isHttps()); Assertions.assertEquals("POST", resp.method()); - Assertions.assertEquals(3, resp.headers().size()); + Assertions.assertEquals(2, resp.headers().size()); Collection matcher = new ArrayList<>(); matcher.add("api_key"); matcher.add("authorization"); @@ -262,7 +262,7 @@ void testAssetDeleteVersionName() { Request resp = asset.deleteVersionName(2).request(); Assertions.assertTrue(resp.isHttps()); Assertions.assertEquals("DELETE", resp.method()); - Assertions.assertEquals(3, resp.headers().size()); + Assertions.assertEquals(2, resp.headers().size()); Collection matcher = new ArrayList<>(); matcher.add("api_key"); matcher.add("authorization"); @@ -366,7 +366,7 @@ void testAssetUnpublish() { Request resp = asset.unpublish(_body).request(); Assertions.assertTrue(resp.isHttps()); Assertions.assertEquals("POST", resp.method()); - Assertions.assertEquals(3, resp.headers().size()); + Assertions.assertEquals(2, resp.headers().size()); Collection matcher = new ArrayList<>(); matcher.add("api_key"); matcher.add("authorization"); @@ -383,7 +383,7 @@ void testAssetSingleFolder() { Request resp = assetFolder.fetch().request(); Assertions.assertTrue(resp.isHttps()); Assertions.assertEquals("GET", resp.method()); - Assertions.assertEquals(3, resp.headers().size()); + Assertions.assertEquals(2, resp.headers().size()); Collection matcher = new ArrayList<>(); matcher.add("api_key"); matcher.add("authorization"); @@ -444,7 +444,7 @@ void testAssetCreateFolder() { Request resp = asset.folder().create(_body).request(); Assertions.assertTrue(resp.isHttps()); Assertions.assertEquals("POST", resp.method()); - Assertions.assertEquals(3, resp.headers().size()); + Assertions.assertEquals(2, resp.headers().size()); Collection matcher = new ArrayList<>(); matcher.add("api_key"); matcher.add("authorization");