summaryrefslogtreecommitdiff
path: root/src/channel
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-10-22 23:25:24 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-10-22 23:25:24 -0400
commit01f9f3549c76702fd56e58d44c5180fecddb4bfa (patch)
treee7a64e70975a8b50bc442d28c17161b82c42c63a /src/channel
parent214a9e6c1fd729fc2c49eb2a5d41b5651ff5bc61 (diff)
Sort out the naming of the various parts of an identity.
* A `cookie::Identity` (`IdentityCookie`) is a specialized CookieJar for working with identities. * An `Identity` is a token/login pair. I hope for this to be a bit more legible. In service of this, `Login` is no longer extractable. You have to get an identity.
Diffstat (limited to 'src/channel')
-rw-r--r--src/channel/routes/channel/delete.rs4
-rw-r--r--src/channel/routes/channel/post.rs6
-rw-r--r--src/channel/routes/channel/test.rs52
-rw-r--r--src/channel/routes/post.rs4
-rw-r--r--src/channel/routes/test.rs6
5 files changed, 55 insertions, 17 deletions
diff --git a/src/channel/routes/channel/delete.rs b/src/channel/routes/channel/delete.rs
index 5f40ddf..91eb506 100644
--- a/src/channel/routes/channel/delete.rs
+++ b/src/channel/routes/channel/delete.rs
@@ -9,14 +9,14 @@ use crate::{
channel::app,
clock::RequestedAt,
error::{Internal, NotFound},
- login::Login,
+ token::extract::Identity,
};
pub async fn handler(
State(app): State<App>,
Path(channel): Path<super::PathInfo>,
RequestedAt(deleted_at): RequestedAt,
- _: Login,
+ _: Identity,
) -> Result<StatusCode, Error> {
app.channels().delete(&channel, &deleted_at).await?;
diff --git a/src/channel/routes/channel/post.rs b/src/channel/routes/channel/post.rs
index d0cae05..b51e691 100644
--- a/src/channel/routes/channel/post.rs
+++ b/src/channel/routes/channel/post.rs
@@ -8,20 +8,20 @@ use crate::{
app::App,
clock::RequestedAt,
error::{Internal, NotFound},
- login::Login,
message::{app::SendError, Body, Message},
+ token::extract::Identity,
};
pub async fn handler(
State(app): State<App>,
Path(channel): Path<super::PathInfo>,
RequestedAt(sent_at): RequestedAt,
- login: Login,
+ identity: Identity,
Json(request): Json<Request>,
) -> Result<Response, Error> {
let message = app
.messages()
- .send(&channel, &login, &sent_at, &request.body)
+ .send(&channel, &identity.login, &sent_at, &request.body)
.await?;
Ok(Response(message))
diff --git a/src/channel/routes/channel/test.rs b/src/channel/routes/channel/test.rs
index b895b69..9a2227d 100644
--- a/src/channel/routes/channel/test.rs
+++ b/src/channel/routes/channel/test.rs
@@ -14,7 +14,7 @@ async fn messages_in_order() {
// Set up the environment
let app = fixtures::scratch_app().await;
- let sender = fixtures::login::create(&app, &fixtures::now()).await;
+ let sender = fixtures::identity::create(&app, &fixtures::now()).await;
let channel = fixtures::channel::create(&app, &fixtures::now()).await;
// Call the endpoint (twice)
@@ -35,7 +35,7 @@ async fn messages_in_order() {
Json(request),
)
.await
- .expect("sending to a valid channel");
+ .expect("sending to a valid channel succeeds");
}
// Verify the semantics
@@ -44,7 +44,7 @@ async fn messages_in_order() {
.events()
.subscribe(None)
.await
- .expect("subscribing to a valid channel")
+ .expect("subscribing to a valid channel succeeds")
.filter_map(fixtures::message::events)
.take(requests.len());
@@ -55,7 +55,7 @@ async fn messages_in_order() {
assert!(matches!(
event,
message::Event::Sent(event)
- if event.message.sender == sender.id
+ if event.message.sender == sender.login.id
&& event.message.body == message
));
}
@@ -66,7 +66,7 @@ async fn nonexistent_channel() {
// Set up the environment
let app = fixtures::scratch_app().await;
- let login = fixtures::login::create(&app, &fixtures::now()).await;
+ let sender = fixtures::identity::create(&app, &fixtures::now()).await;
// Call the endpoint
@@ -79,11 +79,49 @@ async fn nonexistent_channel() {
State(app),
Path(channel.clone()),
sent_at,
- login,
+ sender,
Json(request),
)
.await
- .expect_err("sending to a nonexistent channel");
+ .expect_err("sending to a nonexistent channel fails");
+
+ // Verify the structure of the response
+
+ assert!(matches!(
+ error,
+ SendError::ChannelNotFound(error_channel) if channel == error_channel
+ ));
+}
+
+#[tokio::test]
+async fn deleted_channel() {
+ // Set up the environment
+
+ let app = fixtures::scratch_app().await;
+ let sender = fixtures::identity::create(&app, &fixtures::now()).await;
+ let channel = fixtures::channel::create(&app, &fixtures::now()).await;
+
+ app.channels()
+ .delete(&channel.id, &fixtures::now())
+ .await
+ .expect("deleting a new channel succeeds");
+
+ // Call the endpoint
+
+ let sent_at = fixtures::now();
+ let channel = channel::Id::generate();
+ let request = post::Request {
+ body: fixtures::message::propose(),
+ };
+ let post::Error(error) = post::handler(
+ State(app),
+ Path(channel.clone()),
+ sent_at,
+ sender,
+ Json(request),
+ )
+ .await
+ .expect_err("sending to a deleted channel fails");
// Verify the structure of the response
diff --git a/src/channel/routes/post.rs b/src/channel/routes/post.rs
index 9781dd7..810445c 100644
--- a/src/channel/routes/post.rs
+++ b/src/channel/routes/post.rs
@@ -9,13 +9,13 @@ use crate::{
channel::{app, Channel},
clock::RequestedAt,
error::Internal,
- login::Login,
name::Name,
+ token::extract::Identity,
};
pub async fn handler(
State(app): State<App>,
- _: Login, // requires auth, but doesn't actually care who you are
+ _: Identity, // requires auth, but doesn't actually care who you are
RequestedAt(created_at): RequestedAt,
Json(request): Json<Request>,
) -> Result<Response, Error> {
diff --git a/src/channel/routes/test.rs b/src/channel/routes/test.rs
index 7879ba0..77f283b 100644
--- a/src/channel/routes/test.rs
+++ b/src/channel/routes/test.rs
@@ -14,7 +14,7 @@ async fn new_channel() {
// Set up the environment
let app = fixtures::scratch_app().await;
- let creator = fixtures::login::create(&app, &fixtures::now()).await;
+ let creator = fixtures::identity::create(&app, &fixtures::now()).await;
// Call the endpoint
@@ -65,7 +65,7 @@ async fn duplicate_name() {
// Set up the environment
let app = fixtures::scratch_app().await;
- let creator = fixtures::login::create(&app, &fixtures::now()).await;
+ let creator = fixtures::identity::create(&app, &fixtures::now()).await;
let channel = fixtures::channel::create(&app, &fixtures::now()).await;
// Call the endpoint
@@ -91,7 +91,7 @@ async fn name_reusable_after_delete() {
// Set up the environment
let app = fixtures::scratch_app().await;
- let creator = fixtures::login::create(&app, &fixtures::now()).await;
+ let creator = fixtures::identity::create(&app, &fixtures::now()).await;
let name = fixtures::channel::propose();
// Call the endpoint (first time)