From ad7c0a5e5c3cf4ec97791d06510a21668d07ae96 Mon Sep 17 00:00:00 2001 From: Emerson Oliveira Date: Wed, 11 Sep 2013 09:19:21 -0300 Subject: [PATCH] Adição de testes para o Authorization com o mecanismo de segurança desabilitado --- impl/core/src/test/java/security/authorization/disable/DisabledAuthorizationTest.java | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/resources/security/authorization/disabled/demoiselle.properties | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+), 0 deletions(-) create mode 100644 impl/core/src/test/java/security/authorization/disable/DisabledAuthorizationTest.java create mode 100644 impl/core/src/test/resources/security/authorization/disabled/demoiselle.properties diff --git a/impl/core/src/test/java/security/authorization/disable/DisabledAuthorizationTest.java b/impl/core/src/test/java/security/authorization/disable/DisabledAuthorizationTest.java new file mode 100644 index 0000000..6a51058 --- /dev/null +++ b/impl/core/src/test/java/security/authorization/disable/DisabledAuthorizationTest.java @@ -0,0 +1,98 @@ +/* + * 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.authorization.disable; + +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 junit.framework.Assert; + +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 security.authorization.custom.CustomAuthorizer; +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 DisabledAuthorizationTest { + + private static final String PATH = "src/test/resources/security/authorization/disabled"; + + @Inject + private SecurityContext context; + + private AfterLoginSuccessful event; + + @Deployment + public static JavaArchive createDeployment() { + JavaArchive deployment = Tests.createDeployment(ConfigurationResourceTest.class); + deployment.addClass(CustomAuthorizer.class); + deployment.addAsResource(Tests.createFileAsset(PATH + "/demoiselle.properties"), "demoiselle.properties"); + return deployment; + } + + public void observer(@Observes AfterLoginSuccessful event) { + this.event = event; + } + + @Test + public void hasPermissionProcess() { + Assert.assertTrue(context.hasPermission("resource", "operation")); + Assert.assertTrue(context.hasPermission("falseresource", "falseoperation")); + assertNull(event); + } + + @Test + public void hasRoleProcess(){ + Assert.assertTrue(context.hasRole("role")); + Assert.assertTrue(context.hasRole("falserole")); + assertNull(event); + } +} diff --git a/impl/core/src/test/resources/security/authorization/disabled/demoiselle.properties b/impl/core/src/test/resources/security/authorization/disabled/demoiselle.properties new file mode 100644 index 0000000..f916bfd --- /dev/null +++ b/impl/core/src/test/resources/security/authorization/disabled/demoiselle.properties @@ -0,0 +1,38 @@ +# 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.authorizer.class=security.authorization.custom.CustomAuthorizer +#frameworkdemoiselle.security.authenticator.class=security.athentication.custom.CustomAuthenticator +frameworkdemoiselle.security.enabled=false \ No newline at end of file -- libgit2 0.21.2