You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by xi...@apache.org on 2022/10/04 02:06:19 UTC

[shenyu] branch master updated: [type:test] Add test for casdoor plugin (#4035)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 1cd41f5cf [type:test] Add test for casdoor plugin (#4035)
1cd41f5cf is described below

commit 1cd41f5cfece4b8a6c9b8c8954bba8bb1bfc336e
Author: jakiuncle <88...@users.noreply.github.com>
AuthorDate: Tue Oct 4 10:06:11 2022 +0800

    [type:test] Add test for casdoor plugin (#4035)
    
    * [type:feature] Make an Apache Shenyu SSO authentication plugin based on Casdoor
    
    * [type:feature] Make an Apache Shenyu SSO authentication plugin based on Casdoor
    
    * [type:feature] Make an Apache Shenyu SSO authentication plugin based on Casdoor
    
    * [type:feat] Make an Apache Shenyu SSO authentication plugin based
    
    * [type:feat] Make an Apache Shenyu SSO authentication plugin based
    
    * [type:feat] Make an Apache Shenyu SSO authentication plugin based on casdoor
    
    * [type:feat] Make an Apache Shenyu SSO authentication plugin based on casdoor
    
    * [type:feat] Make an Apache Shenyu SSO authentication plugin based on casdoor
    
    * [type:feat] Make an Apache Shenyu SSO authentication plugin based on casdoor
    
    * [type:feat] Make an Apache Shenyu SSO authentication plugin based on casdoor
    
    * [type:feat] Make an Apache Shenyu SSO authentication plugin based on casdoor
    
    * [type:feat] Make an Apache Shenyu SSO authentication plugin based on casdoor
    
    * [type:feat] Make an Apache Shenyu SSO authentication plugin based on casdoor
    
    * [type:feat] Make an Apache Shenyu SSO authentication plugin based on casdoor
    
    * [type:feat] Make an Apache Shenyu SSO authentication plugin based on casdoor
    
    * [type:feat] Make an Apache Shenyu SSO authentication plugin based on casdoor
    
    * [type:feat] Make an Apache Shenyu SSO authentication plugin based on casdoor
    
    * [type:feat] Add test for CasdoorPlugin and fix a sql error
    
    * [type:feat] Add test for CasdoorPlugin and fix a sql error
    
    * [type:feat] Add test for CasdoorPlugin and fix a sql error
    
    * [type:feat] Add test for CasdoorPlugin and fix a sql error
    
    * [type:feat] Add test for CasdoorPlugin and fix a sql error
    
    Co-authored-by: xiaoyu <xi...@apache.org>
---
 db/init/mysql/schema.sql                           |   2 +-
 db/init/oracle/schema.sql                          |   2 +-
 db/init/pg/create-table.sql                        |   2 +-
 db/upgrade/2.5.0-upgrade-2.5.1-mysql.sql           |   2 +-
 db/upgrade/2.5.0-upgrade-2.5.1-oracle.sql          |   2 +-
 db/upgrade/2.5.0-upgrade-2.5.1-pg.sql              |   2 +-
 .../src/main/resources/sql-script/h2/schema.sql    |   2 +-
 shenyu-plugin/shenyu-plugin-casdoor/pom.xml        |   5 +
 .../shenyu/plugin/casdoor/CasdoorPluginTest.java   | 142 +++++++++++++++++++++
 .../plugin/casdoor/config/CasdoorConfigTest.java   |  51 ++++++++
 .../handle/CasdoorPluginDateHandlerTest.java       |  52 ++++++++
 11 files changed, 257 insertions(+), 7 deletions(-)

diff --git a/db/init/mysql/schema.sql b/db/init/mysql/schema.sql
index 144112c72..04bffd3c9 100644
--- a/db/init/mysql/schema.sql
+++ b/db/init/mysql/schema.sql
@@ -666,7 +666,7 @@ INSERT INTO `plugin` VALUES ('34', 'loggingAliyunSls','{\"projectName\": \"sheny
 INSERT INTO `plugin` VALUES ('35', 'loggingPulsar', '{\"topic":\"shenyu-access-logging\", \"serviceUrl\": \"pulsar://localhost:6650\"}', 'Logging', 185, 0, '2022-06-30 21:00:00', '2022-06-30 21:00:00');
 INSERT INTO `plugin` VALUES ('36', 'loggingTencentCls','{\"endpoint\": \"ap-guangzhou.cls.tencentcs.com\", \"topic\": \"shenyu-topic\"}', 'Logging', 176, 0, '2022-06-30 21:00:00', '2022-06-30 21:00:00');
 INSERT INTO `plugin` VALUES ('38', 'loggingClickHouse', '{\"host\":\"127.0.0.1\",\"port\":\"8123\",\"databse\":\"shenyu-gateway\",\"username\":\"foo\",\"password\":\"bar\"}', 'Logging', 195, 0, '2022-06-30 21:00:00', '2022-06-30 21:00:00');
-INSERT INTO `plugin` VALUES ('39', 'casdoor', '{\"endpoint\":\"localhost:8080\"}', 'Authentication', 40, 0, '2022-09-11 12:00:00', '2022-09-11 12:00:00');
+INSERT INTO `plugin` VALUES ('39', 'casdoor', '{\"endpoint\":\"http://localhost:8000\"}', 'Authentication', 40, 0, '2022-09-11 12:00:00', '2022-09-11 12:00:00');
 
 -- ----------------------------
 -- Table structure for plugin_handle
diff --git a/db/init/oracle/schema.sql b/db/init/oracle/schema.sql
index 5e07f0226..bd0f02b16 100644
--- a/db/init/oracle/schema.sql
+++ b/db/init/oracle/schema.sql
@@ -857,7 +857,7 @@ INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin(id)) */ INTO plugin (id, name, conf
 INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin(id)) */ INTO plugin (id, name, config, role, sort, enabled) VALUES ('35', 'loggingPulsar', '{"topic":"shenyu-access-logging", "serviceUrl": "pulsar://localhost:6650"}', 'Logging', 185, '0')
 INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin(id)) */ INTO plugin (id, name, config, role, sort, enabled) VALUES ('36', 'loggingTencentCls', '{"endpoint": "ap-guangzhou.cls.tencentcs.com", "topic": "shenyu-topic"}', 'Logging', 176, '0');
 INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin(id)) */ INTO plugin (id, name, config, role, sort, enabled) VALUES ('38', 'loggingClickHouse', '{"host":"127.0.0.1","port":"8123","databse":"shenyu-gateway","username":"foo","password":"bar"}', 'Logging', 195, '0');
-INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin(id)) */ INTO plugin (id, name, config, role, sort, enabled) VALUES ('39', 'casdoor', '{"endpoint":"localhost:8080"}' ,'Authentication', 40, '0');
+INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin(id)) */ INTO plugin (id, name, config, role, sort, enabled) VALUES ('39', 'casdoor', '{"endpoint":"http://localhost:8000"}' ,'Authentication', 40, '0');
 
 
 
diff --git a/db/init/pg/create-table.sql b/db/init/pg/create-table.sql
index bf625b5c8..ed2f287c2 100644
--- a/db/init/pg/create-table.sql
+++ b/db/init/pg/create-table.sql
@@ -742,7 +742,7 @@ INSERT INTO "public"."plugin" VALUES ('34', 'loggingAliyunSls', '{"projectName":
 INSERT INTO "public"."plugin" VALUES ('35', 'loggingPulsar', '{"topic":"shenyu-access-logging", "serviceUrl": "pulsar://localhost:6650"}', 'Logging', 185, 0, '2022-05-25 18:08:01', '2022-05-25 18:08:01');
 INSERT INTO "public"."plugin" VALUES ('36', 'loggingTencentCls', '{"endpoint": "ap-guangzhou.cls.tencentcs.com", "topic": "shenyu-topic"}', 'Logging', 176, 0, '2022-06-30 21:00:00', '2022-06-30 21:00:00');
 INSERT INTO "public"."plugin" VALUES ('38', 'loggingClickHouse', '{"host":"127.0.0.1","port":"8123","databse":"shenyu-gateway","username":"foo","password":"bar"}', 'Logging', 195, 0, '2022-06-30 21:00:00', '2022-06-30 21:00:00');
-INSERT INTO "public"."plugin" VALUES ('39', 'casdoor', '{"endpoint":"localhost:8080"}', 'Authentication', 40, 0, '2022-09-11 12:00:00', '2022-09-11 12:00:00');
+INSERT INTO "public"."plugin" VALUES ('39', 'casdoor', '{"endpoint":"http://localhost:8000"}', 'Authentication', 40, 0, '2022-09-11 12:00:00', '2022-09-11 12:00:00');
 
 -- ----------------------------
 -- Table structure for plugin_handle
diff --git a/db/upgrade/2.5.0-upgrade-2.5.1-mysql.sql b/db/upgrade/2.5.0-upgrade-2.5.1-mysql.sql
index 425a77a08..e27311199 100644
--- a/db/upgrade/2.5.0-upgrade-2.5.1-mysql.sql
+++ b/db/upgrade/2.5.0-upgrade-2.5.1-mysql.sql
@@ -91,7 +91,7 @@ INSERT INTO `resource` VALUES ('1572525965625266176', '1346777449787125760', 'SH
 INSERT INTO `permission` VALUES ('1572525965658820608', '1346358560427216896', '1572525965625266176', '2022-09-28 11:50:58', '2022-09-28 11:50:58');
 
 /*insert plugin for casdoor*/
-INSERT INTO `plugin` VALUES ('39', 'casdoor', '{\"endpoint\":\"localhost:8080\"}', 'Authentication', 40, 0, '2022-09-11 12:00:00', '2022-09-11 12:00:00');
+INSERT INTO `plugin` VALUES ('39', 'casdoor', '{\"endpoint\":\"http://localhost:8000\"}', 'Authentication', 40, 0, '2022-09-11 12:00:00', '2022-09-11 12:00:00');
 
 /* insert plugin_handle data for plugin casdoor */
 INSERT INTO `plugin_handle` VALUES ('1570590990341775360', '39', 'endpoint', 'casdoor endpoint', 2, 3, 0, '{"required":"1","rule":""}', '2022-09-16 09:50:46.925', '2022-09-16 09:50:46.925');
diff --git a/db/upgrade/2.5.0-upgrade-2.5.1-oracle.sql b/db/upgrade/2.5.0-upgrade-2.5.1-oracle.sql
index 2dc8b2bde..e85364a27 100644
--- a/db/upgrade/2.5.0-upgrade-2.5.1-oracle.sql
+++ b/db/upgrade/2.5.0-upgrade-2.5.1-oracle.sql
@@ -175,7 +175,7 @@ INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX("resource" (id)) */ INTO resource  (id, pa
 INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (permission(id)) */ INTO permission (id, object_id, resource_id) VALUES ('1572525965658820608', '1346358560427216896', '1572525965625266176');
 
 /*insert plugin for casdoor*/
-INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin(id)) */ INTO plugin (id, name, config, role, sort, enabled) VALUES ('39', 'casdoor', '{"endpoint":"localhost:8080"}' ,'Authentication', 40, '0');
+INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin(id)) */ INTO plugin (id, name, config, role, sort, enabled) VALUES ('39', 'casdoor', '{"endpoint":"http://localhost:8000"}' ,'Authentication', 40, '0');
 
 /* insert plugin_handle data for plugin casdoor */
 insert /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin_handle(plugin_id, field, type)) */ into plugin_handle (ID, PLUGIN_ID, FIELD, LABEL, DATA_TYPE, TYPE, SORT, EXT_OBJ)
