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