From f63168538970c76bdd1639c27606442a80a567a9 Mon Sep 17 00:00:00 2001 From: Jonathan de Jong Date: Mon, 31 Jan 2022 19:39:00 +0100 Subject: [PATCH] client-api: Move token registration to new unstable-spec feature --- README.md | 13 ++++-- crates/ruma-client-api/Cargo.toml | 1 + crates/ruma-client-api/src/r0/account.rs | 2 +- .../check_registration_token_validity.rs | 4 +- crates/ruma-client-api/src/r0/uiaa.rs | 46 +++++++++---------- crates/ruma-client-api/tests/uiaa.rs | 8 ++-- crates/ruma/Cargo.toml | 3 ++ xtask/src/ci.rs | 4 +- 8 files changed, 44 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index c4076e5c..8b4e453b 100644 --- a/README.md +++ b/README.md @@ -38,10 +38,15 @@ them. Check out the documentation [on docs.rs][docs] (or on ## Status -As of 2021-02-10, we support all events and REST endpoints the latest released -versions of the various Matrix APIs. Various changes from the unstable version -of the specifications and some MSCs are also implemented, gated behind the -`unstable-pre-spec` Cargo feature. +As of 2022-01-31, we support all events and REST endpoints of the v1 version of +the Matrix specification, with v1.1 coverage in progress. + +Various changes from the unreleased version of the specification are also +implemented, gated behind the `unstable-spec` Cargo feature. + +Various changes from in-progress MSCs, finished MSCs, +and (often) unreleased versions of the specification are also implemented, +gated behind the `unstable-pre-spec` Cargo feature. ## Contributing diff --git a/crates/ruma-client-api/Cargo.toml b/crates/ruma-client-api/Cargo.toml index 2b04c1bb..af02a119 100644 --- a/crates/ruma-client-api/Cargo.toml +++ b/crates/ruma-client-api/Cargo.toml @@ -24,6 +24,7 @@ compat = [] unstable-exhaustive-types = [] # feature dependency required for r0::room::create_room::CreationContent::into_event_content unstable-pre-spec = ["ruma-events/unstable-pre-spec"] +unstable-spec = [] client = [] server = [] diff --git a/crates/ruma-client-api/src/r0/account.rs b/crates/ruma-client-api/src/r0/account.rs index a3a3159b..30a3033a 100644 --- a/crates/ruma-client-api/src/r0/account.rs +++ b/crates/ruma-client-api/src/r0/account.rs @@ -3,7 +3,7 @@ pub mod add_3pid; pub mod bind_3pid; pub mod change_password; -#[cfg(feature = "unstable-pre-spec")] +#[cfg(feature = "unstable-spec")] // todo: v1.2 pub mod check_registration_token_validity; pub mod deactivate; pub mod delete_3pid; diff --git a/crates/ruma-client-api/src/r0/account/check_registration_token_validity.rs b/crates/ruma-client-api/src/r0/account/check_registration_token_validity.rs index 367d2307..8e57c240 100644 --- a/crates/ruma-client-api/src/r0/account/check_registration_token_validity.rs +++ b/crates/ruma-client-api/src/r0/account/check_registration_token_validity.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/unstable/org.matrix.msc3231/register/org.matrix.msc3231.login.registration_token/validity](https://github.com/matrix-org/matrix-doc/blob/main/proposals/3231-token-authenticated-registration.md#checking-the-validity-of-a-token) +//! [GET /_matrix/client/v1/register/m.login.registration_token/validity](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientv1registermloginregistration_tokenvalidity) use ruma_api::ruma_api; @@ -7,7 +7,7 @@ ruma_api! { description: "Checks to see if the given registration token is valid.", method: GET, name: "check_registration_token_validity", - path: "/_matrix/client/unstable/org.matrix.msc3231/register/org.matrix.msc3231.login.registration_token/validity", + path: "/_matrix/client/v1/register/m.login.registration_token/validity", rate_limited: true, authentication: None, } diff --git a/crates/ruma-client-api/src/r0/uiaa.rs b/crates/ruma-client-api/src/r0/uiaa.rs index 8ec95dd7..0c186312 100644 --- a/crates/ruma-client-api/src/r0/uiaa.rs +++ b/crates/ruma-client-api/src/r0/uiaa.rs @@ -58,8 +58,8 @@ pub enum AuthData<'a> { /// Dummy authentication (`m.login.dummy`). Dummy(Dummy<'a>), - /// Registration token-based authentication (`org.matrix.msc3231.login.registration_token`). - #[cfg(feature = "unstable-pre-spec")] + /// Registration token-based authentication (`m.login.registration_token`). + #[cfg(feature = "unstable-spec")] // todo: v1.2 RegistrationToken(RegistrationToken<'a>), /// Fallback acknowledgement. @@ -85,7 +85,7 @@ impl<'a> AuthData<'a> { Self::EmailIdentity(_) => Some(AuthType::EmailIdentity), Self::Msisdn(_) => Some(AuthType::Msisdn), Self::Dummy(_) => Some(AuthType::Dummy), - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] // todo: v1.2 Self::RegistrationToken(_) => Some(AuthType::RegistrationToken), Self::FallbackAcknowledgement(_) => None, Self::_Custom(c) => Some(AuthType::_Custom(PrivOwnedStr(c.auth_type.into()))), @@ -102,7 +102,7 @@ impl<'a> AuthData<'a> { Self::EmailIdentity(x) => x.session, Self::Msisdn(x) => x.session, Self::Dummy(x) => x.session, - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] // todo: v1.2 Self::RegistrationToken(x) => x.session, Self::FallbackAcknowledgement(x) => Some(x.session), Self::_Custom(x) => x.session, @@ -145,7 +145,7 @@ impl<'a> AuthData<'a> { thirdparty_id_creds: x.thirdparty_id_creds, session: None, })), - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] // todo: v1.2 Self::RegistrationToken(x) => { Cow::Owned(serialize(RegistrationToken { token: x.token, session: None })) } @@ -190,10 +190,8 @@ impl IncomingAuthData { "m.login.email.identity" => Self::EmailIdentity(deserialize_variant(session, data)?), "m.login.msisdn" => Self::Msisdn(deserialize_variant(session, data)?), "m.login.dummy" => Self::Dummy(deserialize_variant(session, data)?), - #[cfg(feature = "unstable-pre-spec")] - "org.matrix.msc3231.login.registration_token" => { - Self::RegistrationToken(deserialize_variant(session, data)?) - } + #[cfg(feature = "unstable-spec")] // todo: v1.2 + "m.registration_token" => Self::RegistrationToken(deserialize_variant(session, data)?), _ => Self::_Custom(IncomingCustomAuthData { auth_type: auth_type.into(), session, @@ -212,7 +210,7 @@ impl IncomingAuthData { Self::EmailIdentity(_) => Some(AuthType::EmailIdentity), Self::Msisdn(_) => Some(AuthType::Msisdn), Self::Dummy(_) => Some(AuthType::Dummy), - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] // todo: v1.2 Self::RegistrationToken(_) => Some(AuthType::RegistrationToken), Self::FallbackAcknowledgement(_) => None, Self::_Custom(c) => Some(AuthType::_Custom(PrivOwnedStr(c.auth_type.as_str().into()))), @@ -229,7 +227,7 @@ impl IncomingAuthData { Self::EmailIdentity(x) => x.session.as_deref(), Self::Msisdn(x) => x.session.as_deref(), Self::Dummy(x) => x.session.as_deref(), - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] // todo: v1.2 Self::RegistrationToken(x) => x.session.as_deref(), Self::FallbackAcknowledgement(x) => Some(&x.session), Self::_Custom(x) => x.session.as_deref(), @@ -272,7 +270,7 @@ impl IncomingAuthData { thirdparty_id_creds: &x.thirdparty_id_creds, session: None, })), - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] // todo: v1.2 Self::RegistrationToken(x) => { Cow::Owned(serialize(RegistrationToken { token: &x.token, session: None })) } @@ -292,7 +290,7 @@ impl IncomingAuthData { Self::EmailIdentity(a) => AuthData::EmailIdentity(a.to_outgoing()), Self::Msisdn(a) => AuthData::Msisdn(a.to_outgoing()), Self::Dummy(a) => AuthData::Dummy(a.to_outgoing()), - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] // todo: v1.2 Self::RegistrationToken(a) => AuthData::RegistrationToken(a.to_outgoing()), Self::FallbackAcknowledgement(a) => AuthData::FallbackAcknowledgement(a.to_outgoing()), Self::_Custom(a) => AuthData::_Custom(CustomAuthData { @@ -335,8 +333,8 @@ impl<'de> Deserialize<'de> for IncomingAuthData { Some("m.login.email.identity") => from_raw_json_value(&json).map(Self::EmailIdentity), Some("m.login.msisdn") => from_raw_json_value(&json).map(Self::Msisdn), Some("m.login.dummy") => from_raw_json_value(&json).map(Self::Dummy), - #[cfg(feature = "unstable-pre-spec")] - Some("org.matrix.msc3231.login.registration_token") => { + #[cfg(feature = "unstable-spec")] // todo: v1.2 + Some("m.login.registration_token") => { from_raw_json_value(&json).map(Self::RegistrationToken) } None => from_raw_json_value(&json).map(Self::FallbackAcknowledgement), @@ -381,9 +379,9 @@ pub enum AuthType { #[ruma_enum(rename = "m.login.dummy")] Dummy, - /// Registration token-based authentication (`org.matrix.msc3231.login.registration_token`). - #[cfg(feature = "unstable-pre-spec")] - #[ruma_enum(rename = "org.matrix.msc3231.login.registration_token")] + /// Registration token-based authentication (`m.login.registration_token`). + #[ruma_enum(rename = "m.login.registration_token")] + #[cfg(feature = "unstable-spec")] // todo: v1.2 RegistrationToken, #[doc(hidden)] @@ -608,13 +606,13 @@ impl IncomingDummy { /// Data for registration token-based UIAA flow. /// -/// See [MSC3231] for how to use this. +/// See [the spec] for how to use this. /// -/// [MSC3231]: https://github.com/matrix-org/matrix-doc/pull/3231 +/// [the spec]: https://spec.matrix.org/unstable/client-server-api/#token-authenticated-registration #[derive(Clone, Debug, Outgoing, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -#[cfg(feature = "unstable-pre-spec")] -#[serde(tag = "type", rename = "org.matrix.msc3231.login.registration_token")] +#[serde(tag = "type", rename = "m.login.registration_token")] +#[cfg(feature = "unstable-spec")] // todo: v1.2 pub struct RegistrationToken<'a> { /// The registration token. pub token: &'a str, @@ -623,7 +621,7 @@ pub struct RegistrationToken<'a> { pub session: Option<&'a str>, } -#[cfg(feature = "unstable-pre-spec")] +#[cfg(feature = "unstable-spec")] // todo: v1.2 impl<'a> RegistrationToken<'a> { /// Creates a new `RegistrationToken` with the given token. pub fn new(token: &'a str) -> Self { @@ -631,7 +629,7 @@ impl<'a> RegistrationToken<'a> { } } -#[cfg(feature = "unstable-pre-spec")] +#[cfg(feature = "unstable-spec")] // todo: v1.2 impl IncomingRegistrationToken { /// Convert from `IncomingRegistrationToken` to `RegistrationToken`. fn to_outgoing(&self) -> RegistrationToken<'_> { diff --git a/crates/ruma-client-api/tests/uiaa.rs b/crates/ruma-client-api/tests/uiaa.rs index 216d231e..988ede2a 100644 --- a/crates/ruma-client-api/tests/uiaa.rs +++ b/crates/ruma-client-api/tests/uiaa.rs @@ -65,7 +65,7 @@ fn deserialize_auth_data_direct_request() { } #[test] -#[cfg(feature = "unstable-pre-spec")] +#[cfg(feature = "unstable-spec")] // todo: v1.2 fn serialize_auth_data_registration_token() { let auth_data = AuthData::RegistrationToken( assign!(uiaa::RegistrationToken::new("mytoken"), { session: Some("session") }), @@ -74,7 +74,7 @@ fn serialize_auth_data_registration_token() { assert_matches!( to_json_value(auth_data), Ok(val) if val == json!({ - "type": "org.matrix.msc3231.login.registration_token", + "type": "m.login.registration_token", "token": "mytoken", "session": "session", }) @@ -82,10 +82,10 @@ fn serialize_auth_data_registration_token() { } #[test] -#[cfg(feature = "unstable-pre-spec")] +#[cfg(feature = "unstable-spec")] // todo: v1.2 fn deserialize_auth_data_registration_token() { let json = json!({ - "type": "org.matrix.msc3231.login.registration_token", + "type": "m.login.registration_token", "token": "mytoken", "session": "session", }); diff --git a/crates/ruma/Cargo.toml b/crates/ruma/Cargo.toml index 6301337b..265e6de7 100644 --- a/crates/ruma/Cargo.toml +++ b/crates/ruma/Cargo.toml @@ -119,6 +119,9 @@ unstable-pre-spec = [ #"ruma-identity-service-api/unstable-pre-spec", #"ruma-push-gateway-api/unstable-pre-spec", ] +unstable-spec = [ + "ruma-client-api/unstable-spec" +] [dependencies] assign = "1.1.1" diff --git a/xtask/src/ci.rs b/xtask/src/ci.rs index 767b0fc3..e971d582 100644 --- a/xtask/src/ci.rs +++ b/xtask/src/ci.rs @@ -72,7 +72,7 @@ impl CiTask { // 2. Run tests let workspace_res = - cmd!("rustup run stable cargo test --workspace --features full,unstable-pre-spec") + cmd!("rustup run stable cargo test --workspace --features full,unstable-pre-spec,unstable-spec") .run(); let events_compat_res = cmd!("rustup run stable cargo test -p ruma-events --features compat compat").run(); @@ -98,7 +98,7 @@ impl CiTask { let clippy_all_res = cmd!( " rustup run nightly cargo clippy - --workspace --all-targets --features=full,compat,unstable-pre-spec -- -D warnings + --workspace --all-targets --features=full,compat,unstable-pre-spec,unstable-spec -- -D warnings " ) .run();