forked from lavina/lavina
Compare commits
6 Commits
b0721160ff
...
80212fd3cc
Author | SHA1 | Date |
---|---|---|
Nikita Vilunov | 80212fd3cc | |
Nikita Vilunov | d2600c4299 | |
Nikita Vilunov | 0944c449ca | |
Mikhail | fd694cd75c | |
Nikita Vilunov | cccc05afe9 | |
Nikita Vilunov | 8b099f9be2 |
|
@ -0,0 +1,21 @@
|
||||||
|
repos:
|
||||||
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
rev: v4.5.0
|
||||||
|
hooks:
|
||||||
|
- id: check-toml
|
||||||
|
- id: end-of-file-fixer
|
||||||
|
- id: fix-byte-order-marker
|
||||||
|
- id: mixed-line-ending
|
||||||
|
- id: trailing-whitespace
|
||||||
|
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
- id: fmt
|
||||||
|
name: fmt
|
||||||
|
description: Format
|
||||||
|
entry: cargo fmt
|
||||||
|
language: system
|
||||||
|
args:
|
||||||
|
- --all
|
||||||
|
types: [ rust ]
|
||||||
|
pass_filenames: false
|
|
@ -45,6 +45,21 @@ version = "0.2.16"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
|
checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "android-tzdata"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "android_system_properties"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstream"
|
name = "anstream"
|
||||||
version = "0.6.13"
|
version = "0.6.13"
|
||||||
|
@ -216,6 +231,20 @@ version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "chrono"
|
||||||
|
version = "0.4.37"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8a0d04d43504c61aa6c7531f1871dd0d418d91130162063b789da00fd7057a5e"
|
||||||
|
dependencies = [
|
||||||
|
"android-tzdata",
|
||||||
|
"iana-time-zone",
|
||||||
|
"js-sys",
|
||||||
|
"num-traits",
|
||||||
|
"wasm-bindgen",
|
||||||
|
"windows-targets 0.52.4",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "4.5.3"
|
version = "4.5.3"
|
||||||
|
@ -274,6 +303,12 @@ version = "0.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
|
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "core-foundation-sys"
|
||||||
|
version = "0.8.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cpufeatures"
|
name = "cpufeatures"
|
||||||
version = "0.2.12"
|
version = "0.2.12"
|
||||||
|
@ -729,6 +764,29 @@ dependencies = [
|
||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "iana-time-zone"
|
||||||
|
version = "0.1.60"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141"
|
||||||
|
dependencies = [
|
||||||
|
"android_system_properties",
|
||||||
|
"core-foundation-sys",
|
||||||
|
"iana-time-zone-haiku",
|
||||||
|
"js-sys",
|
||||||
|
"wasm-bindgen",
|
||||||
|
"windows-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "iana-time-zone-haiku"
|
||||||
|
version = "0.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "idna"
|
name = "idna"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
|
@ -818,6 +876,7 @@ name = "lavina-core"
|
||||||
version = "0.0.2-dev"
|
version = "0.0.2-dev"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"chrono",
|
||||||
"prometheus",
|
"prometheus",
|
||||||
"serde",
|
"serde",
|
||||||
"sqlx",
|
"sqlx",
|
||||||
|
@ -2383,6 +2442,15 @@ version = "0.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-core"
|
||||||
|
version = "0.52.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets 0.52.4",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
version = "0.48.0"
|
version = "0.48.0"
|
||||||
|
|
|
@ -10,3 +10,4 @@ serde.workspace = true
|
||||||
tokio.workspace = true
|
tokio.workspace = true
|
||||||
tracing.workspace = true
|
tracing.workspace = true
|
||||||
prometheus.workspace = true
|
prometheus.workspace = true
|
||||||
|
chrono = "0.4.37"
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
alter table messages add column created_at text;
|
|
@ -87,14 +87,15 @@ impl Storage {
|
||||||
return Err(anyhow!("No such user"));
|
return Err(anyhow!("No such user"));
|
||||||
};
|
};
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
"insert into messages(room_id, id, content, author_id)
|
"insert into messages(room_id, id, content, author_id, created_at)
|
||||||
values (?, ?, ?, ?);
|
values (?, ?, ?, ?, ?);
|
||||||
update rooms set message_count = message_count + 1 where id = ?;",
|
update rooms set message_count = message_count + 1 where id = ?;",
|
||||||
)
|
)
|
||||||
.bind(room_id)
|
.bind(room_id)
|
||||||
.bind(id)
|
.bind(id)
|
||||||
.bind(content)
|
.bind(content)
|
||||||
.bind(author_id)
|
.bind(author_id)
|
||||||
|
.bind(chrono::Utc::now().to_string())
|
||||||
.bind(room_id)
|
.bind(room_id)
|
||||||
.execute(&mut *executor)
|
.execute(&mut *executor)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
|
@ -24,9 +24,9 @@ impl<'a> XmppConnection<'a> {
|
||||||
to: None,
|
to: None,
|
||||||
r#type: IqType::Result,
|
r#type: IqType::Result,
|
||||||
body: BindResponse(Jid {
|
body: BindResponse(Jid {
|
||||||
name: Some(Name("darova".into())),
|
name: Some(self.user.xmpp_name.clone()),
|
||||||
server: Server(self.hostname.clone()),
|
server: Server(self.hostname.clone()),
|
||||||
resource: Some(Resource("kek".into())),
|
resource: Some(self.user.xmpp_resource.clone()),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
req.serialize(output);
|
req.serialize(output);
|
||||||
|
|
|
@ -52,9 +52,17 @@ struct LoadedConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Authenticated {
|
struct Authenticated {
|
||||||
|
/// Identifier of the authenticated player.
|
||||||
|
///
|
||||||
|
/// Used when communicating with lavina-core on behalf of the player.
|
||||||
player_id: PlayerId,
|
player_id: PlayerId,
|
||||||
|
/// The user's XMPP name.
|
||||||
|
///
|
||||||
|
/// Used in `to` and `from` fields of XMPP messages.
|
||||||
xmpp_name: Name,
|
xmpp_name: Name,
|
||||||
|
/// The resource given to this user by the server.
|
||||||
xmpp_resource: Resource,
|
xmpp_resource: Resource,
|
||||||
|
/// The resource used by this user when joining MUCs.
|
||||||
xmpp_muc_name: Resource,
|
xmpp_muc_name: Resource,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,11 +322,13 @@ async fn socket_auth(
|
||||||
return Err(fail("passwords do not match"));
|
return Err(fail("passwords do not match"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let name: Str = name.as_str().into();
|
||||||
|
|
||||||
Ok(Authenticated {
|
Ok(Authenticated {
|
||||||
player_id: PlayerId::from(name.as_str())?,
|
player_id: PlayerId::from(name.clone())?,
|
||||||
xmpp_name: Name(name.to_string().into()),
|
xmpp_name: Name(name.clone()),
|
||||||
xmpp_resource: Resource(name.to_string().into()),
|
xmpp_resource: Resource(name.clone()),
|
||||||
xmpp_muc_name: Resource(name.to_string().into()),
|
xmpp_muc_name: Resource(name.clone()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Err(e) => return Err(e),
|
Err(e) => return Err(e),
|
||||||
|
@ -373,7 +383,7 @@ async fn socket_final(
|
||||||
res = &mut next_xml_event => 's: {
|
res = &mut next_xml_event => 's: {
|
||||||
let (ns, event) = res?;
|
let (ns, event) = res?;
|
||||||
if let Event::Text(ref e) = event {
|
if let Event::Text(ref e) = event {
|
||||||
if e.iter().all(|x| *x == 0xA) {
|
if e.iter().all(|x| *x == b'\n' || *x == b' ') {
|
||||||
break 's true;
|
break 's true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use std::io::ErrorKind;
|
use std::io::ErrorKind;
|
||||||
use std::net::SocketAddr;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
@ -20,7 +19,7 @@ use tokio_rustls::TlsConnector;
|
||||||
use lavina_core::player::PlayerRegistry;
|
use lavina_core::player::PlayerRegistry;
|
||||||
use lavina_core::repo::{Storage, StorageConfig};
|
use lavina_core::repo::{Storage, StorageConfig};
|
||||||
use lavina_core::room::RoomRegistry;
|
use lavina_core::room::RoomRegistry;
|
||||||
use projection_xmpp::{launch, ServerConfig};
|
use projection_xmpp::{launch, RunningServer, ServerConfig};
|
||||||
use proto_xmpp::xml::{Continuation, FromXml, Parser};
|
use proto_xmpp::xml::{Continuation, FromXml, Parser};
|
||||||
|
|
||||||
pub async fn read_irc_message(reader: &mut BufReader<ReadHalf<'_>>, buf: &mut Vec<u8>) -> Result<usize> {
|
pub async fn read_irc_message(reader: &mut BufReader<ReadHalf<'_>>, buf: &mut Vec<u8>) -> Result<usize> {
|
||||||
|
@ -122,29 +121,49 @@ impl ServerCertVerifier for IgnoreCertVerification {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct TestServer {
|
||||||
|
metrics: MetricsRegistry,
|
||||||
|
storage: Storage,
|
||||||
|
rooms: RoomRegistry,
|
||||||
|
players: PlayerRegistry,
|
||||||
|
server: RunningServer,
|
||||||
|
}
|
||||||
|
impl TestServer {
|
||||||
|
async fn start() -> Result<TestServer> {
|
||||||
|
let _ = tracing_subscriber::fmt::try_init();
|
||||||
|
let config = ServerConfig {
|
||||||
|
listen_on: "127.0.0.1:0".parse().unwrap(),
|
||||||
|
cert: "tests/certs/xmpp.pem".parse().unwrap(),
|
||||||
|
key: "tests/certs/xmpp.key".parse().unwrap(),
|
||||||
|
};
|
||||||
|
let mut metrics = MetricsRegistry::new();
|
||||||
|
let mut storage = Storage::open(StorageConfig {
|
||||||
|
db_path: ":memory:".into(),
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
let rooms = RoomRegistry::new(&mut metrics, storage.clone()).unwrap();
|
||||||
|
let players = PlayerRegistry::empty(rooms.clone(), &mut metrics).unwrap();
|
||||||
|
let server = launch(config, players.clone(), rooms.clone(), metrics.clone(), storage.clone()).await.unwrap();
|
||||||
|
Ok(TestServer {
|
||||||
|
metrics,
|
||||||
|
storage,
|
||||||
|
rooms,
|
||||||
|
players,
|
||||||
|
server,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn scenario_basic() -> Result<()> {
|
async fn scenario_basic() -> Result<()> {
|
||||||
tracing_subscriber::fmt::try_init();
|
let mut server = TestServer::start().await?;
|
||||||
let config = ServerConfig {
|
|
||||||
listen_on: "127.0.0.1:0".parse().unwrap(),
|
|
||||||
cert: "tests/certs/xmpp.pem".parse().unwrap(),
|
|
||||||
key: "tests/certs/xmpp.key".parse().unwrap(),
|
|
||||||
};
|
|
||||||
let mut metrics = MetricsRegistry::new();
|
|
||||||
let mut storage = Storage::open(StorageConfig {
|
|
||||||
db_path: ":memory:".into(),
|
|
||||||
})
|
|
||||||
.await?;
|
|
||||||
let rooms = RoomRegistry::new(&mut metrics, storage.clone()).unwrap();
|
|
||||||
let players = PlayerRegistry::empty(rooms.clone(), &mut metrics).unwrap();
|
|
||||||
let server = launch(config, players, rooms, metrics, storage.clone()).await.unwrap();
|
|
||||||
|
|
||||||
// test scenario
|
// test scenario
|
||||||
|
|
||||||
storage.create_user("tester").await?;
|
server.storage.create_user("tester").await?;
|
||||||
storage.set_password("tester", "password").await?;
|
server.storage.set_password("tester", "password").await?;
|
||||||
|
|
||||||
let mut stream = TcpStream::connect(server.addr).await?;
|
let mut stream = TcpStream::connect(server.server.addr).await?;
|
||||||
let mut s = TestScope::new(&mut stream);
|
let mut s = TestScope::new(&mut stream);
|
||||||
tracing::info!("TCP connection established");
|
tracing::info!("TCP connection established");
|
||||||
|
|
||||||
|
@ -169,7 +188,7 @@ async fn scenario_basic() -> Result<()> {
|
||||||
.with_no_client_auth(),
|
.with_no_client_auth(),
|
||||||
));
|
));
|
||||||
tracing::info!("Initiating TLS connection...");
|
tracing::info!("Initiating TLS connection...");
|
||||||
let mut stream = connector.connect(ServerName::IpAddress(server.addr.ip()), stream).await?;
|
let mut stream = connector.connect(ServerName::IpAddress(server.server.addr.ip()), stream).await?;
|
||||||
tracing::info!("TLS connection established");
|
tracing::info!("TLS connection established");
|
||||||
|
|
||||||
let mut s = TestScopeTls::new(&mut stream, buffer);
|
let mut s = TestScopeTls::new(&mut stream, buffer);
|
||||||
|
@ -183,33 +202,20 @@ async fn scenario_basic() -> Result<()> {
|
||||||
|
|
||||||
// wrap up
|
// wrap up
|
||||||
|
|
||||||
server.terminate().await?;
|
server.server.terminate().await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn scenario_basic_without_headers() -> Result<()> {
|
async fn scenario_basic_without_headers() -> Result<()> {
|
||||||
tracing_subscriber::fmt::try_init();
|
let mut server = TestServer::start().await?;
|
||||||
let config = ServerConfig {
|
|
||||||
listen_on: "127.0.0.1:0".parse().unwrap(),
|
|
||||||
cert: "tests/certs/xmpp.pem".parse().unwrap(),
|
|
||||||
key: "tests/certs/xmpp.key".parse().unwrap(),
|
|
||||||
};
|
|
||||||
let mut metrics = MetricsRegistry::new();
|
|
||||||
let mut storage = Storage::open(StorageConfig {
|
|
||||||
db_path: ":memory:".into(),
|
|
||||||
})
|
|
||||||
.await?;
|
|
||||||
let rooms = RoomRegistry::new(&mut metrics, storage.clone()).unwrap();
|
|
||||||
let players = PlayerRegistry::empty(rooms.clone(), &mut metrics).unwrap();
|
|
||||||
let server = launch(config, players, rooms, metrics, storage.clone()).await.unwrap();
|
|
||||||
|
|
||||||
// test scenario
|
// test scenario
|
||||||
|
|
||||||
storage.create_user("tester").await?;
|
server.storage.create_user("tester").await?;
|
||||||
storage.set_password("tester", "password").await?;
|
server.storage.set_password("tester", "password").await?;
|
||||||
|
|
||||||
let mut stream = TcpStream::connect(server.addr).await?;
|
let mut stream = TcpStream::connect(server.server.addr).await?;
|
||||||
let mut s = TestScope::new(&mut stream);
|
let mut s = TestScope::new(&mut stream);
|
||||||
tracing::info!("TCP connection established");
|
tracing::info!("TCP connection established");
|
||||||
|
|
||||||
|
@ -233,7 +239,7 @@ async fn scenario_basic_without_headers() -> Result<()> {
|
||||||
.with_no_client_auth(),
|
.with_no_client_auth(),
|
||||||
));
|
));
|
||||||
tracing::info!("Initiating TLS connection...");
|
tracing::info!("Initiating TLS connection...");
|
||||||
let mut stream = connector.connect(ServerName::IpAddress(server.addr.ip()), stream).await?;
|
let mut stream = connector.connect(ServerName::IpAddress(server.server.addr.ip()), stream).await?;
|
||||||
tracing::info!("TLS connection established");
|
tracing::info!("TLS connection established");
|
||||||
|
|
||||||
let mut s = TestScopeTls::new(&mut stream, buffer);
|
let mut s = TestScopeTls::new(&mut stream, buffer);
|
||||||
|
@ -246,33 +252,20 @@ async fn scenario_basic_without_headers() -> Result<()> {
|
||||||
|
|
||||||
// wrap up
|
// wrap up
|
||||||
|
|
||||||
server.terminate().await?;
|
server.server.terminate().await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn terminate_socket() -> Result<()> {
|
async fn terminate_socket() -> Result<()> {
|
||||||
tracing_subscriber::fmt::try_init();
|
let mut server = TestServer::start().await?;
|
||||||
let config = ServerConfig {
|
|
||||||
listen_on: "127.0.0.1:0".parse().unwrap(),
|
|
||||||
cert: "tests/certs/xmpp.pem".parse().unwrap(),
|
|
||||||
key: "tests/certs/xmpp.key".parse().unwrap(),
|
|
||||||
};
|
|
||||||
let mut metrics = MetricsRegistry::new();
|
|
||||||
let mut storage = Storage::open(StorageConfig {
|
|
||||||
db_path: ":memory:".into(),
|
|
||||||
})
|
|
||||||
.await?;
|
|
||||||
let rooms = RoomRegistry::new(&mut metrics, storage.clone()).unwrap();
|
|
||||||
let players = PlayerRegistry::empty(rooms.clone(), &mut metrics).unwrap();
|
|
||||||
let server = launch(config, players, rooms, metrics, storage.clone()).await.unwrap();
|
|
||||||
let address: SocketAddr = ("127.0.0.1:0".parse().unwrap());
|
|
||||||
// test scenario
|
// test scenario
|
||||||
|
|
||||||
storage.create_user("tester").await?;
|
server.storage.create_user("tester").await?;
|
||||||
storage.set_password("tester", "password").await?;
|
server.storage.set_password("tester", "password").await?;
|
||||||
|
|
||||||
let mut stream = TcpStream::connect(server.addr).await?;
|
let mut stream = TcpStream::connect(server.server.addr).await?;
|
||||||
let mut s = TestScope::new(&mut stream);
|
let mut s = TestScope::new(&mut stream);
|
||||||
tracing::info!("TCP connection established");
|
tracing::info!("TCP connection established");
|
||||||
|
|
||||||
|
@ -288,7 +281,6 @@ async fn terminate_socket() -> Result<()> {
|
||||||
assert_matches!(s.next_xml_event().await?, Event::End(b) => assert_eq!(b.local_name().into_inner(), b"features"));
|
assert_matches!(s.next_xml_event().await?, Event::End(b) => assert_eq!(b.local_name().into_inner(), b"features"));
|
||||||
s.send(r#"<starttls/>"#).await?;
|
s.send(r#"<starttls/>"#).await?;
|
||||||
assert_matches!(s.next_xml_event().await?, Event::Empty(b) => assert_eq!(b.local_name().into_inner(), b"proceed"));
|
assert_matches!(s.next_xml_event().await?, Event::Empty(b) => assert_eq!(b.local_name().into_inner(), b"proceed"));
|
||||||
let buffer = s.buffer;
|
|
||||||
|
|
||||||
let connector = TlsConnector::from(Arc::new(
|
let connector = TlsConnector::from(Arc::new(
|
||||||
ClientConfig::builder()
|
ClientConfig::builder()
|
||||||
|
@ -298,10 +290,10 @@ async fn terminate_socket() -> Result<()> {
|
||||||
));
|
));
|
||||||
|
|
||||||
tracing::info!("Initiating TLS connection...");
|
tracing::info!("Initiating TLS connection...");
|
||||||
let mut stream = connector.connect(ServerName::IpAddress(server.addr.ip()), stream).await?;
|
let mut stream = connector.connect(ServerName::IpAddress(server.server.addr.ip()), stream).await?;
|
||||||
tracing::info!("TLS connection established");
|
tracing::info!("TLS connection established");
|
||||||
|
|
||||||
server.terminate().await?;
|
server.server.terminate().await?;
|
||||||
|
|
||||||
assert_eq!(stream.read_u8().await.unwrap_err().kind(), ErrorKind::UnexpectedEof);
|
assert_eq!(stream.read_u8().await.unwrap_err().kind(), ErrorKind::UnexpectedEof);
|
||||||
|
|
||||||
|
|
|
@ -11,12 +11,15 @@ pub const XMLNS: &'static str = "urn:ietf:params:xml:ns:xmpp-bind";
|
||||||
|
|
||||||
// TODO remove `pub` in newtypes, introduce validation
|
// TODO remove `pub` in newtypes, introduce validation
|
||||||
|
|
||||||
|
/// Name (node identifier) of an XMPP entity. Placed before the `@` in a JID.
|
||||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||||
pub struct Name(pub Str);
|
pub struct Name(pub Str);
|
||||||
|
|
||||||
|
/// Server name of an XMPP entity. Placed after the `@` and before the `/` in a JID.
|
||||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||||
pub struct Server(pub Str);
|
pub struct Server(pub Str);
|
||||||
|
|
||||||
|
/// Resource of an XMPP entity. Placed after the `/` in a JID.
|
||||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||||
pub struct Resource(pub Str);
|
pub struct Resource(pub Str);
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,12 @@ Some useful commands for development and testing.
|
||||||
|
|
||||||
Following commands require `OpenSSL` to be installed. It is provided as `openssl` package in Arch Linux.
|
Following commands require `OpenSSL` to be installed. It is provided as `openssl` package in Arch Linux.
|
||||||
|
|
||||||
Generate self-signed TLS certificate:
|
Generate self-signed TLS certificate. Mind the common name (CN) field, it should match the domain name of the server.
|
||||||
|
Example for localhost:
|
||||||
|
|
||||||
openssl req -x509 -newkey rsa:4096 -sha256 -days 365 -noenc \
|
openssl req -x509 -newkey rsa:4096 -sha256 -days 365 -noenc \
|
||||||
-keyout certs/xmpp.key -out certs/xmpp.pem \
|
-keyout certs/xmpp.key -out certs/xmpp.pem \
|
||||||
-subj "/CN=example.com"
|
-subj "/CN=localhost"
|
||||||
|
|
||||||
Print content of a TLS certificate:
|
Print content of a TLS certificate:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue