Skip to content
Snippets Groups Projects
Commit 3efb3922 authored by Yurii Kondakov's avatar Yurii Kondakov
Browse files

Merge branch 'response-with-400-Bad-reqeust-when-record-id-is-longer-than-512-bytes' into 'master'

Response with 400 (Bad request) when record id is longer than 512 bytes

See merge request !953
parents f14810da eed591a2
No related branches found
No related tags found
1 merge request!953Response with 400 (Bad request) when record id is longer than 512 bytes
Pipeline #290338 passed
......@@ -69,7 +69,7 @@ The following software have components provided under the terms of this license:
- Byte Buddy Java agent (from https://repo1.maven.org/maven2/net/bytebuddy/byte-buddy-agent)
- ClassMate (from http://github.com/cowtowncoder/java-classmate)
- Cloud Key Management Service (KMS) API v1-rev20240918-2.0.0 (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-cloudkms)
- Cloud Storage JSON API v1-rev20240924-2.0.0 (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-storage)
- Cloud Storage JSON API v1-rev20241008-2.0.0 (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-storage)
- Collections (from https://repo1.maven.org/maven2/commons-collections/commons-collections)
- Commons Digester (from http://commons.apache.org/digester/)
- Converter: Jackson (from https://github.com/square/retrofit, https://repo1.maven.org/maven2/com/squareup/retrofit2/converter-jackson)
......
......@@ -28,7 +28,7 @@ From the Storage Service perspective, the metadata to be ingested is called __re
}
```
* __id__: _(optional)_ Unique identifier in the Data Ecosystem. When not provided, the service will create and assign an id to the record. Must follow the naming convention: ``{Data-Partition-Id}:{object-type}:{uuid}``.
* __id__: _(optional)_ Unique identifier in the Data Ecosystem. When not provided, the service will create and assign an id to the record. Must follow the naming convention: ``{Data-Partition-Id}:{object-type}:{uuid}`` and be no longer than 512 bytes.
* __kind__: _(mandatory)_ Kind of data being ingested. Must follow the naming convention: ``{Schema-Authority}:{dataset-name}:{record-type}:{version}``.
* __acl__: _(mandatory)_ Group of users who have access to the record.
* __acl.viewers__: List of valid groups which will have view/read privileges over the record. We follow the naming convention such that data groups begin with ``data.``.
......
......@@ -38,6 +38,7 @@ import org.opengroup.osdu.storage.opa.service.IOPAService;
import org.opengroup.osdu.storage.provider.interfaces.ICloudStorage;
import org.opengroup.osdu.storage.provider.interfaces.IRecordsMetadataRepository;
import org.opengroup.osdu.storage.util.RecordBlocks;
import org.opengroup.osdu.storage.util.RecordConstants;
import org.opengroup.osdu.storage.util.api.RecordUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -158,6 +159,13 @@ public class IngestionServiceImpl implements IngestionService {
throw new AppException(HttpStatus.SC_BAD_REQUEST, "Invalid record id", msg);
}
if (id.getBytes().length > RecordConstants.RECORD_ID_MAX_SIZE_IN_BYTES) {
String msg = String.format(
"The record '%s' does not follow the record id size convention: The record id must be no longer than %s bytes",
id, RecordConstants.RECORD_ID_MAX_SIZE_IN_BYTES);
throw new AppException(HttpStatus.SC_BAD_REQUEST, "Invalid record id", msg);
}
ids.add(id);
} else {
record.createNewRecordId(tenantName, record.getKind());
......
......@@ -32,6 +32,7 @@ public class RecordConstants {
public static final int MAX_RECORD_ID_NUMBER = 100;
public static final String REGEX_VERSION_IDS = "[0-9]+(,[0-9]+)*";
public static final int MAX_VERSION_IDS_NUMBER = 50;
public static final int RECORD_ID_MAX_SIZE_IN_BYTES = 512;
public static final String OPA_FEATURE_NAME = "featureFlag.opa.enabled";
......
......@@ -53,6 +53,7 @@ import org.opengroup.osdu.storage.provider.interfaces.ICloudStorage;
import org.opengroup.osdu.storage.provider.interfaces.IRecordsMetadataRepository;
import org.opengroup.osdu.storage.util.CrcHashGenerator;
import org.opengroup.osdu.storage.util.RecordBlocks;
import org.opengroup.osdu.storage.util.RecordConstants;
import org.opengroup.osdu.storage.util.RecordTestUtil;
import org.opengroup.osdu.storage.util.api.RecordUtil;
......@@ -240,6 +241,27 @@ public class IngestionServiceImplTest {
exception.getError().getMessage());
}
@Test
public void should_throwAppException400_when_recordIdSizeGreaterThanLimit() {
String INVALID_RECORD_ID = "tenant1:record:longidlongidlongidlongidlongidlongidlongidlongidlongidlongidlongid" +
"longidlongidlongidlongidlongidlongidlongidlongidlongidlongidlongidlongidlongidlongidlongidlongid" +
"longidlongidlongidlongidlongidlongidlongidlongidlongidlongidlongidlongidlongidlongidlongidlongid" +
"longidlongidlongidlongidlongidlongidlongidlongidlongidlongidlongidlongidlongidlongidlongidlongid" +
"longidlongidlongidlongidlongidlongidlongidlongidlongidlongidlongidlongidlongidlongidlongidlongid" +
"longidlongidlongidlongidlongidlongidlongidlongid";
this.record1.setId(INVALID_RECORD_ID);
AppException exception = assertThrows(AppException.class, ()->{
this.sut.createUpdateRecords(false, this.records, USER, Optional.empty());
});
assertEquals(HttpStatus.SC_BAD_REQUEST, exception.getError().getCode());
assertEquals("Invalid record id", exception.getError().getReason());
assertEquals("The record '" + INVALID_RECORD_ID + "' does not follow the record id size convention: The record id must be no longer than " +
RecordConstants.RECORD_ID_MAX_SIZE_IN_BYTES + " bytes", exception.getError().getMessage());
}
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void should_createTwoRecords_when_twoRecordsWithoutIdArePersisted() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment