aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>2021-10-14 14:19:06 +0200
committersonartech <sonartech@sonarsource.com>2021-10-14 20:03:05 +0000
commit233a760898a0f33891381e4a0e80553c91c17b45 (patch)
tree6242604228c2cdaadbf95c6ce2167fe4d44722a4
parent470d71bc8f1b098c7a8272114c157a8b8c600124 (diff)
downloadsonarqube-233a760898a0f33891381e4a0e80553c91c17b45.tar.gz
sonarqube-233a760898a0f33891381e4a0e80553c91c17b45.zip
SONAR-15517 fixed an issue when sometimes audit logs could not be downloaded
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserNewValue.java2
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/UserNewValueTest.java69
2 files changed, 70 insertions, 1 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserNewValue.java
index f78f046bd97..e2a42ffde27 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserNewValue.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserNewValue.java
@@ -164,7 +164,7 @@ public class UserNewValue extends NewValue {
addField(sb, "\"onboarded\": ", ObjectUtils.toString(this.onboarded), false);
addField(sb, "\"root\": ", ObjectUtils.toString(this.root), false);
addField(sb, "\"lastConnectionDate\": ", this.lastConnectionDate == null ?
- "" : DateUtils.formatDateTime(this.lastConnectionDate), false);
+ "" : DateUtils.formatDateTime(this.lastConnectionDate), true);
endString(sb);
return sb.toString();
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/UserNewValueTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/UserNewValueTest.java
new file mode 100644
index 00000000000..6c89310123b
--- /dev/null
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/UserNewValueTest.java
@@ -0,0 +1,69 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.audit.model;
+
+import org.json.simple.parser.JSONParser;
+import org.junit.Test;
+import org.sonar.db.user.UserDto;
+
+import static org.junit.Assert.fail;
+
+public class UserNewValueTest {
+
+ private static final JSONParser jsonParser = new JSONParser();
+
+ @Test
+ public void toString_givenAllFieldsWithValue_returnValidJSON() {
+ UserDto userDto = new UserDto();
+ userDto.setName("name");
+ userDto.setEmail("name@email.com");
+ userDto.setActive(true);
+ userDto.setScmAccounts("github-account");
+ userDto.setExternalId("name");
+ userDto.setExternalLogin("name");
+ userDto.setExternalIdentityProvider("github");
+ userDto.setLocal(false);
+ userDto.setOnboarded(true);
+ userDto.setLastConnectionDate(System.currentTimeMillis());
+ UserNewValue userNewValue = new UserNewValue(userDto);
+
+ String jsonString = userNewValue.toString();
+
+ assertValidJSON(jsonString);
+ }
+
+ @Test
+ public void toString_givenUserUuidAndUserLogin_returnValidJSON() {
+ UserNewValue userNewValue = new UserNewValue("userUuid", "userLogin");
+
+ String jsonString = userNewValue.toString();
+
+ assertValidJSON(jsonString);
+ }
+
+ private void assertValidJSON(String jsonString) {
+ try {
+ jsonParser.parse(jsonString);
+ } catch (Exception e) {
+ //if the json is invalid the test will fail
+ fail("UserNewValue.toString() generated invalid JSON. More details: " + e.getMessage());
+ }
+ }
+}