| ... | ... | | @@ -599,6 +599,190 @@ class TestClient extends utest.Test { |
| 599 | 599 | | client.stream.onStanza(stanza); |
| 600 | 600 | | } |
| 601 | 601 | |
|
| 602 | + | public function testLiveRosterRemovalClearsRosterState() { |
| 603 | + | final persistence = new Dummy(); |
| 604 | + | final client = new Client("test@example.com", persistence); |
| 605 | + | final chat = client.getDirectChat("bob@example.com"); |
| 606 | + | final stream = Std.downcast(client.stream, borogove.streams.TestStream); |
| 607 | + |
|
| 608 | + | stream.dispatchIq( |
| 609 | + | new Stanza("iq", { xmlns: "jabber:client", type: "set", from: "example.com" }) |
| 610 | + | .tag("query", { xmlns: "jabber:iq:roster" }) |
| 611 | + | .tag("item", { jid: "bob@example.com", name: "Bob", subscription: "both" }) |
| 612 | + | ); |
| 613 | + |
|
| 614 | + | Assert.isTrue(chat.isTrusted()); |
| 615 | + | Assert.isTrue(chat.isBookmarked); |
| 616 | + | Assert.equals("Bob", chat.getDisplayName()); |
| 617 | + |
|
| 618 | + | chat.setTags(["friends"]); |
| 619 | + | Assert.same(["friends"], chat.getTags()); |
| 620 | + |
|
| 621 | + | chat.uiState = Invited; |
| 622 | + |
|
| 623 | + | stream.dispatchIq( |
| 624 | + | new Stanza("iq", { xmlns: "jabber:client", type: "set", from: "example.com" }) |
| 625 | + | .tag("query", { xmlns: "jabber:iq:roster" }) |
| 626 | + | .tag("item", { jid: "bob@example.com", subscription: "remove" }) |
| 627 | + | ); |
| 628 | + |
|
| 629 | + | Assert.isFalse(chat.isTrusted()); |
| 630 | + | Assert.isFalse(chat.isBookmarked); |
| 631 | + | Assert.same([], chat.getTags()); |
| 632 | + | Assert.equals("Bob", chat.displayName); |
| 633 | + | Assert.equals(Invited, chat.uiState); |
| 634 | + | } |
| 635 | + |
|
| 636 | + | public function testLiveRosterRemovalDoesNotCreateChat() { |
| 637 | + | final persistence = new Dummy(); |
| 638 | + | final client = new Client("test@example.com", persistence); |
| 639 | + | final stream = Std.downcast(client.stream, borogove.streams.TestStream); |
| 640 | + |
|
| 641 | + | stream.dispatchIq( |
| 642 | + | new Stanza("iq", { xmlns: "jabber:client", type: "set", from: "example.com" }) |
| 643 | + | .tag("query", { xmlns: "jabber:iq:roster" }) |
| 644 | + | .tag("item", { jid: "nobody@example.com", subscription: "remove" }) |
| 645 | + | ); |
| 646 | + |
|
| 647 | + | Assert.isNull(client.getChat("nobody@example.com")); |
| 648 | + | } |
| 649 | + |
|
| 650 | + | public function testLiveRosterSubscriptionChangeUntrustsChat() { |
| 651 | + | final persistence = new Dummy(); |
| 652 | + | final client = new Client("test@example.com", persistence); |
| 653 | + | final chat = client.getDirectChat("bob@example.com"); |
| 654 | + | chat.setTrusted(true); |
| 655 | + |
|
| 656 | + | final stream = Std.downcast(client.stream, borogove.streams.TestStream); |
| 657 | + | stream.dispatchIq( |
| 658 | + | new Stanza("iq", { xmlns: "jabber:client", type: "set", from: "example.com" }) |
| 659 | + | .tag("query", { xmlns: "jabber:iq:roster" }) |
| 660 | + | .tag("item", { jid: "bob@example.com", subscription: "to" }) |
| 661 | + | ); |
| 662 | + |
|
| 663 | + | Assert.isFalse(chat.isTrusted()); |
| 664 | + | } |
| 665 | + |
|
| 666 | + | public function testRosterGetFullRosterMissingItemClearsRosterState() { |
| 667 | + | final persistence = new Dummy(); |
| 668 | + | final client = new Client("test@example.com", persistence); |
| 669 | + | final chat = client.getDirectChat("bob@example.com"); |
| 670 | + | chat.setTrusted(true); |
| 671 | + | chat.isBookmarked = true; |
| 672 | + | chat.setTags(["friends"]); |
| 673 | + | chat.displayName = "Bob"; |
| 674 | + | chat.uiState = Invited; |
| 675 | + |
|
| 676 | + | client.stream.on("sendStanza", (stanza: Stanza) -> { |
| 677 | + | if (stanza.name == "iq" && stanza.attr.get("type") == "get" && stanza.getChild("query", "jabber:iq:roster") != null) { |
| 678 | + | client.stream.onStanza( |
| 679 | + | new Stanza("iq", { xmlns: "jabber:client", type: "result", from: "example.com", id: stanza.attr.get("id") }) |
| 680 | + | .tag("query", { xmlns: "jabber:iq:roster", ver: "ver-1" }) |
| 681 | + | .tag("item", { jid: "carol@example.com", subscription: "both" }) |
| 682 | + | ); |
| 683 | + | return EventHandled; |
| 684 | + | } |
| 685 | + | return EventUnhandled; |
| 686 | + | }); |
| 687 | + |
|
| 688 | + | client.rosterGet(); |
| 689 | + |
|
| 690 | + | Assert.isFalse(chat.isTrusted()); |
| 691 | + | Assert.isFalse(chat.isBookmarked); |
| 692 | + | Assert.same([], chat.getTags()); |
| 693 | + | Assert.equals("Bob", chat.displayName); |
| 694 | + | Assert.equals(Invited, chat.uiState); |
| 695 | + | } |
| 696 | + |
|
| 697 | + | public function testRosterGetCachedVersionDoesNotClearRosterState() { |
| 698 | + | final persistence = new Dummy(); |
| 699 | + | final client = new Client("test@example.com", persistence); |
| 700 | + | final chat = client.getDirectChat("bob@example.com"); |
| 701 | + | chat.setTrusted(true); |
| 702 | + | chat.isBookmarked = true; |
| 703 | + | chat.setTags(["friends"]); |
| 704 | + | chat.displayName = "Bob"; |
| 705 | + | chat.uiState = Invited; |
| 706 | + |
|
| 707 | + | client.stream.on("sendStanza", (stanza: Stanza) -> { |
| 708 | + | if (stanza.name == "iq" && stanza.attr.get("type") == "get" && stanza.getChild("query", "jabber:iq:roster") != null) { |
| 709 | + | client.stream.onStanza( |
| 710 | + | new Stanza("iq", { xmlns: "jabber:client", type: "result", from: "example.com", id: stanza.attr.get("id") }) |
| 711 | + | ); |
| 712 | + | return EventHandled; |
| 713 | + | } |
| 714 | + | return EventUnhandled; |
| 715 | + | }); |
| 716 | + |
|
| 717 | + | client.rosterGet(); |
| 718 | + |
|
| 719 | + | Assert.isTrue(chat.isTrusted()); |
| 720 | + | Assert.isTrue(chat.isBookmarked); |
| 721 | + | Assert.same(["friends"], chat.getTags()); |
| 722 | + | Assert.equals("Bob", chat.displayName); |
| 723 | + | Assert.equals(Invited, chat.uiState); |
| 724 | + | } |
| 725 | + |
|
| 726 | + | public function testRosterGetInterimRemovePushClearsRosterState() { |
| 727 | + | final persistence = new Dummy(); |
| 728 | + | final client = new Client("test@example.com", persistence); |
| 729 | + | final chat = client.getDirectChat("bob@example.com"); |
| 730 | + | chat.setTrusted(true); |
| 731 | + | chat.isBookmarked = true; |
| 732 | + | chat.setTags(["friends"]); |
| 733 | + | chat.displayName = "Bob"; |
| 734 | + | chat.uiState = Invited; |
| 735 | + |
|
| 736 | + | client.stream.on("sendStanza", (stanza: Stanza) -> { |
| 737 | + | if (stanza.name == "iq" && stanza.attr.get("type") == "get" && stanza.getChild("query", "jabber:iq:roster") != null) { |
| 738 | + | client.stream.onStanza( |
| 739 | + | new Stanza("iq", { xmlns: "jabber:client", type: "result", from: "example.com", id: stanza.attr.get("id") }) |
| 740 | + | ); |
| 741 | + | return EventHandled; |
| 742 | + | } |
| 743 | + | return EventUnhandled; |
| 744 | + | }); |
| 745 | + |
|
| 746 | + | client.rosterGet(); |
| 747 | + | Assert.isTrue(chat.isTrusted()); |
| 748 | + |
|
| 749 | + | final stream = Std.downcast(client.stream, borogove.streams.TestStream); |
| 750 | + | stream.dispatchIq( |
| 751 | + | new Stanza("iq", { xmlns: "jabber:client", type: "set", from: "example.com" }) |
| 752 | + | .tag("query", { xmlns: "jabber:iq:roster", ver: "ver-2" }) |
| 753 | + | .tag("item", { jid: "bob@example.com", subscription: "remove" }) |
| 754 | + | ); |
| 755 | + |
|
| 756 | + | Assert.isFalse(chat.isTrusted()); |
| 757 | + | Assert.isFalse(chat.isBookmarked); |
| 758 | + | Assert.same([], chat.getTags()); |
| 759 | + | Assert.equals("Bob", chat.displayName); |
| 760 | + | Assert.equals(Invited, chat.uiState); |
| 761 | + | } |
| 762 | + |
|
| 763 | + | public function testRosterGetSubscriptionChangeUntrustsChat() { |
| 764 | + | final persistence = new Dummy(); |
| 765 | + | final client = new Client("test@example.com", persistence); |
| 766 | + | final chat = client.getDirectChat("bob@example.com"); |
| 767 | + | chat.setTrusted(true); |
| 768 | + |
|
| 769 | + | client.stream.on("sendStanza", (stanza: Stanza) -> { |
| 770 | + | if (stanza.name == "iq" && stanza.attr.get("type") == "get" && stanza.getChild("query", "jabber:iq:roster") != null) { |
| 771 | + | client.stream.onStanza( |
| 772 | + | new Stanza("iq", { xmlns: "jabber:client", type: "result", from: "example.com", id: stanza.attr.get("id") }) |
| 773 | + | .tag("query", { xmlns: "jabber:iq:roster", ver: "ver-1" }) |
| 774 | + | .tag("item", { jid: "bob@example.com", subscription: "to" }) |
| 775 | + | ); |
| 776 | + | return EventHandled; |
| 777 | + | } |
| 778 | + | return EventUnhandled; |
| 779 | + | }); |
| 780 | + |
|
| 781 | + | client.rosterGet(); |
| 782 | + |
|
| 783 | + | Assert.isFalse(chat.isTrusted()); |
| 784 | + | } |
| 785 | + |
|
| 602 | 786 | | public function testSortAfterDirectChat() { |
| 603 | 787 | | final persistence = new Dummy(); |
| 604 | 788 | | final client = new Client("test@example.com", persistence); |