mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
commit 20152e16891582f8ff466a93ec2cf01871824d6d Author: Rob Bygrave <robin.bygrave@gmail.com> Date: Tue Feb 27 20:59:51 2024 +1300 #3341 Update DatabaseConfig for fluid style + javadoc commit1c495a7384Author: Roland Praml <roland.praml@foconis.de> Date: Mon Feb 26 10:25:42 2024 +0100 Fix: Compile errors commit574876b758Merge:df7b0487777634fc3eAuthor: Roland Praml <roland.praml@foconis.de> Date: Fri Feb 23 16:16:39 2024 +0100 Merge branch 'master-rob' into FOCONIS-string-length-validation commitdf7b04877dAuthor: Rob Bygrave <robin.bygrave@gmail.com> Date: Mon Jun 26 21:16:32 2023 +1200 #3121 BindMaxLength validation At deploy time derive a BindMaxLength property to use per BeanProperty commit4683877e0bMerge:9a4b9d4bed0020ab8cAuthor: Rob Bygrave <robin.bygrave@gmail.com> Date: Fri Jun 23 16:51:34 2023 +1200 Merge branch 'string-length-validation' of github.com:FOCONIS/ebean into FOCONIS-string-length-validation commitd0020ab8ceAuthor: Roland Praml <roland.praml@foconis.de> Date: Tue Jun 20 14:47:20 2023 +0200 Length validation less invasive commit9b3b8ad46aAuthor: Roland Praml <roland.praml@foconis.de> Date: Tue Jun 20 13:03:04 2023 +0200 extended DataBind, so that it could return the last bound object commitca3c02bc1cAuthor: Roland Praml <roland.praml@foconis.de> Date: Mon Jun 19 09:52:52 2023 +0200 Failing test for SqlServer
102 lines
3.1 KiB
Java
102 lines
3.1 KiB
Java
package org.tests.basic;
|
|
|
|
import io.ebean.DB;
|
|
import io.ebean.DataIntegrityException;
|
|
import io.ebean.xtest.BaseTestCase;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.tests.model.json.EBasicJsonList;
|
|
import org.tests.model.json.EBasicJsonMap;
|
|
import org.tests.model.types.SomeFileBean;
|
|
|
|
import java.io.File;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
|
|
/**
|
|
* @author Roland Praml, FOCONIS AG
|
|
*/
|
|
public class TestLength extends BaseTestCase {
|
|
|
|
@Test
|
|
void testFileSize() throws IOException {
|
|
File f1 = File.createTempFile("testfile", "tmp");
|
|
byte[] buf = new byte[1024];
|
|
try (FileOutputStream fos = new FileOutputStream(f1)) {
|
|
for (int i = 0; i < 100; i++) {
|
|
fos.write(buf);
|
|
}
|
|
}
|
|
|
|
SomeFileBean sfb1 = new SomeFileBean();
|
|
sfb1.setContent(f1);
|
|
DB.save(sfb1);
|
|
|
|
try (FileOutputStream fos = new FileOutputStream(f1)) {
|
|
for (int i = 0; i < 101; i++) {
|
|
fos.write(buf);
|
|
}
|
|
}
|
|
|
|
SomeFileBean sfb2 = new SomeFileBean();
|
|
sfb2.setContent(f1);
|
|
assertThatThrownBy(() -> DB.save(sfb2)).isInstanceOf(DataIntegrityException.class);
|
|
}
|
|
|
|
|
|
/**
|
|
* The property 'EBasicJsonMap.content' is annotated with @DbJson(length=5000). So we assume, that we cannot save Json-objects
|
|
* where the serialized form exceed that limit and we would expect an error on save.
|
|
* The length check works for platforms like h2, as H2 uses a 'varchar(5000)'. So it is impossible to save such long jsons,
|
|
* but it won't work for SqlServer, as here 'nvarchar(max)' is used. No validation happens at DB level and you might get very
|
|
* large Json objects in your database. This mostly happens unintentionally (programming error, misconfiguration)
|
|
* So they are in the database and they cannot be accessed by ebean any more, because there are new limits in Jackson:
|
|
* - Max 5 Meg per string in 2.15.0
|
|
* - Max 20 Meg per string in 2.15.1
|
|
* see https://github.com/FasterXML/jackson-core/issues/1014
|
|
*/
|
|
@Test
|
|
void testLongString() {
|
|
// s is so big, that it could not be deserialized by jackson
|
|
String s = new String(new char[20_000_001]).replace('\0', 'x');
|
|
|
|
EBasicJsonMap bean = new EBasicJsonMap();
|
|
bean.setName("b1");
|
|
bean.setContent(Map.of("string", s));
|
|
|
|
assertThatThrownBy(() -> {
|
|
// we expect, that we can NOT save the bean, this is ensured by the bind validator.
|
|
DB.save(bean);
|
|
}).isInstanceOf(DataIntegrityException.class);
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Tests the UTF8 validation.
|
|
*/
|
|
@Test
|
|
void testUtf8() {
|
|
|
|
String s = new String(new char[40]).replace('\0', '€');
|
|
|
|
EBasicJsonList bean = new EBasicJsonList();
|
|
bean.setName("b1");
|
|
bean.setTags(List.of(s));
|
|
|
|
if (isDb2() || isOracle()) {
|
|
// by default, DB2 && oracle uses bytes in varchar, so an '€' symbol needs 3 bytes
|
|
assertThatThrownBy(() -> {
|
|
// we expect, that we can NOT save the bean, this is ensured by the bind validator.
|
|
DB.save(bean);
|
|
}).isInstanceOf(DataIntegrityException.class);
|
|
} else {
|
|
DB.save(bean);
|
|
}
|
|
}
|
|
|
|
}
|