1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-29 16:43:09 +03:00

Merge branch 'develop' into bwindels/stylepreviewbar

This commit is contained in:
Bruno Windels
2019-04-17 14:24:25 +02:00
7 changed files with 92 additions and 41 deletions

View File

@@ -318,18 +318,18 @@ specification.
To provide the Olm library in a browser application:
* download the transpiled libolm (from https://matrix.org/packages/npm/olm/).
* download the transpiled libolm (from https://packages.matrix.org/npm/olm/).
* load ``olm.js`` as a ``<script>`` *before* ``browser-matrix.js``.
To provide the Olm library in a node.js application:
* ``yarn add https://matrix.org/packages/npm/olm/olm-3.0.0.tgz``
* ``yarn add https://packages.matrix.org/npm/olm/olm-3.0.0.tgz``
(replace the URL with the latest version you want to use from
https://matrix.org/packages/npm/olm/)
https://packages.matrix.org/npm/olm/)
* ``global.Olm = require('olm');`` *before* loading ``matrix-js-sdk``.
If you want to package Olm as dependency for your node.js application, you can
use ``yarn add https://matrix.org/packages/npm/olm/olm-3.0.0.tgz``. If your
use ``yarn add https://packages.matrix.org/npm/olm/olm-3.0.0.tgz``. If your
application also works without e2e crypto enabled, add ``--optional`` to mark it
as an optional dependency.

View File

@@ -82,7 +82,7 @@
"matrix-mock-request": "^1.2.3",
"mocha": "^5.2.0",
"mocha-jenkins-reporter": "^0.4.0",
"olm": "https://matrix.org/packages/npm/olm/olm-3.1.0-pre3.tgz",
"olm": "https://packages.matrix.org/npm/olm/olm-3.1.0-pre3.tgz",
"rimraf": "^2.5.4",
"source-map-support": "^0.4.11",
"sourceify": "^0.1.0",

View File

@@ -157,7 +157,7 @@ describe("MatrixClient events", function() {
return;
}
expect(event.event).toEqual(SYNC_DATA.presence.events[0]);
expect(event.event).toMatch(SYNC_DATA.presence.events[0]);
expect(user.presence).toEqual(
SYNC_DATA.presence.events[0].content.presence,
);

View File

@@ -94,7 +94,7 @@ describe("AutoDiscovery", function() {
const expected = {
"m.homeserver": {
state: "FAIL_PROMPT",
error: "Invalid homeserver discovery response",
error: AutoDiscovery.ERROR_GENERIC_FAILURE,
base_url: null,
},
"m.identity_server": {
@@ -117,7 +117,7 @@ describe("AutoDiscovery", function() {
const expected = {
"m.homeserver": {
state: "FAIL_PROMPT",
error: "Invalid homeserver discovery response",
error: AutoDiscovery.ERROR_GENERIC_FAILURE,
base_url: null,
},
"m.identity_server": {
@@ -140,7 +140,7 @@ describe("AutoDiscovery", function() {
const expected = {
"m.homeserver": {
state: "FAIL_PROMPT",
error: "Invalid homeserver discovery response",
error: AutoDiscovery.ERROR_GENERIC_FAILURE,
base_url: null,
},
"m.identity_server": {
@@ -163,7 +163,7 @@ describe("AutoDiscovery", function() {
const expected = {
"m.homeserver": {
state: "FAIL_PROMPT",
error: "Invalid homeserver discovery response",
error: AutoDiscovery.ERROR_GENERIC_FAILURE,
base_url: null,
},
"m.identity_server": {
@@ -191,7 +191,7 @@ describe("AutoDiscovery", function() {
const expected = {
"m.homeserver": {
state: "FAIL_PROMPT",
error: "Invalid homeserver discovery response",
error: AutoDiscovery.ERROR_GENERIC_FAILURE,
base_url: null,
},
"m.identity_server": {
@@ -217,7 +217,7 @@ describe("AutoDiscovery", function() {
const expected = {
"m.homeserver": {
state: "FAIL_PROMPT",
error: "Invalid homeserver discovery response",
error: AutoDiscovery.ERROR_GENERIC_FAILURE,
base_url: null,
},
"m.identity_server": {
@@ -245,7 +245,7 @@ describe("AutoDiscovery", function() {
const expected = {
"m.homeserver": {
state: "FAIL_ERROR",
error: "Invalid homeserver discovery response",
error: AutoDiscovery.ERROR_INVALID_HS_BASE_URL,
base_url: null,
},
"m.identity_server": {
@@ -274,7 +274,7 @@ describe("AutoDiscovery", function() {
const expected = {
"m.homeserver": {
state: "FAIL_ERROR",
error: "Invalid homeserver discovery response",
error: AutoDiscovery.ERROR_INVALID_HOMESERVER,
base_url: null,
},
"m.identity_server": {
@@ -303,7 +303,7 @@ describe("AutoDiscovery", function() {
const expected = {
"m.homeserver": {
state: "FAIL_ERROR",
error: "Invalid homeserver discovery response",
error: AutoDiscovery.ERROR_INVALID_HOMESERVER,
base_url: null,
},
"m.identity_server": {
@@ -334,7 +334,7 @@ describe("AutoDiscovery", function() {
const expected = {
"m.homeserver": {
state: "FAIL_ERROR",
error: "Invalid homeserver discovery response",
error: AutoDiscovery.ERROR_INVALID_HOMESERVER,
base_url: null,
},
"m.identity_server": {
@@ -439,14 +439,14 @@ describe("AutoDiscovery", function() {
const expected = {
"m.homeserver": {
state: "FAIL_ERROR",
error: "Invalid identity server discovery response",
error: AutoDiscovery.ERROR_INVALID_IS,
// We still expect the base_url to be here for debugging purposes.
base_url: "https://chat.example.org",
},
"m.identity_server": {
state: "FAIL_ERROR",
error: "Invalid identity server discovery response",
error: AutoDiscovery.ERROR_INVALID_IS_BASE_URL,
base_url: null,
},
};
@@ -479,14 +479,14 @@ describe("AutoDiscovery", function() {
const expected = {
"m.homeserver": {
state: "FAIL_ERROR",
error: "Invalid identity server discovery response",
error: AutoDiscovery.ERROR_INVALID_IS,
// We still expect the base_url to be here for debugging purposes.
base_url: "https://chat.example.org",
},
"m.identity_server": {
state: "FAIL_ERROR",
error: "Invalid identity server discovery response",
error: AutoDiscovery.ERROR_INVALID_IS_BASE_URL,
base_url: null,
},
};
@@ -520,14 +520,14 @@ describe("AutoDiscovery", function() {
const expected = {
"m.homeserver": {
state: "FAIL_ERROR",
error: "Invalid identity server discovery response",
error: AutoDiscovery.ERROR_INVALID_IS,
// We still expect the base_url to be here for debugging purposes.
base_url: "https://chat.example.org",
},
"m.identity_server": {
state: "FAIL_ERROR",
error: "Invalid identity server discovery response",
error: AutoDiscovery.ERROR_INVALID_IDENTITY_SERVER,
base_url: null,
},
};
@@ -561,14 +561,14 @@ describe("AutoDiscovery", function() {
const expected = {
"m.homeserver": {
state: "FAIL_ERROR",
error: "Invalid identity server discovery response",
error: AutoDiscovery.ERROR_INVALID_IS,
// We still expect the base_url to be here for debugging purposes
base_url: "https://chat.example.org",
},
"m.identity_server": {
state: "FAIL_ERROR",
error: "Invalid identity server discovery response",
error: AutoDiscovery.ERROR_INVALID_IDENTITY_SERVER,
base_url: null,
},
};

View File

@@ -102,6 +102,56 @@ export class AutoDiscovery {
// translate the meaning of the states in the spec, but also
// support our own if needed.
static get ERROR_INVALID() {
return "Invalid homeserver discovery response";
}
static get ERROR_GENERIC_FAILURE() {
return "Failed to get autodiscovery configuration from server";
}
static get ERROR_INVALID_HS_BASE_URL() {
return "Invalid base_url for m.homeserver";
}
static get ERROR_INVALID_HOMESERVER() {
return "Homeserver URL does not appear to be a valid Matrix homeserver";
}
static get ERROR_INVALID_IS_BASE_URL() {
return "Invalid base_url for m.identity_server";
}
static get ERROR_INVALID_IDENTITY_SERVER() {
return "Identity server URL does not appear to be a valid identity server";
}
static get ERROR_INVALID_IS() {
return "Invalid identity server discovery response";
}
static get ERROR_MISSING_WELLKNOWN() {
return "No .well-known JSON file found";
}
static get ERROR_INVALID_JSON() {
return "Invalid JSON";
}
static get ALL_ERRORS() {
return [
AutoDiscovery.ERROR_INVALID,
AutoDiscovery.ERROR_GENERIC_FAILURE,
AutoDiscovery.ERROR_INVALID_HS_BASE_URL,
AutoDiscovery.ERROR_INVALID_HOMESERVER,
AutoDiscovery.ERROR_INVALID_IS_BASE_URL,
AutoDiscovery.ERROR_INVALID_IDENTITY_SERVER,
AutoDiscovery.ERROR_INVALID_IS,
AutoDiscovery.ERROR_MISSING_WELLKNOWN,
AutoDiscovery.ERROR_INVALID_JSON,
];
}
/**
* The auto discovery failed. The client is expected to communicate
* the error to the user and refuse logging in.
@@ -171,7 +221,7 @@ export class AutoDiscovery {
const clientConfig = {
"m.homeserver": {
state: AutoDiscovery.FAIL_ERROR,
error: "Invalid homeserver discovery response",
error: AutoDiscovery.ERROR_INVALID,
base_url: null,
},
"m.identity_server": {
@@ -202,8 +252,7 @@ export class AutoDiscovery {
} else {
// this can only ever be FAIL_PROMPT at this point.
clientConfig["m.homeserver"].state = AutoDiscovery.FAIL_PROMPT;
clientConfig["m.homeserver"].error =
"Failed to get autodiscovery configuration from server";
clientConfig["m.homeserver"].error = AutoDiscovery.ERROR_GENERIC_FAILURE;
}
return Promise.resolve(clientConfig);
}
@@ -215,7 +264,7 @@ export class AutoDiscovery {
);
if (!hsUrl) {
logger.error("Invalid base_url for m.homeserver");
clientConfig["m.homeserver"].error = "Invalid base_url for m.homeserver";
clientConfig["m.homeserver"].error = AutoDiscovery.ERROR_INVALID_HS_BASE_URL;
return Promise.resolve(clientConfig);
}
@@ -225,8 +274,7 @@ export class AutoDiscovery {
);
if (!hsVersions || !hsVersions.raw["versions"]) {
logger.error("Invalid /versions response");
clientConfig["m.homeserver"].error =
"Homeserver URL does not appear to be a valid Matrix homeserver";
clientConfig["m.homeserver"].error = AutoDiscovery.ERROR_INVALID_HOMESERVER;
return Promise.resolve(clientConfig);
}
@@ -248,7 +296,7 @@ export class AutoDiscovery {
const failingClientConfig = {
"m.homeserver": {
state: AutoDiscovery.FAIL_ERROR,
error: "Invalid identity server discovery response",
error: AutoDiscovery.ERROR_INVALID_IS,
// We'll provide the base_url that was previously valid for
// debugging purposes.
@@ -256,7 +304,7 @@ export class AutoDiscovery {
},
"m.identity_server": {
state: AutoDiscovery.FAIL_ERROR,
error: "Invalid identity server discovery response",
error: AutoDiscovery.ERROR_INVALID_IS,
base_url: null,
},
};
@@ -269,7 +317,7 @@ export class AutoDiscovery {
if (!isUrl) {
logger.error("Invalid base_url for m.identity_server");
failingClientConfig["m.identity_server"].error =
"Invalid base_url for m.identity_server";
AutoDiscovery.ERROR_INVALID_IS_BASE_URL;
return Promise.resolve(failingClientConfig);
}
@@ -281,7 +329,7 @@ export class AutoDiscovery {
if (!isResponse || !isResponse.raw || isResponse.action !== "SUCCESS") {
logger.error("Invalid /api/v1 response");
failingClientConfig["m.identity_server"].error =
"Identity server URL does not appear to be a valid identity server";
AutoDiscovery.ERROR_INVALID_IDENTITY_SERVER;
return Promise.resolve(failingClientConfig);
}
}
@@ -374,7 +422,7 @@ export class AutoDiscovery {
let reason = (err ? err.message : null) || "General failure";
if (response.statusCode === 404) {
action = "IGNORE";
reason = "No .well-known JSON file found";
reason = AutoDiscovery.ERROR_MISSING_WELLKNOWN;
}
resolve({raw: {}, action: action, reason: reason, error: err});
return;
@@ -383,12 +431,15 @@ export class AutoDiscovery {
try {
resolve({raw: JSON.parse(body), action: "SUCCESS"});
} catch (e) {
let reason = "General failure";
if (e.name === "SyntaxError") reason = "Invalid JSON";
let reason = AutoDiscovery.ERROR_INVALID;
if (e.name === "SyntaxError") {
reason = AutoDiscovery.ERROR_INVALID_JSON;
}
resolve({
raw: {},
action: "FAIL_PROMPT",
reason: reason, error: e,
reason: reason,
error: e,
});
}
},

View File

@@ -449,7 +449,7 @@ SyncApi.prototype._shouldAbortSync = function(error) {
if (error.errcode === "M_UNKNOWN_TOKEN") {
// The logout already happened, we just need to stop.
console.warn("Token no longer valid - assuming logout");
self.stop();
this.stop();
return true;
}
return false;

View File

@@ -3520,9 +3520,9 @@ object.pick@^1.3.0:
dependencies:
isobject "^3.0.1"
"olm@https://matrix.org/packages/npm/olm/olm-3.1.0-pre3.tgz":
"olm@https://packages.matrix.org/npm/olm/olm-3.1.0-pre3.tgz":
version "3.1.0-pre3"
resolved "https://matrix.org/packages/npm/olm/olm-3.1.0-pre3.tgz#525aa8191b4b6fcb07a3aa6815687780b99be411"
resolved "https://packages.matrix.org/npm/olm/olm-3.1.0-pre3.tgz#525aa8191b4b6fcb07a3aa6815687780b99be411"
once@1.x, once@^1.3.0:
version "1.4.0"