Skip to content

Commit

Permalink
Merge pull request #23 from zowe/feature/IJMP-1825-v2
Browse files Browse the repository at this point in the history
IJMP-1825 Fix for windows credentials store
  • Loading branch information
ktsytsen authored Aug 12, 2024
2 parents 2edd2d9 + b334fb9 commit 4db02f8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/main/kotlin/org/zowe/kotlinsdk/zowe/config/ZoweConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ data class ZoweConfig(
* @return Nothing.
*/
fun saveNewSecureProperties(
filePath: String,
origFilePath: String,
configCredentialsMap: MutableMap<String, Any?>,
keytar: KeytarWrapper = DefaultKeytarWrapper()
) {
val filePath = origFilePath.split("/").toTypedArray().joinToString(File.separator)
val configCredentials = try {
readZoweCredentialsFromStorage(keytar).toMutableMap()
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import org.zowe.kotlinsdk.zowe.config.encodeToBase64
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import java.io.InputStream
import java.util.*

val TEST_HOST = "example.host"
val TEST_PORT = "443"
Expand Down
19 changes: 13 additions & 6 deletions src/test/kotlin/org/zowe/kotlinsdk/zowe/ZoweCredentialsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.junit.jupiter.api.TestInstance
import org.zowe.kotlinsdk.zowe.config.WINDOWS_MAX_PASSWORD_LENGTH
import org.zowe.kotlinsdk.zowe.config.ZoweConfig
import org.zowe.kotlinsdk.zowe.config.parseConfigJson
import java.io.File


@TestInstance(TestInstance.Lifecycle.PER_CLASS)
Expand All @@ -42,12 +43,12 @@ class ZoweCredentialsTest : ZoweConfigTestBase() {
Assertions.assertEquals(createSinglePassword(TEST_ZOWE_CONFIG_PATH, "testU", "testP"), password)
}
}
zoweConfig.extractSecureProperties(TEST_ZOWE_CONFIG_PATH, testKeytarWrapper)
zoweConfig.extractSecureProperties(TEST_ZOWE_CONFIG_PATH.split("/").toTypedArray().joinToString(File.separator), testKeytarWrapper)
zoweConfig.user = "testU"
zoweConfig.password = "testP"
zoweConfig.saveSecureProperties(TEST_ZOWE_CONFIG_PATH, testKeytarWrapper)
zoweConfig.saveSecureProperties(TEST_ZOWE_CONFIG_PATH.split("/").toTypedArray(), testKeytarWrapper)
zoweConfig.user = "testUser"
zoweConfig.saveSecureProperties("TEST_ZOWE_CONFIG_PATH", testKeytarWrapper)
zoweConfig.saveSecureProperties("TEST_ZOWE_CONFIG_PATH".split("/").toTypedArray(), testKeytarWrapper)
}

@Test
Expand All @@ -56,7 +57,7 @@ class ZoweCredentialsTest : ZoweConfigTestBase() {
override fun setPassword(service: String, account: String, password: String) {
Assertions.assertEquals(ZoweConfig.ZOWE_SERVICE_BASE, service)
Assertions.assertEquals(ZoweConfig.ZOWE_SECURE_ACCOUNT, account)
Assertions.assertEquals(createSinglePassword(TEST_ZOWE_CONFIG_PATH, TEST_USER, TEST_PASSWORD), password)
Assertions.assertEquals(createSinglePassword(TEST_ZOWE_CONFIG_PATH.split("/").toTypedArray().joinToString(File.separator), TEST_USER, TEST_PASSWORD), password)
}

override fun getCredentials(service: String): Map<String, String> {
Expand All @@ -72,10 +73,16 @@ class ZoweCredentialsTest : ZoweConfigTestBase() {
@Test
fun testUpdateNewSecureProperties() {
val testKeytarWrapper = object : DefaultMockKeytarWrapper() {
override fun getCredentials(service: String): Map<String, String> {
return mapOf(Pair(
ZoweConfig.ZOWE_SECURE_ACCOUNT,
createSinglePassword(TEST_ZOWE_CONFIG_PATH.split("/").toTypedArray().joinToString(File.separator), TEST_USER, TEST_PASSWORD)
))
}
override fun setPassword(service: String, account: String, password: String) {
Assertions.assertEquals(ZoweConfig.ZOWE_SERVICE_BASE, service)
Assertions.assertEquals(ZoweConfig.ZOWE_SECURE_ACCOUNT, account)
Assertions.assertEquals(createSinglePassword(TEST_ZOWE_CONFIG_PATH, "testU", "testP"), password)
Assertions.assertEquals(createSinglePassword(TEST_ZOWE_CONFIG_PATH.split("/").toTypedArray().joinToString(File.separator), "testU", "testP"), password)
}
}
val configCredentialsMap = mutableMapOf<String, Any?>()
Expand All @@ -92,7 +99,7 @@ class ZoweCredentialsTest : ZoweConfigTestBase() {
Assertions.assertEquals(ZoweConfig.ZOWE_SECURE_ACCOUNT, account)
Assertions.assertEquals(
createMultiplePasswords(
listOf("TestFilePath", TEST_ZOWE_CONFIG_PATH),
listOf("TestFilePath", TEST_ZOWE_CONFIG_PATH.split("/").toTypedArray().joinToString(File.separator)),
TEST_USER,
TEST_PASSWORD
), password
Expand Down

0 comments on commit 4db02f8

Please sign in to comment.