This is an automated email from the ASF dual-hosted git repository.
Aias00 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 83fece187b fix: correct namespace plugin name existence query (#7016)
83fece187b is described below
commit 83fece187bb63d8d6123cda20db1eda79b44669b
Author: Southern <[email protected]>
AuthorDate: Wed Sep 2 15:38:25 2026 +0800
fix: correct namespace plugin name existence query (#7016)
Modify the `namespace-plugin-rel-sqlmap.xml` file's `nameExistedExclude`
query:
- Associate `namespace_plugin_rel` with the `plugin` table.
- Query the plugin name using `plugin.name`.
- Add table aliases for `plugin_id` and `namespace_id` to avoid ambiguity
in field names.
Add Mapper test cases:
- Verify that it returns true when the name matches.
- Verify that it returns null when excluding the specified plugin.
- Verify that it returns null when the name does not exist.
Co-authored-by: aias00 <[email protected]>
---
.../mappers/namespace-plugin-rel-sqlmap.xml | 9 +++---
.../admin/mapper/NamespacePluginRelMapperTest.java | 37 ++++++++++++++++++++++
2 files changed, 42 insertions(+), 4 deletions(-)
diff --git
a/shenyu-admin/src/main/resources/mappers/namespace-plugin-rel-sqlmap.xml
b/shenyu-admin/src/main/resources/mappers/namespace-plugin-rel-sqlmap.xml
index b0a7354da2..53f4f3fcdf 100644
--- a/shenyu-admin/src/main/resources/mappers/namespace-plugin-rel-sqlmap.xml
+++ b/shenyu-admin/src/main/resources/mappers/namespace-plugin-rel-sqlmap.xml
@@ -194,14 +194,15 @@
<select id="nameExistedExclude" resultType="java.lang.Boolean">
SELECT true
- FROM namespace_plugin_rel
- WHERE name = #{name}
- AND plugin_id NOT IN
+ FROM namespace_plugin_rel npr
+ INNER JOIN plugin p ON npr.plugin_id = p.id
+ WHERE p.name = #{name}
+ AND npr.plugin_id NOT IN
<foreach collection="exclude" item="id" index="index"
open="(" separator="," close=")">
#{id}
</foreach>
- AND namespace_id=#{namespaceId}
+ AND npr.namespace_id = #{namespaceId}
LIMIT 1
</select>
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/NamespacePluginRelMapperTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/NamespacePluginRelMapperTest.java
index b5f0789a36..57fcc9e022 100644
---
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/NamespacePluginRelMapperTest.java
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/NamespacePluginRelMapperTest.java
@@ -20,19 +20,26 @@ package org.apache.shenyu.admin.mapper;
import jakarta.annotation.Resource;
import org.apache.shenyu.admin.AbstractSpringIntegrationTest;
import org.apache.shenyu.admin.model.entity.NamespacePluginRelDO;
+import org.apache.shenyu.admin.model.entity.PluginDO;
import org.apache.shenyu.admin.model.vo.NamespacePluginVO;
import org.apache.shenyu.common.utils.UUIDUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.sql.Timestamp;
+import java.util.Collections;
import java.util.List;
+import static
org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID;
+
class NamespacePluginRelMapperTest extends AbstractSpringIntegrationTest {
@Resource
private NamespacePluginRelMapper namespacePluginRelMapper;
+ @Resource
+ private PluginMapper pluginMapper;
+
@Test
void testSelectByIds() {
String id = UUIDUtils.getInstance().generateShortUuid();
@@ -52,4 +59,34 @@ class NamespacePluginRelMapperTest extends
AbstractSpringIntegrationTest {
Assertions.assertEquals(1, queryResults.size());
Assertions.assertEquals(id, queryResults.get(0).getId());
}
+
+ @Test
+ void testNameExistedExcludeUsesPluginName() {
+ String pluginId = UUIDUtils.getInstance().generateShortUuid();
+ String pluginName = "namespace-plugin-" + pluginId;
+ pluginMapper.insert(PluginDO.builder()
+ .id(pluginId)
+ .name(pluginName)
+ .role("proxy")
+ .sort(0)
+ .enabled(true)
+ .dateCreated(new Timestamp(System.currentTimeMillis()))
+ .dateUpdated(new Timestamp(System.currentTimeMillis()))
+ .build());
+ String relationId = UUIDUtils.getInstance().generateShortUuid();
+ namespacePluginRelMapper.insertSelective(NamespacePluginRelDO.builder()
+ .id(relationId)
+ .pluginId(pluginId)
+ .namespaceId(SYS_DEFAULT_NAMESPACE_ID)
+ .enabled(true)
+ .sort(0)
+ .build());
+
+
Assertions.assertTrue(namespacePluginRelMapper.nameExistedExclude(pluginName,
+ Collections.singletonList("excluded-" + pluginId),
SYS_DEFAULT_NAMESPACE_ID));
+
Assertions.assertNull(namespacePluginRelMapper.nameExistedExclude(pluginName,
+ Collections.singletonList(pluginId),
SYS_DEFAULT_NAMESPACE_ID));
+
Assertions.assertNull(namespacePluginRelMapper.nameExistedExclude("missing-" +
pluginName,
+ Collections.singletonList("excluded-" + pluginId),
SYS_DEFAULT_NAMESPACE_ID));
+ }
}