]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-17195 Add final hash to user UUIDs for telemetry to anonymize older UUIDs
authoralain <108417558+alain-kermis-sonarsource@users.noreply.github.com>
Tue, 27 Sep 2022 11:32:40 +0000 (13:32 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 27 Sep 2022 20:03:17 +0000 (20:03 +0000)
server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryDataJsonWriter.java
server/sonar-server-common/src/test/java/org/sonar/server/telemetry/TelemetryDataJsonWriterTest.java

index bc8e4197583d903a24ffc1fe5c2769096d04911f..690b170f622fa2cade6d91bba281a3a7340e7e44 100644 (file)
@@ -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) {
index 507dade6fb41a19920e3d3c927c01bf53a5b21a4..edef00103c040d48efc3b0fae402f3f8e6d5d398 100644 (file)
@@ -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\"" +
       "    }" +