}
private void setUpValidRequest() {
User user = new User();
user.setAuthorizationToken(new AuthorizationToken(user));
final ExternalUser externalUser = new ExternalUser(user);
String dateString = new DateTime().toString(ISODateTimeFormat.dateTimeNoMillis());
String hashedToken = new String(Base64.encodeBase64(DigestUtils.sha256(user.getAuthorizationToken().getToken() + ":user/555,POST," + dateString + ",123")));
when(containerRequest.getHeaderValue(SecurityContextFilter.HEADER_AUTHORIZATION)).thenReturn(externalUser.getId() + ":" + hashedToken);
when(containerRequest.getHeaderValue(SecurityContextFilter.HEADER_DATE)).thenReturn(dateString);
when(containerRequest.getHeaderValue(SecurityContextFilter.HEADER_NONCE)).thenReturn("123");
when(containerRequest.getPath()).thenReturn("user/555");
when(containerRequest.getMethod()).thenReturn("POST");
when(userRepository.findByUuid(user.getUuid().toString())).thenReturn(user);
doAnswer(new Answer() {
public Object answer(InvocationOnMock invocation) throws Throwable {
SecurityContext context = (SecurityContext) invocation.getArguments()[0];
ExternalUser user = (ExternalUser) context.getUserPrincipal();
assertThat(user.getId(), is(externalUser.getId()));
return null;
}
}).when(containerRequest).setSecurityContext(any(SecurityContext.class));
}