Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vharseko committed Aug 5, 2019
1 parent cfd5422 commit 4cd85a2
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 9 deletions.
Expand Up @@ -66,10 +66,11 @@ public String getModuleId() {
* @return {@inheritDoc}
*/
@Override
public void initialize(MessagePolicy requestPolicy, MessagePolicy responsePolicy, CallbackHandler handler,
Map<String, Object> options) throws AuthenticationException {
public Promise<Void, AuthenticationException> initialize(MessagePolicy requestPolicy, MessagePolicy responsePolicy, CallbackHandler handler,
Map<String, Object> options) {
JsonValue properties = json(options);
authenticationIdAttribute = properties.get(AUTHENTICATION_ID).required().asString();
return org.forgerock.util.promise.Promises.newResultPromise(null);
}

/**
Expand Down
Expand Up @@ -143,4 +143,8 @@ public ObjectMapping createMapping(JsonValue mappingConfig) {
createdMapping.initRelationships(augmentedMappings);
return createdMapping;
}

public void bindEnhancedConfig(EnhancedConfig enhancedConfig2) {
this.enhancedConfig=enhancedConfig2;
}
}
Expand Up @@ -178,13 +178,13 @@ public void testDuplicateRelationshipSuccess(String ref1, String grantType1, Str
relationshipProvider.relationshipValidator.checkForDuplicateRelationshipsInInvocationState(relationshipList);
}

@DataProvider(name = "dulicateRelationshipData")
@DataProvider(name = "duplicateRelationshipData")
public Object[][] createDuplicateRelationshipData() {
return new Object[][] {
{ "ref1", "grantType1", "temporalConstraint1", "ref1", "grantType1", "temporalConstraint1" },
{ "ref1", null, null, "ref1", null, null },
{ "ref1", "grantType1", null, "ref1", "grantType1", null },
{ "ref1", null, "temporalConstraint1", "ref2", null, "temporalConstraint1" }
{ "ref1", null, "temporalConstraint1", "ref1", null, "temporalConstraint1" }
};
}

Expand Down
Expand Up @@ -32,6 +32,7 @@
import org.apache.felix.webconsole.WebConsoleSecurityProvider;
import org.forgerock.json.JsonValue;
import org.forgerock.openidm.config.enhanced.EnhancedConfig;
import org.forgerock.openidm.config.enhanced.JSONEnhancedConfig;
import org.forgerock.openidm.core.ServerConstants;
import org.forgerock.openidm.crypto.CryptoService;
import org.osgi.framework.Constants;
Expand Down Expand Up @@ -71,7 +72,7 @@ public class WebConsoleSecurityProviderService implements WebConsoleSecurityProv
@Activate
public void activate(ComponentContext context) {
final Dictionary<String, Object> dict = context.getProperties();
final String servicePid = (String) dict.get(Constants.SERVICE_PID);
final String servicePid = dict==null?null:(String) dict.get(Constants.SERVICE_PID);

final JsonValue config = enhancedConfig.getConfiguration(dict, servicePid, false);
userId = config.get(USER_NAME).asString();
Expand All @@ -96,4 +97,14 @@ public boolean authorize(final Object user, final String role) {
// accept all roles
return true;
}

public void bindCryptoService(CryptoService cryptoService2) {
cryptoService=cryptoService2;

}

public void bindEnhancedConfig(JSONEnhancedConfig jsonEnhancedConfig) {
enhancedConfig=jsonEnhancedConfig;

}
}
Expand Up @@ -23,6 +23,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.Dictionary;

import org.forgerock.http.util.Json;
import org.forgerock.json.JsonValue;
Expand Down Expand Up @@ -59,7 +60,7 @@ public Object[][] credentials() {
}


@Test
@Test(dataProvider="credentials")
public void testAuthenticateWithValidCredentials(final String username, final String password, final boolean valid)
throws IOException {
// given
Expand All @@ -83,12 +84,12 @@ private WebConsoleSecurityProviderService createWebConsoleSecurityProviderServic
new WebConsoleSecurityProviderService();
final JSONEnhancedConfig jsonEnhancedConfig = mock(JSONEnhancedConfig.class);
final CryptoService cryptoService = mock(CryptoService.class);
when(cryptoService.decryptIfNecessary(any(JsonValue.class))).thenReturn(json(password));
when(cryptoService.decryptIfNecessary(any(JsonValue.class))).thenReturn(json(CORRECT_PASSWORD.equals(password)?password:"BAD"));
webConsoleSecurityProviderService.bindCryptoService(cryptoService);
webConsoleSecurityProviderService.bindEnhancedConfig(jsonEnhancedConfig);

when(jsonEnhancedConfig.getConfigurationAsJson(any(ComponentContext.class)))
.thenReturn(getConfiguration(FELIX_WEBCONSOLE_JSON_CONFIG));
when(jsonEnhancedConfig.getConfigurationAsJson(any(ComponentContext.class))).thenReturn(getConfiguration(FELIX_WEBCONSOLE_JSON_CONFIG));
when(jsonEnhancedConfig.getConfiguration(any(Dictionary.class),any(String.class),any(Boolean.class))).thenReturn(getConfiguration(FELIX_WEBCONSOLE_JSON_CONFIG));
webConsoleSecurityProviderService.activate(mock(ComponentContext.class));
return webConsoleSecurityProviderService;
}
Expand Down
Expand Up @@ -934,4 +934,40 @@ private static Vector<URL> getJarFileListing(URL jarLocation, String filter) {
public void setCallback(MetaDataProviderCallback callback) {
this.callback[0] = callback;
}

protected void bindConnectorFrameworkFactory(ConnectorFrameworkFactory paramConnectorFrameworkFactory)
{
this.connectorFrameworkFactory = paramConnectorFrameworkFactory;
}

protected void unbindConnectorFrameworkFactory(ConnectorFrameworkFactory paramConnectorFrameworkFactory)
{
if (this.connectorFrameworkFactory == paramConnectorFrameworkFactory) {
this.connectorFrameworkFactory = null;
}
}

protected void bindCryptoService(CryptoService paramCryptoService)
{
this.cryptoService = paramCryptoService;
}

protected void unbindCryptoService(CryptoService paramCryptoService)
{
if (this.cryptoService == paramCryptoService) {
this.cryptoService = null;
}
}

protected void bindEnhancedConfig(EnhancedConfig paramEnhancedConfig)
{
this.enhancedConfig = paramEnhancedConfig;
}

protected void unbindEnhancedConfig(EnhancedConfig paramEnhancedConfig)
{
if (this.enhancedConfig == paramEnhancedConfig) {
this.enhancedConfig = null;
}
}
}
Expand Up @@ -16,25 +16,46 @@
package org.forgerock.openidm.security.impl;

import static org.forgerock.json.resource.Requests.newReadRequest;
import static org.forgerock.openidm.core.ServerConstants.LAUNCHER_INSTALL_LOCATION;
import static org.forgerock.openidm.core.ServerConstants.LAUNCHER_PROJECT_LOCATION;
import static org.forgerock.openidm.security.impl.SecurityTestUtils.createKeyStores;
import static org.mockito.Mockito.mock;

import java.nio.file.Paths;
import java.security.Security;

import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.forgerock.json.resource.NotSupportedException;
import org.forgerock.json.resource.ResourceException;
import org.forgerock.json.resource.ResourceResponse;
import org.forgerock.openidm.core.IdentityServer;
import org.forgerock.openidm.crypto.impl.CryptoServiceImpl;
import org.forgerock.openidm.keystore.KeyStoreManagementService;
import org.forgerock.openidm.keystore.KeyStoreService;
import org.forgerock.openidm.keystore.impl.KeyStoreServiceImpl;
import org.forgerock.services.context.RootContext;
import org.forgerock.util.promise.Promise;
import org.forgerock.util.test.assertj.AssertJPromiseAssert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class PrivateKeyResourceProviderTest {

private static final String TEST_KEY_ALIAS = "testCert";

@BeforeClass
public void runInitalSetup() throws Exception {
Security.addProvider(new BouncyCastleProvider());
System.setProperty(LAUNCHER_PROJECT_LOCATION,
Paths.get(getClass().getResource("/").toURI()).toFile().getAbsolutePath());
System.setProperty(LAUNCHER_INSTALL_LOCATION,
Paths.get(getClass().getResource("/").toURI()).toFile().getAbsolutePath());
try {
IdentityServer.initInstance(null);
} catch (final IllegalStateException e) {
// tried to reinitialize ignore
}
}
@Test
public void testReadPrivateKey() throws Exception {
//given
Expand Down

0 comments on commit 4cd85a2

Please sign in to comment.