aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server-common
diff options
context:
space:
mode:
authoralain <108417558+alain-kermis-sonarsource@users.noreply.github.com>2022-09-27 13:32:40 +0200
committersonartech <sonartech@sonarsource.com>2022-09-27 20:03:17 +0000
commit953e90b558a67ef95b99013525c4d90dd7fc3aad (patch)
treeb43e21e2021896b14a894bce5f877cd782930a00 /server/sonar-server-common
parent57a8a41fa35a7949e9cb3582b60e368bd5253e2d (diff)
downloadsonarqube-953e90b558a67ef95b99013525c4d90dd7fc3aad.tar.gz
sonarqube-953e90b558a67ef95b99013525c4d90dd7fc3aad.zip
SONAR-17195 Add final hash to user UUIDs for telemetry to anonymize older UUIDs
Diffstat (limited to 'server/sonar-server-common')
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryDataJsonWriter.java3
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/telemetry/TelemetryDataJsonWriterTest.java11
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\"" +
" }" +