Skip to content

Commit 41d15cd

Browse files
author
Vladimir Kotal
committed
refactor for testing, avoid FAKE parameter
1 parent 17eebd1 commit 41d15cd

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

plugins/src/main/java/opengrok/auth/plugin/AbstractLdapPlugin.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import opengrok.auth.plugin.configuration.Configuration;
3131
import opengrok.auth.plugin.entity.User;
3232
import opengrok.auth.plugin.ldap.AbstractLdapProvider;
33-
import opengrok.auth.plugin.ldap.FakeLdapFacade;
3433
import opengrok.auth.plugin.ldap.LdapFacade;
3534
import org.opengrok.indexer.authorization.IAuthorizationPlugin;
3635
import org.opengrok.indexer.configuration.Group;
@@ -60,7 +59,6 @@ public abstract class AbstractLdapPlugin implements IAuthorizationPlugin {
6059
public static long nextId = 1;
6160

6261
protected static final String CONFIGURATION_PARAM = "configuration";
63-
protected static final String FAKE_PARAM = "fake";
6462

6563
private static final String SESSION_PREFIX = "opengrok-abstract-ldap-plugin-";
6664
protected String SESSION_USERNAME = SESSION_PREFIX + "username";
@@ -124,15 +122,8 @@ void load(AbstractLdapProvider provider) {
124122
*/
125123
@Override
126124
public void load(Map<String, Object> parameters) {
127-
Boolean fake;
128125
String configurationPath;
129126

130-
if ((fake = (Boolean) parameters.get(FAKE_PARAM)) != null
131-
&& fake) {
132-
ldapProvider = new FakeLdapFacade();
133-
return;
134-
}
135-
136127
if ((configurationPath = (String) parameters.get(CONFIGURATION_PARAM)) == null) {
137128
throw new NullPointerException("Missing param [" + CONFIGURATION_PARAM + "]");
138129
}

plugins/src/main/java/opengrok/auth/plugin/LdapAttrPlugin.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,21 @@ public LdapAttrPlugin() {
7676
sessionAllowed += "-" + nextId++;
7777
}
7878

79+
// for testing
80+
void load(Map<String, Object> parameters, AbstractLdapProvider provider) {
81+
super.load(provider);
82+
83+
init(parameters);
84+
}
85+
7986
@Override
8087
public void load(Map<String, Object> parameters) {
8188
super.load(parameters);
8289

90+
init(parameters);
91+
}
92+
93+
void init(Map<String, Object> parameters) {
8394
if ((ldapAttr = (String) parameters.get(ATTR_PARAM)) == null) {
8495
throw new NullPointerException("Missing param [" + ATTR_PARAM + "] in the setup");
8596
}

plugins/src/test/java/opengrok/auth/plugin/LdapAttrPluginTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import javax.servlet.http.HttpServletRequest;
3838
import opengrok.auth.entity.LdapUser;
3939
import opengrok.auth.plugin.entity.User;
40+
import opengrok.auth.plugin.ldap.FakeLdapFacade;
4041
import opengrok.auth.plugin.util.DummyHttpServletRequestLdap;
4142
import org.junit.AfterClass;
4243
import org.junit.Assert;
@@ -73,11 +74,10 @@ public void setUp() {
7374
plugin = new LdapAttrPlugin();
7475
Map<String, Object> parameters = new TreeMap<>();
7576

76-
parameters.put(AbstractLdapPlugin.FAKE_PARAM, true);
7777
parameters.put(LdapAttrPlugin.FILE_PARAM, whitelistFile.getAbsolutePath());
7878
parameters.put(LdapAttrPlugin.ATTR_PARAM, "mail");
7979

80-
plugin.load(parameters);
80+
plugin.load(parameters, new FakeLdapFacade());
8181
}
8282

8383
@SuppressWarnings("unchecked")

0 commit comments

Comments
 (0)