Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Handle wall unfriend message access

Anand Baburajan70ce02704629
diff --git a/rust/e2e/tests/support/wall.rs b/rust/e2e/tests/support/wall.rs
index a2e5135346..2a65ffa1f2 100644
--- a/rust/e2e/tests/support/wall.rs
+++ b/rust/e2e/tests/support/wall.rs
@@ -30,3 +30,11 @@ pub fn assert_http_status<T>(result: Result<T, WallError>, expected_status: u16)
Ok(_) => panic!("expected HTTP {expected_status}, got success"),
}
}
+
+pub fn assert_invalid_input_contains<T>(result: Result<T, WallError>, expected: &str) {
+ match result {
+ Err(WallError::InvalidInput(message)) if message.contains(expected) => {}
+ Err(error) => panic!("expected invalid input containing {expected:?}, got {error:?}"),
+ Ok(_) => panic!("expected invalid input containing {expected:?}, got success"),
+ }
+}
diff --git a/rust/e2e/tests/wall_e2e.rs b/rust/e2e/tests/wall_e2e.rs
index fdd7f7c147..066da55a0c 100644
--- a/rust/e2e/tests/wall_e2e.rs
+++ b/rust/e2e/tests/wall_e2e.rs
@@ -262,6 +262,232 @@ async fn wall_bootstrap_posts_friend_share_and_link_suite() {
wall::assert_http_status(link_ctx.get_wall_profile_raw(None).await, 401);
}
+#[tokio::test]
+#[ignore = "requires local Museum at ENTE_E2E_ENDPOINT or http://localhost:8080"]
+async fn wall_unfriend_revokes_reciprocal_account_access_suite() {
+ let endpoint = support::endpoint();
+ if !support::assert_server_or_skip(&endpoint, "wall unfriend e2e suite").await {
+ return;
+ }
+
+ let owner = auth::create_account(
+ &endpoint,
+ support::unique_test_email("wall-unfriend-owner"),
+ support::unique_password("WallUnfriendOwner"),
+ )
+ .await;
+ let friend = auth::create_account(
+ &endpoint,
+ support::unique_test_email("wall-unfriend-friend"),
+ support::unique_password("WallUnfriendFriender"),
+ )
+ .await;
+
+ let owner_ctx = wall::open_ctx(&endpoint, &owner);
+ let friend_ctx = wall::open_ctx(&endpoint, &friend);
+
+ let owner_slug = format!("unfriend-owner-{}", owner.user_id);
+ let friend_slug = format!("unfriend-friend-{}", friend.user_id);
+ let owner_profile = wall::profile_payload("Unfriend Owner", "Owner bio");
+ let friend_profile = wall::profile_payload("Unfriend Friend", "Friend bio");
+ let owner_wall = owner_ctx
+ .create_wall(&owner_slug, &owner_profile)
+ .await
+ .expect("owner wall creation failed");
+ let friend_wall = friend_ctx
+ .create_wall(&friend_slug, &friend_profile)
+ .await
+ .expect("friend wall creation failed");
+
+ let post_key = owner_ctx.generate_post_key();
+ let object = owner_ctx
+ .upload_post_asset(&post_key, b"unfriend revocation post asset", Some(0))
+ .await
+ .expect("post asset upload should succeed");
+ let (post_id, _post_key) = owner_ctx
+ .create_post(
+ &owner_wall.wall_id,
+ &[object],
+ Some(br#"{"caption":"before unfriend"}"#),
+ Some(&post_key),
+ )
+ .await
+ .expect("post creation should succeed");
+
+ let link = owner_ctx
+ .create_wall_link(&owner_wall.wall_id)
+ .await
+ .expect("wall link should be created");
+ let link_ctx = WallLinkCtx::open(OpenWallLinkCtxInput {
+ base_url: endpoint.clone(),
+ wall_username: link.wall_username.clone(),
+ access_key: link.access_key.clone(),
+ user_agent: Some("ente-e2e".to_string()),
+ client_package: Some("io.ente.photos".to_string()),
+ client_version: Some("ente-e2e".to_string()),
+ })
+ .await
+ .expect("wall link should open");
+ friend_ctx
+ .add_friend_from_link(&link_ctx)
+ .await
+ .expect("friend add should succeed");
+
+ let friend_owner_profile = friend_ctx
+ .get_wall_profile_decrypted(&owner_wall.wall_id, None)
+ .await
+ .expect("friend should decrypt owner profile before unfriend");
+ assert_eq!(friend_owner_profile.profile, owner_profile);
+ let owner_friend_profile = owner_ctx
+ .get_wall_profile_decrypted(&friend_wall.wall_id, None)
+ .await
+ .expect("owner should decrypt friend profile before unfriend");
+ assert_eq!(owner_friend_profile.profile, friend_profile);
+ let feed = friend_ctx
+ .list_feed(None, Some(10))
+ .await
+ .expect("friend feed should load before unfriend");
+ assert!(feed.items.iter().any(|item| item.post_id == post_id));
+ friend_ctx
+ .like_post(post_id, true)
+ .await
+ .expect("friend should like owner post before unfriend");
+ let direct_message = friend_ctx
+ .send_message(&owner_wall.wall_id, "hello before unfriend")
+ .await
+ .expect("friend should send owner a direct message before unfriend");
+ let owner_thread = owner_ctx
+ .list_message_thread(&friend_wall.wall_id, None, Some(10))
+ .await
+ .expect("owner should read direct message thread before unfriend");
+ let owner_thread_message = owner_thread
+ .items
+ .iter()
+ .find(|message| message.message_id == direct_message.message_id)
+ .expect("direct message should be in owner thread before unfriend");
+ let decrypted_message = owner_ctx
+ .decrypt_message(owner_thread_message)
+ .expect("owner should decrypt direct message before unfriend");
+ assert_eq!(decrypted_message.payload.text, "hello before unfriend");
+ owner_ctx
+ .like_message(&direct_message.message_id, true)
+ .await
+ .expect("owner should like direct message before unfriend");
+
+ owner_ctx
+ .unfriend_by_wall(&friend_wall.wall_id)
+ .await
+ .expect("owner should unfriend friend");
+
+ let owner_shares = owner_ctx
+ .list_friend_shares()
+ .await
+ .expect("owner friend shares should load after unfriend");
+ assert!(owner_shares.is_empty());
+ let friend_shares = friend_ctx
+ .list_friend_shares()
+ .await
+ .expect("friend shares should load after unfriend");
+ assert!(friend_shares.is_empty());
+ let owner_friends = owner_ctx
+ .list_wall_friends(&owner_wall.wall_id)
+ .await
+ .expect("owner friend list should load after unfriend");
+ assert!(owner_friends.is_empty());
+ let friend_friends = friend_ctx
+ .list_wall_friends(&friend_wall.wall_id)
+ .await
+ .expect("friend friend list should load after unfriend");
+ assert!(friend_friends.is_empty());
+
+ let owner_relationship = owner_ctx
+ .get_relationship(&friend_wall.wall_id)
+ .await
+ .expect("owner relationship should load after unfriend");
+ assert!(owner_relationship.relationship.is_empty());
+ let friend_relationship = friend_ctx
+ .get_relationship(&owner_wall.wall_id)
+ .await
+ .expect("friend relationship should load after unfriend");
+ assert!(friend_relationship.relationship.is_empty());
+
+ let hydrated = friend_ctx
+ .hydrate_wall_keys()
+ .await
+ .expect("friend wall keys should hydrate after unfriend");
+ assert_eq!(hydrated.owned.len(), 1);
+ assert!(hydrated.friends.is_empty());
+ let feed = friend_ctx
+ .list_feed(None, Some(10))
+ .await
+ .expect("friend feed should load after unfriend");
+ assert!(
+ feed.items
+ .iter()
+ .all(|item| item.wall_id != owner_wall.wall_id)
+ );
+ let owner_thread = owner_ctx
+ .list_message_thread(&friend_wall.wall_id, None, Some(10))
+ .await
+ .expect("owner should still read direct message thread after unfriend");
+ let owner_thread_message = owner_thread
+ .items
+ .iter()
+ .find(|message| message.message_id == direct_message.message_id)
+ .expect("direct message should remain in owner thread after unfriend");
+ let decrypted_message = owner_ctx
+ .decrypt_message(owner_thread_message)
+ .expect("owner should still decrypt old direct message after unfriend");
+ assert_eq!(decrypted_message.payload.text, "hello before unfriend");
+ wall::assert_invalid_input_contains(
+ friend_ctx
+ .send_message(&owner_wall.wall_id, "should fail")
+ .await,
+ "not a friend",
+ );
+ wall::assert_invalid_input_contains(
+ owner_ctx
+ .reply_to_message(
+ &friend_wall.wall_id,
+ &direct_message.message_id,
+ "should fail",
+ )
+ .await,
+ "not a friend",
+ );
+ wall::assert_http_status(
+ owner_ctx
+ .like_message(&direct_message.message_id, false)
+ .await,
+ 403,
+ );
+
+ wall::assert_http_status(
+ friend_ctx
+ .get_wall_profile_raw(&owner_wall.wall_id, None)
+ .await,
+ 403,
+ );
+ wall::assert_http_status(
+ owner_ctx
+ .get_wall_profile_raw(&friend_wall.wall_id, None)
+ .await,
+ 403,
+ );
+ wall::assert_http_status(friend_ctx.fetch_post_decrypted(post_id).await, 403);
+ wall::assert_http_status(friend_ctx.like_post(post_id, true).await, 403);
+ wall::assert_http_status(friend_ctx.reply_to_post(post_id, "should fail").await, 403);
+
+ let likers = owner_ctx
+ .list_post_likers(post_id, None, Some(10))
+ .await
+ .expect("owner should still load post likers after unfriend");
+ assert_eq!(likers.likers.len(), 1);
+ assert_eq!(likers.likers[0].actor.wall_slug, friend_slug);
+ assert!(likers.likers[0].actor.wall_id.is_empty());
+ assert!(likers.likers[0].actor.public_key.is_empty());
+}
+
#[tokio::test]
#[ignore = "requires local Museum at ENTE_E2E_ENDPOINT or http://localhost:8080"]
async fn wall_rotation_history_refresh_and_link_suite() {
diff --git a/server/wall/controller/messages.go b/server/wall/controller/messages.go
index 176c1d88f7..89053d1648 100644
--- a/server/wall/controller/messages.go
+++ b/server/wall/controller/messages.go
@@ -170,6 +170,16 @@ func (c *MessagesController) ToggleLike(ctx *gin.Context, messageID string, req
if message.IsDeleted {
return nil, ente.NewBadRequestWithMessage("cannot like a deleted message")
}
+ otherWallID := message.SenderWallID
+ if message.SenderID == userID {
+ otherWallID = message.RecipientWallID
+ }
+ if _, err := c.FriendsRepo.GetShareForFriendAndWall(ctx.Request.Context(), userID, otherWallID); err != nil {
+ if errors.Is(stacktrace.RootCause(err), sql.ErrNoRows) {
+ return nil, ente.ErrPermissionDenied
+ }
+ return nil, err
+ }
if err := c.MessagesRepo.SetLike(ctx.Request.Context(), messageID, userID, req.Like); err != nil {
return nil, err
}
diff --git a/server/wall/controller/messages_test.go b/server/wall/controller/messages_test.go
index cf42003eff..24b727f6ad 100644
--- a/server/wall/controller/messages_test.go
+++ b/server/wall/controller/messages_test.go
@@ -2,8 +2,10 @@ package controller
import (
"context"
+ "errors"
"testing"
+ "github.com/ente-io/museum/ente"
"github.com/ente-io/museum/internal/testutil"
"github.com/ente-io/museum/wall/models"
wallrepo "github.com/ente-io/museum/wall/repo"
@@ -79,6 +81,13 @@ func TestMessageLikeAndDeleteAccess(t *testing.T) {
require.Equal(t, int64(1), viewed.Likes)
require.True(t, viewed.ViewerLiked)
+ require.NoError(t, repos.Friends.DeleteFriendship(ctx, aliceID, bobWall.WallID))
+ _, err = controller.ToggleLike(newWallControllerContext(aliceID), message.MessageID, models.LikeMessageRequest{Like: false})
+ require.True(t, errors.Is(err, ente.ErrPermissionDenied))
+ thread, _, err := repos.Messages.ListThread(ctx, aliceID, bobWall.WallID, "", 10)
+ require.NoError(t, err)
+ require.Len(t, thread, 1)
+
require.Error(t, controller.Delete(newWallControllerContext(aliceID), message.MessageID))
require.NoError(t, controller.Delete(newWallControllerContext(bobID), message.MessageID))
_, err = controller.ToggleLike(newWallControllerContext(aliceID), message.MessageID, models.LikeMessageRequest{Like: true})
diff --git a/web/apps/social/src/components/ConfirmationActionSheet.tsx b/web/apps/social/src/components/ConfirmationActionSheet.tsx
index e9cd0999fc..9c049cfb80 100644
--- a/web/apps/social/src/components/ConfirmationActionSheet.tsx
+++ b/web/apps/social/src/components/ConfirmationActionSheet.tsx
@@ -16,6 +16,7 @@ interface ConfirmationActionSheetProps {
confirmLabel: string;
confirmActionPhase?: SocialActionPhase | null;
confirmDisabled?: boolean;
+ errorMessage?: string | null;
cancelLabel?: string;
cancelDisabled?: boolean;
onCancel: () => void;
@@ -32,6 +33,7 @@ export const ConfirmationActionSheet: React.FC<
confirmLabel,
confirmActionPhase = null,
confirmDisabled = false,
+ errorMessage = null,
cancelLabel = "Cancel",
cancelDisabled = false,
onCancel,
@@ -130,6 +132,22 @@ export const ConfirmationActionSheet: React.FC<
disabled={cancelDisabled}
onClick={onCancel}
/>
+ {errorMessage && (
+ <Box
+ role="alert"
+ sx={{
+ color: dangerColor,
+ fontFamily: '"Inter Variable", Inter, sans-serif',
+ fontSize: 13,
+ fontWeight: 600,
+ lineHeight: "18px",
+ px: "12px",
+ textAlign: "center",
+ }}
+ >
+ {errorMessage}
+ </Box>
+ )}
</Box>
</Dialog>
);
diff --git a/web/apps/social/src/pages/app/friends/index.tsx b/web/apps/social/src/pages/app/friends/index.tsx
index 5f6bb39cac..b50d9baafe 100644
--- a/web/apps/social/src/pages/app/friends/index.tsx
+++ b/web/apps/social/src/pages/app/friends/index.tsx
@@ -44,12 +44,13 @@ const Page: React.FC = () => {
onOpenFriend={(friendID) =>
void router.push(socialRoutes.friend(friendID))
}
- onUnfriend={(friendID) => {
+ onUnfriend={async (friendID) => {
const friend = friends.find(
(candidate) => candidate.id == friendID,
);
- if (friend?.wallId)
- void removeCurrentWallFriend(friend.wallId);
+ if (!friend?.wallId) return;
+
+ await removeCurrentWallFriend(friend.wallId);
setFriends((currentFriends) =>
currentFriends.filter(
(candidate) => candidate.id != friendID,
diff --git a/web/apps/social/src/screens/FriendsScreen.tsx b/web/apps/social/src/screens/FriendsScreen.tsx
index 6935ed5a94..8328264382 100644
--- a/web/apps/social/src/screens/FriendsScreen.tsx
+++ b/web/apps/social/src/screens/FriendsScreen.tsx
@@ -27,7 +27,7 @@ interface FriendsScreenProps {
friends: FriendProfile[];
onBack?: () => void;
onOpenFriend?: (friendID: string) => void;
- onUnfriend?: (friendID: string) => void;
+ onUnfriend?: (friendID: string) => Promise<void> | void;
}
interface FriendRowProps {
@@ -284,17 +284,31 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({
React.useState<FriendProfile | null>(null);
const [unfriendActionPhase, setUnfriendActionPhase] =
React.useState<SocialActionPhase | null>(null);
+ const [unfriendErrorMessage, setUnfriendErrorMessage] = React.useState<
+ string | null
+ >(null);
const isUnfriendActionRunning = unfriendActionPhase != null;
const cancelUnfriend = () => {
if (isUnfriendActionRunning) return;
+ setUnfriendErrorMessage(null);
setFriendToUnfriend(null);
};
const confirmUnfriend = () => {
if (!friendToUnfriend || isUnfriendActionRunning) return;
- onUnfriend?.(friendToUnfriend.id);
- setUnfriendActionPhase("done");
+ setUnfriendErrorMessage(null);
+ setUnfriendActionPhase("busy");
+ void (async () => {
+ try {
+ await Promise.resolve(onUnfriend?.(friendToUnfriend.id));
+ setUnfriendActionPhase("done");
+ } catch (error) {
+ console.error("Failed to unfriend social friend", error);
+ setUnfriendActionPhase(null);
+ setUnfriendErrorMessage("Couldn't unfriend. Please try again.");
+ }
+ })();
};
React.useEffect(() => {
@@ -308,8 +322,8 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({
}, [unfriendActionPhase]);
const handleUnfriendSheetExited = () => {
- if (!unfriendActionPhase) return;
setUnfriendActionPhase(null);
+ setUnfriendErrorMessage(null);
};
return (
@@ -411,7 +425,10 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({
key={friend.id}
friend={friend}
onOpenFriend={onOpenFriend}
- onUnfriend={() => setFriendToUnfriend(friend)}
+ onUnfriend={() => {
+ setUnfriendErrorMessage(null);
+ setFriendToUnfriend(friend);
+ }}
/>
))}
</Box>
@@ -443,6 +460,7 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({
confirmLabel="Yes, unfriend"
confirmActionPhase={unfriendActionPhase}
confirmDisabled={isUnfriendActionRunning}
+ errorMessage={unfriendErrorMessage}
cancelDisabled={isUnfriendActionRunning}
onCancel={cancelUnfriend}
onConfirm={confirmUnfriend}