Skip to content

Commit

Permalink
GEODE-1647: add more unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jinmeiliao committed Jul 20, 2016
1 parent 16b7356 commit 50aedb1
Showing 1 changed file with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
package com.gemstone.gemfire.internal.security;


import static com.gemstone.gemfire.distributed.ConfigurationProperties.*;
import static org.assertj.core.api.Java6Assertions.*;
import static org.junit.Assert.*;

import java.util.Properties;

import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;

Expand All @@ -28,6 +32,12 @@

@Category(UnitTest.class)
public class GeodeSecurityUtilTest {
Properties properties;
@Before
public void before(){
properties = new Properties();
GeodeSecurityUtil.initSecurity(properties);
}

@Test
public void testGetObjectFromConstructor(){
Expand Down Expand Up @@ -61,6 +71,53 @@ public void testGetObjectFromFactoryMethod(){
.isInstanceOf(GemFireSecurityException.class);
}

@Test
public void testInitialSecurityFlags() {
// initial state of GeodeSecurityUtil
assertFalse(GeodeSecurityUtil.isClientSecurityRequired());
assertFalse(GeodeSecurityUtil.isIntegratedSecurity());
assertFalse(GeodeSecurityUtil.isPeerSecurityRequired());
}

@Test
public void testInitWithSecurityManager() {
properties.setProperty(SECURITY_MANAGER, "org.apache.geode.security.templates.SampleSecurityManager");
GeodeSecurityUtil.initSecurity(properties);
assertTrue(GeodeSecurityUtil.isClientSecurityRequired());
assertTrue(GeodeSecurityUtil.isIntegratedSecurity());
assertTrue(GeodeSecurityUtil.isPeerSecurityRequired());
}

@Test
public void testInitWithClientAuthenticator()
{
properties.setProperty(SECURITY_CLIENT_AUTHENTICATOR, "org.abc.test");
GeodeSecurityUtil.initSecurity(properties);
assertTrue(GeodeSecurityUtil.isClientSecurityRequired());
assertFalse(GeodeSecurityUtil.isIntegratedSecurity());
assertFalse(GeodeSecurityUtil.isPeerSecurityRequired());
}

@Test
public void testInitWithPeerAuthenticator()
{
properties.setProperty(SECURITY_PEER_AUTHENTICATOR, "org.abc.test");
GeodeSecurityUtil.initSecurity(properties);
assertFalse(GeodeSecurityUtil.isClientSecurityRequired());
assertFalse(GeodeSecurityUtil.isIntegratedSecurity());
assertTrue(GeodeSecurityUtil.isPeerSecurityRequired());
}

@Test
public void testInitWithShiroAuthenticator()
{
properties.setProperty(SECURITY_SHIRO_INIT, "shiro.ini");
GeodeSecurityUtil.initSecurity(properties);
assertTrue(GeodeSecurityUtil.isClientSecurityRequired());
assertTrue(GeodeSecurityUtil.isIntegratedSecurity());
assertTrue(GeodeSecurityUtil.isPeerSecurityRequired());
}

private static class Factories{
public static String getString(){
return new String();
Expand Down

0 comments on commit 50aedb1

Please sign in to comment.