mirror of
https://github.com/keycloak/keycloak.git
synced 2026-01-10 15:32:05 -03:30
Prevent NPE in CryptoIntegration.setProvider
Closes #38596 Signed-off-by: Leonid Rozenblyum <lrozenblyum@gmail.com>
This commit is contained in:
parent
50fef70f14
commit
a0852eaa2e
@ -94,7 +94,7 @@ public class CryptoIntegration {
|
||||
}
|
||||
|
||||
public static void setProvider(CryptoProvider provider) {
|
||||
logger.debugf("Using the crypto provider: %s", provider.getClass().getName());
|
||||
logger.debugf("Using the crypto provider: %s", provider != null ? provider.getClass().getName() : "null");
|
||||
cryptoProvider = provider;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,36 @@
|
||||
package org.keycloak.common.crypto;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class CryptoIntegrationTest {
|
||||
private static CryptoProvider originalProvider;
|
||||
|
||||
@BeforeClass
|
||||
public static void keepOriginalProvider() {
|
||||
CryptoIntegrationTest.originalProvider = getSelectedProvider();
|
||||
}
|
||||
|
||||
// doing our best to avoid any side effects on other tests by restoring the initial state of CryptoIntegration
|
||||
@AfterClass
|
||||
public static void restoreOriginalProvider() {
|
||||
CryptoIntegration.setProvider(originalProvider);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canSetNullProvider() {
|
||||
CryptoIntegration.setProvider(null);
|
||||
assertNull(getSelectedProvider());
|
||||
}
|
||||
|
||||
private static CryptoProvider getSelectedProvider() {
|
||||
try {
|
||||
return CryptoIntegration.getProvider();
|
||||
} catch (IllegalStateException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user