Commit f6c720513dc2fbdac1e16dd77d0a456b4ab0ed26

Authored by AndrewVolosytnykhThingsboard
1 parent f1216c97

Validation of version and title

@@ -341,6 +341,7 @@ public class BaseOtaPackageService implements OtaPackageService { @@ -341,6 +341,7 @@ public class BaseOtaPackageService implements OtaPackageService {
341 if (otaPackageOld.getDataSize() != null && !otaPackageOld.getDataSize().equals(otaPackage.getDataSize())) { 341 if (otaPackageOld.getDataSize() != null && !otaPackageOld.getDataSize().equals(otaPackage.getDataSize())) {
342 throw new DataValidationException("Updating otaPackage data size is prohibited!"); 342 throw new DataValidationException("Updating otaPackage data size is prohibited!");
343 } 343 }
  344 +
344 if(otaPackageOld.getUrl() != null && !otaPackageOld.getUrl().equals(otaPackage.getUrl())) { 345 if(otaPackageOld.getUrl() != null && !otaPackageOld.getUrl().equals(otaPackage.getUrl())) {
345 throw new DataValidationException("Updating otaPackage URL is prohibited!"); 346 throw new DataValidationException("Updating otaPackage URL is prohibited!");
346 } 347 }
@@ -374,6 +375,15 @@ public class BaseOtaPackageService implements OtaPackageService { @@ -374,6 +375,15 @@ public class BaseOtaPackageService implements OtaPackageService {
374 if (StringUtils.isEmpty(otaPackageInfo.getVersion())) { 375 if (StringUtils.isEmpty(otaPackageInfo.getVersion())) {
375 throw new DataValidationException("OtaPackage version should be specified!"); 376 throw new DataValidationException("OtaPackage version should be specified!");
376 } 377 }
  378 +
  379 + if(otaPackageInfo.getTitle().length() > 255) {
  380 + throw new DataValidationException("The length of title should be equal or shorter than 255");
  381 + }
  382 +
  383 + if(otaPackageInfo.getVersion().length() > 255) {
  384 + throw new DataValidationException("The length of version should be equal or shorter than 255");
  385 + }
  386 +
377 } 387 }
378 388
379 private PaginatedRemover<TenantId, OtaPackageInfo> tenantOtaPackageRemover = 389 private PaginatedRemover<TenantId, OtaPackageInfo> tenantOtaPackageRemover =
@@ -661,6 +661,38 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { @@ -661,6 +661,38 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
661 otaPackageService.saveOtaPackageInfo(savedFirmwareInfo, true); 661 otaPackageService.saveOtaPackageInfo(savedFirmwareInfo, true);
662 } 662 }
663 663
  664 + @Test
  665 + public void testSaveOtaPackageCantViolateSizeOfTitleAndVersion() {
  666 + OtaPackageInfo firmwareInfo = new OtaPackageInfo();
  667 + firmwareInfo.setDeviceProfileId(deviceProfileId);
  668 + firmwareInfo.setType(FIRMWARE);
  669 + firmwareInfo.setTitle("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
  670 + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
  671 + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
  672 + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
  673 + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
  674 + "aaaaaaaaaa");
  675 + firmwareInfo.setVersion(VERSION);
  676 + firmwareInfo.setUrl(URL);
  677 + firmwareInfo.setTenantId(tenantId);
  678 +
  679 + thrown.expect(DataValidationException.class);
  680 + thrown.expectMessage("The length of title should be equal or shorter than 255");
  681 +
  682 + otaPackageService.saveOtaPackageInfo(firmwareInfo, true);
  683 +
  684 + firmwareInfo.setTitle(TITLE);
  685 + firmwareInfo.setVersion("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
  686 + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
  687 + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
  688 + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
  689 + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
  690 + "aaaaaaaaaa");
  691 + thrown.expectMessage("The length of version should be equal or shorter than 255");
  692 +
  693 + otaPackageService.saveOtaPackageInfo(firmwareInfo, true);
  694 + }
  695 +
664 private OtaPackage createFirmware(TenantId tenantId, String version) { 696 private OtaPackage createFirmware(TenantId tenantId, String version) {
665 OtaPackage firmware = new OtaPackage(); 697 OtaPackage firmware = new OtaPackage();
666 firmware.setTenantId(tenantId); 698 firmware.setTenantId(tenantId);