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 86aea03ff9 fix(admin): persist app auth apply updates (#7081)
86aea03ff9 is described below
commit 86aea03ff9b0ee2071e6e1633855328896680916
Author: Liming Deng <[email protected]>
AuthorDate: Wed Sep 30 09:57:14 2026 +0800
fix(admin): persist app auth apply updates (#7081)
* fix(admin): persist app auth apply updates
* fix(admin): preserve omitted auth open state
---
.../admin/service/impl/AppAuthServiceImpl.java | 9 ++++-
.../shenyu/admin/service/AppAuthServiceTest.java | 40 ++++++++++++++++++++--
2 files changed, 46 insertions(+), 3 deletions(-)
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/AppAuthServiceImpl.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/AppAuthServiceImpl.java
index fab5705e94..c24db4b6a9 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/AppAuthServiceImpl.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/AppAuthServiceImpl.java
@@ -151,6 +151,13 @@ public class AppAuthServiceImpl implements AppAuthService {
if (Objects.isNull(appAuthDO)) {
return
ShenyuAdminResult.error(ShenyuResultMessage.APPKEY_NOT_EXIST_ERROR);
}
+ appAuthDO.setUserId(authApplyDTO.getUserId());
+ appAuthDO.setPhone(authApplyDTO.getPhone());
+ appAuthDO.setExtInfo(authApplyDTO.getExtInfo());
+ if (Objects.nonNull(authApplyDTO.getOpen())) {
+ appAuthDO.setOpen(authApplyDTO.getOpen());
+ }
+ appAuthMapper.updateSelective(appAuthDO);
AuthParamDO authParamDO =
authParamMapper.findByAuthIdAndAppName(appAuthDO.getId(),
authApplyDTO.getAppName());
if (Objects.isNull(authParamDO)) {
@@ -158,7 +165,7 @@ public class AppAuthServiceImpl implements AppAuthService {
authParamMapper.save(AuthParamDO.create(appAuthDO.getId(),
authApplyDTO.getAppName(), authApplyDTO.getAppParam()));
}
- if (Boolean.TRUE.equals(appAuthDO.getOpen())) {
+ if (Boolean.TRUE.equals(authApplyDTO.getOpen())) {
List<AuthPathDO> existList =
authPathMapper.findByAuthIdAndAppName(appAuthDO.getId(),
authApplyDTO.getAppName());
if (CollectionUtils.isNotEmpty(existList)) {
authPathMapper.deleteByAuthIdAndAppName(appAuthDO.getId(),
authApplyDTO.getAppName());
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/AppAuthServiceTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/AppAuthServiceTest.java
index 0d8f736d59..8c86f7c729 100644
---
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/AppAuthServiceTest.java
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/AppAuthServiceTest.java
@@ -19,6 +19,7 @@ package org.apache.shenyu.admin.service;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.admin.listener.DataChangedEvent;
import org.apache.shenyu.admin.mapper.AppAuthMapper;
import org.apache.shenyu.admin.mapper.AuthParamMapper;
import org.apache.shenyu.admin.mapper.AuthPathMapper;
@@ -48,6 +49,7 @@ import org.apache.shenyu.common.utils.UUIDUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
@@ -65,6 +67,7 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.doNothing;
@@ -109,6 +112,28 @@ public final class AppAuthServiceTest {
testApplyUpdateSuccess();
}
+ @Test
+ public void testApplyUpdatePreservesOpenWhenOmitted() {
+ final AuthApplyDTO authApplyDTO = buildAuthApplyDTO();
+ authApplyDTO.setOpen(null);
+ authApplyDTO.setPathList(null);
+ appAuthDO.setOpen(true);
+
given(appAuthMapper.findByAppKey(appAuthDO.getAppKey())).willReturn(appAuthDO);
+ given(authParamMapper.findByAuthIdAndAppName(appAuthDO.getId(),
authApplyDTO.getAppName()))
+ .willReturn(AuthParamDO.create(appAuthDO.getId(),
authApplyDTO.getAppName(), authApplyDTO.getAppParam()));
+
given(authPathMapper.findByAuthId(appAuthDO.getId())).willReturn(Collections.emptyList());
+
given(authParamMapper.findByAuthId(appAuthDO.getId())).willReturn(Collections.emptyList());
+
+ ShenyuAdminResult result = appAuthService.applyUpdate(authApplyDTO);
+
+ assertEquals(ShenyuResultMessage.UPDATE_SUCCESS, result.getMessage());
+ verify(appAuthMapper).updateSelective(argThat(updated ->
Boolean.TRUE.equals(updated.getOpen())));
+ ArgumentCaptor<DataChangedEvent> eventCaptor =
ArgumentCaptor.forClass(DataChangedEvent.class);
+ verify(eventPublisher).publishEvent(eventCaptor.capture());
+ AppAuthData publishedData = (AppAuthData)
eventCaptor.getValue().getSource().get(0);
+ assertEquals(Boolean.TRUE, publishedData.getOpen());
+ }
+
@Test
public void testUpdateDetail() {
AppAuthDTO appAuthDTO =
buildAppAuthDTO(UUIDUtils.getInstance().generateShortUuid());
@@ -331,7 +356,8 @@ public final class AppAuthServiceTest {
}
private void testApplyUpdateSuccess() {
- AuthApplyDTO authApplyDTO = buildAuthApplyDTO();
+ final AuthApplyDTO authApplyDTO = buildAuthApplyDTO();
+ appAuthDO.setOpen(false);
AuthPathDO authPathDO = new AuthPathDO();
String authPathDoId = UUIDUtils.getInstance().generateShortUuid();
String authPathDOAuthId = UUIDUtils.getInstance().generateShortUuid();
@@ -346,8 +372,18 @@ public final class AppAuthServiceTest {
given(this.appAuthMapper.findByAppKey(appAuthDO.getAppKey())).willReturn(appAuthDO);
given(authPathMapper.findByAuthId(eq(appAuthDO.getId()))).willReturn(Collections.singletonList(authPathDO));
given(authParamMapper.findByAuthId(eq(appAuthDO.getId()))).willReturn(authParamDOList);
- ShenyuAdminResult successResult =
this.appAuthService.applyUpdate(buildAuthApplyDTO());
+ ShenyuAdminResult successResult =
this.appAuthService.applyUpdate(authApplyDTO);
assertEquals(ShenyuResultMessage.UPDATE_SUCCESS,
successResult.getMessage());
+ verify(appAuthMapper).updateSelective(argThat(updated ->
authApplyDTO.getUserId().equals(updated.getUserId())
+ && authApplyDTO.getPhone().equals(updated.getPhone())
+ && authApplyDTO.getExtInfo().equals(updated.getExtInfo())
+ && Boolean.TRUE.equals(updated.getOpen())));
+ verify(authPathMapper).batchSave(argThat(paths -> paths.size() == 1
+ &&
authApplyDTO.getPathList().get(0).equals(paths.get(0).getPath())));
+ ArgumentCaptor<DataChangedEvent> eventCaptor =
ArgumentCaptor.forClass(DataChangedEvent.class);
+ verify(eventPublisher).publishEvent(eventCaptor.capture());
+ AppAuthData publishedData = (AppAuthData)
eventCaptor.getValue().getSource().get(0);
+ assertEquals(Boolean.TRUE, publishedData.getOpen());
}
private AuthApplyDTO buildAuthApplyDTO() {