| margaretha | 03ae28d | 2019-06-27 14:20:30 +0200 | [diff] [blame] | 1 | package de.ids_mannheim.korap.authentication; |
| 2 | |
| 3 | import static org.junit.Assert.assertEquals; |
| 4 | |
| 5 | import javax.ws.rs.core.Response.Status; |
| 6 | |
| 7 | import org.junit.Test; |
| 8 | import org.springframework.beans.factory.annotation.Autowired; |
| 9 | |
| 10 | import com.fasterxml.jackson.databind.JsonNode; |
| 11 | import com.sun.jersey.api.client.ClientResponse; |
| 12 | |
| 13 | import de.ids_mannheim.korap.config.FullConfiguration; |
| 14 | import de.ids_mannheim.korap.constant.AuthenticationMethod; |
| 15 | import de.ids_mannheim.korap.exceptions.KustvaktException; |
| 16 | import de.ids_mannheim.korap.utils.JsonUtils; |
| 17 | import de.ids_mannheim.korap.web.controller.OAuth2TestBase; |
| 18 | |
| 19 | public class LdapTest extends OAuth2TestBase { |
| 20 | |
| 21 | @Autowired |
| 22 | private FullConfiguration config; |
| 23 | |
| 24 | @Test |
| 25 | public void testRequestTokenPasswordUnknownUser () |
| 26 | throws KustvaktException { |
| 27 | |
| 28 | config.setOAuth2passwordAuthentication(AuthenticationMethod.LDAP); |
| 29 | ClientResponse response = requestTokenWithPassword(superClientId, |
| 30 | clientSecret, "unknown", "password"); |
| 31 | |
| 32 | assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus()); |
| 33 | |
| 34 | String entity = response.getEntity(String.class); |
| 35 | JsonNode node = JsonUtils.readTree(entity); |
| 36 | assertEquals(2022, node.at("/errors/0/0").asInt()); |
| 37 | assertEquals( |
| 38 | "LDAP Authentication failed due to unknown user or password!", |
| 39 | node.at("/errors/0/1").asText()); |
| 40 | config.setOAuth2passwordAuthentication(AuthenticationMethod.TEST); |
| 41 | } |
| 42 | } |