Commit 3e59c914 by Antonio Rueda

Nuevo test para comprobar que un cliente no puede acceder a los datos

de otro
parent a5f04382
......@@ -83,7 +83,7 @@ public class ControladorRESTTest {
* test de alta y login de cliente
*/
@Test
public void testAltaYLoginClienteCuenta() {
public void testAltaYAccesoDatosCliente() {
DTOCliente cliente = new DTOCliente(
"11995667D",
"Juan España España",
......@@ -108,7 +108,7 @@ public class ControladorRESTTest {
.getForEntity(
"/clientes/{dni}",
DTOCliente.class,
cliente.getDni(), cliente.getClave()
cliente.getDni()
);
Assertions.assertThat(respuestaLogin.getStatusCode()).isEqualTo(HttpStatus.OK);
......@@ -118,6 +118,57 @@ public class ControladorRESTTest {
}
/**
* test de alta e intento de acceso a datos de otro cliente
*/
@Test
public void testAltaYAccesoDatosClienteDiferente() {
DTOCliente cliente = new DTOCliente(
"11995667D",
"Juan España España",
LocalDate.of(1990, 11, 1),
"Cl La Luz, 13 - Jaén",
"988674533",
"jee@gmail.com",
"clave");
TestRestTemplate restTemplate = new TestRestTemplate(restTemplateBuilder);
restTemplate.postForEntity(
"/clientes",
cliente,
DTOCuenta.class
);
// Crear segundo cliente
DTOCliente cliente2 = new DTOCliente(
"99207668E",
"Pedro Jaén, Jaén",
LocalDate.of(1992, 1, 2),
"Cl La Paz, 20 - Jaén",
"670701570",
"pjj@gmail.com",
"clavezzz"
);
restTemplate.postForEntity(
"/clientes",
cliente2,
DTOCuenta.class
).getBody();
TestRestTemplate restTemplateAutenticado = new TestRestTemplate(restTemplateBuilder.basicAuthentication(cliente.getDni(), cliente.getClave()));
// Acceso con credenciales del primer cliente a la información del segundo
ResponseEntity<DTOCliente> respuestaLogin = restTemplateAutenticado
.getForEntity(
"/clientes/{dni}",
DTOCliente.class,
cliente2.getDni()
);
Assertions.assertThat(respuestaLogin.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
}
/**
* Creación de cuenta adicional
*/
@Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment