Browse Source

fixed mobile application validator

pull/10591/head
dashevchenko 2 years ago
parent
commit
4ee969fa1e
  1. 22
      application/src/test/java/org/thingsboard/server/controller/MobileApplicationControllerTest.java
  2. 10
      dao/src/main/java/org/thingsboard/server/dao/service/validator/MobileAppSettingsDataValidator.java

22
application/src/test/java/org/thingsboard/server/controller/MobileApplicationControllerTest.java

@ -110,7 +110,7 @@ public class MobileApplicationControllerTest extends AbstractControllerTest {
mobileAppSettings.setIosConfig(IosConfig.builder().enabled(false).build()); mobileAppSettings.setIosConfig(IosConfig.builder().enabled(false).build());
doPost("/api/mobile/app/settings", mobileAppSettings) doPost("/api/mobile/app/settings", mobileAppSettings)
.andExpect(status().isBadRequest()) .andExpect(status().isBadRequest())
.andExpect(statusReason(containsString("Qr code config is required!"))); .andExpect(statusReason(containsString("Qr code configuration is required!")));
mobileAppSettings.setQrCodeConfig(QRCodeConfig.builder().showOnHomePage(false).build()); mobileAppSettings.setQrCodeConfig(QRCodeConfig.builder().showOnHomePage(false).build());
doPost("/api/mobile/app/settings", mobileAppSettings) doPost("/api/mobile/app/settings", mobileAppSettings)
@ -121,6 +121,7 @@ public class MobileApplicationControllerTest extends AbstractControllerTest {
public void testShouldNotSaveMobileAppSettingsWithoutRequiredAndroidConf() throws Exception { public void testShouldNotSaveMobileAppSettingsWithoutRequiredAndroidConf() throws Exception {
loginSysAdmin(); loginSysAdmin();
MobileAppSettings mobileAppSettings = doGet("/api/mobile/app/settings", MobileAppSettings.class); MobileAppSettings mobileAppSettings = doGet("/api/mobile/app/settings", MobileAppSettings.class);
mobileAppSettings.setUseDefaultApp(false);
AndroidConfig androidConfig = AndroidConfig.builder() AndroidConfig androidConfig = AndroidConfig.builder()
.enabled(true) .enabled(true)
.appPackage(null) .appPackage(null)
@ -130,12 +131,12 @@ public class MobileApplicationControllerTest extends AbstractControllerTest {
doPost("/api/mobile/app/settings", mobileAppSettings) doPost("/api/mobile/app/settings", mobileAppSettings)
.andExpect(status().isBadRequest()) .andExpect(status().isBadRequest())
.andExpect(statusReason(containsString("Application package and sha256 cert fingerprints are required for enabled android settings!"))); .andExpect(statusReason(containsString("Application package and sha256 cert fingerprints are required for custom android application!")));
androidConfig.setAppPackage("test_app_package"); androidConfig.setAppPackage("test_app_package");
doPost("/api/mobile/app/settings", mobileAppSettings) doPost("/api/mobile/app/settings", mobileAppSettings)
.andExpect(status().isBadRequest()) .andExpect(status().isBadRequest())
.andExpect(statusReason(containsString("Application package and sha256 cert fingerprints are required for enabled android settings!"))); .andExpect(statusReason(containsString("Application package and sha256 cert fingerprints are required for custom android application!")));
androidConfig.setSha256CertFingerprints("test_sha_256"); androidConfig.setSha256CertFingerprints("test_sha_256");
doPost("/api/mobile/app/settings", mobileAppSettings) doPost("/api/mobile/app/settings", mobileAppSettings)
@ -146,6 +147,7 @@ public class MobileApplicationControllerTest extends AbstractControllerTest {
public void testShouldNotSaveMobileAppSettingsWithoutRequiredIosConf() throws Exception { public void testShouldNotSaveMobileAppSettingsWithoutRequiredIosConf() throws Exception {
loginSysAdmin(); loginSysAdmin();
MobileAppSettings mobileAppSettings = doGet("/api/mobile/app/settings", MobileAppSettings.class); MobileAppSettings mobileAppSettings = doGet("/api/mobile/app/settings", MobileAppSettings.class);
mobileAppSettings.setUseDefaultApp(false);
IosConfig iosConfig = IosConfig.builder() IosConfig iosConfig = IosConfig.builder()
.enabled(true) .enabled(true)
.appId(null) .appId(null)
@ -154,13 +156,25 @@ public class MobileApplicationControllerTest extends AbstractControllerTest {
doPost("/api/mobile/app/settings", mobileAppSettings) doPost("/api/mobile/app/settings", mobileAppSettings)
.andExpect(status().isBadRequest()) .andExpect(status().isBadRequest())
.andExpect(statusReason(containsString("Application id is required for enabled ios settings!"))); .andExpect(statusReason(containsString("Application id is required for custom ios application!")));
iosConfig.setAppId("test_app_id"); iosConfig.setAppId("test_app_id");
doPost("/api/mobile/app/settings", mobileAppSettings) doPost("/api/mobile/app/settings", mobileAppSettings)
.andExpect(status().isOk()); .andExpect(status().isOk());
} }
@Test
public void testShouldSaveMobileAppSettingsForDefaultApp() throws Exception {
loginSysAdmin();
MobileAppSettings mobileAppSettings = doGet("/api/mobile/app/settings", MobileAppSettings.class);
mobileAppSettings.setUseDefaultApp(true);
mobileAppSettings.setIosConfig(null);
mobileAppSettings.setAndroidConfig(null);
doPost("/api/mobile/app/settings", mobileAppSettings)
.andExpect(status().isOk());
}
@Test @Test
public void testGetApplicationAssociations() throws Exception { public void testGetApplicationAssociations() throws Exception {
loginSysAdmin(); loginSysAdmin();

10
dao/src/main/java/org/thingsboard/server/dao/service/validator/MobileAppSettingsDataValidator.java

@ -38,14 +38,14 @@ public class MobileAppSettingsDataValidator extends DataValidator<MobileAppSetti
throw new DataValidationException("Android/ios settings are required to use custom application!"); throw new DataValidationException("Android/ios settings are required to use custom application!");
} }
if (qrCodeConfig == null) { if (qrCodeConfig == null) {
throw new DataValidationException("Qr code config is required!"); throw new DataValidationException("Qr code configuration is required!");
} }
if (androidConfig != null && androidConfig.isEnabled() && if (androidConfig != null && androidConfig.isEnabled() && !mobileAppSettings.isUseDefaultApp() &&
(androidConfig.getAppPackage() == null || androidConfig.getSha256CertFingerprints() == null)) { (androidConfig.getAppPackage() == null || androidConfig.getSha256CertFingerprints() == null)) {
throw new DataValidationException("Application package and sha256 cert fingerprints are required for enabled android settings!"); throw new DataValidationException("Application package and sha256 cert fingerprints are required for custom android application!");
} }
if (iosConfig != null && iosConfig.isEnabled() && iosConfig.getAppId() == null) { if (iosConfig != null && iosConfig.isEnabled() && !mobileAppSettings.isUseDefaultApp() && iosConfig.getAppId() == null) {
throw new DataValidationException("Application id is required for enabled ios settings!"); throw new DataValidationException("Application id is required for custom ios application!");
} }
} }
} }

Loading…
Cancel
Save