diff --git a/db/upgrade/2.5.0-upgrade-2.5.1-pg.sql b/db/upgrade/2.5.0-upgrade-2.5.1-pg.sql
index 722015ac0..32de3c768 100644
--- a/db/upgrade/2.5.0-upgrade-2.5.1-pg.sql
+++ b/db/upgrade/2.5.0-upgrade-2.5.1-pg.sql
@@ -93,7 +93,7 @@ INSERT INTO "public"."resource" VALUES ('1572525965625266176', '1346777449787125
 INSERT INTO "public"."permission" VALUES ('1572525965658820608', '1346358560427216896', '1572525965625266176', '2022-09-28 11:50:58', '2022-09-28 11:50:58');
 
 /*insert plugin for casdoor*/
-INSERT INTO "public"."plugin" VALUES ('39', 'casdoor', '{"endpoint":"localhost:8080"}', 'Authentication', 40, 0, '2022-09-11 12:00:00', '2022-09-11 12:00:00');
+INSERT INTO "public"."plugin" VALUES ('39', 'casdoor', '{"endpoint":"http://localhost:8000"}', 'Authentication', 40, 0, '2022-09-11 12:00:00', '2022-09-11 12:00:00');
 
 /* insert plugin_handle data for plugin casdoor */
 INSERT INTO "public"."plugin_handle" VALUES ('1529402613204172802', '8', 'loadBalance', 'loadStrategy', 3, 2, 3, '{"defaultValue":"roundRobin","rule":""}', '2022-06-30 21:00:00', '2022-06-30 21:00:00');
diff --git a/shenyu-admin/src/main/resources/sql-script/h2/schema.sql b/shenyu-admin/src/main/resources/sql-script/h2/schema.sql
index 5fe0f7ada..c4c4aa0a9 100755
--- a/shenyu-admin/src/main/resources/sql-script/h2/schema.sql
+++ b/shenyu-admin/src/main/resources/sql-script/h2/schema.sql
@@ -408,7 +408,7 @@ INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`, `enabled`)
 INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`, `enabled`) VALUES ('35', 'loggingPulsar', 'Logging', 185, '{"topic":"shenyu-access-logging", "serviceUrl": "pulsar://localhost:6650"}', '0');
 INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`, `enabled`) VALUES ('36', 'loggingTencentCls', 'Logging', 176, '{"endpoint": "ap-guangzhou.cls.tencentcs.com", "topic": "shenyu-topic"}', '0');
 INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`, `enabled`) VALUES ('38', 'loggingClickHouse', 'Logging', 195, '{"host":"127.0.0.1","port":"8123","databse":"shenyu-gateway","username":"foo","password":"bar"}', '0');
-INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`, `enabled`) VALUES ('39', 'casdoor', 'Authentication', 40, '{"endpoint":"localhost:8080"}', '0');
+INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`, `enabled`) VALUES ('39', 'casdoor', 'Authentication', 40, '{"endpoint":"http://localhost:8000"}', '0');
 /*insert plugin_handle data for sentinel*/
 INSERT IGNORE INTO plugin_handle (`id`, `plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`ext_obj`) VALUES ('1529402613195784246', '10', 'flowRuleGrade', 'flowRuleGrade', 3, 2, 8, '{"required":"1","defaultValue":"1","rule":""}');
 INSERT IGNORE INTO plugin_handle (`id`, `plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`ext_obj`) VALUES ('1529402613199978496', '10', 'flowRuleControlBehavior', 'flowRuleControlBehavior', 3, 2, 5, '{"required":"1","defaultValue":"0","rule":""}');
diff --git a/shenyu-plugin/shenyu-plugin-casdoor/pom.xml b/shenyu-plugin/shenyu-plugin-casdoor/pom.xml
index 88ce92c9c..95fb5453d 100644
--- a/shenyu-plugin/shenyu-plugin-casdoor/pom.xml
+++ b/shenyu-plugin/shenyu-plugin-casdoor/pom.xml
@@ -45,5 +45,10 @@
             <artifactId>spring-test</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>io.projectreactor</groupId>
