Commit efc7520404ce33d27b02302e1c7dfc6ed45516a1
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
Showing
1 changed file
with
20 additions
and
11 deletions
Show diff stats
impl/extension/servlet/src/test/java/security/authentication/basic/BasicAuthenticationFilterTest.java
1 | 1 | package security.authentication.basic; |
2 | 2 | |
3 | 3 | import static org.apache.http.HttpStatus.SC_UNAUTHORIZED; |
4 | +import static org.apache.http.HttpStatus.SC_FORBIDDEN; | |
4 | 5 | import static org.apache.http.HttpStatus.SC_OK; |
5 | 6 | import static org.junit.Assert.assertEquals; |
6 | 7 | |
... | ... | @@ -11,6 +12,7 @@ import org.apache.commons.codec.binary.Base64; |
11 | 12 | import org.apache.http.HttpResponse; |
12 | 13 | import org.apache.http.client.ClientProtocolException; |
13 | 14 | import org.apache.http.client.methods.HttpGet; |
15 | +import org.apache.http.impl.client.CloseableHttpClient; | |
14 | 16 | import org.apache.http.impl.client.HttpClientBuilder; |
15 | 17 | import org.jboss.arquillian.container.test.api.Deployment; |
16 | 18 | import org.jboss.arquillian.junit.Arquillian; |
... | ... | @@ -37,17 +39,24 @@ public class BasicAuthenticationFilterTest { |
37 | 39 | |
38 | 40 | @Test |
39 | 41 | public void loginSucessfull() throws ClientProtocolException, IOException { |
42 | + CloseableHttpClient client = HttpClientBuilder.create().build(); | |
43 | + HttpGet get; | |
44 | + HttpResponse response; | |
45 | + int status; | |
46 | + | |
40 | 47 | String username = "demoiselle"; |
41 | 48 | String password = "changeit"; |
42 | - | |
43 | - HttpGet httpGet = new HttpGet(deploymentUrl + "/helper"); | |
49 | + get = new HttpGet(deploymentUrl + "/helper"); | |
44 | 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 | 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 | 62 | @Test |
... | ... | @@ -55,13 +64,13 @@ public class BasicAuthenticationFilterTest { |
55 | 64 | String username = "invalid"; |
56 | 65 | String password = "invalid"; |
57 | 66 | |
58 | - HttpGet httpGet = new HttpGet(deploymentUrl + "/helper"); | |
67 | + HttpGet get = new HttpGet(deploymentUrl + "/helper"); | |
59 | 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 | 74 | assertEquals(SC_UNAUTHORIZED, status); |
66 | 75 | } |
67 | 76 | } | ... | ... |