1212
1313@cases .mark_services
1414class BouncerTestCase (cases .BaseServerTestCase ):
15- @cases .mark_specifications ("Ergo" )
16- def testBouncer (self ):
17- """Test basic bouncer functionality."""
15+ def setUp (self ):
16+ super ().setUp ()
1817 self .controller .registerUser (self , "observer" , "observerpassword" )
1918 self .controller .registerUser (self , "testuser" , "mypassword" )
2019
@@ -40,6 +39,7 @@ def testBouncer(self):
4039 self .assertMessageMatch (welcomes [0 ], params = ["testnick" , ANYSTR ])
4140 self .joinChannel (2 , "#chan" )
4241
42+ def _connectClient3 (self ):
4343 self .addClient ()
4444 self .sendLine (3 , "CAP LS 302" )
4545 self .sendLine (3 , "AUTHENTICATE PLAIN" )
@@ -57,41 +57,33 @@ def testBouncer(self):
5757 # we should be automatically joined to #chan
5858 self .assertMessageMatch (joins [0 ], params = ["#chan" ])
5959
60- # disable multiclient in nickserv
61- self .sendLine (3 , "NS SET MULTICLIENT OFF" )
62- self .getMessages (3 )
63-
60+ def _connectClient4 (self ):
61+ # connect a client similar to 3, but without the message-tags and account-tag
62+ # capabilities, to make sure it does not receive the associated tags
6463 self .addClient ()
6564 self .sendLine (4 , "CAP LS 302" )
6665 self .sendLine (4 , "AUTHENTICATE PLAIN" )
6766 self .sendLine (4 , sasl_plain_blob ("testuser" , "mypassword" ))
6867 self .sendLine (4 , "NICK testnick" )
6968 self .sendLine (4 , "USER a 0 * a" )
70- self .sendLine (4 , "CAP REQ : server-time message-tags " )
69+ self .sendLine (4 , "CAP REQ server-time" )
7170 self .sendLine (4 , "CAP END" )
72- # with multiclient disabled, we should not be able to attach to the nick
7371 messages = self .getMessages (4 )
7472 welcomes = [message for message in messages if message .command == RPL_WELCOME ]
75- self .assertEqual (len (welcomes ), 0 )
76- errors = [
77- message for message in messages if message .command == ERR_NICKNAMEINUSE
78- ]
79- self .assertEqual (len (errors ), 1 )
80-
81- self .sendLine (3 , "NS SET MULTICLIENT ON" )
82- self .getMessages (3 )
83- self .addClient ()
84- self .sendLine (5 , "CAP LS 302" )
85- self .sendLine (5 , "AUTHENTICATE PLAIN" )
86- self .sendLine (5 , sasl_plain_blob ("testuser" , "mypassword" ))
87- self .sendLine (5 , "NICK testnick" )
88- self .sendLine (5 , "USER a 0 * a" )
89- self .sendLine (5 , "CAP REQ server-time" )
90- self .sendLine (5 , "CAP END" )
91- messages = self .getMessages (5 )
92- welcomes = [message for message in messages if message .command == RPL_WELCOME ]
9373 self .assertEqual (len (welcomes ), 1 )
9474
75+ @cases .mark_specifications ("Ergo" )
76+ def testAutomaticResumption (self ):
77+ """Test logging into an account that already has a client joins the client's session"""
78+ self ._connectClient3 ()
79+
80+ @cases .mark_specifications ("Ergo" )
81+ def testChannelMessageFromOther (self ):
82+ """Test that all clients attached to a session get messages sent by someone else
83+ to a channel"""
84+ self ._connectClient3 ()
85+ self ._connectClient4 ()
86+
9587 self .sendLine (1 , "@+clientOnlyTag=Value PRIVMSG #chan :hey" )
9688 self .getMessages (1 )
9789 messagesfortwo = [
@@ -104,22 +96,84 @@ def testBouncer(self):
10496 self .assertEqual (len (messagesforthree ), 1 )
10597 messagefortwo = messagesfortwo [0 ]
10698 messageforthree = messagesforthree [0 ]
107- messageforfive = self .getMessage (5 )
99+ messageforfour = self .getMessage (4 )
108100 self .assertMessageMatch (messagefortwo , params = ["#chan" , "hey" ])
109101 self .assertMessageMatch (messageforthree , params = ["#chan" , "hey" ])
110- self .assertMessageMatch (messageforfive , params = ["#chan" , "hey" ])
102+ self .assertMessageMatch (messageforfour , params = ["#chan" , "hey" ])
111103 self .assertIn ("time" , messagefortwo .tags )
112104 self .assertIn ("time" , messageforthree .tags )
113- self .assertIn ("time" , messageforfive .tags )
105+ self .assertIn ("time" , messageforfour .tags )
114106 # 3 has account-tag
115107 self .assertIn ("account" , messageforthree .tags )
116108 # should get same msgid
117109 self .assertEqual (messagefortwo .tags ["msgid" ], messageforthree .tags ["msgid" ])
118- # 5 only has server-time, shouldn't get account or msgid tags
119- self .assertNotIn ("account" , messageforfive .tags )
120- self .assertNotIn ("msgid" , messageforfive .tags )
110+ # 4 only has server-time, shouldn't get account or msgid tags
111+ self .assertNotIn ("account" , messageforfour .tags )
112+ self .assertNotIn ("msgid" , messageforfour .tags )
113+
114+ @cases .mark_specifications ("Ergo" )
115+ def testChannelMessageFromSelf (self ):
116+ """Test that all clients attached to a session get messages sent by an other client
117+
118+ (TODO: check when the initial sender has echo-message too)"""
119+ self ._connectClient3 ()
120+ self ._connectClient4 ()
121+
122+ self .sendLine (2 , "@+clientOnlyTag=Value PRIVMSG #chan :hey" )
123+ messagesfortwo = [
124+ msg for msg in self .getMessages (2 ) if msg .command == "PRIVMSG"
125+ ]
126+ messagesforone = [
127+ msg for msg in self .getMessages (1 ) if msg .command == "PRIVMSG"
128+ ]
129+ messagesforthree = [
130+ msg for msg in self .getMessages (3 ) if msg .command == "PRIVMSG"
131+ ]
132+ self .assertEqual (len (messagesforone ), 1 )
133+ self .assertEqual (len (messagesfortwo ), 0 ) # echo-message not enabled
134+ self .assertEqual (len (messagesforthree ), 1 )
135+ messageforone = messagesforone [0 ]
136+ messageforthree = messagesforthree [0 ]
137+ messageforfour = self .getMessage (4 )
138+ self .assertMessageMatch (messageforone , params = ["#chan" , "hey" ])
139+ self .assertMessageMatch (messageforthree , params = ["#chan" , "hey" ])
140+ self .assertMessageMatch (messageforfour , params = ["#chan" , "hey" ])
141+ self .assertIn ("time" , messageforone .tags )
142+ self .assertIn ("time" , messageforthree .tags )
143+ self .assertIn ("time" , messageforfour .tags )
144+ # 3 has account-tag
145+ self .assertIn ("account" , messageforthree .tags )
146+ # should get same msgid
147+ self .assertEqual (messageforone .tags ["msgid" ], messageforthree .tags ["msgid" ])
148+ # 4 only has server-time, shouldn't get account or msgid tags
149+ self .assertNotIn ("account" , messageforfour .tags )
150+ self .assertNotIn ("msgid" , messageforfour .tags )
151+
152+ @cases .mark_specifications ("Ergo" )
153+ def testDirectMessageFromOther (self ):
154+ """Test that all clients attached to a session get copies of messages sent
155+ by an other client of that session directly to an other user"""
156+ self ._connectClient3 ()
157+ self ._connectClient4 ()
158+
159+ self .sendLine (1 , "PRIVMSG testnick :this is a direct message" )
160+ self .getMessages (1 )
161+ messagefortwo = [
162+ msg for msg in self .getMessages (2 ) if msg .command == "PRIVMSG"
163+ ][0 ]
164+ messageforthree = [
165+ msg for msg in self .getMessages (3 ) if msg .command == "PRIVMSG"
166+ ][0 ]
167+ self .assertEqual (messagefortwo .params , messageforthree .params )
168+ self .assertEqual (messagefortwo .tags ["msgid" ], messageforthree .tags ["msgid" ])
169+
170+ @cases .mark_specifications ("Ergo" )
171+ def testDirectMessageFromSelf (self ):
172+ """Test that all clients attached to a session get copies of messages sent
173+ by an other client of that session directly to an other user"""
174+ self ._connectClient3 ()
175+ self ._connectClient4 ()
121176
122- # test that copies of sent messages go out to other sessions
123177 self .sendLine (2 , "PRIVMSG observer :this is a direct message" )
124178 self .getMessages (2 )
125179 messageForRecipient = [
@@ -133,6 +187,13 @@ def testBouncer(self):
133187 messageForRecipient .tags ["msgid" ], copyForOtherSession .tags ["msgid" ]
134188 )
135189
190+ @cases .mark_specifications ("Ergo" )
191+ def testQuit (self ):
192+ """Test that a single client of a session does not make the whole user quit
193+ (and is generally not visible to anyone else, not even their other sessions),
194+ until the last client quits"""
195+ self ._connectClient3 ()
196+ self ._connectClient4 ()
136197 self .sendLine (2 , "QUIT :two out" )
137198 quitLines = [msg for msg in self .getMessages (2 ) if msg .command == "QUIT" ]
138199 self .assertEqual (len (quitLines ), 1 )
@@ -154,8 +215,8 @@ def testBouncer(self):
154215 messagesforthree [0 ], command = "PRIVMSG" , params = ["#chan" , "hey again" ]
155216 )
156217
157- self .sendLine (5 , "QUIT :five out" )
158- self .getMessages (5 )
218+ self .sendLine (4 , "QUIT :four out" )
219+ self .getMessages (4 )
159220 self .sendLine (3 , "QUIT :three out" )
160221 quitLines = [msg for msg in self .getMessages (3 ) if msg .command == "QUIT" ]
161222 self .assertEqual (len (quitLines ), 1 )
@@ -164,3 +225,26 @@ def testBouncer(self):
164225 quitLines = [msg for msg in self .getMessages (1 ) if msg .command == "QUIT" ]
165226 self .assertEqual (len (quitLines ), 1 )
166227 self .assertMessageMatch (quitLines [0 ], params = [StrRe (".*three out.*" )])
228+
229+ @cases .mark_specifications ("Ergo" )
230+ def testDisableAutomaticResumption (self ):
231+ # disable multiclient in nickserv
232+ self .sendLine (2 , "NS SET MULTICLIENT OFF" )
233+ self .getMessages (2 )
234+
235+ self .addClient ()
236+ self .sendLine (3 , "CAP LS 302" )
237+ self .sendLine (3 , "AUTHENTICATE PLAIN" )
238+ self .sendLine (3 , sasl_plain_blob ("testuser" , "mypassword" ))
239+ self .sendLine (3 , "NICK testnick" )
240+ self .sendLine (3 , "USER a 0 * a" )
241+ self .sendLine (3 , "CAP REQ :server-time message-tags" )
242+ self .sendLine (3 , "CAP END" )
243+ # with multiclient disabled, we should not be able to attach to the nick
244+ messages = self .getMessages (3 )
245+ welcomes = [message for message in messages if message .command == RPL_WELCOME ]
246+ self .assertEqual (len (welcomes ), 0 )
247+ errors = [
248+ message for message in messages if message .command == ERR_NICKNAMEINUSE
249+ ]
250+ self .assertEqual (len (errors ), 1 )
0 commit comments