Commit a625faa5 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Test fixes

parent a691f54c
package it.inaf.ia2.gms.authn; package it.inaf.ia2.gms.authn;
import java.util.ArrayList; import it.inaf.ia2.aa.data.User;
import java.util.HashMap;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import static org.mockito.ArgumentMatchers.eq;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public class SessionDataTest { public class SessionDataTest {
...@@ -26,15 +25,17 @@ public class SessionDataTest { ...@@ -26,15 +25,17 @@ public class SessionDataTest {
@Test @Test
public void testExpired() { public void testExpired() {
OAuth2AccessToken accessToken = mock(OAuth2AccessToken.class); HttpSession session = mock(HttpSession.class);
when(accessToken.getExpiresIn()).thenReturn(3600); when(request.getSession(eq(false))).thenReturn(session);
CustomAuthenticationData data = new CustomAuthenticationData("user", User user = new User()
new HashMap<>(), new ArrayList<>(), accessToken, "refresh_token"); .setUserId("123")
.setUserLabel("Name Surname")
.setAccessToken("<access_token>")
.setRefreshToken("<refresh_token>")
.setExpiresIn(3600);
OAuth2Authentication auth = mock(OAuth2Authentication.class); when(session.getAttribute(eq("user_data"))).thenReturn(user);
when(auth.getUserAuthentication()).thenReturn(data);
when(request.getUserPrincipal()).thenReturn(auth);
sessionData.init(); sessionData.init();
......
...@@ -148,6 +148,6 @@ public class RapClientTest { ...@@ -148,6 +148,6 @@ public class RapClientTest {
// verifies that token is refreshed // verifies that token is refreshed
verify(sessionData, times(1)).setAccessToken(eq("<access_token>")); verify(sessionData, times(1)).setAccessToken(eq("<access_token>"));
verify(sessionData, times(1)).setExpiresIn(eq(3600)); verify(sessionData, times(1)).setExpiresIn(eq(3600l));
} }
} }
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