You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2021/04/26 08:22:44 UTC
[iotdb] 01/01: [IOTDB-1132] username,
password and rolename shouldn't contains spaces
This is an automated email from the ASF dual-hosted git repository.
haonan pushed a commit to branch password_s
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit dea4df23bc1d423767a474e8a23468e0a8e24cb8
Author: HTHou <hh...@outlook.com>
AuthorDate: Mon Apr 26 16:22:07 2021 +0800
[IOTDB-1132] username, password and rolename shouldn't contains spaces
---
.../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++) {