Browse Source
Merge pull request #9229 from dashevchenko/spaceKeyValidation
Added validation on space key for telemetry and attributes
pull/9240/head
Andrew Shvayka
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
16 additions and
2 deletions
-
application/src/test/java/org/thingsboard/server/controller/TelemetryControllerTest.java
-
dao/src/main/java/org/thingsboard/server/dao/util/KvUtils.java
|
|
|
@ -149,6 +149,19 @@ public class TelemetryControllerTest extends AbstractControllerTest { |
|
|
|
doPostAsync("/api/plugins/telemetry/DEVICE/" + device.getId() + "/timeseries/smth", invalidRequestBody, String.class, status().isBadRequest()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testEmptyKeyIsProhibited() throws Exception { |
|
|
|
loginTenantAdmin(); |
|
|
|
Device device = createDevice(); |
|
|
|
String invalidRequestBody = "{\"\": \"value\"}"; |
|
|
|
doPostAsync("/api/plugins/telemetry/" + device.getId() + "/SHARED_SCOPE", invalidRequestBody, String.class, status().isBadRequest()); |
|
|
|
doPostAsync("/api/plugins/telemetry/DEVICE/" + device.getId() + "/timeseries/smth", invalidRequestBody, String.class, status().isBadRequest()); |
|
|
|
|
|
|
|
String invalidRequestBody2 = "{\" \": \"value\"}"; |
|
|
|
doPostAsync("/api/plugins/telemetry/" + device.getId() + "/SHARED_SCOPE", invalidRequestBody2, String.class, status().isBadRequest()); |
|
|
|
doPostAsync("/api/plugins/telemetry/DEVICE/" + device.getId() + "/timeseries/smth", invalidRequestBody2, String.class, status().isBadRequest()); |
|
|
|
} |
|
|
|
|
|
|
|
private Device createDevice() throws Exception { |
|
|
|
String testToken = "TEST_TOKEN"; |
|
|
|
|
|
|
|
|
|
|
|
@ -18,6 +18,7 @@ package org.thingsboard.server.dao.util; |
|
|
|
import com.fasterxml.jackson.databind.JsonNode; |
|
|
|
import com.github.benmanes.caffeine.cache.Cache; |
|
|
|
import com.github.benmanes.caffeine.cache.Caffeine; |
|
|
|
import org.thingsboard.server.common.data.StringUtils; |
|
|
|
import org.thingsboard.server.common.data.kv.KvEntry; |
|
|
|
import org.thingsboard.server.dao.exception.DataValidationException; |
|
|
|
import org.thingsboard.server.dao.exception.IncorrectParameterException; |
|
|
|
@ -48,8 +49,8 @@ public class KvUtils { |
|
|
|
|
|
|
|
String key = tsKvEntry.getKey(); |
|
|
|
|
|
|
|
if (key == null) { |
|
|
|
throw new DataValidationException("Key can't be null"); |
|
|
|
if (StringUtils.isBlank(key)) { |
|
|
|
throw new DataValidationException("Key can't be null or empty"); |
|
|
|
} |
|
|
|
|
|
|
|
if (key.length() > 255) { |
|
|
|
|