Skip to content

Commit

Permalink
[PDI-13754] LDAP Input Step - Using variable for "Trust store path"
Browse files Browse the repository at this point in the history
-added resolving variable for trust store path
-added resolving and decoding variable for Trust store password
-added tests
  • Loading branch information
AliaksandrShuhayeu committed Jan 5, 2017
1 parent 020c3ea commit a5a619f
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2016 by Pentaho : http://www.pentaho.com
* Copyright (C) 2002-2017 by Pentaho : http://www.pentaho.com
*
*******************************************************************************
*
Expand All @@ -27,6 +27,7 @@

import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.logging.LogChannelInterface;
import org.pentaho.di.core.util.Utils;
import org.pentaho.di.core.variables.VariableSpace;
import org.pentaho.di.trans.steps.ldapinput.store.CustomSocketFactory;

Expand All @@ -46,9 +47,9 @@ public LdapSslProtocol( LogChannelInterface log, VariableSpace variableSpace, Ld
boolean trustAllCertificates = false;

if ( meta.isUseCertificate() ) {
trustStorePath = meta.getParentStepMeta().getParentTransMeta().
environmentSubstitute( meta.getTrustStorePath() );
trustStorePassword = meta.getTrustStorePassword();
trustStorePath = variableSpace.environmentSubstitute( meta.getTrustStorePath() );
trustStorePassword = Utils.resolvePassword( variableSpace,
meta.getTrustStorePassword() );
trustAllCertificates = meta.isTrustAllCertificates();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2013 by Pentaho : http://www.pentaho.com
* Copyright (C) 2002-2017 by Pentaho : http://www.pentaho.com
*
*******************************************************************************
*
Expand Down Expand Up @@ -36,6 +36,7 @@

import org.junit.Before;
import org.junit.Test;
import org.pentaho.di.core.KettleClientEnvironment;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.logging.LogChannelInterface;
import org.pentaho.di.core.variables.VariableSpace;
Expand Down Expand Up @@ -212,6 +213,8 @@ public void testLdapProtocolConfiguresSocketFactoryIfNecessary() throws KettleEx

when( mockVariableSpace.environmentSubstitute( eq( hostConcrete ) ) ).thenReturn( hostConcrete );
when( mockVariableSpace.environmentSubstitute( eq( portConcrete ) ) ).thenReturn( portConcrete );
when( mockVariableSpace.environmentSubstitute( eq( trustStorePath ) ) ).thenReturn( trustStorePath );
when( mockVariableSpace.environmentSubstitute( eq( trustStorePassword ) ) ).thenReturn( trustStorePassword );

TestableLdapProtocol testableLdapProtocol =
new TestableLdapProtocol( mockLogChannelInterface, mockVariableSpace, mockLdapMeta, null );
Expand All @@ -221,4 +224,94 @@ public void testLdapProtocolConfiguresSocketFactoryIfNecessary() throws KettleEx
assertEquals( trustStorePath, testableLdapProtocol.trustStorePath );
assertEquals( trustStorePassword, testableLdapProtocol.trustStorePassword );
}

@Test
public void testResolvingPathVariables() throws KettleException {
String hostConcrete = "host_concrete";
String portConcrete = "12345";
String trustStorePath = "${KETTLE_SSL_PATH}";
String trustStorePathResolved = "/home/test_path";
String trustStorePassword = "TEST_PASSWORD";

when( mockLdapMeta.getHost() ).thenReturn( hostConcrete );
when( mockLdapMeta.getPort() ).thenReturn( portConcrete );
when( mockLdapMeta.getDerefAliases() ).thenReturn( "always" );
when( mockLdapMeta.getReferrals() ).thenReturn( "follow" );
when( mockLdapMeta.isUseCertificate() ).thenReturn( true );
when( mockLdapMeta.isTrustAllCertificates() ).thenReturn( true );
when( mockLdapMeta.getTrustStorePath() ).thenReturn( trustStorePath );
when( mockLdapMeta.getTrustStorePassword() ).thenReturn( trustStorePassword );

when( mockVariableSpace.environmentSubstitute( eq( hostConcrete ) ) ).thenReturn( hostConcrete );
when( mockVariableSpace.environmentSubstitute( eq( portConcrete ) ) ).thenReturn( portConcrete );
when( mockVariableSpace.environmentSubstitute( eq( trustStorePath ) ) ).thenReturn( trustStorePathResolved );
when( mockVariableSpace.environmentSubstitute( eq( trustStorePassword ) ) ).thenReturn( trustStorePassword );

KettleClientEnvironment.init();
TestableLdapProtocol testableLdapProtocol =
new TestableLdapProtocol( mockLogChannelInterface, mockVariableSpace, mockLdapMeta, null );
testableLdapProtocol.connect( null, null );
assertEquals( trustStorePathResolved, testableLdapProtocol.trustStorePath );
}


@Test
public void testResolvingPasswordVariables() throws KettleException {
String hostConcrete = "host_concrete";
String portConcrete = "12345";
String trustStorePath = "/home/test_path";
String trustStorePassword = "${PASSWORD_VARIABLE}";
String trustStorePasswordResolved = "TEST_PASSWORD_VALUE";

when( mockLdapMeta.getHost() ).thenReturn( hostConcrete );
when( mockLdapMeta.getPort() ).thenReturn( portConcrete );
when( mockLdapMeta.getDerefAliases() ).thenReturn( "always" );
when( mockLdapMeta.getReferrals() ).thenReturn( "follow" );
when( mockLdapMeta.isUseCertificate() ).thenReturn( true );
when( mockLdapMeta.isTrustAllCertificates() ).thenReturn( true );
when( mockLdapMeta.getTrustStorePath() ).thenReturn( trustStorePath );
when( mockLdapMeta.getTrustStorePassword() ).thenReturn( trustStorePassword );

when( mockVariableSpace.environmentSubstitute( eq( hostConcrete ) ) ).thenReturn( hostConcrete );
when( mockVariableSpace.environmentSubstitute( eq( portConcrete ) ) ).thenReturn( portConcrete );
when( mockVariableSpace.environmentSubstitute( eq( trustStorePath ) ) ).thenReturn( trustStorePath );
when( mockVariableSpace.environmentSubstitute( eq( trustStorePassword ) ) ).thenReturn( trustStorePasswordResolved );

KettleClientEnvironment.init();
TestableLdapProtocol testableLdapProtocol =
new TestableLdapProtocol( mockLogChannelInterface, mockVariableSpace, mockLdapMeta, null );
testableLdapProtocol.connect( null, null );
assertEquals( trustStorePasswordResolved, testableLdapProtocol.trustStorePassword );
}

@Test
public void testResolvingPasswordAndDecryptVariables() throws KettleException {
String hostConcrete = "host_concrete";
String portConcrete = "12345";
String trustStorePath = "/home/test_path";
String trustStorePassword = "${PASSWORD_VARIABLE}";
String trustStorePasswordResolved = "Encrypted 2be98afc86aa7f2e4cb79ff228dc6fa8c"; //original value 123456


when( mockLdapMeta.getHost() ).thenReturn( hostConcrete );
when( mockLdapMeta.getPort() ).thenReturn( portConcrete );
when( mockLdapMeta.getDerefAliases() ).thenReturn( "always" );
when( mockLdapMeta.getReferrals() ).thenReturn( "follow" );
when( mockLdapMeta.isUseCertificate() ).thenReturn( true );
when( mockLdapMeta.isTrustAllCertificates() ).thenReturn( true );
when( mockLdapMeta.getTrustStorePath() ).thenReturn( trustStorePath );
when( mockLdapMeta.getTrustStorePassword() ).thenReturn( trustStorePassword );

when( mockVariableSpace.environmentSubstitute( eq( hostConcrete ) ) ).thenReturn( hostConcrete );
when( mockVariableSpace.environmentSubstitute( eq( portConcrete ) ) ).thenReturn( portConcrete );
when( mockVariableSpace.environmentSubstitute( eq( trustStorePath ) ) ).thenReturn( trustStorePath );
when( mockVariableSpace.environmentSubstitute( eq( trustStorePassword ) ) ).thenReturn( trustStorePasswordResolved );

KettleClientEnvironment.init();
TestableLdapProtocol testableLdapProtocol =
new TestableLdapProtocol( mockLogChannelInterface, mockVariableSpace, mockLdapMeta, null );
testableLdapProtocol.connect( null, null );
assertEquals( "123456", testableLdapProtocol.trustStorePassword );
}

}

0 comments on commit a5a619f

Please sign in to comment.