You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2021/05/02 06:27:13 UTC

[shardingsphere] branch master updated: Fix the hostname of grantee after proxy test (#10241)

This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new f98892c  Fix the hostname of grantee after proxy test (#10241)
f98892c is described below

commit f98892ce043761ce019ef7913e453dd75f270224
Author: Juan Pan(Trista) <pa...@apache.org>
AuthorDate: Sun May 2 14:26:48 2021 +0800

    Fix the hostname of grantee after proxy test (#10241)
    
    * Instead of save() with two interfaces.
    
    * Fix the hostname of grantee after proxy test
---
 .../org/apache/shardingsphere/infra/metadata/user/Grantee.java | 10 +++++++++-
 .../apache/shardingsphere/infra/metadata/user/GranteeTest.java |  8 ++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/user/Grantee.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/user/Grantee.java
index 489734a..a40baeb 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/user/Grantee.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/user/Grantee.java
@@ -26,9 +26,9 @@ import lombok.RequiredArgsConstructor;
  * Grantee.
  */
 @RequiredArgsConstructor
-@Getter
 public final class Grantee {
     
+    @Getter
     private final String username;
     
     private final String hostname;
@@ -50,6 +50,14 @@ public final class Grantee {
         return Strings.isNullOrEmpty(hostname) || "%".equals(hostname);
     }
     
+    /**
+     * Get host name.
+     * @return host name
+     */
+    public String getHostname() {
+        return Strings.isNullOrEmpty(hostname) ? "%" : hostname;
+    }
+    
     @Override
     public int hashCode() {
         return isUnlimitedHost() ? Objects.hashCode(username.toUpperCase()) : Objects.hashCode(username.toUpperCase(), hostname.toUpperCase());
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/user/GranteeTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/user/GranteeTest.java
index 6b5b5be..c6fdaa4 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/user/GranteeTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/user/GranteeTest.java
@@ -43,4 +43,12 @@ public final class GranteeTest {
         assertThat(grantee.hashCode(), is(grantee1.hashCode()));
         assertThat(grantee1.hashCode(), not(grantee2.hashCode()));
     }
+    
+    @Test
+    public void assertHostname() {
+        Grantee grantee = new Grantee("name", "%");
+        Grantee grantee1 = new Grantee("name", "");
+        assertThat(grantee.getHostname(), is("%"));
+        assertThat(grantee1.getHostname(), is("%"));
+    }
 }