You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by li...@apache.org on 2023/06/12 01:23:21 UTC

[shenyu] branch master updated: fix password rule that it not think =_+- are special characters (#4727)

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

likeguo 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 e18d032f0 fix password rule that it not think =_+- are special characters (#4727)
e18d032f0 is described below

commit e18d032f071998763909677d7a6c663ac6eb6466
Author: tomsun28 <to...@outlook.com>
AuthorDate: Mon Jun 12 09:23:15 2023 +0800

    fix password rule that it not think =_+- are special characters (#4727)
    
    * fix password rule that it not think =_+- are special characters
    
    * add modifyPassword unit test
    
    * fix warning
---
 .../shenyu/admin/model/constant/RegConstant.java   |  2 +-
 .../model/dto/DashboardUserModifyPasswordDTO.java  |  7 ++++
 .../controller/DashboardUserControllerTest.java    | 38 +++++++++++++++++++++-
 3 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/constant/RegConstant.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/constant/RegConstant.java
index eaa3c408b..848e8fe86 100644
--- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/constant/RegConstant.java
+++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/constant/RegConstant.java
@@ -25,7 +25,7 @@ public final class RegConstant {
     /**
      * Minimum length of 8, including upper and lower case letters, numbers and special characters.
      */
-    public static final String PASSWORD_RULE = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@$!%*?&])[A-Za-z\\d@$!%*?&]{8,}$";
+    public static final String PASSWORD_RULE = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@$!%*?&=_+-])[A-Za-z\\d@$!%*?&=_+-]{8,}$";
     
     
     /**
diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/DashboardUserModifyPasswordDTO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/DashboardUserModifyPasswordDTO.java
index 4cba4dca8..6aec394e3 100644
--- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/DashboardUserModifyPasswordDTO.java
+++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/DashboardUserModifyPasswordDTO.java
@@ -61,6 +61,13 @@ public class DashboardUserModifyPasswordDTO implements Serializable {
         this.password = password;
     }
     
+    public DashboardUserModifyPasswordDTO(final String id, final String userName, final String password, final String oldPassword) {
+        this.id = id;
+        this.userName = userName;
+        this.password = password;
+        this.oldPassword = oldPassword;
+    }
+    
     /**
      * Gets the value of id.
      *
diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/DashboardUserControllerTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/DashboardUserControllerTest.java
index 4aecd5c60..b1ffe4b90 100644
--- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/DashboardUserControllerTest.java
+++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/DashboardUserControllerTest.java
@@ -19,6 +19,7 @@ package org.apache.shenyu.admin.controller;
 
 import org.apache.shenyu.admin.model.custom.UserInfo;
 import org.apache.shenyu.admin.model.dto.DashboardUserDTO;
+import org.apache.shenyu.admin.model.dto.DashboardUserModifyPasswordDTO;
 import org.apache.shenyu.admin.model.page.CommonPager;
 import org.apache.shenyu.admin.model.page.PageParameter;
 import org.apache.shenyu.admin.model.vo.DashboardUserEditVO;
@@ -28,6 +29,10 @@ import org.apache.shenyu.admin.service.DashboardUserService;
 import org.apache.shenyu.admin.utils.SessionUtil;
 import org.apache.shenyu.admin.utils.ShenyuResultMessage;
 import org.apache.shenyu.common.utils.GsonUtils;
+import org.apache.shiro.mgt.DefaultSecurityManager;
+import org.apache.shiro.subject.SimplePrincipalMap;
+import org.apache.shiro.subject.Subject;
+import org.apache.shiro.util.ThreadContext;
 import org.assertj.core.util.Lists;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -79,7 +84,10 @@ public final class DashboardUserControllerTest {
 
     private final DashboardUserDTO dashboardUserDTO = new DashboardUserDTO("2", "userName",
             "Admin@123", 0, Lists.newArrayList("1"), false);
-
+    
+    private final DashboardUserModifyPasswordDTO modifyPasswordDTO = new DashboardUserModifyPasswordDTO("2", 
+            "admin", "ShenYu=123", "ShenYu=123");
+    
     @BeforeEach
     public void setUp() throws Exception {
         mockMvc = MockMvcBuilders.standaloneSetup(dashboardUserController).build();
@@ -164,4 +172,32 @@ public final class DashboardUserControllerTest {
                 .andExpect(jsonPath("$.message", is(ShenyuResultMessage.DELETE_SUCCESS)))
                 .andExpect(jsonPath("$.data", is(0)));
     }
+    
+    @Test
+    public void modifyPassword() throws Exception {
+        final String url = "/dashboardUser/modify-password/2";
+        UserInfo userInfo = UserInfo.builder().userId("2").userName("admin").build();
+        SimplePrincipalMap principalMap = new SimplePrincipalMap();
+        principalMap.put("real", userInfo);
+        ThreadContext.bind(new DefaultSecurityManager());
+        ThreadContext.bind(new Subject.Builder().principals(principalMap).buildSubject());
+        
+        given(dashboardUserService.modifyPassword(any())).willReturn(1);
+        mockMvc.perform(put(url, modifyPasswordDTO)
+                        .content(GsonUtils.getInstance().toJson(modifyPasswordDTO))
+                        .contentType(MediaType.APPLICATION_JSON))
+                .andExpect(status().isOk())
+                .andDo(print())
+                .andExpect(jsonPath("$.message", is(ShenyuResultMessage.UPDATE_SUCCESS)))
+                .andExpect(jsonPath("$.data", is(1)));
+        
+        ThreadContext.bind(new Subject.Builder().principals(new SimplePrincipalMap()).buildSubject());
+        mockMvc.perform(put(url, modifyPasswordDTO)
+                        .content(GsonUtils.getInstance().toJson(modifyPasswordDTO))
+                        .contentType(MediaType.APPLICATION_JSON))
+                .andExpect(status().isOk())
+                .andDo(print())
+                .andExpect(jsonPath("$.message", is(ShenyuResultMessage.DASHBOARD_USER_LOGIN_ERROR)));
+        
+    }
 }