Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/test/java/com/contentstack/cms/stack/AssetAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -377,21 +377,27 @@ 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);
listAsset.addHeader("authorization", MANAGEMENT_TOKEN);
Response<ResponseBody> 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<String> 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
Expand Down
30 changes: 18 additions & 12 deletions src/test/java/com/contentstack/cms/stack/AssetUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> matcher = new ArrayList<>();
matcher.add("api_key");
matcher.add("authorization");
Expand Down Expand Up @@ -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<String> matcher = new ArrayList<>();
matcher.add("api_key");
matcher.add("authorization");
Expand Down Expand Up @@ -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<String> matcher = new ArrayList<>();
matcher.add("api_key");
matcher.add("authorization");
Expand All @@ -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<String> matcher = new ArrayList<>();
matcher.add("api_key");
matcher.add("authorization");
Expand All @@ -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<String> matcher = new ArrayList<>();
matcher.add("api_key");
matcher.add("authorization");
Expand Down Expand Up @@ -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<String> matcher = new ArrayList<>();
matcher.add("api_key");
matcher.add("authorization");
Expand Down Expand Up @@ -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<String> matcher = new ArrayList<>();
matcher.add("api_key");
matcher.add("authorization");
Expand All @@ -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<String> matcher = new ArrayList<>();
matcher.add("api_key");
matcher.add("authorization");
Expand Down Expand Up @@ -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<String> matcher = new ArrayList<>();
matcher.add("api_key");
matcher.add("authorization");
Expand Down Expand Up @@ -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<String, Object> 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"));
Expand Down
Loading