Commit 8f83b890ec7c8de81d9fceb615b473a72b9496e6
1 parent
522e424b
Exists in
master
IN PROGRESS - issue FWK-119: Testes da extensão Servlet
https://demoiselle.atlassian.net/browse/FWK-119
Showing
1 changed file
with
7 additions
and
20 deletions
Show diff stats
impl/extension/servlet/src/test/java/security/authentication/basic/BasicAuthenticationFilterTest.java
1 | package security.authentication.basic; | 1 | package security.authentication.basic; |
2 | 2 | ||
3 | -import static org.apache.http.HttpStatus.SC_OK; | ||
4 | import static org.apache.http.HttpStatus.SC_FORBIDDEN; | 3 | import static org.apache.http.HttpStatus.SC_FORBIDDEN; |
4 | +import static org.apache.http.HttpStatus.SC_OK; | ||
5 | import static org.junit.Assert.assertEquals; | 5 | import static org.junit.Assert.assertEquals; |
6 | 6 | ||
7 | import java.io.IOException; | 7 | import java.io.IOException; |
@@ -9,14 +9,9 @@ import java.net.URL; | @@ -9,14 +9,9 @@ import java.net.URL; | ||
9 | 9 | ||
10 | import org.apache.commons.codec.binary.Base64; | 10 | import org.apache.commons.codec.binary.Base64; |
11 | import org.apache.http.HttpResponse; | 11 | import org.apache.http.HttpResponse; |
12 | -import org.apache.http.auth.AuthScope; | ||
13 | -import org.apache.http.auth.UsernamePasswordCredentials; | ||
14 | import org.apache.http.client.ClientProtocolException; | 12 | import org.apache.http.client.ClientProtocolException; |
15 | -import org.apache.http.client.CredentialsProvider; | ||
16 | import org.apache.http.client.methods.HttpGet; | 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 | import org.jboss.arquillian.container.test.api.Deployment; | 15 | import org.jboss.arquillian.container.test.api.Deployment; |
21 | import org.jboss.arquillian.junit.Arquillian; | 16 | import org.jboss.arquillian.junit.Arquillian; |
22 | import org.jboss.arquillian.test.api.ArquillianResource; | 17 | import org.jboss.arquillian.test.api.ArquillianResource; |
@@ -42,18 +37,14 @@ public class BasicAuthenticationFilterTest { | @@ -42,18 +37,14 @@ public class BasicAuthenticationFilterTest { | ||
42 | 37 | ||
43 | @Test | 38 | @Test |
44 | public void loginSucessfull() throws ClientProtocolException, IOException { | 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 | String username = "demoiselle"; | 40 | String username = "demoiselle"; |
50 | String password = "changeit"; | 41 | String password = "changeit"; |
51 | - | 42 | + |
52 | HttpGet httpGet = new HttpGet(deploymentUrl + "/helper"); | 43 | HttpGet httpGet = new HttpGet(deploymentUrl + "/helper"); |
53 | byte[] encoded = Base64.encodeBase64((username + ":" + password).getBytes()); | 44 | byte[] encoded = Base64.encodeBase64((username + ":" + password).getBytes()); |
54 | httpGet.setHeader("Authorization", "Basic " + new String(encoded)); | 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 | int status = httpResponse.getStatusLine().getStatusCode(); | 49 | int status = httpResponse.getStatusLine().getStatusCode(); |
59 | assertEquals(SC_OK, status); | 50 | assertEquals(SC_OK, status); |
@@ -61,18 +52,14 @@ public class BasicAuthenticationFilterTest { | @@ -61,18 +52,14 @@ public class BasicAuthenticationFilterTest { | ||
61 | 52 | ||
62 | @Test | 53 | @Test |
63 | public void loginFailed() throws ClientProtocolException, IOException { | 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 | String username = "invalid"; | 55 | String username = "invalid"; |
69 | - String password = "changeit"; | ||
70 | - | 56 | + String password = "invalid"; |
57 | + | ||
71 | HttpGet httpGet = new HttpGet(deploymentUrl + "/helper"); | 58 | HttpGet httpGet = new HttpGet(deploymentUrl + "/helper"); |
72 | byte[] encoded = Base64.encodeBase64((username + ":" + password).getBytes()); | 59 | byte[] encoded = Base64.encodeBase64((username + ":" + password).getBytes()); |
73 | httpGet.setHeader("Authorization", "Basic " + new String(encoded)); | 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 | int status = httpResponse.getStatusLine().getStatusCode(); | 64 | int status = httpResponse.getStatusLine().getStatusCode(); |
78 | assertEquals(SC_FORBIDDEN, status); | 65 | assertEquals(SC_FORBIDDEN, status); |