Commit a8fcb366 authored by Jyrgen Hannus's avatar Jyrgen Hannus
Browse files

technical-debt: resolved code smells, refactored code, replaced deprecated...

technical-debt: resolved code smells, refactored code, replaced deprecated functionality with currently applicable ones, resolved NPE situations with better error handling
parent fee1b85e
......@@ -7,6 +7,7 @@ import ee.sm.ti.teis.servicecommon.config.PropertyLogger;
import org.camunda.bpm.spring.boot.starter.annotation.EnableProcessApplication;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Import;
@SpringBootApplication
......@@ -15,6 +16,7 @@ import org.springframework.context.annotation.Import;
ExchangeConfig.class,
QueueConfigurator.class,
DataSourceConfig.class})
@EnableConfigurationProperties
public class CommonApiGateway {
public static void main(String[] args) {
SpringApplication.run(CommonApiGateway.class, args);
......
......@@ -44,7 +44,7 @@ public class FileContentService {
private final FileMetaProcessingService fileMetaProcessingService;
private final FileProcessingService fileProcessingService;
@Value("${teis.file.file-reference.update-timeout}")
private final int fileReferenceUpdateTimeout = 5000;
private int fileReferenceUpdateTimeout;
@Value("${minio.bucket}")
private String bucketName;
@Value("${minio.bucket-thumbnail}")
......
package ee.sm.ti.teis.commongateway.security.auth;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "teis.auth-user-info-api")
@Getter
@Setter
public class AuthUserInfoProperties {
private String url;
private String secret;
private String userInfoPath;
private String mockUserInfoPath;
private String officeUserInfoPath;
private String mockOfficeUserInfoPath;
}
......@@ -23,9 +23,12 @@ import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import static ee.sm.ti.teis.commongateway.security.auth.GrantType.AUTHORIZATION_CODE;
import static ee.sm.ti.teis.commongateway.security.auth.GrantType.REFRESH_TOKEN;
import static ee.sm.ti.teis.servicerequest.UserType.SYSTEM;
import static org.apache.commons.lang.StringUtils.defaultString;
import static org.apache.commons.lang.StringUtils.isEmpty;
import static org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED;
@Service
@Slf4j
......@@ -33,10 +36,12 @@ public class KeycloakTokenService {
private static final String OFFICE_ROLES_SCOPE = "TeIS_Office_Roles";
private static final String PORTAL_ROLES_SCOPE = "TeIS_Roles";
private final JwtDecoder jwtDecoder;
private final PersonProcessingService personProcessingService;
private final AuthProperties authProperties;
private final AuthConfig authConfig;
@Value("${teis.system.name}")
private String systemName;
......@@ -61,7 +66,7 @@ public class KeycloakTokenService {
public OAuthToken exchangeAccessTokenRequest(TokenRequest tokenRequest, RequestMetaDTO requestMetaDTO) {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = getHttpHeaders(MediaType.APPLICATION_FORM_URLENCODED);
HttpHeaders headers = getHttpHeaders(APPLICATION_FORM_URLENCODED);
MultiValueMap<String, String> keycloakTokenRequest = getAccessTokenRequestParams(tokenRequest);
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(keycloakTokenRequest, headers);
log.debug("Get access token with parameters: " + keycloakTokenRequest.toString());
......@@ -69,12 +74,15 @@ public class KeycloakTokenService {
ResponseEntity<OAuthToken> response = restTemplate.exchange(getAuthConfig().getTokenEndpoint(),
HttpMethod.POST, request, OAuthToken.class);
OAuthToken keycloakToken = response.getBody();
if (tokenRequest.getGrantType() == GrantType.AUTHORIZATION_CODE
if (keycloakToken == null) {
throw new IllegalArgumentException("Key cloak token missing from request");
}
if (tokenRequest.getGrantType() == AUTHORIZATION_CODE
&& isPortalRequest(tokenRequest.getClientId())) {
boolean personNameUpdated = updatePersonNameIfChanged(keycloakToken, requestMetaDTO);
if (personNameUpdated) {
tokenRequest.setRefreshToken(keycloakToken.getRefreshToken());
tokenRequest.setGrantType(GrantType.REFRESH_TOKEN);
tokenRequest.setGrantType(REFRESH_TOKEN);
keycloakTokenRequest = getAccessTokenRequestParams(tokenRequest);
request = new HttpEntity<>(keycloakTokenRequest, headers);
log.info("Get new access token with updated Person name using refresh token with parameters: "
......@@ -93,7 +101,7 @@ public class KeycloakTokenService {
public void logout(LogoutRequest logoutRequest, RequestMetaDTO requestMetaDTO) {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = getHttpHeaders(MediaType.APPLICATION_FORM_URLENCODED);
HttpHeaders headers = getHttpHeaders(APPLICATION_FORM_URLENCODED);
MultiValueMap<String, String> keycloakLogoutRequest = getLogoutRequestParams(logoutRequest);
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(keycloakLogoutRequest, headers);
log.debug("Logout user with parameters: " + keycloakLogoutRequest.toString());
......@@ -153,10 +161,10 @@ public class KeycloakTokenService {
MultiValueMap<String, String> requestParams = new LinkedMultiValueMap<>();
addClientIdParam(tokenRequest.getClientId(), requestParams);
requestParams.add("grant_type", tokenRequest.getGrantType().getValue());
if (tokenRequest.getGrantType() == GrantType.AUTHORIZATION_CODE) {
if (tokenRequest.getGrantType() == AUTHORIZATION_CODE) {
requestParams.add("redirect_uri", tokenRequest.getRedirectUri());
requestParams.add("code", tokenRequest.getCode());
} else if (tokenRequest.getGrantType() == GrantType.REFRESH_TOKEN) {
} else if (tokenRequest.getGrantType() == REFRESH_TOKEN) {
requestParams.add("refresh_token", tokenRequest.getRefreshToken());
}
String scopesStr = defaultString(tokenRequest.getScope());
......
package ee.sm.ti.teis.commongateway.security.mock;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "teis.mockauth")
@Getter
@Setter
public class MockAuthProperties {
private String tokenSecret;
private Long expire;
}
......@@ -4,15 +4,16 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import ee.sm.ti.teis.ErrorDTO;
import ee.sm.ti.teis.commongateway.auth.AuthServiceUserInfo;
import ee.sm.ti.teis.commongateway.person.PersonProcessingService;
import ee.sm.ti.teis.commongateway.security.auth.AuthUserInfoProperties;
import ee.sm.ti.teis.exceptions.TeisRestException;
import ee.sm.ti.teis.security.JwtUserInfo;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtParser;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.security.Keys;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.http.HttpEntity;
......@@ -23,62 +24,25 @@ import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import java.security.Key;
import java.util.Date;
import java.util.Map;
import static io.jsonwebtoken.io.Decoders.BASE64;
import static org.apache.commons.lang3.StringUtils.isEmpty;
@Component
@Profile({"mockauth", "local", "integtest"})
@Slf4j
@RequiredArgsConstructor
public class MockAuthService {
private final PersonProcessingService personProcessingService;
private final Long expirationTime;
private final String tokenSecret;
private final String authApiUrl;
private final String authApiSecret;
private final String teisClaimName;
private final String authApiUserInfoPath;
private final String authApiMockUserInfoPath;
private final String authApiOfficeUserInfoPath;
private final String authApiMockOfficeUserInfoPath;
private final RestTemplate restTemplate;
@Autowired
public MockAuthService(
RestTemplate restTemplate,
PersonProcessingService personProcessingService,
@Value("${teis.mockauth.token-secret}")
String tokenSecret,
@Value("${teis.mockauth.expire:86400}")
Long expirationTime,
@Value("${teis.auth-user-info-api.url}")
String authApiUrl,
@Value("${teis.auth-user-info-api.secret}")
String authApiSecret,
@Value("${teis.auth-user-info-api.user-info-path}")
String authApiUserInfoPath,
@Value("${teis.auth-user-info-api.mock-user-info-path}")
String authApiMockUserInfoPath,
@Value("${teis.auth-user-info-api.office-user-info-path}")
String authApiOfficeUserInfoPath,
@Value("${teis.auth-user-info-api.mock-office-user-info-path}")
String authApiMockOfficeUserInfoPath,
@Value("${teis.oauth2.user-info-claim-name}")
String userInfoClaimName) {
this.restTemplate = restTemplate;
this.personProcessingService = personProcessingService;
this.tokenSecret = tokenSecret;
this.expirationTime = expirationTime;
this.authApiUrl = authApiUrl;
this.authApiSecret = authApiSecret;
this.authApiUserInfoPath = authApiUserInfoPath;
this.authApiMockUserInfoPath = authApiMockUserInfoPath;
this.teisClaimName = userInfoClaimName;
this.authApiOfficeUserInfoPath = authApiOfficeUserInfoPath;
this.authApiMockOfficeUserInfoPath = authApiMockOfficeUserInfoPath;
}
private final MockAuthProperties mockAuthProperties;
private final AuthUserInfoProperties authUserInfoProperties;
@Value("${teis.oauth2.user-info-claim-name}")
private String teisClaimName;
MockAuthResponse createMockAuthResponse(MockUserLoginRequest mockUser, RequestMetaDTO requestMetaDTO) {
// Get user info from Auth service
......@@ -112,7 +76,7 @@ public class MockAuthService {
}
String refreshToken(String accessToken, RequestMetaDTO requestMetaDTO) {
Claims tokenBody = Jwts.parser().setSigningKey(tokenSecret).parseClaimsJws(accessToken).getBody();
Claims tokenBody = Jwts.parser().setSigningKey(mockAuthProperties.getTokenSecret()).parseClaimsJws(accessToken).getBody();
String preferredUserName = (String) tokenBody.get("preferred_username");
if (isEmpty(preferredUserName)) {
throw new IllegalArgumentException("preferred_username field is empty in access token.");
......@@ -126,7 +90,7 @@ public class MockAuthService {
}
JwtUserInfo parseToken(String token) {
Claims body = Jwts.parser().setSigningKey(tokenSecret).parseClaimsJws(token).getBody();
Claims body = Jwts.parser().setSigningKey(mockAuthProperties.getTokenSecret()).parseClaimsJws(token).getBody();
Map<String, Object> userInfo = (Map<String, Object>) body.get(teisClaimName);
ObjectMapper mapper = new ObjectMapper();
return mapper.convertValue(userInfo, JwtUserInfo.class);
......@@ -135,8 +99,8 @@ public class MockAuthService {
private AuthServiceUserInfo getMockUserInfoFromAuthService(MockUserLoginRequest mockUser, boolean isOfficeUser) {
HttpHeaders headers = new HttpHeaders();
String personalCode = mockUser.getCountryCode().toLowerCase() + mockUser.getIdCode();
if (!isEmpty(authApiSecret)) {
headers.add("Authorization", authApiSecret);
if (!isEmpty(authUserInfoProperties.getSecret())) {
headers.add("Authorization", authUserInfoProperties.getSecret());
}
UriComponentsBuilder uriBuilder;
boolean hasMockRoles = mockUser.getRoles() != null && !mockUser.getRoles().isEmpty();
......@@ -149,7 +113,11 @@ public class MockAuthService {
try {
HttpEntity<AuthServiceUserInfo> userInfoResponse = restTemplate.exchange(uriBuilder.toUriString(),
HttpMethod.GET, request, AuthServiceUserInfo.class);
return userInfoResponse.getBody();
AuthServiceUserInfo userInfo = userInfoResponse.getBody();
if (userInfo == null) {
throw new IllegalArgumentException("User info missing from auth service");
}
return userInfo;
} catch (HttpStatusCodeException e) {
ErrorDTO errorDto = ErrorDTO.builder()
.httpResponse(e.getStatusCode())
......@@ -160,19 +128,21 @@ public class MockAuthService {
}
}
private UriComponentsBuilder composeUserInfoUri(MockUserLoginRequest mockUser, boolean isOfficeUser, boolean hasMockRoles, boolean hasMockPrivileges) {
private UriComponentsBuilder composeUserInfoUri(MockUserLoginRequest mockUser, boolean isOfficeUser,
boolean hasMockRoles, boolean hasMockPrivileges) {
UriComponentsBuilder uriBuilder;
if (isOfficeUser) {
if (hasMockRoles || hasMockPrivileges) {
uriBuilder = composeMockUri(mockUser, authApiMockOfficeUserInfoPath);
uriBuilder = composeMockUri(mockUser, authUserInfoProperties.getOfficeUserInfoPath());
} else {
uriBuilder = UriComponentsBuilder.fromHttpUrl(authApiUrl + authApiOfficeUserInfoPath);
uriBuilder = UriComponentsBuilder.fromHttpUrl(authUserInfoProperties.getUrl() +
authUserInfoProperties.getOfficeUserInfoPath());
}
} else {
if (mockUser.getSelectedCompanyRegCode() != null) {
uriBuilder = composeMockUri(mockUser, authApiMockUserInfoPath);
uriBuilder = composeMockUri(mockUser, authUserInfoProperties.getMockUserInfoPath());
} else {
uriBuilder = UriComponentsBuilder.fromHttpUrl(authApiUrl + authApiUserInfoPath);
uriBuilder = UriComponentsBuilder.fromHttpUrl(authUserInfoProperties.getUrl() + authUserInfoProperties.getUserInfoPath());
}
}
return uriBuilder;
......@@ -180,7 +150,7 @@ public class MockAuthService {
private UriComponentsBuilder composeMockUri(MockUserLoginRequest mockUser, String mockUserInfoPath) {
UriComponentsBuilder uriBuilder;
uriBuilder = UriComponentsBuilder.fromHttpUrl(authApiUrl + mockUserInfoPath);
uriBuilder = UriComponentsBuilder.fromHttpUrl(authUserInfoProperties.getUrl() + mockUserInfoPath);
if (mockUser.getRoles() != null && !mockUser.getRoles().isEmpty()) {
uriBuilder.queryParam("roles", String.join(",", mockUser.getRoles()));
}
......@@ -193,7 +163,6 @@ public class MockAuthService {
}
public String generateToken(MockUserLoginRequest mockUser, AuthServiceUserInfo authServiceUserInfo) {
JwtUserInfo userInfo = JwtUserInfo.builder()
.userId(authServiceUserInfo.getPersonId())
.idCode(authServiceUserInfo.getPersonalCode())
......@@ -220,15 +189,20 @@ public class MockAuthService {
.setClaims(claims)
.setIssuedAt(createdDate)
.setExpiration(expirationDate)
.signWith(SignatureAlgorithm.HS512, tokenSecret)
.signWith(getSigningKey())
.compact();
}
private Key getSigningKey() {
byte[] keyBytes = BASE64.decode(mockAuthProperties.getTokenSecret());
return Keys.hmacShaKeyFor(keyBytes);
}
private Date calculateExpirationDate(Date createdDate) {
return new Date(createdDate.getTime() + (expirationTime * 1000));
return new Date(createdDate.getTime() + (mockAuthProperties.getExpire() * 1000));
}
public JwtParser getMockJwtParser() {
return Jwts.parser().setSigningKey(tokenSecret);
return Jwts.parser().setSigningKey(mockAuthProperties.getTokenSecret());
}
}
......@@ -4,7 +4,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import ee.sm.ti.teis.gatewaycommon.security.TeisSecurityConfig;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import io.jsonwebtoken.JwsHeader;
import io.jsonwebtoken.JwtParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -42,12 +41,11 @@ public class MockSecurityConfig extends TeisSecurityConfig {
public Jwt decode(String token) {
try {
Jws<Claims> jwtParserClaims = mockJwtParser.parseClaimsJws(token);
JwsHeader headers = jwtParserClaims.getHeader();
Claims body = jwtParserClaims.getBody();
ObjectMapper mapper = new ObjectMapper();
return new Jwt(token, body.getIssuedAt().toInstant(), body.getExpiration().toInstant(),
mapper.convertValue(headers, Map.class), mapper.convertValue(body, Map.class));
mapper.convertValue(jwtParserClaims.getHeader(), Map.class), mapper.convertValue(body, Map.class));
} catch (Exception e) {
return defaultJwtDecoder == null ? null : defaultJwtDecoder.decode(token);
}
......
......@@ -3,13 +3,18 @@ package ee.sm.ti.teis.commongateway.security.auth;
import ee.sm.ti.teis.commongateway.auth.AuthServiceUserInfo;
import ee.sm.ti.teis.commongateway.auth.OAuthToken;
import ee.sm.ti.teis.commongateway.person.PersonProcessingService;
import ee.sm.ti.teis.commongateway.security.mock.MockAuthProperties;
import ee.sm.ti.teis.commongateway.security.mock.MockAuthService;
import ee.sm.ti.teis.commongateway.security.mock.MockNoKeycloakSecurityConfig;
import ee.sm.ti.teis.commongateway.security.mock.MockUserLoginRequest;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
......@@ -22,22 +27,33 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.mockito.quality.Strictness.LENIENT;
public class KeycloakTokenServiceTest {
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = LENIENT)
class KeycloakTokenServiceTest {
private final String ISSUER_URI = "http://localhost:8080";
private final String CLIENT_ID = "teis";
private PersonProcessingService personProcessingService;
private KeycloakTokenService keycloakTokenService;
private MockAuthService mockAuthService;
private static final String ISSUER_URI = "http://localhost:8080";
private static final String CLIENT_ID = "teis";
@Mock
MockAuthProperties mockAuthProperties;
PersonProcessingService personProcessingService;
KeycloakTokenService keycloakTokenService;
MockAuthService mockAuthService;
@BeforeEach
public void setUp() {
void setUp() {
this.personProcessingService = Mockito.mock(PersonProcessingService.class);
MockNoKeycloakSecurityConfig securityConfig = new MockNoKeycloakSecurityConfig();
this.mockAuthService = new MockAuthService(null, personProcessingService,
TOKEN_SECRET, 86400l, "http://loclahost:8080/user-info", null,
"/internal/usr-info", null, null, null, USER_INFO_CLAIM);
this.mockAuthService = new MockAuthService(personProcessingService, null, mockAuthProperties, null);
when(mockAuthProperties.getTokenSecret()).thenReturn(TOKEN_SECRET);
when(mockAuthProperties.getExpire()).thenReturn(124312L);
ReflectionTestUtils.setField(mockAuthService, "teisClaimName", USER_INFO_CLAIM);
ReflectionTestUtils.setField(securityConfig, "mockAuthService", mockAuthService);
AuthProperties authProperties = AuthProperties.builder()
.issuerUri(ISSUER_URI)
......@@ -53,8 +69,7 @@ public class KeycloakTokenServiceTest {
}
@Test
public void auth_config_is_created() {
void auth_config_is_created() {
AuthConfig authConfig = keycloakTokenService.getAuthConfig();
assertThat(authConfig.getIssuer()).isEqualTo("http://localhost:8080");
......@@ -66,7 +81,7 @@ public class KeycloakTokenServiceTest {
}
@Test
public void return_auth_request_when_code_is_provided() {
void return_auth_request_when_code_is_provided() {
TokenRequest tokenRequest = TokenRequest.builder()
.clientId("teis")
.grantType(GrantType.AUTHORIZATION_CODE)
......@@ -83,7 +98,7 @@ public class KeycloakTokenServiceTest {
}
@Test
public void return_auth_request_when_refresh_token_is_provided() {
void return_auth_request_when_refresh_token_is_provided() {
TokenRequest tokenRequest = TokenRequest.builder()
.clientId("teis")
.grantType(GrantType.REFRESH_TOKEN)
......@@ -100,7 +115,7 @@ public class KeycloakTokenServiceTest {
}
@Test
public void update_person_not_called_when_name_in_token_is_empty() {
void update_person_not_called_when_name_in_token_is_empty() {
MockUserLoginRequest mockUserRequest = MockUserLoginRequest.builder()
.idCode("1234567890")
.countryCode("EE")
......@@ -122,7 +137,7 @@ public class KeycloakTokenServiceTest {
}
@Test
public void update_person_not_called_when_names_are_equal() {
void update_person_not_called_when_names_are_equal() {
MockUserLoginRequest mockUserRequest = MockUserLoginRequest.builder()
.idCode("1234567890")
.firstName("Eesnimi")
......@@ -146,7 +161,7 @@ public class KeycloakTokenServiceTest {
}
@Test
public void update_person_is_called_when_names_are_different() {
void update_person_is_called_when_names_are_different() {
MockUserLoginRequest mockUserRequest = MockUserLoginRequest.builder()
.idCode("1234567890")
.firstName("Uusnimi")
......@@ -171,7 +186,7 @@ public class KeycloakTokenServiceTest {
}
@Test
public void use_public_client_id_if_clientId_parameter_is_null() {
void use_public_client_id_if_clientId_parameter_is_null() {
MultiValueMap<String, String> requestParams = new LinkedMultiValueMap<>();
keycloakTokenService.addClientIdParam(null, requestParams);
assertThat(requestParams.getFirst("client_id")).isEqualTo("teis");
......
......@@ -2,6 +2,7 @@ package ee.sm.ti.teis.commongateway.security.mock;
import ee.sm.ti.teis.commongateway.auth.AuthServiceUserInfo;
import ee.sm.ti.teis.commongateway.person.PersonProcessingService;
import ee.sm.ti.teis.commongateway.security.auth.AuthUserInfoProperties;
import ee.sm.ti.teis.security.JwtUserInfo;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.BeforeEach;
......@@ -10,8 +11,10 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.client.RestTemplate;
import java.util.UUID;
......@@ -23,22 +26,35 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;
import static org.mockito.quality.Strictness.LENIENT;
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = LENIENT)
class MockAuthServiceTest {
@Mock
PersonProcessingService personProcessingService;
@Mock
RestTemplate restTemplate;
private MockAuthService mockAuthService;
@Mock
MockAuthProperties mockAuthProperties;
@Mock
AuthUserInfoProperties authUserInfoProperties;
MockAuthService mockAuthService;
@BeforeEach
void setUp() {
MockitoAnnotations.initMocks(this);
mockAuthService = new MockAuthService(restTemplate, personProcessingService,
TOKEN_SECRET, 86400L, "http://loclahost:8080/user-info", null,
"/internal/user-info", null, null, null, USER_INFO_CLAIM);
mockAuthService = new MockAuthService(personProcessingService, restTemplate, mockAuthProperties, authUserInfoProperties);
when(mockAuthProperties.getTokenSecret()).thenReturn(TOKEN_SECRET);
when(mockAuthProperties.getExpire()).thenReturn(124312L);
when(authUserInfoProperties.getUrl()).thenReturn("http://loclahost:8080/user-info");
when(authUserInfoProperties.getUserInfoPath()).thenReturn("/internal/user-info");
ReflectionTestUtils.setField(mockAuthService, "teisClaimName", USER_INFO_CLAIM);
}
@Test
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment