From 95da4575a3aa9267c37694f19fc7908f23e391fb Mon Sep 17 00:00:00 2001 From: Cleverson Sacramento Date: Mon, 15 Apr 2013 16:57:09 -0300 Subject: [PATCH] Mais implementações de teste para controle de acesso --- impl/core/src/test/java/security/athentication/custom/CustomAuthenticatorTest.java | 6 ++++++ impl/core/src/test/java/security/athentication/custom/EventObserver.java | 20 ++++++++++++++++++++ impl/core/src/test/java/security/athentication/disabled/DisabledAuthenticationTest.java | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/resources/security/authenticator/disabled/demoiselle.properties | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 167 insertions(+), 0 deletions(-) create mode 100644 impl/core/src/test/java/security/athentication/custom/EventObserver.java create mode 100644 impl/core/src/test/java/security/athentication/disabled/DisabledAuthenticationTest.java create mode 100644 impl/core/src/test/resources/security/authenticator/disabled/demoiselle.properties diff --git a/impl/core/src/test/java/security/athentication/custom/CustomAuthenticatorTest.java b/impl/core/src/test/java/security/athentication/custom/CustomAuthenticatorTest.java index 0e286c2..320d1eb 100644 --- a/impl/core/src/test/java/security/athentication/custom/CustomAuthenticatorTest.java +++ b/impl/core/src/test/java/security/athentication/custom/CustomAuthenticatorTest.java @@ -38,6 +38,7 @@ package security.athentication.custom; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -59,10 +60,14 @@ public class CustomAuthenticatorTest { @Inject private SecurityContext context; + @Inject + private EventObserver observer; + @Deployment public static JavaArchive createDeployment() { JavaArchive deployment = Tests.createDeployment(ConfigurationResourceTest.class); deployment.addClass(CustomAuthenticator.class); + deployment.addClass(EventObserver.class); return deployment; } @@ -76,6 +81,7 @@ public class CustomAuthenticatorTest { public void loginProcess() { context.login(); assertTrue(context.isLoggedIn()); + assertNotNull(observer.getEvent()); assertEquals("demoiselle", context.getCurrentUser().getName()); } diff --git a/impl/core/src/test/java/security/athentication/custom/EventObserver.java b/impl/core/src/test/java/security/athentication/custom/EventObserver.java new file mode 100644 index 0000000..a8e20fb --- /dev/null +++ b/impl/core/src/test/java/security/athentication/custom/EventObserver.java @@ -0,0 +1,20 @@ +package security.athentication.custom; + +import javax.enterprise.context.RequestScoped; +import javax.enterprise.event.Observes; + +import br.gov.frameworkdemoiselle.security.AfterLoginSuccessful; + +@RequestScoped +public class EventObserver { + + private AfterLoginSuccessful event; + + public void observer(@Observes AfterLoginSuccessful event) { + this.event = event; + } + + public AfterLoginSuccessful getEvent() { + return this.event; + } +} diff --git a/impl/core/src/test/java/security/athentication/disabled/DisabledAuthenticationTest.java b/impl/core/src/test/java/security/athentication/disabled/DisabledAuthenticationTest.java new file mode 100644 index 0000000..e898d42 --- /dev/null +++ b/impl/core/src/test/java/security/athentication/disabled/DisabledAuthenticationTest.java @@ -0,0 +1,104 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package security.athentication.disabled; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import javax.enterprise.context.RequestScoped; +import javax.enterprise.event.Observes; +import javax.inject.Inject; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import security.athentication.custom.CustomAuthenticator; +import test.Tests; +import br.gov.frameworkdemoiselle.security.AfterLoginSuccessful; +import br.gov.frameworkdemoiselle.security.SecurityContext; +import configuration.resource.ConfigurationResourceTest; + +@RequestScoped +@RunWith(Arquillian.class) +public class DisabledAuthenticationTest { + + private static final String PATH = "src/test/resources/security/authenticator/disabled"; + + @Inject + private SecurityContext context; + + private AfterLoginSuccessful event; + + @Deployment + public static JavaArchive createDeployment() { + JavaArchive deployment = Tests.createDeployment(ConfigurationResourceTest.class); + deployment.addClass(CustomAuthenticator.class); + deployment.addAsResource(Tests.createFileAsset(PATH + "/demoiselle.properties"), "demoiselle.properties"); + return deployment; + } + + public void observer(@Observes AfterLoginSuccessful event) { + this.event = event; + } + + @Test + public void unauthenticated() { + assertTrue(context.isLoggedIn()); + assertEquals("demoiselle", context.getCurrentUser().getName()); + } + + @Test + public void loginProcess() { + context.login(); + assertTrue(context.isLoggedIn()); + assertNull(event); + assertEquals("demoiselle", context.getCurrentUser().getName()); + } + + // + // @Test + // public void logoutProcess() { + // context.login(); + // context.logout(); + // assertFalse(context.isLoggedIn()); + // assertNull(context.getCurrentUser()); + // } +} diff --git a/impl/core/src/test/resources/security/authenticator/disabled/demoiselle.properties b/impl/core/src/test/resources/security/authenticator/disabled/demoiselle.properties new file mode 100644 index 0000000..4f5f74a --- /dev/null +++ b/impl/core/src/test/resources/security/authenticator/disabled/demoiselle.properties @@ -0,0 +1,37 @@ +# Demoiselle Framework +# Copyright (C) 2010 SERPRO +# ---------------------------------------------------------------------------- +# This file is part of Demoiselle Framework. +# +# Demoiselle Framework is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License version 3 +# as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License version 3 +# along with this program; if not, see +# or write to the Free Software Foundation, Inc., 51 Franklin Street, +# Fifth Floor, Boston, MA 02110-1301, USA. +# ---------------------------------------------------------------------------- +# Este arquivo é parte do Framework Demoiselle. +# +# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou +# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação +# do Software Livre (FSF). +# +# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA +# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou +# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português +# para maiores detalhes. +# +# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título +# "LICENCA.txt", junto com esse programa. Se não, acesse +# ou escreva para a Fundação do Software Livre (FSF) Inc., +# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + +frameworkdemoiselle.security.authenticator.class=security.athentication.custom.CustomAuthenticator +frameworkdemoiselle.security.enabled=false \ No newline at end of file -- libgit2 0.21.2