Commit 95da4575a3aa9267c37694f19fc7908f23e391fb
1 parent
9abaf03d
Exists in
master
Mais implementações de teste para controle de acesso
Showing
4 changed files
with
167 additions
and
0 deletions
Show diff stats
impl/core/src/test/java/security/athentication/custom/CustomAuthenticatorTest.java
| ... | ... | @@ -38,6 +38,7 @@ package security.athentication.custom; |
| 38 | 38 | |
| 39 | 39 | import static org.junit.Assert.assertEquals; |
| 40 | 40 | import static org.junit.Assert.assertFalse; |
| 41 | +import static org.junit.Assert.assertNotNull; | |
| 41 | 42 | import static org.junit.Assert.assertNull; |
| 42 | 43 | import static org.junit.Assert.assertTrue; |
| 43 | 44 | |
| ... | ... | @@ -59,10 +60,14 @@ public class CustomAuthenticatorTest { |
| 59 | 60 | @Inject |
| 60 | 61 | private SecurityContext context; |
| 61 | 62 | |
| 63 | + @Inject | |
| 64 | + private EventObserver observer; | |
| 65 | + | |
| 62 | 66 | @Deployment |
| 63 | 67 | public static JavaArchive createDeployment() { |
| 64 | 68 | JavaArchive deployment = Tests.createDeployment(ConfigurationResourceTest.class); |
| 65 | 69 | deployment.addClass(CustomAuthenticator.class); |
| 70 | + deployment.addClass(EventObserver.class); | |
| 66 | 71 | return deployment; |
| 67 | 72 | } |
| 68 | 73 | |
| ... | ... | @@ -76,6 +81,7 @@ public class CustomAuthenticatorTest { |
| 76 | 81 | public void loginProcess() { |
| 77 | 82 | context.login(); |
| 78 | 83 | assertTrue(context.isLoggedIn()); |
| 84 | + assertNotNull(observer.getEvent()); | |
| 79 | 85 | assertEquals("demoiselle", context.getCurrentUser().getName()); |
| 80 | 86 | } |
| 81 | 87 | ... | ... |
impl/core/src/test/java/security/athentication/custom/EventObserver.java
0 → 100644
| ... | ... | @@ -0,0 +1,20 @@ |
| 1 | +package security.athentication.custom; | |
| 2 | + | |
| 3 | +import javax.enterprise.context.RequestScoped; | |
| 4 | +import javax.enterprise.event.Observes; | |
| 5 | + | |
| 6 | +import br.gov.frameworkdemoiselle.security.AfterLoginSuccessful; | |
| 7 | + | |
| 8 | +@RequestScoped | |
| 9 | +public class EventObserver { | |
| 10 | + | |
| 11 | + private AfterLoginSuccessful event; | |
| 12 | + | |
| 13 | + public void observer(@Observes AfterLoginSuccessful event) { | |
| 14 | + this.event = event; | |
| 15 | + } | |
| 16 | + | |
| 17 | + public AfterLoginSuccessful getEvent() { | |
| 18 | + return this.event; | |
| 19 | + } | |
| 20 | +} | ... | ... |
impl/core/src/test/java/security/athentication/disabled/DisabledAuthenticationTest.java
0 → 100644
| ... | ... | @@ -0,0 +1,104 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 37 | +package security.athentication.disabled; | |
| 38 | + | |
| 39 | +import static org.junit.Assert.assertEquals; | |
| 40 | +import static org.junit.Assert.assertNull; | |
| 41 | +import static org.junit.Assert.assertTrue; | |
| 42 | + | |
| 43 | +import javax.enterprise.context.RequestScoped; | |
| 44 | +import javax.enterprise.event.Observes; | |
| 45 | +import javax.inject.Inject; | |
| 46 | + | |
| 47 | +import org.jboss.arquillian.container.test.api.Deployment; | |
| 48 | +import org.jboss.arquillian.junit.Arquillian; | |
| 49 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | |
| 50 | +import org.junit.Test; | |
| 51 | +import org.junit.runner.RunWith; | |
| 52 | + | |
| 53 | +import security.athentication.custom.CustomAuthenticator; | |
| 54 | +import test.Tests; | |
| 55 | +import br.gov.frameworkdemoiselle.security.AfterLoginSuccessful; | |
| 56 | +import br.gov.frameworkdemoiselle.security.SecurityContext; | |
| 57 | +import configuration.resource.ConfigurationResourceTest; | |
| 58 | + | |
| 59 | +@RequestScoped | |
| 60 | +@RunWith(Arquillian.class) | |
| 61 | +public class DisabledAuthenticationTest { | |
| 62 | + | |
| 63 | + private static final String PATH = "src/test/resources/security/authenticator/disabled"; | |
| 64 | + | |
| 65 | + @Inject | |
| 66 | + private SecurityContext context; | |
| 67 | + | |
| 68 | + private AfterLoginSuccessful event; | |
| 69 | + | |
| 70 | + @Deployment | |
| 71 | + public static JavaArchive createDeployment() { | |
| 72 | + JavaArchive deployment = Tests.createDeployment(ConfigurationResourceTest.class); | |
| 73 | + deployment.addClass(CustomAuthenticator.class); | |
| 74 | + deployment.addAsResource(Tests.createFileAsset(PATH + "/demoiselle.properties"), "demoiselle.properties"); | |
| 75 | + return deployment; | |
| 76 | + } | |
| 77 | + | |
| 78 | + public void observer(@Observes AfterLoginSuccessful event) { | |
| 79 | + this.event = event; | |
| 80 | + } | |
| 81 | + | |
| 82 | + @Test | |
| 83 | + public void unauthenticated() { | |
| 84 | + assertTrue(context.isLoggedIn()); | |
| 85 | + assertEquals("demoiselle", context.getCurrentUser().getName()); | |
| 86 | + } | |
| 87 | + | |
| 88 | + @Test | |
| 89 | + public void loginProcess() { | |
| 90 | + context.login(); | |
| 91 | + assertTrue(context.isLoggedIn()); | |
| 92 | + assertNull(event); | |
| 93 | + assertEquals("demoiselle", context.getCurrentUser().getName()); | |
| 94 | + } | |
| 95 | + | |
| 96 | + // | |
| 97 | + // @Test | |
| 98 | + // public void logoutProcess() { | |
| 99 | + // context.login(); | |
| 100 | + // context.logout(); | |
| 101 | + // assertFalse(context.isLoggedIn()); | |
| 102 | + // assertNull(context.getCurrentUser()); | |
| 103 | + // } | |
| 104 | +} | ... | ... |
impl/core/src/test/resources/security/authenticator/disabled/demoiselle.properties
0 → 100644
| ... | ... | @@ -0,0 +1,37 @@ |
| 1 | +# Demoiselle Framework | |
| 2 | +# Copyright (C) 2010 SERPRO | |
| 3 | +# ---------------------------------------------------------------------------- | |
| 4 | +# This file is part of Demoiselle Framework. | |
| 5 | +# | |
| 6 | +# Demoiselle Framework is free software; you can redistribute it and/or | |
| 7 | +# modify it under the terms of the GNU Lesser General Public License version 3 | |
| 8 | +# as published by the Free Software Foundation. | |
| 9 | +# | |
| 10 | +# This program is distributed in the hope that it will be useful, | |
| 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 | +# GNU General Public License for more details. | |
| 14 | +# | |
| 15 | +# You should have received a copy of the GNU Lesser General Public License version 3 | |
| 16 | +# along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 17 | +# or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 18 | +# Fifth Floor, Boston, MA 02110-1301, USA. | |
| 19 | +# ---------------------------------------------------------------------------- | |
| 20 | +# Este arquivo é parte do Framework Demoiselle. | |
| 21 | +# | |
| 22 | +# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 23 | +# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 24 | +# do Software Livre (FSF). | |
| 25 | +# | |
| 26 | +# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 27 | +# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 28 | +# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 29 | +# para maiores detalhes. | |
| 30 | +# | |
| 31 | +# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 32 | +# "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 33 | +# ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 34 | +# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 35 | + | |
| 36 | +frameworkdemoiselle.security.authenticator.class=security.athentication.custom.CustomAuthenticator | |
| 37 | +frameworkdemoiselle.security.enabled=false | |
| 0 | 38 | \ No newline at end of file | ... | ... |