Commit ad7c0a5e5c3cf4ec97791d06510a21668d07ae96
1 parent
283fb6a6
Exists in
master
Adição de testes para o Authorization com o mecanismo de segurança
desabilitado
Showing
2 changed files
with
136 additions
and
0 deletions
Show diff stats
impl/core/src/test/java/security/authorization/disable/DisabledAuthorizationTest.java
0 → 100644
| @@ -0,0 +1,98 @@ | @@ -0,0 +1,98 @@ | ||
| 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.authorization.disable; | ||
| 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 junit.framework.Assert; | ||
| 48 | + | ||
| 49 | +import org.jboss.arquillian.container.test.api.Deployment; | ||
| 50 | +import org.jboss.arquillian.junit.Arquillian; | ||
| 51 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
| 52 | +import org.junit.Test; | ||
| 53 | +import org.junit.runner.RunWith; | ||
| 54 | + | ||
| 55 | +import security.athentication.custom.CustomAuthenticator; | ||
| 56 | +import security.authorization.custom.CustomAuthorizer; | ||
| 57 | +import test.Tests; | ||
| 58 | +import br.gov.frameworkdemoiselle.security.AfterLoginSuccessful; | ||
| 59 | +import br.gov.frameworkdemoiselle.security.SecurityContext; | ||
| 60 | +import configuration.resource.ConfigurationResourceTest; | ||
| 61 | + | ||
| 62 | +@RequestScoped | ||
| 63 | +@RunWith(Arquillian.class) | ||
| 64 | +public class DisabledAuthorizationTest { | ||
| 65 | + | ||
| 66 | + private static final String PATH = "src/test/resources/security/authorization/disabled"; | ||
| 67 | + | ||
| 68 | + @Inject | ||
| 69 | + private SecurityContext context; | ||
| 70 | + | ||
| 71 | + private AfterLoginSuccessful event; | ||
| 72 | + | ||
| 73 | + @Deployment | ||
| 74 | + public static JavaArchive createDeployment() { | ||
| 75 | + JavaArchive deployment = Tests.createDeployment(ConfigurationResourceTest.class); | ||
| 76 | + deployment.addClass(CustomAuthorizer.class); | ||
| 77 | + deployment.addAsResource(Tests.createFileAsset(PATH + "/demoiselle.properties"), "demoiselle.properties"); | ||
| 78 | + return deployment; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + public void observer(@Observes AfterLoginSuccessful event) { | ||
| 82 | + this.event = event; | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + @Test | ||
| 86 | + public void hasPermissionProcess() { | ||
| 87 | + Assert.assertTrue(context.hasPermission("resource", "operation")); | ||
| 88 | + Assert.assertTrue(context.hasPermission("falseresource", "falseoperation")); | ||
| 89 | + assertNull(event); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + @Test | ||
| 93 | + public void hasRoleProcess(){ | ||
| 94 | + Assert.assertTrue(context.hasRole("role")); | ||
| 95 | + Assert.assertTrue(context.hasRole("falserole")); | ||
| 96 | + assertNull(event); | ||
| 97 | + } | ||
| 98 | +} |
impl/core/src/test/resources/security/authorization/disabled/demoiselle.properties
0 → 100644
| @@ -0,0 +1,38 @@ | @@ -0,0 +1,38 @@ | ||
| 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.authorizer.class=security.authorization.custom.CustomAuthorizer | ||
| 37 | +#frameworkdemoiselle.security.authenticator.class=security.athentication.custom.CustomAuthenticator | ||
| 38 | +frameworkdemoiselle.security.enabled=false | ||
| 0 | \ No newline at end of file | 39 | \ No newline at end of file |