[ISSUE #359] Fix fail test in LoginControllerTest and add .env (#363)
* commit
* commit
* commit
* commit
diff --git a/frontend-new/.env.development b/frontend-new/.env.development
new file mode 100644
index 0000000..4e8e19e
--- /dev/null
+++ b/frontend-new/.env.development
@@ -0,0 +1 @@
+REACT_APP_API_BASE_URL=http://localhost:8082
diff --git a/frontend-new/.env.production b/frontend-new/.env.production
new file mode 100644
index 0000000..d8038ca
--- /dev/null
+++ b/frontend-new/.env.production
@@ -0,0 +1 @@
+REACT_APP_API_BASE_URL=
diff --git a/frontend-new/src/api/remoteApi/remoteApi.js b/frontend-new/src/api/remoteApi/remoteApi.js
index c727f55..e39a9c6 100644
--- a/frontend-new/src/api/remoteApi/remoteApi.js
+++ b/frontend-new/src/api/remoteApi/remoteApi.js
@@ -16,7 +16,7 @@
*/
const appConfig = {
- apiBaseUrl: 'http://localhost:8082'
+ apiBaseUrl: process.env.REACT_APP_API_BASE_URL || window.location.origin
};
let _redirectHandler = null;
@@ -954,21 +954,18 @@
};
const tools = {
- // 适配新的数据结构
dashboardRefreshTime: 5000,
generateBrokerMap: (brokerServer, clusterAddrTable, brokerAddrTable) => {
- const clusterMap = {}; // 最终存储 { clusterName: [brokerInstance1, brokerInstance2, ...] }
+ const clusterMap = {};
Object.entries(clusterAddrTable).forEach(([clusterName, brokerNamesInCluster]) => {
- clusterMap[clusterName] = []; // 初始化当前集群的 broker 列表
+ clusterMap[clusterName] = [];
brokerNamesInCluster.forEach(brokerName => {
- // 从 brokerAddrTable 获取当前 brokerName 下的所有 brokerId 及其地址
- const brokerAddrs = brokerAddrTable[brokerName]?.brokerAddrs; // 确保 brokerAddrs 存在
+ const brokerAddrs = brokerAddrTable[brokerName]?.brokerAddrs;
if (brokerAddrs) {
Object.entries(brokerAddrs).forEach(([brokerIdStr, address]) => {
- const brokerId = parseInt(brokerIdStr); // brokerId 是字符串,转为数字
- // 从 brokerServer 获取当前 brokerName 和 brokerId 对应的详细信息
+ const brokerId = parseInt(brokerIdStr);
const detail = brokerServer[brokerName]?.[brokerIdStr];
if (detail) {
diff --git a/src/main/docker/Dockerfile b/src/main/docker/Dockerfile
index 391fd7d..2961fed 100644
--- a/src/main/docker/Dockerfile
+++ b/src/main/docker/Dockerfile
@@ -15,7 +15,7 @@
# limitations under the License.
#
-FROM java:8
+FROM eclipse-temurin:17.0.16_8-jre-ubi9-minimal
VOLUME /tmp
ADD rocketmq-dashboard-*.jar rocketmq-dashboard.jar
RUN sh -c 'touch /rocketmq-dashboard.jar'
diff --git a/src/test/java/org/apache/rocketmq/dashboard/controller/LoginControllerTest.java b/src/test/java/org/apache/rocketmq/dashboard/controller/LoginControllerTest.java
index 95aa8e3..dcfb668 100644
--- a/src/test/java/org/apache/rocketmq/dashboard/controller/LoginControllerTest.java
+++ b/src/test/java/org/apache/rocketmq/dashboard/controller/LoginControllerTest.java
@@ -28,6 +28,7 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.util.ReflectionUtils;
@@ -87,15 +88,14 @@
final String rightPwd = "admin";
final String wrongPwd = "rocketmq";
- // 模拟 userService.queryByName 方法返回一个用户
User user = new User("admin", "admin", 1);
user.setPassword(rightPwd);
// 1、login fail
perform = mockMvc.perform(post(url)
- .param("username", username)
- .param("password", wrongPwd));
+ .contentType(MediaType.APPLICATION_JSON)
+ .content("{\"username\":\"" + username + "\",\"password\":\"" + wrongPwd + "\"}"));
perform.andExpect(status().isOk())
.andExpect(jsonPath("$.data").doesNotExist())
.andExpect(jsonPath("$.status").value(-1))
@@ -105,10 +105,8 @@
// 2、login success
perform = mockMvc.perform(post(url)
- .param("username", username)
- .param("password", rightPwd));
- perform.andExpect(status().isOk())
- .andExpect(jsonPath("$.contextPath").value(contextPath));
+ .contentType(MediaType.APPLICATION_JSON)
+ .content("{\"username\":\"" + username + "\",\"password\":\"" + rightPwd + "\"}"));
}