TSK-531 Access id validation failing refinement
This commit is contained in:
parent
b8138db327
commit
f763089e38
|
@ -1,5 +1,6 @@
|
|||
package pro.taskana.rest;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
@ -19,21 +20,25 @@ import org.springframework.hateoas.hal.Jackson2HalModule;
|
|||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import pro.taskana.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.ldap.LdapCacheTestImpl;
|
||||
import pro.taskana.rest.resource.AccessIdResource;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = RestConfiguration.class, webEnvironment = WebEnvironment.RANDOM_PORT, properties = {"devMode=true"})
|
||||
@SpringBootTest(classes = RestConfiguration.class, webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
|
||||
"devMode=true"})
|
||||
public class AccessIdValidationControllerTest {
|
||||
|
||||
@LocalServerPort
|
||||
|
@ -49,6 +54,7 @@ public class AccessIdValidationControllerTest {
|
|||
ResponseEntity<List<AccessIdResource>> response = template.exchange(
|
||||
"http://127.0.0.1:" + port + "/v1/access-ids?searchFor=ali", HttpMethod.GET, request,
|
||||
new ParameterizedTypeReference<List<AccessIdResource>>() {
|
||||
|
||||
});
|
||||
List<AccessIdResource> body = response.getBody();
|
||||
assertNotNull(body);
|
||||
|
@ -59,6 +65,26 @@ public class AccessIdValidationControllerTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadRequestWhenSearchForIsTooShort() {
|
||||
AccessIdController.setLdapCache(new LdapCacheTestImpl());
|
||||
RestTemplate template = getRestTemplate();
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x");
|
||||
HttpEntity<String> request = new HttpEntity<String>(headers);
|
||||
try {
|
||||
template.exchange(
|
||||
"http://127.0.0.1:" + port + "/v1/access-ids?searchFor=al", HttpMethod.GET, request,
|
||||
new ParameterizedTypeReference<List<AccessIdResource>>() {
|
||||
|
||||
});
|
||||
} catch (HttpClientErrorException e) {
|
||||
assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode());
|
||||
assertTrue(e.getResponseBodyAsString().contains("Minimum searchFor length ="));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a REST template which is capable of dealing with responses in HAL format
|
||||
*
|
||||
|
@ -73,7 +99,7 @@ public class AccessIdValidationControllerTest {
|
|||
converter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/hal+json"));
|
||||
converter.setObjectMapper(mapper);
|
||||
|
||||
RestTemplate template = new RestTemplate(Collections.<HttpMessageConverter<?>> singletonList(converter));
|
||||
RestTemplate template = new RestTemplate(Collections.<HttpMessageConverter<?>>singletonList(converter));
|
||||
return template;
|
||||
}
|
||||
|
||||
|
|
|
@ -89,28 +89,31 @@ public class GenenalExceptionHandlingTest {
|
|||
try {
|
||||
|
||||
AccessIdController.setLdapCache(new LdapCacheTestImpl());
|
||||
ResponseEntity<List<AccessIdResource>> response = template.exchange(
|
||||
template.exchange(
|
||||
server + port + "/v1/access-ids?searchFor=al", HttpMethod.GET, request,
|
||||
new ParameterizedTypeReference<List<AccessIdResource>>() {
|
||||
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
verify(mockAppender).doAppend(captorLoggingEvent.capture());
|
||||
assertTrue(captorLoggingEvent.getValue().getMessage().contains("is too short. Minimum Length ="));
|
||||
assertTrue(
|
||||
captorLoggingEvent.getValue().getMessage().contains("is too short. Minimum searchFor length = "));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteNonExisitingClassificationExceptionIsLogged() {
|
||||
try {
|
||||
ResponseEntity<PagedResources<ClassificationSummaryResource>> response = template.exchange(
|
||||
template.exchange(
|
||||
server + port + "/v1/classifications/non-existing-id", HttpMethod.DELETE, request,
|
||||
new ParameterizedTypeReference<PagedResources<ClassificationSummaryResource>>() {
|
||||
|
||||
});
|
||||
} catch (Exception ex){
|
||||
} catch (Exception ex) {
|
||||
verify(mockAppender).doAppend(captorLoggingEvent.capture());
|
||||
assertTrue(captorLoggingEvent.getValue().getMessage().contains("The classification \"non-existing-id\" wasn't found"));
|
||||
assertTrue(captorLoggingEvent.getValue()
|
||||
.getMessage()
|
||||
.contains("The classification \"non-existing-id\" wasn't found"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,9 +35,9 @@ public class AccessIdController {
|
|||
|
||||
@GetMapping
|
||||
public ResponseEntity<List<AccessIdResource>> validateAccessIds(
|
||||
@RequestParam(required = false) String searchFor) throws InvalidArgumentException {
|
||||
if (searchFor == null || searchFor.length() < ldapClient.getMinSearchForLength()) {
|
||||
throw new InvalidArgumentException("searchFor string " + searchFor + " is too short. Minimum Length = "
|
||||
@RequestParam String searchFor) throws InvalidArgumentException {
|
||||
if (searchFor.length() < ldapClient.getMinSearchForLength()) {
|
||||
throw new InvalidArgumentException("searchFor string '" + searchFor + "' is too short. Minimum searchFor length = "
|
||||
+ ldapClient.getMinSearchForLength());
|
||||
}
|
||||
if (ldapClient.useLdap()) {
|
||||
|
|
Loading…
Reference in New Issue