Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Disabled users are able to login #264

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
select
<include refid="Base_Column_List"/>
from `user`
where username = #{username,jdbcType=VARCHAR} and password = #{password,jdbcType=VARCHAR}
where status = 0 and username = #{username,jdbcType=VARCHAR} and password = #{password,jdbcType=VARCHAR}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

status=1 semantically makes sense for a user to be enabled, 0 should be considered disabled. Can we please check, what changes would be required for the same?

we can revisit UserServiceImpl#add

</select>
<select id="queryEnabledUsers" resultType="org.apache.seatunnel.app.dal.entity.User">
select
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public enum SeatunnelErrorEnum {

USERNAME_PASSWORD_NO_MATCHED(
10007,
"username and password no matched",
"The user name and password do not match, please check your input"),
"username and password no matched or user is disabled.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix the typo,

Suggested change
"username and password no matched or user is disabled.",
"username and password not matched or user is disabled."

"The user name and password do not match or user is disabled, please check your input"),

TOKEN_ILLEGAL(10008, "token illegal", "The token is expired or invalid, please login again."),
NO_SUCH_JOB(10009, "no such job", "No such job. Maybe deleted by others."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
public class SeatunnelWebTestingBase {
protected final String baseUrl = "http://localhost:8802/seatunnel/api/v1";

protected Result<UserSimpleInfoRes> login(UserLoginReq userLoginReq) {
public Result<UserSimpleInfoRes> login(UserLoginReq userLoginReq) {
String requestBody = JsonUtils.toJsonString(userLoginReq);
String response = sendRequest(url("user/login"), requestBody, "POST");
return JSONTestUtils.parseObject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@
import org.apache.seatunnel.app.controller.UserControllerWrapper;
import org.apache.seatunnel.app.domain.request.user.AddUserReq;
import org.apache.seatunnel.app.domain.request.user.UpdateUserReq;
import org.apache.seatunnel.app.domain.request.user.UserLoginReq;
import org.apache.seatunnel.app.domain.response.user.AddUserRes;
import org.apache.seatunnel.app.domain.response.user.UserSimpleInfoRes;
import org.apache.seatunnel.server.common.SeatunnelErrorEnum;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -95,6 +100,36 @@ public void listUsers_shouldReturnUsers_whenUsersExist() {
assertNotNull(result.getData());
}

@Test
public void disabledUser_shouldNotBeAbleToLogin() {
String user = "disabledUser" + uniqueId;
String pass = "pass4";
AddUserReq addUserReq = getAddUserReq(user, pass);
Result<AddUserRes> result = userControllerWrapper.addUser(addUserReq);
assertTrue(result.isSuccess());

// Disable the user
UpdateUserReq updateUserReq = new UpdateUserReq();
updateUserReq.setUsername(user);
updateUserReq.setUserId(result.getData().getId());
updateUserReq.setPassword(pass);
updateUserReq.setStatus((byte) 1);
updateUserReq.setType((byte) 0);
Result<Void> disableUserResult =
userControllerWrapper.updateUser(
Long.toString(result.getData().getId()), updateUserReq);
assertTrue(disableUserResult.isSuccess());

// Attempt to login with the disabled user
UserLoginReq loginReq = new UserLoginReq();
loginReq.setUsername(user);
loginReq.setPassword(pass);
Result<UserSimpleInfoRes> loginResult = userControllerWrapper.login(loginReq);
assertFalse(loginResult.isSuccess());
assertEquals(
SeatunnelErrorEnum.USERNAME_PASSWORD_NO_MATCHED.getCode(), loginResult.getCode());
}

@AfterAll
public static void tearDown() {
Result<Void> logout = userControllerWrapper.logout();
Expand Down
Loading