+            <artifactId>reactor-test</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
\ No newline at end of file
diff --git a/shenyu-plugin/shenyu-plugin-casdoor/src/test/java/org/apache/shenyu/plugin/casdoor/CasdoorPluginTest.java b/shenyu-plugin/shenyu-plugin-casdoor/src/test/java/org/apache/shenyu/plugin/casdoor/CasdoorPluginTest.java
new file mode 100644
index 000000000..b3a3f3d00
--- /dev/null
+++ b/shenyu-plugin/shenyu-plugin-casdoor/src/test/java/org/apache/shenyu/plugin/casdoor/CasdoorPluginTest.java
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.plugin.casdoor;
+
+import org.apache.shenyu.common.dto.PluginData;
+import org.apache.shenyu.common.dto.RuleData;
+import org.apache.shenyu.common.dto.SelectorData;
+import org.apache.shenyu.common.enums.PluginEnum;
+import org.apache.shenyu.common.utils.Singleton;
+import org.apache.shenyu.plugin.api.ShenyuPluginChain;
+import org.apache.shenyu.plugin.api.result.DefaultShenyuResult;
+import org.apache.shenyu.plugin.api.result.ShenyuResult;
+import org.apache.shenyu.plugin.api.utils.SpringBeanUtils;
+import org.apache.shenyu.plugin.casdoor.handle.CasdoorPluginDateHandler;
+import org.casbin.casdoor.entity.CasdoorUser;
+import org.casbin.casdoor.exception.CasdoorAuthException;
+import org.casbin.casdoor.service.CasdoorAuthService;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
+import org.mockito.Mockito;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.http.HttpHeaders;
+import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
+import org.springframework.mock.web.server.MockServerWebExchange;
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Mono;
+import reactor.test.StepVerifier;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class CasdoorPluginTest {
+    @InjectMocks
+    @Spy
+    private CasdoorPlugin casdoorPluginTest;
+
+    @Spy
+    private CasdoorPluginDateHandler casdoorPluginDateHandlerTest;
+
+    private ServerWebExchange exchange;
+
+    @Mock
+    private ShenyuPluginChain chain;
+
+    @Mock
+    private SelectorData selector;
+
+    @Mock
+    private RuleData rule;
+
+    @BeforeEach
+    void setup() {
+        ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
+        when(context.getBean(ShenyuResult.class)).thenReturn(new DefaultShenyuResult());
+        SpringBeanUtils springBeanUtils = SpringBeanUtils.getInstance();
+        springBeanUtils.setApplicationContext(context);
+        MockitoAnnotations.openMocks(this);
+        exchange = MockServerWebExchange.from(MockServerHttpRequest
+                .get("localshost")
+                .header(HttpHeaders.AUTHORIZATION, "token")
+                .build());
+
+    }
+
+    @Test
+    void doExecute() {
+        final PluginData pluginData = new PluginData("pluginId", "pluginName", "{\"organization-name\":\"test\",\"application-name\":\"app-test\",\"endpoint\":\"http://localhost:8000\",\"client_secrect\":\"a4209d412a33a842b7a9c05a3446e623cbb7262d\",\"client_id\":\"6e3a84154e73d1fb156a\",\"certificate\":\"-----BEGIN CERTIFICATE-----\\n\"}", "0", false);
+        casdoorPluginDateHandlerTest.handlerPlugin(pluginData);
+        try {
+            CasdoorAuthService casdoorAuthService = Singleton.INST.get(CasdoorAuthService.class);
+            casdoorPluginTest.doExecute(exchange, chain, selector, rule);
+        } catch (Exception e) {
+            Assumptions.assumeTrue(e instanceof CasdoorAuthException);
+        }
+
+        CasdoorAuthService casdoorAuthService = mock(CasdoorAuthService.class);
+        String token = exchange.getRequest().getHeaders().getFirst(HttpHeaders.AUTHORIZATION);
+        CasdoorUser casdoorUser = new CasdoorUser();
+        Mockito.when(casdoorAuthService.parseJwtToken(token)).thenReturn(casdoorUser);
+        Singleton.INST.single(CasdoorAuthService.class, casdoorAuthService);
+        when(this.chain.execute(any())).thenReturn(Mono.empty());
+        Mono<Void> mono = casdoorPluginTest.doExecute(exchange, chain, selector, rule);
+        StepVerifier.create(mono).expectSubscription().verifyComplete();
+
+        exchange = MockServerWebExchange.from(MockServerHttpRequest
+                .get("localshost")
+                .queryParam("state", "state")
+                .queryParam("code", "code")
+                .build());
+        Mockito.when(casdoorAuthService.getOAuthToken("code", "state")).thenReturn(token);
+        Singleton.INST.single(CasdoorAuthService.class, casdoorAuthService);
+        mono = casdoorPluginTest.doExecute(exchange, chain, selector, rule);
+        StepVerifier.create(mono).expectSubscription().verifyComplete();
+
+        exchange = MockServerWebExchange.from(MockServerHttpRequest
+                .get("localshost")
+                .build());
+        mono = casdoorPluginTest.doExecute(exchange, chain, selector, rule);
+        StepVerifier.create(mono).expectSubscription().verifyComplete();
+    }
+
+    @Test
+    public void testNamed() {
+        final String result = casdoorPluginTest.named();
+        Assertions.assertEquals(PluginEnum.CASDOOR.getName(), result);
+    }
+
+    @Test
+    public void testGetOrder() {
+        final int result = casdoorPluginTest.getOrder();
+        Assertions.assertEquals(PluginEnum.CASDOOR.getCode(), result);
+    }
+
+    @Test
+    public void skipTest() {
+        Assumptions.assumeFalse(casdoorPluginTest.skip(exchange));
+    }
+
+}
diff --git a/shenyu-plugin/shenyu-plugin-casdoor/src/test/java/org/apache/shenyu/plugin/casdoor/config/CasdoorConfigTest.java b/shenyu-plugin/shenyu-plugin-casdoor/src/test/java/org/apache/shenyu/plugin/casdoor/config/CasdoorConfigTest.java
new file mode 100644
index 000000000..5c70c289c
--- /dev/null
+++ b/shenyu-plugin/shenyu-plugin-casdoor/src/test/java/org/apache/shenyu/plugin/casdoor/config/CasdoorConfigTest.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.plugin.casdoor.config;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class CasdoorConfigTest {
+
+    @Test
+    public void casdoorConfig() {
+        CasdoorConfig casdoorConfig = new CasdoorConfig("a", "b", "c", "d", "e", "f");
+        assertEquals("a", casdoorConfig.getEndpoint());
+        assertEquals("b", casdoorConfig.getClientId());
+        assertEquals("c", casdoorConfig.getClientSecret());
+        assertEquals("d", casdoorConfig.getCertificate());
+        assertEquals("e", casdoorConfig.getOrganizationName());
+        assertEquals("f", casdoorConfig.getApplicationName());
+
+        CasdoorConfig casdoorConfig1 = new CasdoorConfig();
+        casdoorConfig1.setEndpoint("a");
+        casdoorConfig1.setClientId("b");
+        casdoorConfig1.setClientSecret("c");
+        casdoorConfig1.setCertificate("d");
+        casdoorConfig1.setOrganizationName("e");
+        casdoorConfig1.setApplicationName("f");
+        assertEquals("a", casdoorConfig1.getEndpoint());
+        assertEquals("b", casdoorConfig1.getClientId());
+        assertEquals("c", casdoorConfig1.getClientSecret());
+        assertEquals("d", casdoorConfig1.getCertificate());
+        assertEquals("e", casdoorConfig1.getOrganizationName());
+        assertEquals("f", casdoorConfig1.getApplicationName());
+        assertEquals("authConfig{endpoint='a', clientId='b', clientSecret='c', certificate='d', organizationName='e', applicationName='f'}", casdoorConfig1.toString());
+    }
+}
diff --git a/shenyu-plugin/shenyu-plugin-casdoor/src/test/java/org/apache/shenyu/plugin/casdoor/handle/CasdoorPluginDateHandlerTest.java b/shenyu-plugin/shenyu-plugin-casdoor/src/test/java/org/apache/shenyu/plugin/casdoor/handle/CasdoorPluginDateHandlerTest.java
new file mode 100644
index 000000000..7347f944c
--- /dev/null
+++ b/shenyu-plugin/shenyu-plugin-casdoor/src/test/java/org/apache/shenyu/plugin/casdoor/handle/CasdoorPluginDateHandlerTest.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.plugin.casdoor.handle;
+
+import org.apache.shenyu.common.dto.PluginData;
+import org.apache.shenyu.common.enums.PluginEnum;
+import org.apache.shenyu.common.utils.Singleton;
+import org.casbin.casdoor.service.CasdoorAuthService;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class CasdoorPluginDateHandlerTest {
+
+    private CasdoorPluginDateHandler casdoorPluginDateHandlerTest;
+
+    @BeforeEach
+    public void setup() {
+        casdoorPluginDateHandlerTest = new CasdoorPluginDateHandler();
+    }
+
+    @Test
+    public void handlerPlugin() {
+        final PluginData pluginData = new PluginData("pluginId", "pluginName", "{\"organization-name\":\"test\",\"application-name\":\"app-test\",\"endpoint\":\"http://localhost:8000\",\"client_secrect\":\"a4209d412a33a842b7a9c05a3446e623cbb7262d\",\"client_id\":\"6e3a84154e73d1fb156a\",\"certificate\":\"-----BEGIN CERTIFICATE-----\\n\"}", "0", false);
+        casdoorPluginDateHandlerTest.handlerPlugin(pluginData);
+        CasdoorAuthService casdoorAuthService = Singleton.INST.get(CasdoorAuthService.class);
+        String redirect = "http://localhost:9195/http/hi";
+        assertEquals(casdoorAuthService.getSigninUrl(redirect), "http://localhost:8000/login/oauth/authorize?client_id=6e3a84154e73d1fb156a&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A9195%2Fhttp%2Fhi&scope=read&state=app-test");
+    }
+
+    @Test
+    public void testPluginNamed() {
+        final String result = casdoorPluginDateHandlerTest.pluginNamed();
+        assertEquals(PluginEnum.CASDOOR.getName(), result);
+    }
+}