Skip to content

Commit 988794a

Browse files
committed
change user id format
1 parent 61539c7 commit 988794a

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,9 @@ tasks {
316316

317317
)
318318

319-
//to simulate external user
319+
//to simulate external user. don't change the value it's used in UniqueGeneratedUserId
320320
// environment(
321-
// "devenv" to "notdigma"
321+
// "devenv" to "externalUserSimulator"
322322
// )
323323

324324
}

ide-common/src/main/kotlin/org/digma/intellij/plugin/common/UniqueGeneratedUserId.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ object UniqueGeneratedUserId {
1616
val userName = System.getProperty("user.name") ?: "user"
1717
userId = "$userName@${CommonUtils.getLocalHostname()}"
1818
isDevUser = true
19+
} else if (System.getenv("devenv") == "externalUserSimulator") {
20+
if (service<PersistenceService>().getUserId() == null) {
21+
service<PersistenceService>().setUserId(generateUniqueUserId("digma"))
22+
}
23+
userId = service<PersistenceService>().getUserId()!!
24+
isDevUser = false
1925
} else {
2026
if (service<PersistenceService>().getUserId() == null) {
2127
service<PersistenceService>().setUserId(generateUniqueUserId())
@@ -28,7 +34,7 @@ object UniqueGeneratedUserId {
2834

2935

3036
//this method is outside the class so that it can be tested,UniqueGeneratedUserId can not be instantiated in regular unit tests
31-
fun generateUniqueUserId(): String {
37+
fun generateUniqueUserId(salt: String = ""): String {
3238
try {
3339
val userName = System.getProperty("user.name")
3440
val userHome = System.getProperty("user.home")
@@ -37,7 +43,7 @@ fun generateUniqueUserId(): String {
3743
//MUST BE SORTED
3844
val ni = NetworkInterface.networkInterfaces().toList().mapNotNull { it.hardwareAddress }.map { macAddressToString(it) }.sorted()
3945
.joinToString("-")
40-
val baseString = "$userName-$userHome-$osName-$osArch-$ni"
46+
val baseString = salt + userName + userHome + osName + osArch + ni
4147
return DigestUtils.sha1Hex(baseString)
4248
} catch (e: Throwable) {
4349
return DigestUtils.sha1Hex(UUID.randomUUID().toString())

ide-common/src/test/kotlin/org/digma/intellij/plugin/common/UserIdTests.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,13 @@ class UserIdTests {
1414
}
1515
}
1616

17+
@Test
18+
fun testUniquenessWithSalt() {
19+
val myId = generateUniqueUserId("digma")
20+
repeat(10) {
21+
val id = generateUniqueUserId("digma")
22+
assertEquals(myId, id)
23+
}
24+
}
25+
1726
}

0 commit comments

Comments
 (0)