Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public JCESecurityModule (Configuration cfg, Logger logger, String realm) throws
*/
@Override
public void setConfiguration (Configuration cfg) throws ConfigurationException {
this.cfg = cfg;
super.setConfiguration(cfg);
try {
init(cfg.get("provider"), cfg.get("lmk", null), cfg.getBoolean("rebuildlmk"));
} catch (SMException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
import org.jpos.security.SMException;
import org.jpos.security.SecureDESKey;
import org.jpos.util.Logger;
import org.jpos.util.LogEvent;
import org.jpos.util.LogListener;
import java.io.File;
import static org.mockito.Mockito.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -323,12 +327,8 @@ public void testConstructorThrowsNullPointerException2() throws Throwable {
try {
new JCESecurityModule(cfg, new Logger(), "testJCESecurityModuleRealm");
fail("Expected NullPointerException to be thrown");
} catch (NullPointerException ex) {
if (isJavaVersionAtMost(JAVA_14)) {
assertNull(ex.getMessage(), "ex.getMessage()");
} else {
assertEquals("Cannot invoke \"org.jpos.core.Configuration.get(String)\" because \"this.cfg\" is null", ex.getMessage(), "ex.getMessage()");
}
} catch (NullPointerException _) {
//expected
}
}

Expand Down Expand Up @@ -680,12 +680,8 @@ public void testSetConfigurationThrowsNullPointerException() throws Throwable {
try {
jCESecurityModule.setConfiguration(cfg);
fail("Expected NullPointerException to be thrown");
} catch (NullPointerException ex) {
if (isJavaVersionAtMost(JAVA_14)) {
assertNull(ex.getMessage(), "ex.getMessage()");
} else {
assertEquals("Cannot invoke \"org.jpos.core.Configuration.get(String)\" because \"this.cfg\" is null", ex.getMessage(), "ex.getMessage()");
}
} catch (NullPointerException _) {
//expected
}
}

Expand Down Expand Up @@ -1821,4 +1817,30 @@ public void testFormKeyFromClearComponent() throws Throwable {
assertArrayEquals(ISOUtil.hex2byte("40D522"), sdk.getKeyCheckValue(), "3: KeyCheck was " + ISOUtil.hexString(sdk.getKeyCheckValue()));
}

@Test
public void testDebugPropertyEnablesLogging() throws Exception {
JCESecurityModule module = new JCESecurityModule();
Configuration cfg = new SimpleConfiguration();

File tempLmk = File.createTempFile("test-lmk", ".lmk");
tempLmk.deleteOnExit();

cfg.put("lmk", tempLmk.getAbsolutePath());
cfg.put("rebuildlmk", "true");
cfg.put("debug", "true");


module.setConfiguration(cfg);

Logger logger = new Logger();
LogListener listener = mock(LogListener.class);
logger.addListener(listener);
module.setLogger(logger, "test-realm");

// Generate a key to trigger logging
module.generateKey((short) 128, "ZPK");

verify(listener, times(1)).log(any(LogEvent.class));
}

}
Loading