aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-auth
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2021-10-22 10:38:45 -0500
committersonartech <sonartech@sonarsource.com>2021-10-25 20:03:24 +0000
commit6519110cd4f98fabf3bef46896eecbead3eb646a (patch)
treead84a08da8ba0d590dd1a2d5e9bd2f85ff1c8a8e /server/sonar-webserver-auth
parent7525c90c3f489b47e902e5f8eecce2c9deab9658 (diff)
downloadsonarqube-6519110cd4f98fabf3bef46896eecbead3eb646a.tar.gz
sonarqube-6519110cd4f98fabf3bef46896eecbead3eb646a.zip
Fix code quality issues
Diffstat (limited to 'server/sonar-webserver-auth')
-rw-r--r--server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/CredentialsLocalAuthentication.java2
-rw-r--r--server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/InitFilterTest.java6
-rw-r--r--server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/JwtHttpHandlerTest.java24
-rw-r--r--server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/OAuth2ContextFactoryTest.java2
-rw-r--r--server/sonar-webserver-auth/src/test/java/org/sonar/server/usertoken/UserTokenAuthenticationTest.java2
5 files changed, 18 insertions, 18 deletions
diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/CredentialsLocalAuthentication.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/CredentialsLocalAuthentication.java
index c7aa4d5acae..fe7dcc2ce72 100644
--- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/CredentialsLocalAuthentication.java
+++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/CredentialsLocalAuthentication.java
@@ -244,7 +244,7 @@ public class CredentialsLocalAuthentication {
.setSalt(saltStr);
}
- private String hash(byte[] salt, String password, int iterations) {
+ private static String hash(byte[] salt, String password, int iterations) {
try {
SecretKeyFactory skf = SecretKeyFactory.getInstance(ALGORITHM);
PBEKeySpec spec = new PBEKeySpec(password.toCharArray(), salt, iterations, KEY_LEN);
diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/InitFilterTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/InitFilterTest.java
index 1a450e5f9e4..cba0e20cb44 100644
--- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/InitFilterTest.java
+++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/InitFilterTest.java
@@ -133,7 +133,7 @@ public class InitFilterTest {
underTest.doFilter(request, response, chain);
- verify(auth2AuthenticationParameters).init(eq(request), eq(response));
+ verify(auth2AuthenticationParameters).init(request, response);
}
@Test
@@ -143,7 +143,7 @@ public class InitFilterTest {
underTest.doFilter(request, response, chain);
- verify(auth2AuthenticationParameters, never()).init(eq(request), eq(response));
+ verify(auth2AuthenticationParameters, never()).init(request, response);
}
@Test
@@ -263,7 +263,7 @@ public class InitFilterTest {
}
private void verifyDeleteAuthCookie() {
- verify(auth2AuthenticationParameters).delete(eq(request), eq(response));
+ verify(auth2AuthenticationParameters).delete(request, response);
}
private static class FailWithUnauthorizedExceptionIdProvider extends FakeBasicIdentityProvider {
diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/JwtHttpHandlerTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/JwtHttpHandlerTest.java
index e6c24b5176b..ba25da81862 100644
--- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/JwtHttpHandlerTest.java
+++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/JwtHttpHandlerTest.java
@@ -119,7 +119,7 @@ public class JwtHttpHandlerTest {
verify(jwtSerializer).encode(jwtArgumentCaptor.capture());
JwtSerializer.JwtSession token = jwtArgumentCaptor.getValue();
- assertThat(token.getProperties().get("xsrfToken")).isEqualTo(CSRF_STATE);
+ assertThat(token.getProperties()).containsEntry("xsrfToken", CSRF_STATE);
}
@Test
@@ -200,7 +200,7 @@ public class JwtHttpHandlerTest {
Claims claims = createToken(sessionToken, NOW);
when(jwtSerializer.decode(JWT_TOKEN)).thenReturn(Optional.of(claims));
- assertThat(underTest.validateToken(request, response).isPresent()).isTrue();
+ assertThat(underTest.validateToken(request, response)).isPresent();
verify(jwtSerializer, never()).encode(any(JwtSerializer.JwtSession.class));
}
@@ -215,7 +215,7 @@ public class JwtHttpHandlerTest {
claims.put("lastRefreshTime", SIX_MINUTES_AGO);
when(jwtSerializer.decode(JWT_TOKEN)).thenReturn(Optional.of(claims));
- assertThat(underTest.validateToken(request, response).isPresent()).isTrue();
+ assertThat(underTest.validateToken(request, response)).isPresent();
verify(jwtSerializer).refresh(any(Claims.class), eq(NOW + 3 * 24 * 60 * 60 * 1000L));
assertThat(dbClient.sessionTokensDao().selectByUuid(dbSession, sessionToken.getUuid()).get().getExpirationDate())
@@ -233,7 +233,7 @@ public class JwtHttpHandlerTest {
claims.put("lastRefreshTime", FOUR_MINUTES_AGO);
when(jwtSerializer.decode(JWT_TOKEN)).thenReturn(Optional.of(claims));
- assertThat(underTest.validateToken(request, response).isPresent()).isTrue();
+ assertThat(underTest.validateToken(request, response)).isPresent();
verify(jwtSerializer, never()).refresh(any(Claims.class), anyInt());
}
@@ -248,7 +248,7 @@ public class JwtHttpHandlerTest {
claims.put("lastRefreshTime", FOUR_MINUTES_AGO);
when(jwtSerializer.decode(JWT_TOKEN)).thenReturn(Optional.of(claims));
- assertThat(underTest.validateToken(request, response).isPresent()).isFalse();
+ assertThat(underTest.validateToken(request, response)).isEmpty();
}
@Test
@@ -259,7 +259,7 @@ public class JwtHttpHandlerTest {
Claims claims = createToken(sessionToken, NOW);
when(jwtSerializer.decode(JWT_TOKEN)).thenReturn(Optional.of(claims));
- assertThat(underTest.validateToken(request, response).isPresent()).isFalse();
+ assertThat(underTest.validateToken(request, response)).isEmpty();
}
@Test
@@ -268,7 +268,7 @@ public class JwtHttpHandlerTest {
when(jwtSerializer.decode(JWT_TOKEN)).thenReturn(Optional.empty());
- assertThat(underTest.validateToken(request, response).isPresent()).isFalse();
+ assertThat(underTest.validateToken(request, response)).isEmpty();
}
@Test
@@ -276,7 +276,7 @@ public class JwtHttpHandlerTest {
underTest.validateToken(request, response);
verifyNoInteractions(httpSession, jwtSerializer);
- assertThat(underTest.validateToken(request, response).isPresent()).isFalse();
+ assertThat(underTest.validateToken(request, response)).isEmpty();
}
@Test
@@ -286,7 +286,7 @@ public class JwtHttpHandlerTest {
underTest.validateToken(request, response);
verifyNoInteractions(httpSession, jwtSerializer);
- assertThat(underTest.validateToken(request, response).isPresent()).isFalse();
+ assertThat(underTest.validateToken(request, response)).isEmpty();
}
@Test
@@ -314,7 +314,7 @@ public class JwtHttpHandlerTest {
underTest.validateToken(request, response);
- assertThat(underTest.validateToken(request, response).isPresent()).isFalse();
+ assertThat(underTest.validateToken(request, response)).isEmpty();
}
@Test
@@ -330,7 +330,7 @@ public class JwtHttpHandlerTest {
underTest.validateToken(request, response);
- assertThat(underTest.validateToken(request, response).isPresent()).isFalse();
+ assertThat(underTest.validateToken(request, response)).isEmpty();
}
@Test
@@ -394,7 +394,7 @@ public class JwtHttpHandlerTest {
private void verifyToken(JwtSerializer.JwtSession token, UserDto user, long expectedExpirationDuration, long expectedRefreshTime) {
assertThat(token.getExpirationTime()).isEqualTo(NOW + expectedExpirationDuration * 1000L);
assertThat(token.getUserLogin()).isEqualTo(user.getUuid());
- assertThat(token.getProperties().get("lastRefreshTime")).isEqualTo(expectedRefreshTime);
+ assertThat(token.getProperties()).containsEntry("lastRefreshTime", expectedRefreshTime);
}
private Optional<Cookie> findCookie(String name) {
diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/OAuth2ContextFactoryTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/OAuth2ContextFactoryTest.java
index 88bb0e0b719..ea5ebad1ccb 100644
--- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/OAuth2ContextFactoryTest.java
+++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/OAuth2ContextFactoryTest.java
@@ -209,7 +209,7 @@ public class OAuth2ContextFactoryTest {
callback.redirectToRequestedPage();
- verify(oAuthParameters).delete(eq(request), eq(response));
+ verify(oAuthParameters).delete(request, response);
}
private OAuth2IdentityProvider.InitContext newInitContext() {
diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/usertoken/UserTokenAuthenticationTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/usertoken/UserTokenAuthenticationTest.java
index 0659c0520eb..b1919b83d59 100644
--- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/usertoken/UserTokenAuthenticationTest.java
+++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/usertoken/UserTokenAuthenticationTest.java
@@ -62,7 +62,7 @@ public class UserTokenAuthenticationTest {
Optional<String> login = underTest.authenticate(token);
assertThat(login.isPresent()).isTrue();
- assertThat(login.get()).isEqualTo(user1.getUuid());
+ assertThat(login).contains(user1.getUuid());
verify(userLastConnectionDatesUpdater).updateLastConnectionDateIfNeeded(any(UserTokenDto.class));
}