Commit efc7520404ce33d27b02302e1c7dfc6ed45516a1

Authored by Cleverson Sacramento
1 parent b4872a11
Exists in master

OPEN - issue FWK-172: Filtro para autenticação BASIC não efetua o logout

após o término do request 
https://demoiselle.atlassian.net/browse/FWK-172
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_UNAUTHORIZED; 3 import static org.apache.http.HttpStatus.SC_UNAUTHORIZED;
  4 +import static org.apache.http.HttpStatus.SC_FORBIDDEN;
4 import static org.apache.http.HttpStatus.SC_OK; 5 import static org.apache.http.HttpStatus.SC_OK;
5 import static org.junit.Assert.assertEquals; 6 import static org.junit.Assert.assertEquals;
6 7
@@ -11,6 +12,7 @@ import org.apache.commons.codec.binary.Base64; @@ -11,6 +12,7 @@ import org.apache.commons.codec.binary.Base64;
11 import org.apache.http.HttpResponse; 12 import org.apache.http.HttpResponse;
12 import org.apache.http.client.ClientProtocolException; 13 import org.apache.http.client.ClientProtocolException;
13 import org.apache.http.client.methods.HttpGet; 14 import org.apache.http.client.methods.HttpGet;
  15 +import org.apache.http.impl.client.CloseableHttpClient;
14 import org.apache.http.impl.client.HttpClientBuilder; 16 import org.apache.http.impl.client.HttpClientBuilder;
15 import org.jboss.arquillian.container.test.api.Deployment; 17 import org.jboss.arquillian.container.test.api.Deployment;
16 import org.jboss.arquillian.junit.Arquillian; 18 import org.jboss.arquillian.junit.Arquillian;
@@ -37,17 +39,24 @@ public class BasicAuthenticationFilterTest { @@ -37,17 +39,24 @@ public class BasicAuthenticationFilterTest {
37 39
38 @Test 40 @Test
39 public void loginSucessfull() throws ClientProtocolException, IOException { 41 public void loginSucessfull() throws ClientProtocolException, IOException {
  42 + CloseableHttpClient client = HttpClientBuilder.create().build();
  43 + HttpGet get;
  44 + HttpResponse response;
  45 + int status;
  46 +
40 String username = "demoiselle"; 47 String username = "demoiselle";
41 String password = "changeit"; 48 String password = "changeit";
42 -  
43 - HttpGet httpGet = new HttpGet(deploymentUrl + "/helper"); 49 + get = new HttpGet(deploymentUrl + "/helper");
44 byte[] encoded = Base64.encodeBase64((username + ":" + password).getBytes()); 50 byte[] encoded = Base64.encodeBase64((username + ":" + password).getBytes());
45 - httpGet.setHeader("Authorization", "Basic " + new String(encoded));  
46 -  
47 - HttpResponse httpResponse = HttpClientBuilder.create().build().execute(httpGet);  
48 -  
49 - int status = httpResponse.getStatusLine().getStatusCode(); 51 + get.setHeader("Authorization", "Basic " + new String(encoded));
  52 + response = client.execute(get);
  53 + status = response.getStatusLine().getStatusCode();
50 assertEquals(SC_OK, status); 54 assertEquals(SC_OK, status);
  55 +
  56 + get = new HttpGet(deploymentUrl + "/helper");
  57 + response = client.execute(get);
  58 + status = response.getStatusLine().getStatusCode();
  59 + assertEquals(SC_FORBIDDEN, status);
51 } 60 }
52 61
53 @Test 62 @Test
@@ -55,13 +64,13 @@ public class BasicAuthenticationFilterTest { @@ -55,13 +64,13 @@ public class BasicAuthenticationFilterTest {
55 String username = "invalid"; 64 String username = "invalid";
56 String password = "invalid"; 65 String password = "invalid";
57 66
58 - HttpGet httpGet = new HttpGet(deploymentUrl + "/helper"); 67 + HttpGet get = new HttpGet(deploymentUrl + "/helper");
59 byte[] encoded = Base64.encodeBase64((username + ":" + password).getBytes()); 68 byte[] encoded = Base64.encodeBase64((username + ":" + password).getBytes());
60 - httpGet.setHeader("Authorization", "Basic " + new String(encoded)); 69 + get.setHeader("Authorization", "Basic " + new String(encoded));
61 70
62 - HttpResponse httpResponse = HttpClientBuilder.create().build().execute(httpGet); 71 + HttpResponse response = HttpClientBuilder.create().build().execute(get);
63 72
64 - int status = httpResponse.getStatusLine().getStatusCode(); 73 + int status = response.getStatusLine().getStatusCode();
65 assertEquals(SC_UNAUTHORIZED, status); 74 assertEquals(SC_UNAUTHORIZED, status);
66 } 75 }
67 } 76 }