Merge remote-tracking branch 'upstream/main' into conduwuit-changes
This commit is contained in:
commit
3a9c8fb87d
35
.github/workflows/ci.yml
vendored
35
.github/workflows/ci.yml
vendored
@ -17,10 +17,10 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Check xtask cache
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
id: xtask-cache
|
||||
with:
|
||||
path: target/debug/xtask
|
||||
@ -40,7 +40,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install rust nightly toolchain
|
||||
uses: dtolnay/rust-toolchain@master
|
||||
@ -50,7 +50,7 @@ jobs:
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
|
||||
- name: Check spelling
|
||||
uses: crate-ci/typos@v1.16.17
|
||||
uses: crate-ci/typos@v1.20.3
|
||||
|
||||
- name: Install cargo-sort
|
||||
uses: taiki-e/cache-cargo-install-action@v1
|
||||
@ -58,7 +58,7 @@ jobs:
|
||||
tool: cargo-sort
|
||||
|
||||
- name: Get xtask
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: target/debug/xtask
|
||||
key: xtask-${{ hashFiles('Cargo.toml', 'xtask/src/**', 'xtask/Cargo.toml') }}
|
||||
@ -90,7 +90,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install MSRV toolchain
|
||||
uses: dtolnay/rust-toolchain@master
|
||||
@ -105,7 +105,7 @@ jobs:
|
||||
shared-key: msrv1.75
|
||||
|
||||
- name: Get xtask
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: target/debug/xtask
|
||||
key: xtask-${{ hashFiles('Cargo.toml', 'xtask/src/**', 'xtask/Cargo.toml') }}
|
||||
@ -137,7 +137,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install rust stable toolchain
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
@ -145,7 +145,7 @@ jobs:
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
|
||||
- name: Get xtask
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: target/debug/xtask
|
||||
key: xtask-${{ hashFiles('Cargo.toml', 'xtask/src/**', 'xtask/Cargo.toml') }}
|
||||
@ -180,7 +180,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install rust nightly toolchain
|
||||
uses: dtolnay/rust-toolchain@master
|
||||
@ -191,7 +191,7 @@ jobs:
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
|
||||
- name: Get xtask
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: target/debug/xtask
|
||||
key: xtask-${{ hashFiles('Cargo.toml', 'xtask/src/**', 'xtask/Cargo.toml') }}
|
||||
@ -212,7 +212,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install nightly rust toolchain
|
||||
# Nightly needed for use of unstable options
|
||||
@ -223,7 +223,7 @@ jobs:
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
|
||||
- name: Get xtask
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: target/debug/xtask
|
||||
key: xtask-${{ hashFiles('Cargo.toml', 'xtask/src/**', 'xtask/Cargo.toml') }}
|
||||
@ -231,6 +231,9 @@ jobs:
|
||||
- name: Build docs
|
||||
run: target/debug/xtask doc --deny-warnings
|
||||
|
||||
- name: Remove .lock file
|
||||
run: rm target/doc/.lock
|
||||
|
||||
- name: Compress docs
|
||||
if: github.event_name == 'pull_request'
|
||||
run: |
|
||||
@ -238,17 +241,17 @@ jobs:
|
||||
|
||||
- name: Upload docs as artifact
|
||||
if: github.event_name == 'pull_request'
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: docs
|
||||
path: docs.tar.zstd
|
||||
|
||||
- name: Upload docs as pages artifact
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||
uses: actions/upload-pages-artifact@v1
|
||||
uses: actions/upload-pages-artifact@v3
|
||||
with:
|
||||
path: target/doc
|
||||
|
||||
- name: Deploy to GitHub Pages
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||
uses: actions/deploy-pages@v2
|
||||
uses: actions/deploy-pages@v4
|
||||
|
4
.github/workflows/deps.yml
vendored
4
.github/workflows/deps.yml
vendored
@ -20,7 +20,7 @@ jobs:
|
||||
if: github.event.name != 'schedule'
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: EmbarkStudios/cargo-deny-action@v1
|
||||
with:
|
||||
command: check bans licenses sources
|
||||
@ -30,7 +30,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: EmbarkStudios/cargo-deny-action@v1
|
||||
with:
|
||||
command: check advisories
|
||||
|
4
.github/workflows/docs-preview.yml
vendored
4
.github/workflows/docs-preview.yml
vendored
@ -12,7 +12,7 @@ jobs:
|
||||
if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.pull_requests[0] != null
|
||||
steps:
|
||||
- name: Download artifact
|
||||
uses: actions/github-script@v6
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
|
||||
@ -40,7 +40,7 @@ jobs:
|
||||
- name: Deploy PR preview
|
||||
continue-on-error: true
|
||||
id: deploy_preview
|
||||
uses: dswistowski/surge-sh-action@v1.0.1
|
||||
uses: dswistowski/surge-sh-action@v1.0.3
|
||||
with:
|
||||
domain: pr-${{ github.event.workflow_run.pull_requests[0].number }}--ruma-docs.surge.sh
|
||||
project: doc
|
||||
|
2
.github/workflows/docs-remove-preview.yml
vendored
2
.github/workflows/docs-remove-preview.yml
vendored
@ -12,7 +12,7 @@ jobs:
|
||||
if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request'
|
||||
steps:
|
||||
- name: Get PR number
|
||||
uses: actions/github-script@v6
|
||||
uses: actions/github-script@v7
|
||||
id: get_pr
|
||||
continue-on-error: true
|
||||
with:
|
||||
|
@ -1,11 +1,11 @@
|
||||
[default.extend-words]
|
||||
# Remove this once base64 gets correctly ignored by typos
|
||||
# Or if we're able to ignore certain lines.
|
||||
Hd = "Hd"
|
||||
NAX = "NAX"
|
||||
Nd = "Nd"
|
||||
Pn = "Pn"
|
||||
Wya = "Wya"
|
||||
# thead html tag is not a typo, upstream PR pending
|
||||
thead = "thead"
|
||||
|
||||
# all of these are valid words, but should never appear in this repo
|
||||
sing = "sign"
|
||||
|
@ -35,6 +35,7 @@ serde_html_form = "0.2.0"
|
||||
serde_json = "1.0.87"
|
||||
thiserror = "1.0.37"
|
||||
tracing = { version = "0.1.37", default-features = false, features = ["std"] }
|
||||
web-time = "1.1.0"
|
||||
|
||||
[profile.dev]
|
||||
# Speeds up test times by more than 10% in a simple test
|
||||
|
@ -13,6 +13,9 @@ Breaking changes:
|
||||
- The `ts` field in `Request` for `get_media_preview` is now `Option`.
|
||||
- The query parameter of `check_registration_token_validity` endpoint
|
||||
has been renamed from `registration_token` to `token`
|
||||
- `Error` is now non-exhaustive.
|
||||
- `ErrorKind::Forbidden` is now a non-exhaustive struct variant that can be
|
||||
constructed with `ErrorKind::forbidden()`.
|
||||
|
||||
Improvements:
|
||||
|
||||
|
@ -27,7 +27,12 @@ mod kind_serde;
|
||||
#[non_exhaustive]
|
||||
pub enum ErrorKind {
|
||||
/// M_FORBIDDEN
|
||||
Forbidden,
|
||||
#[non_exhaustive]
|
||||
Forbidden {
|
||||
/// The `WWW-Authenticate` header error message.
|
||||
#[cfg(feature = "unstable-msc2967")]
|
||||
authenticate: Option<AuthenticateError>,
|
||||
},
|
||||
|
||||
/// M_UNKNOWN_TOKEN
|
||||
UnknownToken {
|
||||
@ -192,6 +197,23 @@ pub enum ErrorKind {
|
||||
_Custom { errcode: PrivOwnedStr, extra: Extra },
|
||||
}
|
||||
|
||||
impl ErrorKind {
|
||||
/// Constructs an empty [`ErrorKind::Forbidden`] variant.
|
||||
pub fn forbidden() -> Self {
|
||||
Self::Forbidden {
|
||||
#[cfg(feature = "unstable-msc2967")]
|
||||
authenticate: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Constructs an [`ErrorKind::Forbidden`] variant with the given `WWW-Authenticate` header
|
||||
/// error message.
|
||||
#[cfg(feature = "unstable-msc2967")]
|
||||
pub fn forbidden_with_authenticate(authenticate: AuthenticateError) -> Self {
|
||||
Self::Forbidden { authenticate: Some(authenticate) }
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Extra(BTreeMap<String, JsonValue>);
|
||||
@ -199,7 +221,7 @@ pub struct Extra(BTreeMap<String, JsonValue>);
|
||||
impl AsRef<str> for ErrorKind {
|
||||
fn as_ref(&self) -> &str {
|
||||
match self {
|
||||
Self::Forbidden => "M_FORBIDDEN",
|
||||
Self::Forbidden { .. } => "M_FORBIDDEN",
|
||||
Self::UnknownToken { .. } => "M_UNKNOWN_TOKEN",
|
||||
Self::MissingToken => "M_MISSING_TOKEN",
|
||||
Self::BadJson => "M_BAD_JSON",
|
||||
@ -298,20 +320,23 @@ pub struct StandardErrorBody {
|
||||
|
||||
/// A Matrix Error
|
||||
#[derive(Debug, Clone)]
|
||||
#[allow(clippy::exhaustive_structs)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub struct Error {
|
||||
/// The http status code.
|
||||
pub status_code: http::StatusCode,
|
||||
|
||||
/// The `WWW-Authenticate` header error message.
|
||||
#[cfg(feature = "unstable-msc2967")]
|
||||
pub authenticate: Option<AuthenticateError>,
|
||||
|
||||
/// The http response's body.
|
||||
pub body: ErrorBody,
|
||||
}
|
||||
|
||||
impl Error {
|
||||
/// Constructs a new `Error` with the given status code and body.
|
||||
///
|
||||
/// This is equivalent to calling `body.into_error(status_code)`.
|
||||
pub fn new(status_code: http::StatusCode, body: ErrorBody) -> Self {
|
||||
Self { status_code, body }
|
||||
}
|
||||
|
||||
/// If `self` is a server error in the `errcode` + `error` format expected
|
||||
/// for client-server API endpoints, returns the error kind (`errcode`).
|
||||
pub fn error_kind(&self) -> Option<&ErrorKind> {
|
||||
@ -323,16 +348,24 @@ impl EndpointError for Error {
|
||||
fn from_http_response<T: AsRef<[u8]>>(response: http::Response<T>) -> Self {
|
||||
let status = response.status();
|
||||
|
||||
#[cfg(feature = "unstable-msc2967")]
|
||||
let authenticate = response
|
||||
.headers()
|
||||
.get(http::header::WWW_AUTHENTICATE)
|
||||
.and_then(|val| val.to_str().ok())
|
||||
.and_then(AuthenticateError::from_str);
|
||||
|
||||
let body_bytes = &response.body().as_ref();
|
||||
let error_body: ErrorBody = match from_json_slice(body_bytes) {
|
||||
Ok(StandardErrorBody { kind, message }) => ErrorBody::Standard { kind, message },
|
||||
Ok(StandardErrorBody { kind, message }) => {
|
||||
#[cfg(feature = "unstable-msc2967")]
|
||||
let kind = if let ErrorKind::Forbidden { .. } = kind {
|
||||
let authenticate = response
|
||||
.headers()
|
||||
.get(http::header::WWW_AUTHENTICATE)
|
||||
.and_then(|val| val.to_str().ok())
|
||||
.and_then(AuthenticateError::from_str);
|
||||
|
||||
ErrorKind::Forbidden { authenticate }
|
||||
} else {
|
||||
kind
|
||||
};
|
||||
|
||||
ErrorBody::Standard { kind, message }
|
||||
}
|
||||
Err(_) => match MatrixErrorBody::from_bytes(body_bytes) {
|
||||
MatrixErrorBody::Json(json) => ErrorBody::Json(json),
|
||||
MatrixErrorBody::NotJson { bytes, deserialization_error, .. } => {
|
||||
@ -341,13 +374,7 @@ impl EndpointError for Error {
|
||||
},
|
||||
};
|
||||
|
||||
let error = error_body.into_error(status);
|
||||
|
||||
#[cfg(not(feature = "unstable-msc2967"))]
|
||||
return error;
|
||||
|
||||
#[cfg(feature = "unstable-msc2967")]
|
||||
Self { authenticate, ..error }
|
||||
error_body.into_error(status)
|
||||
}
|
||||
}
|
||||
|
||||
@ -368,13 +395,10 @@ impl std::error::Error for Error {}
|
||||
|
||||
impl ErrorBody {
|
||||
/// Convert the ErrorBody into an Error by adding the http status code.
|
||||
///
|
||||
/// This is equivalent to calling `Error::new(status_code, self)`.
|
||||
pub fn into_error(self, status_code: http::StatusCode) -> Error {
|
||||
Error {
|
||||
status_code,
|
||||
#[cfg(feature = "unstable-msc2967")]
|
||||
authenticate: None,
|
||||
body: self,
|
||||
}
|
||||
Error { status_code, body: self }
|
||||
}
|
||||
}
|
||||
|
||||
@ -387,7 +411,11 @@ impl OutgoingResponse for Error {
|
||||
.status(self.status_code);
|
||||
|
||||
#[cfg(feature = "unstable-msc2967")]
|
||||
let builder = if let Some(auth_error) = &self.authenticate {
|
||||
let builder = if let ErrorBody::Standard {
|
||||
kind: ErrorKind::Forbidden { authenticate: Some(auth_error) },
|
||||
..
|
||||
} = &self.body
|
||||
{
|
||||
builder.header(http::header::WWW_AUTHENTICATE, auth_error)
|
||||
} else {
|
||||
builder
|
||||
@ -532,7 +560,13 @@ mod tests {
|
||||
}))
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(deserialized.kind, ErrorKind::Forbidden);
|
||||
assert_eq!(
|
||||
deserialized.kind,
|
||||
ErrorKind::Forbidden {
|
||||
#[cfg(feature = "unstable-msc2967")]
|
||||
authenticate: None
|
||||
}
|
||||
);
|
||||
assert_eq!(deserialized.message, "You are not authorized to ban users in this room.");
|
||||
}
|
||||
|
||||
@ -603,9 +637,9 @@ mod tests {
|
||||
|
||||
assert_eq!(error.status_code, http::StatusCode::UNAUTHORIZED);
|
||||
assert_matches!(error.body, ErrorBody::Standard { kind, message });
|
||||
assert_eq!(kind, ErrorKind::Forbidden);
|
||||
assert_matches!(kind, ErrorKind::Forbidden { authenticate });
|
||||
assert_eq!(message, "Insufficient privilege");
|
||||
assert_matches!(error.authenticate, Some(AuthenticateError::InsufficientScope { scope }));
|
||||
assert_matches!(authenticate, Some(AuthenticateError::InsufficientScope { scope }));
|
||||
assert_eq!(scope, "something_privileged");
|
||||
}
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ impl<'de> Visitor<'de> for ErrorKindVisitor {
|
||||
let extra = Extra(extra);
|
||||
|
||||
Ok(match errcode {
|
||||
ErrCode::Forbidden => ErrorKind::Forbidden,
|
||||
ErrCode::Forbidden => ErrorKind::forbidden(),
|
||||
ErrCode::UnknownToken => ErrorKind::UnknownToken {
|
||||
soft_logout: soft_logout
|
||||
.map(from_json_value)
|
||||
@ -361,7 +361,13 @@ mod tests {
|
||||
#[test]
|
||||
fn deserialize_forbidden() {
|
||||
let deserialized: ErrorKind = from_json_value(json!({ "errcode": "M_FORBIDDEN" })).unwrap();
|
||||
assert_eq!(deserialized, ErrorKind::Forbidden);
|
||||
assert_eq!(
|
||||
deserialized,
|
||||
ErrorKind::Forbidden {
|
||||
#[cfg(feature = "unstable-msc2967")]
|
||||
authenticate: None
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -372,7 +378,13 @@ mod tests {
|
||||
}))
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(deserialized, ErrorKind::Forbidden);
|
||||
assert_eq!(
|
||||
deserialized,
|
||||
ErrorKind::Forbidden {
|
||||
#[cfg(feature = "unstable-msc2967")]
|
||||
authenticate: None
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -125,7 +125,7 @@ fn deserialize_uiaa_info() {
|
||||
assert_eq!(info.flows[1].stages, vec![AuthType::EmailIdentity, AuthType::Msisdn]);
|
||||
assert_eq!(info.session.as_deref(), Some("xxxxxx"));
|
||||
let auth_error = info.auth_error.unwrap();
|
||||
assert_eq!(auth_error.kind, ErrorKind::Forbidden);
|
||||
assert_matches!(auth_error.kind, ErrorKind::Forbidden { .. });
|
||||
assert_eq!(auth_error.message, "Invalid password");
|
||||
assert_eq!(
|
||||
from_json_str::<JsonValue>(info.params.get()).unwrap(),
|
||||
@ -207,7 +207,7 @@ fn try_uiaa_response_from_http_response() {
|
||||
assert_eq!(info.flows[1].stages, vec![AuthType::EmailIdentity, AuthType::Msisdn]);
|
||||
assert_eq!(info.session.as_deref(), Some("xxxxxx"));
|
||||
let auth_error = info.auth_error.unwrap();
|
||||
assert_eq!(auth_error.kind, ErrorKind::Forbidden);
|
||||
assert_matches!(auth_error.kind, ErrorKind::Forbidden { .. });
|
||||
assert_eq!(auth_error.message, "Invalid password");
|
||||
assert_eq!(
|
||||
from_json_str::<JsonValue>(info.params.get()).unwrap(),
|
||||
|
@ -77,7 +77,7 @@ time = "0.3.34"
|
||||
tracing = { workspace = true, features = ["attributes"] }
|
||||
url = "2.2.2"
|
||||
uuid = { version = "1.0.0", optional = true, features = ["v4"] }
|
||||
web-time = "1.1.0"
|
||||
web-time = { workspace = true }
|
||||
wildmatch = "2.0.0"
|
||||
|
||||
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
|
||||
|
@ -267,6 +267,7 @@ __ci = [
|
||||
assign = { workspace = true }
|
||||
js_int = { workspace = true }
|
||||
js_option = "0.1.1"
|
||||
web-time = { workspace = true }
|
||||
|
||||
ruma-common = { workspace = true }
|
||||
|
||||
|
@ -130,3 +130,4 @@ pub use js_option::JsOption;
|
||||
#[cfg(feature = "client-ext-client-api")]
|
||||
pub use ruma_client::Client;
|
||||
pub use ruma_common::*;
|
||||
pub use web_time as time;
|
||||
|
Loading…
x
Reference in New Issue
Block a user