From 42be1d633c8639d24024d634891306e620beff35 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 4 Jun 2019 23:44:33 -0600 Subject: [PATCH 1/3] Do not fail on server liveliness checks during startup Also warn about deprecated config option usage. See https://github.com/vector-im/riot-web/issues/9828 --- README.md | 8 ++++---- src/vector/index.js | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index cf86f37f..dba59fd7 100644 --- a/README.md +++ b/README.md @@ -113,10 +113,10 @@ For a good example, see https://riot.im/develop/config.json. Riot to use. The object is the same as returned by [https:///.well-known/matrix/client](https://matrix.org/docs/spec/client_server/latest.html#get-well-known-matrix-client), with added support for a `server_name` under the `m.homeserver` section to display a custom homeserver name. Alternatively, the config can contain a `default_server_name` - instead which is where Riot will go to get that same object - see the `.well-known` - link above for more information. Note that the `default_server_name` is used to get - a complete server configuration whereas the `server_name` in the `default_server_config` - is for display purposes only. + instead which is where Riot will go to get that same object, although this option is + deprecated - see the `.well-known` link above for more information on using this option. + Note that the `default_server_name` is used to get a complete server configuration + whereas the `server_name` in the `default_server_config` is for display purposes only. * *Note*: The URLs can also be individually specified as `default_hs_url` and `default_is_url`, however these are deprecated. They are maintained for backwards compatibility with older configurations. `default_is_url` is respected only diff --git a/src/vector/index.js b/src/vector/index.js index ad490267..6ca06b31 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -465,6 +465,11 @@ async function verifyServerConfig() { // context of email validation. Because we don't respect them otherwise, we do not need // to parse or consider them here. + // Note: Although we throw all 3 possible configuration options through a .well-known-style + // verification, we do not care if the servers are online at this point. We do moderately + // care if they are syntactically correct though, so we shove them through the .well-known + // validators for that purpose. + const config = SdkConfig.get(); let wkConfig = config['default_server_config']; // overwritten later under some conditions const serverName = config['default_server_name']; @@ -486,6 +491,10 @@ async function verifyServerConfig() { if (hsUrl) { console.log("Config uses a default_hs_url - constructing a default_server_config using this information"); + console.warn( + "DEPRECATED CONFIG OPTION: In the future, default_hs_url will not be accepted. Please use " + + "default_server_config instead.", + ); wkConfig = { "m.homeserver": { @@ -507,10 +516,14 @@ async function verifyServerConfig() { if (serverName) { console.log("Config uses a default_server_name - doing .well-known lookup"); + console.warn( + "DEPRECATED CONFIG OPTION: In the future, default_server_name will not be accepted. Please " + + "use default_server_config instead.", + ); discoveryResult = await AutoDiscovery.findClientConfig(serverName); } - validatedConfig = AutoDiscoveryUtils.buildValidatedConfigFromDiscovery(serverName, discoveryResult); + validatedConfig = AutoDiscoveryUtils.buildValidatedConfigFromDiscovery(serverName, discoveryResult, true); } catch (e) { const {hsUrl, isUrl, userId} = Lifecycle.getLocalStorageSessionVars(); if (hsUrl && userId) { @@ -518,7 +531,7 @@ async function verifyServerConfig() { console.warn("A session was found - suppressing config error and using the session's homeserver"); console.log("Using pre-existing hsUrl and isUrl: ", {hsUrl, isUrl}); - validatedConfig = await AutoDiscoveryUtils.validateServerConfigWithStaticUrls(hsUrl, isUrl); + validatedConfig = await AutoDiscoveryUtils.validateServerConfigWithStaticUrls(hsUrl, isUrl, true); } else { // the user is not logged in, so scream throw e; From c68a621a715b047c0bdf8886dc24f5cc359a02fe Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 5 Jun 2019 09:53:22 -0600 Subject: [PATCH 2/3] Fix tests for liveliness checks --- test/app-tests/loading.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/test/app-tests/loading.js b/test/app-tests/loading.js index 8e7a7807..0450d9fc 100644 --- a/test/app-tests/loading.js +++ b/test/app-tests/loading.js @@ -240,6 +240,10 @@ describe('loading:', function() { uriFragment: "#/room/!room:id", }); + // Pass the liveliness checks + httpBackend.when("GET", "/versions").respond(200, {versions: ["r0.4.0"]}); + httpBackend.when("GET", "/api/v1").respond(200, {}); + Promise.delay(1).then(() => { // at this point, we're trying to do a guest registration; // we expect a spinner @@ -277,6 +281,10 @@ describe('loading:', function() { uriFragment: "#/login", }); + // Pass the liveliness checks + httpBackend.when("GET", "/versions").respond(200, {versions: ["r0.4.0"]}); + httpBackend.when("GET", "/api/v1").respond(200, {}); + return awaitLoginComponent(matrixChat).then(() => { // we expect a single component ReactTestUtils.findRenderedComponentWithType( @@ -285,8 +293,13 @@ describe('loading:', function() { // the only outstanding request should be a GET /login // (in particular there should be no /register request for // guest registration). + const allowedRequests = [ + "/_matrix/client/r0/login", + "/versions", + "/api/v1", + ]; for (const req of httpBackend.requests) { - if (req.method === 'GET' && req.path.endsWith('/_matrix/client/r0/login')) { + if (req.method === 'GET' && allowedRequests.find(p => req.path.endsWith(p))) { continue; } @@ -387,6 +400,10 @@ describe('loading:', function() { }); it('shows a login view', function() { + // Pass the liveliness checks + httpBackend.when("GET", "/versions").respond(200, {versions: ["r0.4.0"]}); + httpBackend.when("GET", "/api/v1").respond(200, {}); + // we expect a single component ReactTestUtils.findRenderedComponentWithType( matrixChat, sdk.getComponent('structures.auth.Login'), @@ -395,8 +412,13 @@ describe('loading:', function() { // the only outstanding request should be a GET /login // (in particular there should be no /register request for // guest registration, nor /sync, etc). + const allowedRequests = [ + "/_matrix/client/r0/login", + "/versions", + "/api/v1", + ]; for (const req of httpBackend.requests) { - if (req.method === 'GET' && req.path.endsWith('/_matrix/client/r0/login')) { + if (req.method === 'GET' && allowedRequests.find(p => req.path.endsWith(p))) { continue; } @@ -405,6 +427,10 @@ describe('loading:', function() { }); it('shows the homepage after login', function() { + // Pass the liveliness checks + httpBackend.when("GET", "/versions").respond(200, {versions: ["r0.4.0"]}); + httpBackend.when("GET", "/api/v1").respond(200, {}); + return completeLogin(matrixChat).then(() => { // we should see a home page, even though we previously had // a stored mx_last_room_id From 490595cb35880a3ed39087fdf52eeba838d0dddf Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 5 Jun 2019 11:32:33 -0600 Subject: [PATCH 3/3] Use new copy for big red box --- src/i18n/strings/en_EN.json | 2 +- src/vector/index.js | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 7f09a09f..2718b8e4 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1,6 +1,6 @@ { "Unexpected error preparing the app. See console for details.": "Unexpected error preparing the app. See console for details.", - "This installation of Riot seems to have an invalid server configuration. If you are the administrator, please correct the error below": "This installation of Riot seems to have an invalid server configuration. If you are the administrator, please correct the error below", + "Your Riot is misconfigured": "Your Riot is misconfigured", "Invalid configuration: can only specify one of default_server_config, default_server_name, or default_hs_url.": "Invalid configuration: can only specify one of default_server_config, default_server_name, or default_hs_url.", "Invalid configuration: no default server specified.": "Invalid configuration: no default server specified.", "Riot Desktop on %(platformName)s": "Riot Desktop on %(platformName)s", diff --git a/src/vector/index.js b/src/vector/index.js index 6ca06b31..597b3f37 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -368,20 +368,12 @@ async function loadApp() { let errorMessage = err.translatedMessage || _t("Unexpected error preparing the app. See console for details."); - errorMessage = - {_t( - "This installation of Riot seems to have an invalid server configuration. " + - "If you are the administrator, please correct the error below", - )} -
-
- {errorMessage} -
; + errorMessage = {errorMessage}; // Like the compatibility page, AWOOOOOGA at the user const GenericErrorPage = sdk.getComponent("structures.GenericErrorPage"); window.matrixChat = ReactDOM.render( - , + , document.getElementById('matrixchat'), ); });