Skip to content

Commit

Permalink
Merge pull request #25 from zowe/bugfix/IJMP-1990
Browse files Browse the repository at this point in the history
IJMP-1990 Fixed work with encrypted/plaintext credentials
  • Loading branch information
KUGDev authored Nov 15, 2024
2 parents a649e7e + 3f1e48f commit d76846e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 14 deletions.
32 changes: 22 additions & 10 deletions src/main/kotlin/org/zowe/kotlinsdk/zowe/config/ZoweConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,12 @@ data class ZoweConfig(
ps.forEach { (_, profile) ->
if (profile.profiles != null) extractSecureProperties(configCredentialsMap, profile.profiles)
profile.secure?.forEach { secureProfileProp ->
profile.properties?.set(
secureProfileProp,
configCredentialsMap["profiles.${buildCredPath(profile, ".profiles.")}.properties.${secureProfileProp}"]
)
if (profile.properties?.get(secureProfileProp) == null &&
configCredentialsMap["profiles.${buildCredPath(profile, ".profiles.")}.properties.${secureProfileProp}"] != null)
profile.properties?.set(
"secure"+secureProfileProp,
configCredentialsMap["profiles.${buildCredPath(profile, ".profiles.")}.properties.${secureProfileProp}"]
)
}
}
}
Expand Down Expand Up @@ -345,11 +347,11 @@ data class ZoweConfig(
}
val curr = buildCredPath(profile, ".profiles.")
profile.secure?.forEach { propName ->
if (profile.properties?.containsKey(propName) == true)
if (profile.properties?.containsKey("secure"+propName) == true)
if (curr == zosmfProfileName)
zosmfConfigCredentialsMap["profiles.${curr}.properties.${propName}"] = profile.properties[propName]
zosmfConfigCredentialsMap["profiles.${curr}.properties.${propName}"] = profile.properties["secure"+propName]
else if (curr == baseProfileName)
baseConfigCredentialsMap["profiles.${curr}.properties.${propName}"] = profile.properties[propName]
baseConfigCredentialsMap["profiles.${curr}.properties.${propName}"] = profile.properties["secure"+propName]
}
}
}
Expand Down Expand Up @@ -395,7 +397,7 @@ data class ZoweConfig(
private fun removeSecure(ps: Map<String, ZoweConfigProfile>?) {
ps?.forEach { (_, v) ->
v.secure?.forEach { propName ->
v.properties?.remove(propName)
v.properties?.remove("secure"+propName)
}
removeSecure(v.profiles)
}
Expand Down Expand Up @@ -425,11 +427,21 @@ data class ZoweConfig(

var user: String?
get() = searchProperty("user") { zosmf(); base() } as String?
set(el) { updateProperty("user", el ?: "") { zosmf(); base() } }
?: searchProperty("secureuser") { zosmf(); base() } as String?
set(el) { if (searchProperty("user") { zosmf(); base() } as String? != null)
updateProperty("user", el ?: "") { zosmf(); base() }
else
updateProperty("secureuser", el ?: "") { zosmf(); base() } }

var password: String?
get() = searchProperty("password") { zosmf(); base() } as String?
set(el) { updateProperty("password", el ?: "") { zosmf(); base() } }
?: searchProperty("securepassword") { zosmf(); base() } as String?
set(el) {
if (searchProperty("password") { zosmf(); base() } as String? != null)
updateProperty("password", el ?: "") { zosmf(); base() }
else
updateProperty("securepassword", el ?: "") { zosmf(); base() }
}

var host: String?
get() = searchProperty("host") { zosmf(); base() } as String?
Expand Down
19 changes: 16 additions & 3 deletions src/test/kotlin/org/zowe/kotlinsdk/zowe/ZoweConfigParsingTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,26 @@ class ZoweConfigParsingTest: ZoweConfigTestBase() {
Assertions.assertEquals(zoweConfig.encoding, 1037)
zoweConfig.responseTimeout = 300
Assertions.assertEquals(zoweConfig.responseTimeout, 300)
Assertions.assertEquals(zoweConfig.user, "zosmfUser")
zoweConfig.user = null
Assertions.assertEquals(zoweConfig.user, "")
zoweConfig.user = "zUser"
Assertions.assertEquals(zoweConfig.user, "zUser")
Assertions.assertEquals(zoweConfig.password, "zosmfPassword")
zoweConfig.password = null
Assertions.assertEquals(zoweConfig.password, "")
zoweConfig.password = "zPassword"
Assertions.assertEquals(zoweConfig.password, "zPassword")
zoweConfig.restoreProfile()
Assertions.assertEquals(fullProfileName(zoweConfig.zosmfProfile), "lpar1.zosmf")
Assertions.assertEquals(zoweConfig.sshProfile?.name, "ssh")
Assertions.assertEquals(zoweConfig.tsoProfile?.name, "tso")
Assertions.assertNull(zoweConfig.profile(null))
Assertions.assertNull(zoweConfig.profile("."))
Assertions.assertNull(zoweConfig.profile("non.existent.profile"))
zoweConfig.setProfile("lpar1.section1.section2.emptyZosmfProfile")
Assertions.assertEquals(zoweConfig.user, "testUser")
zoweConfig.user = "zUser1"
Assertions.assertEquals(zoweConfig.user, "zUser1")
zoweConfig.extractSecureProperties("/wrong/zowe/config/path", keytarWrapper)
}

Expand All @@ -164,8 +177,8 @@ class ZoweConfigParsingTest: ZoweConfigTestBase() {
ZOSConnection(
"example.host2",
"443",
"testUser",
"testPassword",
"zosmfUser",
"zosmfPassword",
profileName = "lpar1.section1.testParametersProfile",
rejectUnauthorized = false,
basePath = "/api",
Expand Down
21 changes: 20 additions & 1 deletion src/test/resources/zowe.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
"basePath": "/api"
},
"profiles": {
"section2": {
"profiles": {
"emptyZosmfProfile": {
"secure": [
"user",
"password"
]
}
}
},
"testParametersProfile": {
"type": "zosmf",
"properties": {
Expand All @@ -26,7 +36,9 @@
"rejectUnauthorized": false,
"protocol": "https",
"encoding": 37,
"responseTimeout": 600
"responseTimeout": 600,
"user": "zosmfUser",
"password": "zosmfPassword"
}
}
}
Expand All @@ -37,6 +49,13 @@
"port": 10443
},
"secure": []
},
"base": {
"type": "base",
"secure": [
"user",
"password"
]
}
}
},
Expand Down

0 comments on commit d76846e

Please sign in to comment.