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 387d164  Fix test cases. (#12359)
387d164 is described below

commit 387d164780be8f77cf386fd3628d0ca982496bef
Author: Guocheng Tang <[email protected]>
AuthorDate: Sat Sep 11 10:18:27 2021 +0800

    Fix test cases. (#12359)
    
    * Optimize the integration test mirror code.
    
    * Fix assertLoginWithUnauthorizedSchema and assertWatch.
---
 .../MySQLAuthenticationHandlerTest.java            | 27 +++++++++++++---------
 .../api/impl/GovernanceRepositoryAPIImplTest.java  |  5 +---
 2 files changed, 17 insertions(+), 15 deletions(-)

diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationHandlerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationHandlerTest.java
index 1916896..3dbaa7b 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationHandlerTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationHandlerTest.java
@@ -39,7 +39,6 @@ import org.apache.shardingsphere.mode.persist.PersistService;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.junit.MockitoJUnitRunner;
@@ -48,6 +47,7 @@ import java.lang.reflect.Field;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Properties;
 
 import static org.hamcrest.CoreMatchers.is;
@@ -114,12 +114,10 @@ public final class MySQLAuthenticationHandlerTest {
     }
     
     @Test
-    @Ignore
-    // TODO mock return false for SQLCheckEngine
     public void assertLoginWithUnauthorizedSchema() {
-        initProxyContext(new ShardingSphereUser("root", "root", ""));
+        initProxyContext(new ShardingSphereUser("root", "root", ""), false);
         byte[] authResponse = {-27, 89, -20, -27, 65, -120, -64, -101, 86, 
-100, -108, -100, 6, -125, -37, 117, 14, -43, 95, -113};
-        assertThat(authenticationHandler.login("root", "", authResponse, 
"db2").orElse(null), is(MySQLServerErrorCode.ER_DBACCESS_DENIED_ERROR));
+        assertThat(authenticationHandler.login("root", "", authResponse, 
"db11").orElse(null), is(MySQLServerErrorCode.ER_DBACCESS_DENIED_ERROR));
     }
     
     @Test
@@ -130,22 +128,22 @@ public final class MySQLAuthenticationHandlerTest {
     private void setAuthority(final ShardingSphereUser user) {
         NativeAuthorityProviderAlgorithm algorithm = new 
NativeAuthorityProviderAlgorithm();
         algorithm.init(Collections.emptyMap(), Collections.emptyList());
-        initProxyContext(user);
+        initProxyContext(user, true);
     }
     
     @SneakyThrows(ReflectiveOperationException.class)
-    private void initProxyContext(final ShardingSphereUser user) {
+    private void initProxyContext(final ShardingSphereUser user, final boolean 
isNeedSuper) {
         Field contextManagerField = 
ProxyContext.getInstance().getClass().getDeclaredField("contextManager");
         contextManagerField.setAccessible(true);
         ContextManager contextManager = mock(ContextManager.class, 
RETURNS_DEEP_STUBS);
-        MetaDataContexts metaDataContexts = getMetaDataContexts(user);
+        MetaDataContexts metaDataContexts = getMetaDataContexts(user, 
isNeedSuper);
         
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
         contextManagerField.set(ProxyContext.getInstance(), contextManager);
     }
     
-    private MetaDataContexts getMetaDataContexts(final ShardingSphereUser 
user) {
+    private MetaDataContexts getMetaDataContexts(final ShardingSphereUser 
user, final boolean isNeedSuper) throws NoSuchFieldException, 
IllegalAccessException {
         return new MetaDataContexts(mock(PersistService.class), 
getMetaDataMap(),
-                buildGlobalRuleMetaData(user), mock(ExecutorEngine.class), new 
ConfigurationProperties(new Properties()), mock(OptimizeContextFactory.class));
+                buildGlobalRuleMetaData(user, isNeedSuper), 
mock(ExecutorEngine.class), new ConfigurationProperties(new Properties()), 
mock(OptimizeContextFactory.class));
     }
     
     private Map<String, ShardingSphereMetaData> getMetaDataMap() {
@@ -158,9 +156,16 @@ public final class MySQLAuthenticationHandlerTest {
         return result;
     }
     
-    private ShardingSphereRuleMetaData buildGlobalRuleMetaData(final 
ShardingSphereUser user) {
+    private ShardingSphereRuleMetaData buildGlobalRuleMetaData(final 
ShardingSphereUser user, final boolean isNeedSuper) throws 
NoSuchFieldException, IllegalAccessException {
         AuthorityRuleConfiguration ruleConfig = new 
AuthorityRuleConfiguration(Collections.singletonList(user), new 
ShardingSphereAlgorithmConfiguration("NATIVE", new Properties()));
         AuthorityRule rule = new AuthorityRuleBuilder().build(ruleConfig, 
Collections.emptyMap());
+        if (!isNeedSuper) {
+            Field providerField = 
AuthorityRule.class.getDeclaredField("provider");
+            NativeAuthorityProviderAlgorithm nativeAuthorityProviderAlgorithm 
= mock(NativeAuthorityProviderAlgorithm.class, RETURNS_DEEP_STUBS);
+            
when(nativeAuthorityProviderAlgorithm.findPrivileges(user.getGrantee())).thenReturn(Optional.empty());
+            providerField.setAccessible(true);
+            providerField.set(rule, nativeAuthorityProviderAlgorithm);
+        }
         return new 
ShardingSphereRuleMetaData(Collections.singletonList(ruleConfig), 
Collections.singletonList(rule));
     }
 }
diff --git 
a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/api/impl/GovernanceRepositoryAPIImplTest.java
 
b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/api/impl/GovernanceRepositoryAPIImplTest.java
index 460693e..d93f5b7 100644
--- 
a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/api/impl/GovernanceRepositoryAPIImplTest.java
+++ 
b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/api/impl/GovernanceRepositoryAPIImplTest.java
@@ -17,9 +17,9 @@
 
 package org.apache.shardingsphere.scaling.core.api.impl;
 
+import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
 import 
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
 import 
org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEvent;
-import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
 import org.apache.shardingsphere.scaling.core.api.GovernanceRepositoryAPI;
 import org.apache.shardingsphere.scaling.core.api.ScalingAPIFactory;
 import org.apache.shardingsphere.scaling.core.common.constant.ScalingConstant;
@@ -38,7 +38,6 @@ import 
org.apache.shardingsphere.scaling.core.job.task.inventory.InventoryTask;
 import org.apache.shardingsphere.scaling.core.util.ReflectionUtil;
 import org.apache.shardingsphere.scaling.core.util.ResourceUtil;
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import java.util.List;
@@ -84,8 +83,6 @@ public final class GovernanceRepositoryAPIImplTest {
     }
     
     @Test
-    @Ignore
-    // TODO fix me
     public void assertWatch() throws InterruptedException {
         CountDownLatch countDownLatch = new CountDownLatch(1);
         String key = ScalingConstant.SCALING_ROOT + "/1";

Reply via email to