From 953e90b558a67ef95b99013525c4d90dd7fc3aad Mon Sep 17 00:00:00 2001 From: alain <108417558+alain-kermis-sonarsource@users.noreply.github.com> Date: Tue, 27 Sep 2022 13:32:40 +0200 Subject: [PATCH] SONAR-17195 Add final hash to user UUIDs for telemetry to anonymize older UUIDs --- .../server/telemetry/TelemetryDataJsonWriter.java | 3 ++- .../server/telemetry/TelemetryDataJsonWriterTest.java | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryDataJsonWriter.java b/server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryDataJsonWriter.java index bc8e4197583..690b170f622 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryDataJsonWriter.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryDataJsonWriter.java @@ -23,6 +23,7 @@ import java.time.Instant; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.Locale; +import org.apache.commons.codec.digest.DigestUtils; import org.jetbrains.annotations.NotNull; import org.sonar.api.utils.text.JsonWriter; @@ -89,7 +90,7 @@ public class TelemetryDataJsonWriter { json.beginArray(); statistics.getUserTelemetries().forEach(user -> { json.beginObject(); - json.prop("userUuid", user.getUuid()); + json.prop("userUuid", DigestUtils.sha3_224Hex(user.getUuid())); json.prop("status", user.isActive() ? "active" : "inactive"); if (user.getLastConnectionDate() != null) { diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/telemetry/TelemetryDataJsonWriterTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/telemetry/TelemetryDataJsonWriterTest.java index 507dade6fb4..edef00103c0 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/telemetry/TelemetryDataJsonWriterTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/telemetry/TelemetryDataJsonWriterTest.java @@ -31,6 +31,7 @@ import java.util.Map; import java.util.Random; import java.util.stream.Collectors; import java.util.stream.IntStream; +import org.apache.commons.codec.digest.DigestUtils; import org.jetbrains.annotations.NotNull; import org.junit.Test; import org.junit.runner.RunWith; @@ -269,7 +270,7 @@ public class TelemetryDataJsonWriterTest { } @Test - public void writes_all_users() { + public void writes_all_users_with_anonymous_md5_uuids() { TelemetryData data = SOME_TELEMETRY_DATA .setUsers(getUsers()) .build(); @@ -279,20 +280,20 @@ public class TelemetryDataJsonWriterTest { assertJson(json).isSimilarTo("{" + " \"users\": [" + " {" + - " \"userUuid\":\"uuid-0\"," + + " \"userUuid\":\"" + DigestUtils.sha3_224Hex("uuid-0") + "\"," + " \"lastActivity\":\"1970-01-01T00:00:00+0000\"," + " \"lastSonarlintActivity\":\"1970-01-01T00:00:00+0000\"," + " \"status\":\"active\"" + " }," + " {" + - " \"userUuid\":\"uuid-1\"," + + " \"userUuid\":\"" + DigestUtils.sha3_224Hex("uuid-1") + "\"," + " \"lastActivity\":\"1970-01-01T00:00:00+0000\"," + " \"lastSonarlintActivity\":\"1970-01-01T00:00:00+0000\"," + " \"status\":\"inactive\"" + " }," + " {" + - " \"userUuid\":\"uuid-2\"," + - " \"lastActivity\":\"1970-01-01T01:00:00+0100\"," + + " \"userUuid\":\"" + DigestUtils.sha3_224Hex("uuid-2") + "\"," + + " \"lastActivity\":\"1970-01-01T00:00:00+0000\"," + " \"lastSonarlintActivity\":\"1970-01-01T00:00:00+0000\"," + " \"status\":\"active\"" + " }" + -- 2.39.5