package net.sf.jguard.core.authentication.configuration;

import net.sf.jguard.core.authentication.loginmodules.UserLoginModule;
import org.junit.Assert;
import org.junit.Test;

import javax.security.auth.login.AppConfigurationEntry;
import java.util.HashMap;
import java.util.Map;

/**
 * @author <a href="mailto:diabolo512@users.sourceforge.net">Charles Lescot</a>
 */
public class GuestAppConfigurationEntryFilterTest {

    @Test
    public void testFilterWithUnknownClass() {
        GuestAppConfigurationEntryFilter filter = new GuestAppConfigurationEntryFilter();
        Map<String, ?> options = new HashMap<String, Object>();
        AppConfigurationEntry entry = new AppConfigurationEntry("toto", AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, options);
        Assert.assertTrue(filter.filter(entry) == null);
    }

    @Test
    public void testFilterWithExistingClassButNotASubclassOfUserLoginModule() {
        GuestAppConfigurationEntryFilter filter = new GuestAppConfigurationEntryFilter();
        Map<String, ?> options = new HashMap<String, Object>();
        AppConfigurationEntry entry = new AppConfigurationEntry("com.sun.security.auth.module.KeyStoreLoginModule", AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, options);
        Assert.assertTrue(filter.filter(entry) == null);
    }

    @Test
    public void testFilterWithExistingClassAndASubclassOfUserLoginModule() {
        GuestAppConfigurationEntryFilter filter = new GuestAppConfigurationEntryFilter();
        Map<String, ?> options = new HashMap<String, Object>();
        AppConfigurationEntry entry = new AppConfigurationEntry("net.sf.jguard.core.authentication.loginmodules.UserLoginModule", AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, options);
        AppConfigurationEntry returnedEntry = filter.filter(entry);
        Assert.assertTrue(returnedEntry != null);
        Assert.assertTrue(returnedEntry.getOptions().containsKey(UserLoginModule.SKIP_CREDENTIAL_CHECK));
        Assert.assertTrue(returnedEntry.getOptions().get(UserLoginModule.SKIP_CREDENTIAL_CHECK).equals(Boolean.TRUE.toString()));
    }
}

@@ -51,16 +51,73 @@
 ation;%0A%0A
+import com.sun.security.auth.module.KeyStoreLoginModule;%0A
 import n
@@ -1198,38 +1198,8 @@
 try(
-%22com.sun.security.auth.module.
 KeyS
@@ -1205,33 +1205,48 @@
 StoreLoginModule
-%22
+.class.getName()
 , AppConfigurati
@@ -1669,72 +1669,39 @@
 try(
-%22net.sf.jguard.core.authentication.l
+UserL
 ogin
-m
+M
 odule
-s.UserLoginModule%22
+.class.getName()
 , Ap

replace appConfigurationEntry names by classNames for test