Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Don't accidentally accept that a chat protection is broken #4550

Merged
merged 3 commits into from
Aug 8, 2023

Conversation

Hocuri
Copy link
Collaborator

@Hocuri Hocuri commented Jul 17, 2023

In one of the tests I wrote, I called send_recv_accept(), which accepted the protection-brokenness, and I spent a long time debugging this.

So, send_recv_accept() asserts that the chat is a request, and if a chat is not a request, accept() doesn't accept the protection-brokenness.

@@ -398,7 +398,10 @@ impl ChatId {

match chat.typ {
Chattype::Undefined => bail!("Can't accept chat of undefined chattype"),
Chattype::Single if chat.protected == ProtectionStatus::ProtectionBroken => {
Chattype::Single
if chat.blocked == Blocked::Not
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this check was added?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea of this PR is:

send_recv_accept() asserts that the chat is a request, and if a chat is not a request, accept() doesn't accept the protection-brokenness.

I.e. this check makes sure that send_recv_accept() never accidentally accepts the protection-brokenness.

Also, it just seemed the correct behavior to me that if a chat is both a request and protection-broken, the request is accepted. Though this shouldn't actually happen, anyway, so, this doesn't really matter.

...That said, this line isn't a very important part of the PR, I can also revert it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why then Blocked::Not is here, not Blocked::Request?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iequidoo if chat.blocked == Blocked::Not, i.e. it's NOT a Request, then this accepts the broken protection.

Otherwise (Blocked::Request or Blocked::Yes), this goes on to the next match arm, and accepts the request / unblocks the chat.

Copy link
Collaborator

@iequidoo iequidoo Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but is the comment below correct then?
The chat was in the 'Request' state because the protection was broken.
Because the chat is not a request, but has a broken protection.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, I'll change the comment. It's from an early prototype when chats with a broken protection were also marked as Requests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But as I said, it'd be no problem to revert this change, the important part of the change is in test_utils.rs.

src/test_utils.rs Outdated Show resolved Hide resolved
@Hocuri Hocuri requested review from link2xt and iequidoo July 20, 2023 09:16
@Hocuri
Copy link
Collaborator Author

Hocuri commented Jul 31, 2023

@link2xt @iequidoo would be good if you can review, very easy PR, +14 and -11 lines, mainly changes tests. If the if chat.blocked == Blocked::Not is making you hesitate, just tell me, then I'll revert it.

@link2xt
Copy link
Collaborator

link2xt commented Jul 31, 2023

@Hocuri In the discussion you said "Ah, yes, I'll change the comment." and the comment is not changed so I assumed it is not ready for review yet. Is there some change not pushed?

@Hocuri
Copy link
Collaborator Author

Hocuri commented Jul 31, 2023

Oops yes, forgot to commit&push this, thanks for reminding!

@Hocuri Hocuri force-pushed the hoc/dont-accidentally-accept branch from 1f64227 to 40c2d9c Compare July 31, 2023 20:06
In one of the tests I wrote, I called `send_recv_accept()`, which
accepted the protection-brokenness, and I spent a long time debugging
this.

So, `send_recv_accept()` asserts that the chat is a request, and if a
chat is not a request, accept() doesn't accept the
protection-brokenness.
@Hocuri Hocuri force-pushed the hoc/dont-accidentally-accept branch from 40c2d9c to e297c70 Compare August 7, 2023 17:55
@Hocuri Hocuri merged commit 53f04a1 into master Aug 8, 2023
36 checks passed
@Hocuri Hocuri deleted the hoc/dont-accidentally-accept branch August 8, 2023 09:35
@link2xt link2xt mentioned this pull request Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants