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

Test fixes

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