From 999e36c3fddc07fee840595f11b583c51d71aa65 Mon Sep 17 00:00:00 2001 From: lhw414 Date: Tue, 2 Jan 2024 21:28:57 +0900 Subject: [PATCH] =?UTF-8?q?Fix=20:=20=EB=B9=8C=EB=93=9C=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EC=95=88=EB=82=98=EB=8F=84=EB=A1=9D=20#5=20?= =?UTF-8?q?=EC=9D=B4=EC=A0=84=EC=9C=BC=EB=A1=9C=20Rollback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team3server/user/dto/LocalLoginRequest.kt | 6 -- .../user/dto/LocalLoginResponse.kt | 7 --- .../user/repository/UserRepository.kt | 4 +- .../team3server/user/service/UserService.kt | 10 +-- .../user/service/UserServiceImpl.kt | 18 +----- .../team3server/auth/LoginServiceTest.kt | 62 ------------------- 6 files changed, 3 insertions(+), 104 deletions(-) delete mode 100644 src/main/kotlin/com/everywaffle/team3server/user/dto/LocalLoginRequest.kt delete mode 100644 src/main/kotlin/com/everywaffle/team3server/user/dto/LocalLoginResponse.kt delete mode 100644 src/test/kotlin/com/everywaffle/team3server/auth/LoginServiceTest.kt diff --git a/src/main/kotlin/com/everywaffle/team3server/user/dto/LocalLoginRequest.kt b/src/main/kotlin/com/everywaffle/team3server/user/dto/LocalLoginRequest.kt deleted file mode 100644 index c752e1b..0000000 --- a/src/main/kotlin/com/everywaffle/team3server/user/dto/LocalLoginRequest.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.everywaffle.team3server.user.dto - -data class LocalLoginRequest( - val id: String, - val password: String, -) diff --git a/src/main/kotlin/com/everywaffle/team3server/user/dto/LocalLoginResponse.kt b/src/main/kotlin/com/everywaffle/team3server/user/dto/LocalLoginResponse.kt deleted file mode 100644 index c282e7c..0000000 --- a/src/main/kotlin/com/everywaffle/team3server/user/dto/LocalLoginResponse.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.everywaffle.team3server.user.dto - -data class LocalLoginResponse( - val userId: String, - val token: String, - val message: String = "ok", -) diff --git a/src/main/kotlin/com/everywaffle/team3server/user/repository/UserRepository.kt b/src/main/kotlin/com/everywaffle/team3server/user/repository/UserRepository.kt index 284647f..16f22c3 100644 --- a/src/main/kotlin/com/everywaffle/team3server/user/repository/UserRepository.kt +++ b/src/main/kotlin/com/everywaffle/team3server/user/repository/UserRepository.kt @@ -3,6 +3,4 @@ package com.everywaffle.team3server.user.repository import com.everywaffle.team3server.user.model.UserEntity import org.springframework.data.jpa.repository.JpaRepository -interface UserRepository : JpaRepository { - fun findByUserId(id: String): UserEntity? -} \ No newline at end of file +interface UserRepository : JpaRepository \ No newline at end of file diff --git a/src/main/kotlin/com/everywaffle/team3server/user/service/UserService.kt b/src/main/kotlin/com/everywaffle/team3server/user/service/UserService.kt index 3aa3ab6..aeeb370 100644 --- a/src/main/kotlin/com/everywaffle/team3server/user/service/UserService.kt +++ b/src/main/kotlin/com/everywaffle/team3server/user/service/UserService.kt @@ -1,11 +1,3 @@ package com.everywaffle.team3server.user.service -import com.everywaffle.team3server.user.dto.LocalLoginRequest -import com.everywaffle.team3server.user.dto.LocalLoginResponse - - -interface UserService { - fun localLogin(localLoginRequest: LocalLoginRequest): LocalLoginResponse? - fun authenticate(username: String, password: String) - // TODO: 다른 메서드 정의 -} +interface UserService \ No newline at end of file diff --git a/src/main/kotlin/com/everywaffle/team3server/user/service/UserServiceImpl.kt b/src/main/kotlin/com/everywaffle/team3server/user/service/UserServiceImpl.kt index 3bb3541..b3570e2 100644 --- a/src/main/kotlin/com/everywaffle/team3server/user/service/UserServiceImpl.kt +++ b/src/main/kotlin/com/everywaffle/team3server/user/service/UserServiceImpl.kt @@ -1,22 +1,6 @@ package com.everywaffle.team3server.user.service -import com.everywaffle.team3server.auth.JwtTokenProvider -import com.everywaffle.team3server.user.dto.LocalLoginRequest -import com.everywaffle.team3server.user.dto.LocalLoginResponse -import com.everywaffle.team3server.user.repository.UserRepository -import org.springframework.security.crypto.password.PasswordEncoder import org.springframework.stereotype.Service @Service -class UserServiceImpl( - private val userRepository: UserRepository, - private val passwordEncoder: PasswordEncoder, - private val jwtTokenProvider: JwtTokenProvider -) : UserService{ - override fun localLogin(localLoginRequest: LocalLoginRequest): LocalLoginResponse? { - TODO("Not yet implemented") - } - override fun authenticate(username: String, password: String) { - TODO("Not yet implemented") - } -} \ No newline at end of file +class UserServiceImpl \ No newline at end of file diff --git a/src/test/kotlin/com/everywaffle/team3server/auth/LoginServiceTest.kt b/src/test/kotlin/com/everywaffle/team3server/auth/LoginServiceTest.kt deleted file mode 100644 index 3c51dd7..0000000 --- a/src/test/kotlin/com/everywaffle/team3server/auth/LoginServiceTest.kt +++ /dev/null @@ -1,62 +0,0 @@ -package com.everywaffle.team3server.auth - -import com.everywaffle.team3server.user.dto.LocalLoginRequest -import com.everywaffle.team3server.user.model.UserEntity -import com.everywaffle.team3server.user.repository.UserRepository -import com.everywaffle.team3server.user.service.UserServiceImpl -import org.junit.jupiter.api.Assertions.assertNotNull -import org.junit.jupiter.api.Assertions.assertNull -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -import org.mockito.Mock -import org.mockito.kotlin.whenever -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.security.crypto.password.PasswordEncoder - - -@SpringBootTest -class LoginServiceTest { - @Mock - private lateinit var userRepository: UserRepository - - @Mock - private lateinit var passwordEncoder: PasswordEncoder - - @Mock - private lateinit var jwtTokenProvider: JwtTokenProvider - - private lateinit var userService: UserServiceImpl - - @BeforeEach - fun setUp() { - userService = UserServiceImpl(userRepository, passwordEncoder, jwtTokenProvider) - } - @Test - fun `자체 로그인 시 유효한 자격의 경우 Null 반환하지 않아야 한다`() { - val loginRequest = LocalLoginRequest(id = "user", password = "password") - val userEntity = UserEntity(userName = loginRequest.id, password = "encodedPassword", email = "dummy@email.com") - val jwtToken = "jwtToken" - - whenever(userRepository.findByUserId(loginRequest.id)).thenReturn(userEntity) - whenever(passwordEncoder.matches(loginRequest.password, userEntity.password)).thenReturn(true) - whenever(jwtTokenProvider.createToken(loginRequest.id)).thenReturn(jwtToken) - - val result = userService.localLogin(loginRequest) - - assertNotNull(result) - result?.let { - assert(it.userId == loginRequest.id) - assert(it.token == jwtToken) - } - } - @Test - fun `자체 로그인 시 유효하지 않은 자격의 경우 Null을 반환해야한다`() { - val loginRequest = LocalLoginRequest(id = "user", password = "wrongPassword") - - whenever(userRepository.findByUserId(loginRequest.id)).thenReturn(null) - - val result = userService.localLogin(loginRequest) - - assertNull(result, "No response should be returned for invalid credentials") - } -}