@Before public void standUp() throws DatatypeConfigurationException { dataTypeFactory = DatatypeFactory.newInstance(); when(request.getRequestURI()).thenReturn("/start/104772/resource"); when(request.getHeader(anyString())).thenReturn("tokenId"); Calendar expires = getCalendarWithOffset(1000); authResponse = new AuthenticateResponse(); UserForAuthenticateResponse userForAuthenticateResponse = new UserForAuthenticateResponse(); userForAuthenticateResponse.setId("104772"); userForAuthenticateResponse.setName("user2"); userForAuthenticateResponse.setRoles(defaultRoleList()); Token token = new Token(); token.setId("tokenId"); TenantForAuthenticateResponse tenant = new TenantForAuthenticateResponse(); tenant.setId("104772"); tenant.setName("tenantName"); token.setTenant(tenant); token.setExpires(dataTypeFactory.newXMLGregorianCalendar((GregorianCalendar) expires)); authResponse.setToken(token); authResponse.setUser(userForAuthenticateResponse); }
@Test public void shouldNotUseCachedUserInfoForBadTokenId() { authResponse.getToken().setId("differentId"); final AuthToken user = new OpenStackToken(authResponse); when(authService.validateToken(anyString(), anyString())).thenReturn(user); when(store.get(eq(AUTH_TOKEN_CACHE_PREFIX + ".104772"))).thenReturn(user); final FilterDirector director = handlerWithCache.handleRequest(request, response); verify(authService, times(1)).validateToken(anyString(), anyString()); assertEquals( "Auth component must pass valid requests", FilterAction.PASS, director.getFilterAction()); }