This is an automated email from the ASF dual-hosted git repository.
qiaojialin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 7148f15 [IOTDB-1132] username, password and rolename shouldn't
contains spaces (#3069)
7148f15 is described below
commit 7148f155933ea97410f30d7e67ebf6e72acaf953
Author: Haonan <[email protected]>
AuthorDate: Tue Apr 27 14:58:10 2021 +0800
[IOTDB-1132] username, password and rolename shouldn't contains spaces
(#3069)
---
.../main/java/org/apache/iotdb/db/utils/AuthUtils.java | 9 +++++++++
.../iotdb/db/auth/role/LocalFileRoleManagerTest.java | 6 ++++++
.../iotdb/db/auth/user/LocalFileUserManagerTest.java | 16 ++++++++++++++++
3 files changed, 31 insertions(+)
diff --git a/server/src/main/java/org/apache/iotdb/db/utils/AuthUtils.java
b/server/src/main/java/org/apache/iotdb/db/utils/AuthUtils.java
index 2c20a7d..cdad123 100644
--- a/server/src/main/java/org/apache/iotdb/db/utils/AuthUtils.java
+++ b/server/src/main/java/org/apache/iotdb/db/utils/AuthUtils.java
@@ -57,6 +57,9 @@ public class AuthUtils {
throw new AuthException(
"Password's size must be greater than or equal to " +
MIN_PASSWORD_LENGTH);
}
+ if (password.contains(" ")) {
+ throw new AuthException("Password cannot contain spaces");
+ }
}
/**
@@ -70,6 +73,9 @@ public class AuthUtils {
throw new AuthException(
"Username's size must be greater than or equal to " +
MIN_USERNAME_LENGTH);
}
+ if (username.contains(" ")) {
+ throw new AuthException("Username cannot contain spaces");
+ }
}
/**
@@ -83,6 +89,9 @@ public class AuthUtils {
throw new AuthException(
"Role name's size must be greater than or equal to " +
MIN_ROLENAME_LENGTH);
}
+ if (rolename.contains(" ")) {
+ throw new AuthException("Rolename cannot contain spaces");
+ }
}
/**
diff --git
a/server/src/test/java/org/apache/iotdb/db/auth/role/LocalFileRoleManagerTest.java
b/server/src/test/java/org/apache/iotdb/db/auth/role/LocalFileRoleManagerTest.java
index c7fe76d..cc374a5 100644
---
a/server/src/test/java/org/apache/iotdb/db/auth/role/LocalFileRoleManagerTest.java
+++
b/server/src/test/java/org/apache/iotdb/db/auth/role/LocalFileRoleManagerTest.java
@@ -87,6 +87,12 @@ public class LocalFileRoleManagerTest {
caught = true;
}
assertTrue(caught);
+ try {
+ manager.createRole("rolename ");
+ } catch (AuthException e) {
+ caught = true;
+ }
+ assertTrue(caught);
// delete
assertFalse(manager.deleteRole("not a role"));
diff --git
a/server/src/test/java/org/apache/iotdb/db/auth/user/LocalFileUserManagerTest.java
b/server/src/test/java/org/apache/iotdb/db/auth/user/LocalFileUserManagerTest.java
index e62b90b..c5f0bbf 100644
---
a/server/src/test/java/org/apache/iotdb/db/auth/user/LocalFileUserManagerTest.java
+++
b/server/src/test/java/org/apache/iotdb/db/auth/user/LocalFileUserManagerTest.java
@@ -59,6 +59,22 @@ public class LocalFileUserManagerTest {
}
@Test
+ public void testIllegalInput() throws AuthException {
+ // Password contains space
+ try {
+ manager.createUser("username1", "password_ ");
+ } catch (AuthException e) {
+ assertTrue(e.getMessage().contains("cannot contain spaces"));
+ }
+ // Username contains space
+ try {
+ assertFalse(manager.createUser("username 2", "password_"));
+ } catch (AuthException e) {
+ assertTrue(e.getMessage().contains("cannot contain spaces"));
+ }
+ }
+
+ @Test
public void test() throws AuthException {
User[] users = new User[5];
for (int i = 0; i < users.length; i++) {