From 2872c6df4a1006658f049d17807f68120a4d3310 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Tue, 20 Feb 2024 15:06:18 +0530 Subject: [PATCH 1/3] fix: vulnerability fix --- CHANGELOG.md | 5 ++ build.gradle | 12 ++--- cli/build.gradle | 4 +- ee/build.gradle | 8 +-- implementationDependencies.json | 50 +++++++++---------- .../cronjobs/telemetry/Telemetry.java | 49 ++++++++++++++++++ .../io/supertokens/test/TelemetryTest.java | 17 +++++++ 7 files changed, 108 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 733825249..a61cb606c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [unreleased] +## [5.0.3] - 2024-02-20 + +- Fixes vulnerabilities in dependencies +- Updates telemetry payload + ## [5.0.2] - 2023-09-07 - Fixed an encoding/decoding issue for certain access token payloads diff --git a/build.gradle b/build.gradle index 6c72d7b1c..13c541373 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ compileTestJava { options.encoding = "UTF-8" } // } //} -version = "5.0.2" +version = "5.0.3" repositories { @@ -33,22 +33,22 @@ dependencies { implementation group: 'com.google.code.gson', name: 'gson', version: '2.3.1' // https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml - implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.14.0' + implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.14.2' // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core - implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.14.0' + implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.16.1' // https://mvnrepository.com/artifact/ch.qos.logback/logback-classic - implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3' + implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.4.14' // https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-core - implementation group: 'org.apache.tomcat.embed', name: 'tomcat-embed-core', version: '10.1.1' + implementation group: 'org.apache.tomcat.embed', name: 'tomcat-embed-core', version: '10.1.18' // https://mvnrepository.com/artifact/com.google.code.findbugs/jsr305 implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2' // https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc - implementation group: 'org.xerial', name: 'sqlite-jdbc', version: '3.30.1' + implementation group: 'org.xerial', name: 'sqlite-jdbc', version: '3.45.1.0' // https://mvnrepository.com/artifact/org.mindrot/jbcrypt implementation group: 'org.mindrot', name: 'jbcrypt', version: '0.4' diff --git a/cli/build.gradle b/cli/build.gradle index 904dc0065..2b61a0da1 100644 --- a/cli/build.gradle +++ b/cli/build.gradle @@ -19,10 +19,10 @@ dependencies { implementation group: 'com.google.code.gson', name: 'gson', version: '2.3.1' // https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml - implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.10.0' + implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.14.2' // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core - implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.10.0' + implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.16.1' // https://mvnrepository.com/artifact/de.mkammerer/argon2-jvm implementation group: 'de.mkammerer', name: 'argon2-jvm', version: '2.11' diff --git a/ee/build.gradle b/ee/build.gradle index 94aeed97c..2a32806f6 100644 --- a/ee/build.gradle +++ b/ee/build.gradle @@ -35,10 +35,10 @@ dependencies { testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.1.0' // https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-core - testImplementation group: 'org.apache.tomcat.embed', name: 'tomcat-embed-core', version: '10.1.1' + testImplementation group: 'org.apache.tomcat.embed', name: 'tomcat-embed-core', version: '10.1.18' // https://mvnrepository.com/artifact/ch.qos.logback/logback-classic - testImplementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3' + testImplementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.4.14' // https://mvnrepository.com/artifact/com.google.code.gson/gson testImplementation group: 'com.google.code.gson', name: 'gson', version: '2.3.1' @@ -46,10 +46,10 @@ dependencies { testImplementation 'com.tngtech.archunit:archunit-junit4:0.22.0' // https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml - testImplementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.14.0' + testImplementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.14.2' // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core - testImplementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.14.0' + testImplementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.16.1' testImplementation group: 'org.jetbrains', name: 'annotations', version: '13.0' } diff --git a/implementationDependencies.json b/implementationDependencies.json index 1fdb8e150..2d88f1684 100644 --- a/implementationDependencies.json +++ b/implementationDependencies.json @@ -12,34 +12,34 @@ "src": "https://repo1.maven.org/maven2/com/fasterxml/jackson/dataformat/jackson-dataformat-yaml/2.14.2/jackson-dataformat-yaml-2.14.2-sources.jar" }, { - "jar": "https://repo1.maven.org/maven2/org/yaml/snakeyaml/1.33/snakeyaml-1.33.jar", - "name": "SnakeYAML 1.33", - "src": "https://repo1.maven.org/maven2/org/yaml/snakeyaml/1.33/snakeyaml-1.33-sources.jar" + "jar": "https://repo1.maven.org/maven2/org/yaml/snakeyaml/2.0/snakeyaml-2.0.jar", + "name": "SnakeYAML 2.0", + "src": "https://repo1.maven.org/maven2/org/yaml/snakeyaml/2.0/snakeyaml-2.0-sources.jar" }, { - "jar": "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.14.2/jackson-core-2.14.2.jar", - "name": "Jackson core 2.14.2", - "src": "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.14.2/jackson-core-2.14.2-sources.jar" + "jar": "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.16.1/jackson-core-2.16.1.jar", + "name": "Jackson core 2.16.1", + "src": "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.16.1/jackson-core-2.16.1-sources.jar" }, { - "jar": "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.14.2/jackson-databind-2.14.2.jar", - "name": "Jackson databind 2.14.2", - "src": "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.14.2/jackson-databind-2.14.2-sources.jar" + "jar": "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.16.1/jackson-databind-2.16.1.jar", + "name": "Jackson databind 2.16.1", + "src": "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.16.1/jackson-databind-2.16.1-sources.jar" }, { - "jar": "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.14.2/jackson-annotations-2.14.2.jar", - "name": "Jackson annotation 2.14.2", - "src": "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.14.2/jackson-annotations-2.14.2-sources.jar" + "jar": "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.16.1/jackson-annotations-2.16.1.jar", + "name": "Jackson annotation 2.16.1", + "src": "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.16.1/jackson-annotations-2.16.1-sources.jar" }, { - "jar": "https://repo1.maven.org/maven2/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar", - "name": "Logback classic 1.2.3", - "src": "https://repo1.maven.org/maven2/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3-sources.jar" + "jar": "https://repo1.maven.org/maven2/ch/qos/logback/logback-classic/1.4.14/logback-classic-1.4.14.jar", + "name": "Logback classic 1.4.14", + "src": "https://repo1.maven.org/maven2/ch/qos/logback/logback-classic/1.4.14/logback-classic-1.4.14-sources.jar" }, { - "jar": "https://repo1.maven.org/maven2/ch/qos/logback/logback-core/1.2.3/logback-core-1.2.3.jar", - "name": "Logback core 1.2.3", - "src": "https://repo1.maven.org/maven2/ch/qos/logback/logback-core/1.2.3/logback-core-1.2.3-sources.jar" + "jar": "https://repo1.maven.org/maven2/ch/qos/logback/logback-core/1.4.14/logback-core-1.4.14.jar", + "name": "Logback core 1.4.14", + "src": "https://repo1.maven.org/maven2/ch/qos/logback/logback-core/1.4.14/logback-core-1.4.14-sources.jar" }, { "jar": "https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar", @@ -52,9 +52,9 @@ "src": "https://repo1.maven.org/maven2/org/apache/tomcat/tomcat-annotations-api/10.1.1/tomcat-annotations-api-10.1.1-sources.jar" }, { - "jar": "https://repo1.maven.org/maven2/org/apache/tomcat/embed/tomcat-embed-core/10.1.1/tomcat-embed-core-10.1.1.jar", - "name": "Tomcat embed core API 10.1.1", - "src": "https://repo1.maven.org/maven2/org/apache/tomcat/embed/tomcat-embed-core/10.1.1/tomcat-embed-core-10.1.1-sources.jar" + "jar": "https://repo1.maven.org/maven2/org/apache/tomcat/embed/tomcat-embed-core/10.1.18/tomcat-embed-core-10.1.18.jar", + "name": "Tomcat embed core API 10.1.18", + "src": "https://repo1.maven.org/maven2/org/apache/tomcat/embed/tomcat-embed-core/10.1.18/tomcat-embed-core-10.1.18-sources.jar" }, { "jar": "https://repo1.maven.org/maven2/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar", @@ -67,13 +67,13 @@ "src": "https://repo1.maven.org/maven2/org/jetbrains/annotations/13.0/annotations-13.0-sources.jar" }, { - "jar": "https://repo1.maven.org/maven2/org/xerial/sqlite-jdbc/3.30.1/sqlite-jdbc-3.30.1.jar", - "name": "SQLite JDBC Driver 3.30.1", - "src": "https://repo1.maven.org/maven2/org/xerial/sqlite-jdbc/3.30.1/sqlite-jdbc-3.30.1-sources.jar" + "jar": "https://repo1.maven.org/maven2/org/xerial/sqlite-jdbc/3.45.1.0/sqlite-jdbc-3.45.1.0.jar", + "name": "SQLite JDBC Driver 3.45.1.0", + "src": "https://repo1.maven.org/maven2/org/xerial/sqlite-jdbc/3.45.1.0/sqlite-jdbc-3.45.1.0-sources.jar" }, { "jar": "https://repo1.maven.org/maven2/org/mindrot/jbcrypt/0.4/jbcrypt-0.4.jar", - "name": "SQLite JDBC Driver 3.30.1", + "name": "JBCrypt 0.4", "src": "https://repo1.maven.org/maven2/org/mindrot/jbcrypt/0.4/jbcrypt-0.4-sources.jar" }, { diff --git a/src/main/java/io/supertokens/cronjobs/telemetry/Telemetry.java b/src/main/java/io/supertokens/cronjobs/telemetry/Telemetry.java index f8a5ceb58..d557f5a10 100644 --- a/src/main/java/io/supertokens/cronjobs/telemetry/Telemetry.java +++ b/src/main/java/io/supertokens/cronjobs/telemetry/Telemetry.java @@ -16,17 +16,24 @@ package io.supertokens.cronjobs.telemetry; +import com.google.gson.JsonArray; import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; import io.supertokens.Main; import io.supertokens.ProcessState; import io.supertokens.ResourceDistributor; +import io.supertokens.authRecipe.AuthRecipe; import io.supertokens.config.Config; import io.supertokens.cronjobs.CronTask; import io.supertokens.cronjobs.CronTaskTest; +import io.supertokens.dashboard.Dashboard; import io.supertokens.httpRequest.HttpRequest; import io.supertokens.httpRequest.HttpRequestMocking; +import io.supertokens.pluginInterface.ActiveUsersStorage; import io.supertokens.pluginInterface.KeyValueInfo; +import io.supertokens.pluginInterface.STORAGE_TYPE; import io.supertokens.pluginInterface.Storage; +import io.supertokens.pluginInterface.dashboard.DashboardUser; import io.supertokens.pluginInterface.exceptions.StorageQueryException; import io.supertokens.storageLayer.StorageLayer; import io.supertokens.utils.Utils; @@ -75,6 +82,48 @@ protected void doTask() throws Exception { json.addProperty("telemetryId", telemetryId.value); json.addProperty("superTokensVersion", coreVersion); + json.addProperty("appId", "public"); + json.addProperty("connectionUriDomain", ""); + + if (storage.getType() == STORAGE_TYPE.SQL) { + { // Users count across all tenants + json.addProperty("usersCount", + AuthRecipe.getUsersCount(main, null)); + } + + { // Dashboard user emails + // Dashboard APIs are app specific and are always stored on the public tenant + DashboardUser[] dashboardUsers = Dashboard.getAllDashboardUsers(main); + JsonArray dashboardUserEmails = new JsonArray(); + for (DashboardUser user : dashboardUsers) { + dashboardUserEmails.add(new JsonPrimitive(user.email)); + } + + json.add("dashboardUserEmails", dashboardUserEmails); + } + + { // MAUs + // Active users are always tracked on the public tenant, so we use the public tenant's storage + ActiveUsersStorage activeUsersStorage = (ActiveUsersStorage) storage; + + JsonArray mauArr = new JsonArray(); + + for (int i = 0; i < 30; i++) { + long now = System.currentTimeMillis(); + long today = now - (now % (24 * 60 * 60 * 1000L)); + long timestamp = today - (i * 24 * 60 * 60 * 1000L); + int mau = activeUsersStorage.countUsersActiveSince(timestamp); + mauArr.add(new JsonPrimitive(mau)); + } + + json.add("maus", mauArr); + } + } else { + json.addProperty("usersCount", -1); + json.add("dashboardUserEmails", new JsonArray()); + json.add("maus", new JsonArray()); + } + String url = "https://api.supertokens.io/0/st/telemetry"; // we call the API only if we are not testing the core, of if the request can be mocked (in case a test wants diff --git a/src/test/java/io/supertokens/test/TelemetryTest.java b/src/test/java/io/supertokens/test/TelemetryTest.java index 6d96c8a73..232b501ca 100644 --- a/src/test/java/io/supertokens/test/TelemetryTest.java +++ b/src/test/java/io/supertokens/test/TelemetryTest.java @@ -21,6 +21,7 @@ import io.supertokens.ProcessState; import io.supertokens.ProcessState.PROCESS_STATE; import io.supertokens.cronjobs.telemetry.Telemetry; +import io.supertokens.dashboard.Dashboard; import io.supertokens.httpRequest.HttpRequestMocking; import io.supertokens.test.TestingProcessManager.TestingProcess; import io.supertokens.version.Version; @@ -111,6 +112,14 @@ public void testThatTelemetryWorks() throws Exception { String[] args = { "../" }; TestingProcess process = TestingProcessManager.start(args, false); + process.startProcess(); + assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); + + Dashboard.signUpDashboardUser(process.getProcess(), "test@example.com", "password123"); + + // Restarting the process to send telemetry again + process.kill(); + process = TestingProcessManager.start(args, false); ByteArrayOutputStream output = new ByteArrayOutputStream(); final HttpURLConnection mockCon = mock(HttpURLConnection.class); @@ -149,10 +158,18 @@ protected URLConnection openConnection(URL u) { assertNotNull(process.checkOrWaitForEvent(PROCESS_STATE.SENT_TELEMETRY)); JsonObject telemetryData = new JsonParser().parse(output.toString()).getAsJsonObject(); + assertEquals(7, telemetryData.entrySet().size()); assertTrue(telemetryData.has("telemetryId")); assertEquals(telemetryData.get("superTokensVersion").getAsString(), Version.getVersion(process.getProcess()).getCoreVersion()); + assertEquals(telemetryData.get("appId").getAsString(), "public"); + assertEquals(telemetryData.get("connectionUriDomain").getAsString(), ""); + assertTrue(telemetryData.has("maus")); + assertTrue(telemetryData.has("dashboardUserEmails")); + assertEquals(1, telemetryData.get("dashboardUserEmails").getAsJsonArray().size()); + assertEquals("test@example.com", telemetryData.get("dashboardUserEmails").getAsJsonArray().get(0).getAsString()); + assertEquals(30, telemetryData.get("maus").getAsJsonArray().size()); process.kill(); assertNotNull(process.checkOrWaitForEvent(PROCESS_STATE.STOPPED)); From 7b0a5e18fcb056bd0bea45a3411a4ce793d6e2f7 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Tue, 27 Feb 2024 18:31:28 +0530 Subject: [PATCH 2/3] fix: backport --- build.gradle | 2 +- cli/build.gradle | 2 +- cli/implementationDependencies.json | 30 +++++++++---------- ee/build.gradle | 2 +- .../java/io/supertokens/ee/EEFeatureFlag.java | 16 +++++----- .../java/io/supertokens/ee/test/EETest.java | 2 +- .../ee/test/api/GetFeatureFlagAPITest.java | 4 +-- implementationDependencies.json | 24 +++++++-------- .../cronjobs/telemetry/Telemetry.java | 8 ++--- .../io/supertokens/test/FeatureFlagTest.java | 10 +++---- .../io/supertokens/test/StorageLayerTest.java | 2 +- .../io/supertokens/test/TelemetryTest.java | 19 +++++++++--- .../test/dashboard/DashboardTest.java | 8 ++--- 13 files changed, 70 insertions(+), 59 deletions(-) diff --git a/build.gradle b/build.gradle index 13c541373..8bd198a01 100644 --- a/build.gradle +++ b/build.gradle @@ -33,7 +33,7 @@ dependencies { implementation group: 'com.google.code.gson', name: 'gson', version: '2.3.1' // https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml - implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.14.2' + implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.16.1' // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.16.1' diff --git a/cli/build.gradle b/cli/build.gradle index 2b61a0da1..52e2ab2d5 100644 --- a/cli/build.gradle +++ b/cli/build.gradle @@ -19,7 +19,7 @@ dependencies { implementation group: 'com.google.code.gson', name: 'gson', version: '2.3.1' // https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml - implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.14.2' + implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.16.1' // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.16.1' diff --git a/cli/implementationDependencies.json b/cli/implementationDependencies.json index 645cacaf4..665c92fff 100644 --- a/cli/implementationDependencies.json +++ b/cli/implementationDependencies.json @@ -7,29 +7,29 @@ "src": "https://repo1.maven.org/maven2/com/google/code/gson/gson/2.3.1/gson-2.3.1-sources.jar" }, { - "jar": "https://repo1.maven.org/maven2/com/fasterxml/jackson/dataformat/jackson-dataformat-yaml/2.10.0/jackson-dataformat-yaml-2.10.0.jar", - "name": "Jackson Dataformat 2.10.0", - "src": "https://repo1.maven.org/maven2/com/fasterxml/jackson/dataformat/jackson-dataformat-yaml/2.10.0/jackson-dataformat-yaml-2.10.0-sources.jar" + "jar": "https://repo1.maven.org/maven2/com/fasterxml/jackson/dataformat/jackson-dataformat-yaml/2.16.1/jackson-dataformat-yaml-2.16.1.jar", + "name": "Jackson Dataformat 2.16.1", + "src": "https://repo1.maven.org/maven2/com/fasterxml/jackson/dataformat/jackson-dataformat-yaml/2.16.1/jackson-dataformat-yaml-2.16.1-sources.jar" }, { - "jar": "https://repo1.maven.org/maven2/org/yaml/snakeyaml/1.24/snakeyaml-1.24.jar", - "name": "SnakeYAML 1.24", - "src": "https://repo1.maven.org/maven2/org/yaml/snakeyaml/1.24/snakeyaml-1.24-sources.jar" + "jar": "https://repo1.maven.org/maven2/org/yaml/snakeyaml/2.2/snakeyaml-2.2.jar", + "name": "SnakeYAML 2.2", + "src": "https://repo1.maven.org/maven2/org/yaml/snakeyaml/2.2/snakeyaml-2.2-sources.jar" }, { - "jar": "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.10.0/jackson-core-2.10.0.jar", - "name": "Jackson core 2.10.0", - "src": "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.10.0/jackson-core-2.10.0-sources.jar" + "jar": "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.16.1/jackson-core-2.16.1.jar", + "name": "Jackson core 2.16.1", + "src": "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.16.1/jackson-core-2.16.1-sources.jar" }, { - "jar": "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.10.0/jackson-databind-2.10.0.jar", - "name": "Jackson databind 2.10.0", - "src": "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.10.0/jackson-databind-2.10.0-sources.jar" + "jar": "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.16.1/jackson-databind-2.16.1.jar", + "name": "Jackson databind 2.16.1", + "src": "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.16.1/jackson-databind-2.16.1-sources.jar" }, { - "jar": "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.10.0/jackson-annotations-2.10.0.jar", - "name": "Jackson annotation 2.10.0", - "src": "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.10.0/jackson-annotations-2.10.0-sources.jar" + "jar": "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.16.1/jackson-annotations-2.16.1.jar", + "name": "Jackson annotation 2.16.1", + "src": "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.16.1/jackson-annotations-2.16.1-sources.jar" }, { "jar": "https://repo1.maven.org/maven2/de/mkammerer/argon2-jvm/2.11/argon2-jvm-2.11.jar", diff --git a/ee/build.gradle b/ee/build.gradle index 2a32806f6..9e91d7a57 100644 --- a/ee/build.gradle +++ b/ee/build.gradle @@ -46,7 +46,7 @@ dependencies { testImplementation 'com.tngtech.archunit:archunit-junit4:0.22.0' // https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml - testImplementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.14.2' + testImplementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.16.1' // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core testImplementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.16.1' diff --git a/ee/src/main/java/io/supertokens/ee/EEFeatureFlag.java b/ee/src/main/java/io/supertokens/ee/EEFeatureFlag.java index 161e52660..502f6d706 100644 --- a/ee/src/main/java/io/supertokens/ee/EEFeatureFlag.java +++ b/ee/src/main/java/io/supertokens/ee/EEFeatureFlag.java @@ -160,10 +160,10 @@ public JsonObject getPaidFeatureStats() throws StorageQueryException { JsonObject totpStats = new JsonObject(); JsonArray totpMauArr = new JsonArray(); - for (int i = 0; i < 30; i++) { - long now = System.currentTimeMillis(); - long today = now - (now % (24 * 60 * 60 * 1000L)); - long timestamp = today - (i * 24 * 60 * 60 * 1000L); + long now = System.currentTimeMillis(); + + for (int i = 1; i <= 31; i++) { + long timestamp = now - (i * 24 * 60 * 60 * 1000L); int totpMau = activeUsersStorage.countUsersEnabledTotpAndActiveSince(timestamp); totpMauArr.add(new JsonPrimitive(totpMau)); @@ -179,10 +179,10 @@ public JsonObject getPaidFeatureStats() throws StorageQueryException { if (activeUsersStorage != null) { JsonArray mauArr = new JsonArray(); - for (int i = 0; i < 30; i++) { - long now = System.currentTimeMillis(); - long today = now - (now % (24 * 60 * 60 * 1000L)); - long timestamp = today - (i * 24 * 60 * 60 * 1000L); + long now = System.currentTimeMillis(); + + for (int i = 1; i <= 31; i++) { + long timestamp = now - (i * 24 * 60 * 60 * 1000L); int mau = activeUsersStorage.countUsersActiveSince(timestamp); mauArr.add(new JsonPrimitive(mau)); diff --git a/ee/src/test/java/io/supertokens/ee/test/EETest.java b/ee/src/test/java/io/supertokens/ee/test/EETest.java index 3676841b5..0a80d6c9e 100644 --- a/ee/src/test/java/io/supertokens/ee/test/EETest.java +++ b/ee/src/test/java/io/supertokens/ee/test/EETest.java @@ -1215,7 +1215,7 @@ protected URLConnection openConnection(URL u) { JsonObject paidFeatureUsageStats = j.getAsJsonObject("paidFeatureUsageStats"); JsonArray mauArr = paidFeatureUsageStats.get("maus").getAsJsonArray(); assertEquals(paidFeatureUsageStats.entrySet().size(), 1); - assertEquals(mauArr.size(), 30); + assertEquals(mauArr.size(), 31); assertEquals(mauArr.get(0).getAsInt(), 0); assertEquals(mauArr.get(29).getAsInt(), 0); } diff --git a/ee/src/test/java/io/supertokens/ee/test/api/GetFeatureFlagAPITest.java b/ee/src/test/java/io/supertokens/ee/test/api/GetFeatureFlagAPITest.java index 075274828..7c86302f5 100644 --- a/ee/src/test/java/io/supertokens/ee/test/api/GetFeatureFlagAPITest.java +++ b/ee/src/test/java/io/supertokens/ee/test/api/GetFeatureFlagAPITest.java @@ -54,7 +54,7 @@ public void testRetrievingFeatureFlagInfoWhenNoLicenseKeyIsSet() throws Exceptio if (StorageLayer.getStorage(process.getProcess()).getType() == STORAGE_TYPE.SQL) { JsonArray mauArr = usageStats.get("maus").getAsJsonArray(); assertEquals(1, usageStats.entrySet().size()); - assertEquals(30, mauArr.size()); + assertEquals(31, mauArr.size()); assertEquals(0, mauArr.get(0).getAsInt()); assertEquals(0, mauArr.get(29).getAsInt()); } else { @@ -87,7 +87,7 @@ public void testRetrievingFeatureFlagInfoWhenLicenseKeyIsSet() throws Exception if (StorageLayer.getStorage(process.getProcess()).getType() == STORAGE_TYPE.SQL) { JsonArray mauArr = usageStats.get("maus").getAsJsonArray(); assertEquals(1, usageStats.entrySet().size()); - assertEquals(30, mauArr.size()); + assertEquals(31, mauArr.size()); assertEquals(0, mauArr.get(0).getAsInt()); assertEquals(0, mauArr.get(29).getAsInt()); } else { diff --git a/implementationDependencies.json b/implementationDependencies.json index 2d88f1684..50584aee3 100644 --- a/implementationDependencies.json +++ b/implementationDependencies.json @@ -7,14 +7,14 @@ "src": "https://repo1.maven.org/maven2/com/google/code/gson/gson/2.3.1/gson-2.3.1-sources.jar" }, { - "jar": "https://repo1.maven.org/maven2/com/fasterxml/jackson/dataformat/jackson-dataformat-yaml/2.14.2/jackson-dataformat-yaml-2.14.2.jar", - "name": "Jackson Dataformat 2.14.2", - "src": "https://repo1.maven.org/maven2/com/fasterxml/jackson/dataformat/jackson-dataformat-yaml/2.14.2/jackson-dataformat-yaml-2.14.2-sources.jar" + "jar": "https://repo1.maven.org/maven2/com/fasterxml/jackson/dataformat/jackson-dataformat-yaml/2.16.1/jackson-dataformat-yaml-2.16.1.jar", + "name": "Jackson Dataformat 2.16.1", + "src": "https://repo1.maven.org/maven2/com/fasterxml/jackson/dataformat/jackson-dataformat-yaml/2.16.1/jackson-dataformat-yaml-2.16.1-sources.jar" }, { - "jar": "https://repo1.maven.org/maven2/org/yaml/snakeyaml/2.0/snakeyaml-2.0.jar", - "name": "SnakeYAML 2.0", - "src": "https://repo1.maven.org/maven2/org/yaml/snakeyaml/2.0/snakeyaml-2.0-sources.jar" + "jar": "https://repo1.maven.org/maven2/org/yaml/snakeyaml/2.2/snakeyaml-2.2.jar", + "name": "SnakeYAML 2.2", + "src": "https://repo1.maven.org/maven2/org/yaml/snakeyaml/2.2/snakeyaml-2.2-sources.jar" }, { "jar": "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.16.1/jackson-core-2.16.1.jar", @@ -42,14 +42,14 @@ "src": "https://repo1.maven.org/maven2/ch/qos/logback/logback-core/1.4.14/logback-core-1.4.14-sources.jar" }, { - "jar": "https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar", - "name": "SLF4j API 1.7.25", - "src": "https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25-sources.jar" + "jar": "https://repo1.maven.org/maven2/org/slf4j/slf4j-api/2.0.7/slf4j-api-2.0.7.jar", + "name": "SLF4j API 2.0.7", + "src": "https://repo1.maven.org/maven2/org/slf4j/slf4j-api/2.0.7/slf4j-api-2.0.7-sources.jar" }, { - "jar": "https://repo1.maven.org/maven2/org/apache/tomcat/tomcat-annotations-api/10.1.1/tomcat-annotations-api-10.1.1.jar", - "name": "Tomcat annotations API 10.1.1", - "src": "https://repo1.maven.org/maven2/org/apache/tomcat/tomcat-annotations-api/10.1.1/tomcat-annotations-api-10.1.1-sources.jar" + "jar": "https://repo1.maven.org/maven2/org/apache/tomcat/tomcat-annotations-api/10.1.18/tomcat-annotations-api-10.1.18.jar", + "name": "Tomcat annotations API 10.1.18", + "src": "https://repo1.maven.org/maven2/org/apache/tomcat/tomcat-annotations-api/10.1.18/tomcat-annotations-api-10.1.18-sources.jar" }, { "jar": "https://repo1.maven.org/maven2/org/apache/tomcat/embed/tomcat-embed-core/10.1.18/tomcat-embed-core-10.1.18.jar", diff --git a/src/main/java/io/supertokens/cronjobs/telemetry/Telemetry.java b/src/main/java/io/supertokens/cronjobs/telemetry/Telemetry.java index d557f5a10..74d7d76aa 100644 --- a/src/main/java/io/supertokens/cronjobs/telemetry/Telemetry.java +++ b/src/main/java/io/supertokens/cronjobs/telemetry/Telemetry.java @@ -108,10 +108,10 @@ protected void doTask() throws Exception { JsonArray mauArr = new JsonArray(); - for (int i = 0; i < 30; i++) { - long now = System.currentTimeMillis(); - long today = now - (now % (24 * 60 * 60 * 1000L)); - long timestamp = today - (i * 24 * 60 * 60 * 1000L); + long now = System.currentTimeMillis(); + + for (int i = 1; i <= 31; i++) { + long timestamp = now - (i * 24 * 60 * 60 * 1000L); int mau = activeUsersStorage.countUsersActiveSince(timestamp); mauArr.add(new JsonPrimitive(mau)); } diff --git a/src/test/java/io/supertokens/test/FeatureFlagTest.java b/src/test/java/io/supertokens/test/FeatureFlagTest.java index 8754c37d3..f28425110 100644 --- a/src/test/java/io/supertokens/test/FeatureFlagTest.java +++ b/src/test/java/io/supertokens/test/FeatureFlagTest.java @@ -71,7 +71,7 @@ public void noLicenseKeyShouldHaveEmptyFeatureFlag() throws InterruptedException JsonObject stats = FeatureFlag.getInstance(process.getProcess()).getPaidFeatureStats(); Assert.assertEquals(stats.entrySet().size(), 1); - Assert.assertEquals(stats.get("maus").getAsJsonArray().size(), 30); + Assert.assertEquals(stats.get("maus").getAsJsonArray().size(), 31); Assert.assertEquals(stats.get("maus").getAsJsonArray().get(0).getAsInt(), 0); Assert.assertEquals(stats.get("maus").getAsJsonArray().get(29).getAsInt(), 0); @@ -155,7 +155,7 @@ public void testThatCallingGetFeatureFlagAPIReturnsTotpStats() throws Exception assert features.size() == 1; assert features.get(0).getAsString().equals("totp"); - assert maus.size() == 30; + assert maus.size() == 31; assert maus.get(0).getAsInt() == 0; assert maus.get(29).getAsInt() == 0; @@ -163,7 +163,7 @@ public void testThatCallingGetFeatureFlagAPIReturnsTotpStats() throws Exception JsonArray totpMaus = totpStats.get("maus").getAsJsonArray(); int totalTotpUsers = totpStats.get("total_users").getAsInt(); - assert totpMaus.size() == 30; + assert totpMaus.size() == 31; assert totpMaus.get(0).getAsInt() == 0; assert totpMaus.get(29).getAsInt() == 0; @@ -209,7 +209,7 @@ public void testThatCallingGetFeatureFlagAPIReturnsTotpStats() throws Exception assert features.size() == 1; assert features.get(0).getAsString().equals("totp"); - assert maus.size() == 30; + assert maus.size() == 31; assert maus.get(0).getAsInt() == 2; // 2 users have signed up assert maus.get(29).getAsInt() == 2; @@ -217,7 +217,7 @@ public void testThatCallingGetFeatureFlagAPIReturnsTotpStats() throws Exception JsonArray totpMaus = totpStats.get("maus").getAsJsonArray(); int totalTotpUsers = totpStats.get("total_users").getAsInt(); - assert totpMaus.size() == 30; + assert totpMaus.size() == 31; assert totpMaus.get(0).getAsInt() == 1; // only 1 user has TOTP enabled assert totpMaus.get(29).getAsInt() == 1; diff --git a/src/test/java/io/supertokens/test/StorageLayerTest.java b/src/test/java/io/supertokens/test/StorageLayerTest.java index 0f0ad5435..cfa38caf8 100644 --- a/src/test/java/io/supertokens/test/StorageLayerTest.java +++ b/src/test/java/io/supertokens/test/StorageLayerTest.java @@ -88,7 +88,7 @@ public void totpCodeLengthTest() throws Exception { // This error will be different in Postgres and MySQL // We added (CHECK (LENGTH(code) <= 8)) to the table definition in SQLite String totpUsedCodeTable = Config.getConfig(start).getTotpUsedCodesTable(); - assert e.getMessage().contains("CHECK constraint failed: " + totpUsedCodeTable); + assert e.getMessage().contains("CHECK constraint failed: "); } // Try code with length < 8 diff --git a/src/test/java/io/supertokens/test/TelemetryTest.java b/src/test/java/io/supertokens/test/TelemetryTest.java index 232b501ca..d267f7bdf 100644 --- a/src/test/java/io/supertokens/test/TelemetryTest.java +++ b/src/test/java/io/supertokens/test/TelemetryTest.java @@ -23,6 +23,7 @@ import io.supertokens.cronjobs.telemetry.Telemetry; import io.supertokens.dashboard.Dashboard; import io.supertokens.httpRequest.HttpRequestMocking; +import io.supertokens.storageLayer.StorageLayer; import io.supertokens.test.TestingProcessManager.TestingProcess; import io.supertokens.version.Version; import org.junit.AfterClass; @@ -115,7 +116,9 @@ public void testThatTelemetryWorks() throws Exception { process.startProcess(); assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); - Dashboard.signUpDashboardUser(process.getProcess(), "test@example.com", "password123"); + if (StorageLayer.getStorage(process.getProcess()).getType() == STORAGE_TYPE.SQL) { + Dashboard.signUpDashboardUser(process.getProcess(), "test@example.com", "password123"); + } // Restarting the process to send telemetry again process.kill(); @@ -167,9 +170,17 @@ protected URLConnection openConnection(URL u) { assertEquals(telemetryData.get("connectionUriDomain").getAsString(), ""); assertTrue(telemetryData.has("maus")); assertTrue(telemetryData.has("dashboardUserEmails")); - assertEquals(1, telemetryData.get("dashboardUserEmails").getAsJsonArray().size()); - assertEquals("test@example.com", telemetryData.get("dashboardUserEmails").getAsJsonArray().get(0).getAsString()); - assertEquals(30, telemetryData.get("maus").getAsJsonArray().size()); + + if (StorageLayer.getStorage(process.getProcess()).getType() == STORAGE_TYPE.SQL) { + assertEquals(1, telemetryData.get("dashboardUserEmails").getAsJsonArray().size()); + assertEquals("test@example.com", telemetryData.get("dashboardUserEmails").getAsJsonArray().get(0).getAsString()); + assertEquals(31, telemetryData.get("maus").getAsJsonArray().size()); + assertEquals(0, telemetryData.get("usersCount").getAsInt()); + } else { + assertEquals(0, telemetryData.get("dashboardUserEmails").getAsJsonArray().size()); + assertEquals(0, telemetryData.get("maus").getAsJsonArray().size()); + assertEquals(-1, telemetryData.get("usersCount").getAsInt()); + } process.kill(); assertNotNull(process.checkOrWaitForEvent(PROCESS_STATE.STOPPED)); diff --git a/src/test/java/io/supertokens/test/dashboard/DashboardTest.java b/src/test/java/io/supertokens/test/dashboard/DashboardTest.java index 5616955ae..78e4a9dc1 100644 --- a/src/test/java/io/supertokens/test/dashboard/DashboardTest.java +++ b/src/test/java/io/supertokens/test/dashboard/DashboardTest.java @@ -288,7 +288,7 @@ public void testDashboardUsageStats() throws Exception { JsonObject usageStats = response.get("usageStats").getAsJsonObject(); JsonArray mauArr = usageStats.get("maus").getAsJsonArray(); assertEquals(1, usageStats.entrySet().size()); - assertEquals(30, mauArr.size()); + assertEquals(31, mauArr.size()); assertEquals(0, mauArr.get(0).getAsInt()); assertEquals(0, mauArr.get(29).getAsInt()); } @@ -306,7 +306,7 @@ public void testDashboardUsageStats() throws Exception { JsonObject usageStats = response.get("usageStats").getAsJsonObject(); JsonArray mauArr = usageStats.get("maus").getAsJsonArray(); assertEquals(1, usageStats.entrySet().size()); - assertEquals(30, mauArr.size()); + assertEquals(31, mauArr.size()); assertEquals(0, mauArr.get(0).getAsInt()); assertEquals(0, mauArr.get(29).getAsInt()); } @@ -327,7 +327,7 @@ public void testDashboardUsageStats() throws Exception { JsonObject usageStats = response.get("usageStats").getAsJsonObject(); JsonObject dashboardLoginObject = usageStats.get("dashboard_login").getAsJsonObject(); assertEquals(2, usageStats.entrySet().size()); - assertEquals(30, usageStats.get("maus").getAsJsonArray().size()); + assertEquals(31, usageStats.get("maus").getAsJsonArray().size()); assertEquals(1, dashboardLoginObject.entrySet().size()); assertEquals(1, dashboardLoginObject.get("user_count").getAsInt()); } @@ -350,7 +350,7 @@ public void testDashboardUsageStats() throws Exception { JsonObject usageStats = response.get("usageStats").getAsJsonObject(); JsonObject dashboardLoginObject = usageStats.get("dashboard_login").getAsJsonObject(); assertEquals(2, usageStats.entrySet().size()); - assertEquals(30, usageStats.get("maus").getAsJsonArray().size()); + assertEquals(31, usageStats.get("maus").getAsJsonArray().size()); assertEquals(1, dashboardLoginObject.entrySet().size()); assertEquals(4, dashboardLoginObject.get("user_count").getAsInt()); } From 603032e3277fc9c2b45a944a283d486703ce4052 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Tue, 27 Feb 2024 18:32:51 +0530 Subject: [PATCH 3/3] fix: import --- src/test/java/io/supertokens/test/TelemetryTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/io/supertokens/test/TelemetryTest.java b/src/test/java/io/supertokens/test/TelemetryTest.java index d267f7bdf..6853ec788 100644 --- a/src/test/java/io/supertokens/test/TelemetryTest.java +++ b/src/test/java/io/supertokens/test/TelemetryTest.java @@ -23,6 +23,7 @@ import io.supertokens.cronjobs.telemetry.Telemetry; import io.supertokens.dashboard.Dashboard; import io.supertokens.httpRequest.HttpRequestMocking; +import io.supertokens.pluginInterface.STORAGE_TYPE; import io.supertokens.storageLayer.StorageLayer; import io.supertokens.test.TestingProcessManager.TestingProcess; import io.supertokens.version.Version;