-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
787 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,9 @@ | |
import io.supertokens.cronjobs.telemetry.Telemetry; | ||
import io.supertokens.dashboard.Dashboard; | ||
import io.supertokens.httpRequest.HttpRequestMocking; | ||
import io.supertokens.multitenancy.Multitenancy; | ||
import io.supertokens.pluginInterface.STORAGE_TYPE; | ||
import io.supertokens.pluginInterface.multitenancy.AppIdentifier; | ||
import io.supertokens.storageLayer.StorageLayer; | ||
import io.supertokens.test.TestingProcessManager.TestingProcess; | ||
import io.supertokens.version.Version; | ||
|
@@ -187,6 +189,89 @@ protected URLConnection openConnection(URL u) { | |
assertNotNull(process.checkOrWaitForEvent(PROCESS_STATE.STOPPED)); | ||
} | ||
|
||
@Test | ||
public void testThatTelemetryWorksWithApiDomainAndWebsiteDomainSet() throws Exception { | ||
String[] args = { "../" }; | ||
|
||
TestingProcess process = TestingProcessManager.start(args, false); | ||
process.startProcess(); | ||
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); | ||
|
||
if (StorageLayer.getBaseStorage(process.getProcess()).getType() == STORAGE_TYPE.SQL) { | ||
Dashboard.signUpDashboardUser(process.getProcess(), "[email protected]", "password123"); | ||
} | ||
|
||
Multitenancy.saveWebsiteAndAPIDomainForApp(StorageLayer.getBaseStorage(process.getProcess()), | ||
new AppIdentifier(null, null), "https://example.com", "https://api.example.com"); | ||
|
||
// Restarting the process to send telemetry again | ||
process.kill(false); | ||
process = TestingProcessManager.start(args, false); | ||
|
||
ByteArrayOutputStream output = new ByteArrayOutputStream(); | ||
final HttpURLConnection mockCon = mock(HttpURLConnection.class); | ||
InputStream inputStrm = new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)); | ||
when(mockCon.getInputStream()).thenReturn(inputStrm); | ||
when(mockCon.getResponseCode()).thenReturn(200); | ||
when(mockCon.getOutputStream()).thenReturn(new OutputStream() { | ||
@Override | ||
public void write(int b) { | ||
output.write(b); | ||
} | ||
}); | ||
|
||
HttpRequestMocking.getInstance(process.getProcess()).setMockURL(Telemetry.REQUEST_ID, | ||
new HttpRequestMocking.URLGetter() { | ||
|
||
@Override | ||
public URL getUrl(String url) throws MalformedURLException { | ||
URLStreamHandler stubURLStreamHandler = new URLStreamHandler() { | ||
@Override | ||
protected URLConnection openConnection(URL u) { | ||
return mockCon; | ||
} | ||
}; | ||
return new URL(null, url, stubURLStreamHandler); | ||
} | ||
}); | ||
|
||
process.startProcess(); | ||
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); | ||
|
||
if (Version.getVersion(process.getProcess()).getPluginName().equals("sqlite")) { | ||
return; | ||
} | ||
|
||
assertNotNull(process.checkOrWaitForEvent(PROCESS_STATE.SENT_TELEMETRY)); | ||
|
||
JsonObject telemetryData = new JsonParser().parse(output.toString()).getAsJsonObject(); | ||
assertEquals(9, 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("https://example.com", telemetryData.get("websiteDomain").getAsString()); | ||
assertEquals("https://api.example.com", telemetryData.get("apiDomain").getAsString()); | ||
|
||
if (StorageLayer.getBaseStorage(process.getProcess()).getType() == STORAGE_TYPE.SQL) { | ||
assertEquals(1, telemetryData.get("dashboardUserEmails").getAsJsonArray().size()); | ||
assertEquals("[email protected]", 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)); | ||
} | ||
|
||
@Test | ||
public void testThatTelemetryIdDoesNotChange() throws Exception { | ||
String telemetryId = null; | ||
|
Oops, something went wrong.