Skip to content

Commit

Permalink
!hotfix: 디바이스 토큰 cascade 설정 삭제 (#447)
Browse files Browse the repository at this point in the history
* fix: 디바이스 토큰 cascade 설정 삭제

* refactor: 디바이스 토큰 영속 시 문자열 널 검증 추가
  • Loading branch information
kwonyj1022 authored and swonny committed Oct 6, 2023
1 parent 4305dbe commit b674daa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class DeviceTokenService {
@Transactional
public void persist(final Long userId, final PersistDeviceTokenDto deviceTokenDto) {
final String newDeviceToken = deviceTokenDto.deviceToken();
if (newDeviceToken.isBlank()) {
if (newDeviceToken == null || newDeviceToken.isBlank()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.ddang.ddang.device.domain;

import com.ddang.ddang.user.domain.User;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
Expand All @@ -28,7 +27,7 @@ public class DeviceToken {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@OneToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", foreignKey = @ForeignKey(name = "fk_device_token_user"))
private User user;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.ddang.ddang.configuration.IsolateDatabase;
import com.ddang.ddang.device.application.DeviceTokenService;
import com.ddang.ddang.device.application.dto.PersistDeviceTokenDto;
import com.ddang.ddang.device.domain.DeviceToken;
import com.ddang.ddang.device.infrastructure.persistence.JpaDeviceTokenRepository;
import com.ddang.ddang.image.application.exception.ImageNotFoundException;
import com.ddang.ddang.image.domain.ProfileImage;
Expand Down Expand Up @@ -42,7 +43,6 @@
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willDoNothing;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;

Expand Down Expand Up @@ -76,10 +76,10 @@ class AuthenticationServiceTest {
TokenDecoder tokenDecoder;

@Autowired
BlackListTokenService mockBlackListTokenService;
BlackListTokenService blackListTokenService;

@Autowired
JpaDeviceTokenRepository mockDeviceTokenRepository;
JpaDeviceTokenRepository deviceTokenRepository;

@Autowired
JwtEncoder jwtEncoder;
Expand All @@ -95,17 +95,15 @@ void setUp(
) {
mockProvider = mock(OAuth2UserInformationProvider.class);
mockProviderComposite = mock(Oauth2UserInformationProviderComposite.class);
mockBlackListTokenService = mock(BlackListTokenService.class);
mockDeviceTokenRepository = mock(JpaDeviceTokenRepository.class);
authenticationService = new AuthenticationService(
deviceTokenService,
mockProviderComposite,
userRepository,
profileImageRepository,
tokenEncoder,
tokenDecoder,
mockBlackListTokenService,
mockDeviceTokenRepository
blackListTokenService,
deviceTokenRepository
);

doNothing().when(deviceTokenService).persist(anyLong(), any(PersistDeviceTokenDto.class));
Expand Down Expand Up @@ -335,6 +333,9 @@ void setUp(

userRepository.save(user);

final DeviceToken deviceToken = new DeviceToken(user, "test");
deviceTokenRepository.save(deviceToken);

final Map<String, Object> privateClaims = Map.of("userId", 1L);
final String accessToken = "Bearer " + tokenEncoder.encode(
LocalDateTime.now(),
Expand All @@ -351,8 +352,6 @@ void setUp(

given(mockProviderComposite.findProvider(Oauth2Type.KAKAO)).willReturn(mockProvider);
given(mockProvider.findUserInformation(anyString())).willReturn(userInformationDto);
willDoNothing().given(mockDeviceTokenRepository).deleteById(anyLong());
willDoNothing().given(mockBlackListTokenService).registerBlackListToken(anyString(), anyString());

// when
authenticationService.withdrawal(Oauth2Type.KAKAO, accessToken, refreshToken);
Expand Down

0 comments on commit b674daa

Please sign in to comment.