Commit 8f83b890ec7c8de81d9fceb615b473a72b9496e6

Authored by Cleverson Sacramento
1 parent 522e424b
Exists in master

IN PROGRESS - issue FWK-119: Testes da extensão Servlet

https://demoiselle.atlassian.net/browse/FWK-119
impl/extension/servlet/src/test/java/security/authentication/basic/BasicAuthenticationFilterTest.java
1 1 package security.authentication.basic;
2 2  
3   -import static org.apache.http.HttpStatus.SC_OK;
4 3 import static org.apache.http.HttpStatus.SC_FORBIDDEN;
  4 +import static org.apache.http.HttpStatus.SC_OK;
5 5 import static org.junit.Assert.assertEquals;
6 6  
7 7 import java.io.IOException;
... ... @@ -9,14 +9,9 @@ import java.net.URL;
9 9  
10 10 import org.apache.commons.codec.binary.Base64;
11 11 import org.apache.http.HttpResponse;
12   -import org.apache.http.auth.AuthScope;
13   -import org.apache.http.auth.UsernamePasswordCredentials;
14 12 import org.apache.http.client.ClientProtocolException;
15   -import org.apache.http.client.CredentialsProvider;
16 13 import org.apache.http.client.methods.HttpGet;
17   -import org.apache.http.impl.client.BasicCredentialsProvider;
18   -import org.apache.http.impl.client.CloseableHttpClient;
19   -import org.apache.http.impl.client.HttpClients;
  14 +import org.apache.http.impl.client.HttpClientBuilder;
20 15 import org.jboss.arquillian.container.test.api.Deployment;
21 16 import org.jboss.arquillian.junit.Arquillian;
22 17 import org.jboss.arquillian.test.api.ArquillianResource;
... ... @@ -42,18 +37,14 @@ public class BasicAuthenticationFilterTest {
42 37  
43 38 @Test
44 39 public void loginSucessfull() throws ClientProtocolException, IOException {
45   - CredentialsProvider credsProvider = new BasicCredentialsProvider();
46   - credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("demoiselle", "changeit"));
47   - CloseableHttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
48   -
49 40 String username = "demoiselle";
50 41 String password = "changeit";
51   -
  42 +
52 43 HttpGet httpGet = new HttpGet(deploymentUrl + "/helper");
53 44 byte[] encoded = Base64.encodeBase64((username + ":" + password).getBytes());
54 45 httpGet.setHeader("Authorization", "Basic " + new String(encoded));
55 46  
56   - HttpResponse httpResponse = httpClient.execute(httpGet);
  47 + HttpResponse httpResponse = HttpClientBuilder.create().build().execute(httpGet);
57 48  
58 49 int status = httpResponse.getStatusLine().getStatusCode();
59 50 assertEquals(SC_OK, status);
... ... @@ -61,18 +52,14 @@ public class BasicAuthenticationFilterTest {
61 52  
62 53 @Test
63 54 public void loginFailed() throws ClientProtocolException, IOException {
64   - CredentialsProvider credsProvider = new BasicCredentialsProvider();
65   - credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("demoiselle", "changeit"));
66   - CloseableHttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
67   -
68 55 String username = "invalid";
69   - String password = "changeit";
70   -
  56 + String password = "invalid";
  57 +
71 58 HttpGet httpGet = new HttpGet(deploymentUrl + "/helper");
72 59 byte[] encoded = Base64.encodeBase64((username + ":" + password).getBytes());
73 60 httpGet.setHeader("Authorization", "Basic " + new String(encoded));
74 61  
75   - HttpResponse httpResponse = httpClient.execute(httpGet);
  62 + HttpResponse httpResponse = HttpClientBuilder.create().build().execute(httpGet);
76 63  
77 64 int status = httpResponse.getStatusLine().getStatusCode();
78 65 assertEquals(SC_FORBIDDEN, status);
... ...