forked from pentaho/pentaho-kettle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request pentaho#9303 from soagarwal1/BACKLOG-40063
[BACKLOG-40063] - Address review comments
- Loading branch information
Showing
4 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
core/src/test/java/org/pentaho/di/connections/common/bucket/TestConnectionDetailsChild.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/*! ****************************************************************************** | ||
* | ||
* Pentaho Data Integration | ||
* | ||
* Copyright (C) 2024 by Hitachi Vantara : http://www.pentaho.com | ||
* | ||
******************************************************************************* | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
******************************************************************************/ | ||
|
||
package org.pentaho.di.connections.common.bucket; | ||
|
||
import org.pentaho.metastore.persist.MetaStoreAttribute; | ||
|
||
/** | ||
* Child class to validate encrypted fields in Parent Classes getting encrypted without failure | ||
*/ | ||
public class TestConnectionDetailsChild extends TestConnectionDetails { | ||
|
||
@MetaStoreAttribute | ||
private String password3; | ||
|
||
public void setPassword3( String password3 ) { | ||
this.password3 = password3; | ||
} | ||
|
||
public String getPassword3() { | ||
return password3; | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
core/src/test/java/org/pentaho/di/connections/utils/EncryptUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/*! ****************************************************************************** | ||
* | ||
* Pentaho Data Integration | ||
* | ||
* Copyright (C) 2024 by Hitachi Vantara : http://www.pentaho.com | ||
* | ||
******************************************************************************* | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
******************************************************************************/ | ||
|
||
package org.pentaho.di.connections.utils; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.pentaho.di.connections.common.bucket.TestConnectionDetailsChild; | ||
import org.pentaho.di.core.KettleClientEnvironment; | ||
import org.pentaho.di.core.encryption.Encr; | ||
|
||
public class EncryptUtilsTest { | ||
|
||
private static String PASSWORD = "testpassword"; | ||
private static String PASSWORD2 = "testpassword2"; | ||
private static String PASSWORD3 = "testpassword3"; | ||
|
||
|
||
@Before | ||
public void setUp() throws Exception { | ||
KettleClientEnvironment.init(); | ||
} | ||
|
||
@Test | ||
public void testTransformFields() { | ||
TestConnectionDetailsChild testConnectionDetails = new TestConnectionDetailsChild(); | ||
testConnectionDetails.setPassword( PASSWORD ); | ||
testConnectionDetails.setPassword3( PASSWORD3 ); | ||
EncryptUtils.transformFields( testConnectionDetails, Encr::encryptPasswordIfNotUsingVariables ); | ||
Assert.assertTrue( testConnectionDetails.getPassword().startsWith( "Encrypted " ) ); | ||
} | ||
|
||
@Test | ||
public void testGetValue() throws NoSuchFieldException { | ||
TestConnectionDetailsChild testConnectionDetails = new TestConnectionDetailsChild(); | ||
testConnectionDetails.setPassword( PASSWORD ); | ||
testConnectionDetails.setPassword3( PASSWORD3 ); | ||
String value = EncryptUtils.getValue( testConnectionDetails, | ||
testConnectionDetails.getClass().getDeclaredField( "password3" ) ); | ||
Assert.assertNotNull( value ); | ||
Assert.assertEquals( PASSWORD3, value ); | ||
} | ||
|
||
@Test | ||
public void testSetValue() throws NoSuchFieldException { | ||
TestConnectionDetailsChild testConnectionDetails = new TestConnectionDetailsChild(); | ||
testConnectionDetails.setPassword( PASSWORD ); | ||
testConnectionDetails.setPassword3( PASSWORD3 ); | ||
EncryptUtils.setValue( testConnectionDetails, | ||
testConnectionDetails.getClass().getDeclaredField( "password3" ), PASSWORD2 ); | ||
Assert.assertEquals( testConnectionDetails.getPassword3(), PASSWORD2 ); | ||
} | ||
} |