Adaugă codul complet al proiectului underchat-ircd
This commit is contained in:
1 parent
caba5224bf
commit
5fdc1cc27c
462 files changed
+164488
No files matched your search
@@ -0,0 +1,35 @@
|
||||
define srv1 localhost:7601
|
||||
define srv1-name irc.example.net
|
||||
define hidden-srv *.undernet.org
|
||||
define channel #random-channel
|
||||
define cl1-nick Ch4n0pm4n
|
||||
define cl2-nick D00dm4n
|
||||
|
||||
# Connect two clients. Join one to the test channel.
|
||||
connect cl1 %cl1-nick% op3rm4n %srv1% :Some Chanop
|
||||
connect cl2 %cl2-nick% d00dm4n %srv1% :Someone Else
|
||||
:cl1 join %channel%
|
||||
:cl1 mode %channel% +D
|
||||
:cl1 expect %cl1-nick% mode %channel% \\+D
|
||||
|
||||
# Now join the other client, and let the chanop remove -D. Both
|
||||
# should see the channel become +d.
|
||||
:cl2 wait cl1
|
||||
:cl2 join %channel%
|
||||
:cl1 wait cl2
|
||||
:cl1 mode %channel% -D
|
||||
:cl1 expect %cl1-nick% mode %channel% -D\\+d
|
||||
:cl2 expect %cl1-nick% mode %channel% -D\\+d
|
||||
|
||||
# Bug 1640796 is that if the chanop sends +D-D, the channel is
|
||||
# improperly marked -d. (An empty mode change is also sent to other
|
||||
# servers.)
|
||||
:cl1 mode %channel% +D-D
|
||||
:cl1 mode %channel%
|
||||
:cl1 expect %srv1-name% 324 %channel% \\+.*d
|
||||
|
||||
# Make sure that client 1 does see the -d when client 2 quits
|
||||
:cl2 wait cl1
|
||||
:cl1 expect %hidden-srv% mode %channel% -d
|
||||
:cl2 part %channel%
|
||||
:cl1 quit done
|
||||
@@ -0,0 +1,33 @@
|
||||
define srv1 127.0.0.1:7611
|
||||
define srv1-name irc-2.example.net
|
||||
define srv2 127.0.0.2:7621
|
||||
define srv2-name irc-3.example.net
|
||||
define cl1-nick oper1
|
||||
define cl2-nick oper2
|
||||
define cl3-nick oper3
|
||||
|
||||
# Connect two clients to server 1, one to server 2, and oper them all up.
|
||||
connect cl1 %cl1-nick% oper %srv1% :Oper 1
|
||||
connect cl2 %cl2-nick% oper %srv1% :Oper 2
|
||||
connect cl3 %cl3-nick% oper %srv2% :Oper 3
|
||||
:cl1 oper oper oper
|
||||
:cl2 oper oper oper
|
||||
:cl3 oper oper oper
|
||||
|
||||
# Check that we get local privileges properly.
|
||||
:cl1 wait cl2,cl3
|
||||
:cl1 raw :privs %cl1-nick%
|
||||
:cl1 expect %srv1-name% 270 %cl1-nick% :CHAN_LIMIT
|
||||
:cl1 raw :privs %cl2-nick%
|
||||
:cl1 expect %srv1-name% 270 %cl2-nick% :CHAN_LIMIT
|
||||
|
||||
# Bug 1674539 is that remote /privs do not get any response.
|
||||
# Testing shows that the problem only shows up with a hub between.
|
||||
:cl1 raw :privs %cl3-nick%
|
||||
:cl1 expect %srv2-name% 270 %cl3-nick% :CHAN_LIMIT
|
||||
|
||||
# Synchronize everything
|
||||
sync cl1,cl2,cl3
|
||||
:cl1 quit done
|
||||
:cl2 quit done
|
||||
:cl3 quit done
|
||||
@@ -0,0 +1,9 @@
|
||||
define srv1 localhost:7601
|
||||
define srv1-name irc.example.net
|
||||
define cl1-nick Bug1685648
|
||||
define channel #random-channel
|
||||
|
||||
connect cl1 %cl1-nick% buguser %srv1% :Some buggy user
|
||||
:cl1 join %channel%
|
||||
:cl1 expect %srv1-name% 366 %channel%
|
||||
:cl1 quit done
|
||||
@@ -0,0 +1,39 @@
|
||||
define srv1 localhost:7601
|
||||
define srv1-name irc.example.net
|
||||
define hidden-srv *.undernet.org
|
||||
define channel #random-channel
|
||||
define cl1-nick Ch4n0pm4n
|
||||
|
||||
# Connect a client and join it to the test channel.
|
||||
connect cl1 %cl1-nick% op3rm4n %srv1% :Some Chanop
|
||||
:cl1 join %channel%
|
||||
|
||||
# Issue a variety of bans, all of which should be accepted.
|
||||
:cl1 mode %channel% +b *!*@1.0.0.0/16
|
||||
:cl1 mode %channel% +b *!*@1.0.0.*
|
||||
:cl1 mode %channel% +b *!*@*.example.com
|
||||
:cl1 mode %channel% +b *!foo@*.example.org
|
||||
:cl1 mode %channel% +b *!*@*.bar.example.*
|
||||
|
||||
# Check the modes on the channel.
|
||||
:cl1 mode %channel% +b
|
||||
# These regexps make my eyes bleed almost enough to add a load of code to test-driver.pl.
|
||||
# There's another test-driver problem here, too: one "expect" works fine, but a second
|
||||
# one never sees the second numeric response from the server.
|
||||
:cl1 expect %srv1-name% 367 %channel% \\*!\\*@\\*\\.bar\\.example\\.* %cl1-nick% \\d+
|
||||
|
||||
# Check that a more-encompassing ban removes the old bans.
|
||||
:cl1 mode %channel% +b *!*@1.0.*
|
||||
:cl1 expect %cl1-nick% mode %channel% -bb\\+b \\*!\\*@1\\.0\\.0\\.\\* \\*!\\*@1\\.0\\.0\\.0/16 \\*!\\*@1\\.0\\.\\*
|
||||
|
||||
# Check that a narrower ban cannot be added.
|
||||
# Somewhat sadly, the first command gets no response at all.
|
||||
:cl1 mode %channel% +b *!*@1.0.0.1
|
||||
:cl1 mode %channel% +b
|
||||
:cl1 expect %srv1-name% 367 %channel% \\*!\\*@1\\.0\\.\\* %cl1-nick% \\d+
|
||||
|
||||
# Can we remove a broader ban and add a narrow ban at the same time?
|
||||
# This was the core of the bug report (SF#1840011).
|
||||
:cl1 mode %channel% -b+b *!*@1.0.* *!*@1.0.0.1
|
||||
:cl1 expect %cl1-nick% mode %channel% -b\\+b \\*!\\*@1\\.0\\.\\* \\*!\\*@1\\.0\\.0\\.1
|
||||
:cl1 quit done
|
||||
@@ -0,0 +1,15 @@
|
||||
define srv1 localhost:7601
|
||||
define srv1-name irc.example.net
|
||||
define cl1-nick Op3rm4n
|
||||
define channel1 #1234567890123456789012345678901234567890123456789
|
||||
define channel2 #12345678901234567890123456789012345678901234567890
|
||||
|
||||
|
||||
# Connect a client and try to join the two channels.
|
||||
# The second channel's name is one character too long, and should be truncated.
|
||||
connect cl1 %cl1-nick% oper %srv1% :Some Channel Operator
|
||||
:cl1 join %channel1%
|
||||
:cl1 join %channel2%
|
||||
:cl1 expect %srv1-name% 403 %channel2% :No such channel
|
||||
# Force cl1 to do something else so the expect is checked.
|
||||
:cl1 part %channel1%
|
||||
@@ -0,0 +1,45 @@
|
||||
define srv1 localhost:7601
|
||||
define srv1-name irc.example.net
|
||||
define srv2 localhost:7611
|
||||
define srv2-name irc-2.example.net
|
||||
define cl1-nick Op3rm4n
|
||||
define cl2-nick Monitor
|
||||
define channel #keytest
|
||||
|
||||
# Connect a client to each server, and join them to the same channel.
|
||||
connect cl1 %cl1-nick% oper %srv1% :Some Channel Operator
|
||||
connect cl2 %cl2-nick% oper %srv2% :Snoopy
|
||||
:cl1 join %channel%
|
||||
sync cl1,cl2
|
||||
:cl2 join %channel%
|
||||
sync cl1,cl2
|
||||
|
||||
# Set a plain and simple key initially.
|
||||
:cl1 mode %channel% +k foo
|
||||
:cl2 expect %cl1-nick% mode %channel% \\+k foo
|
||||
|
||||
# Slighly funny quoting here: one : for test-driver.pl and one for quoting.
|
||||
# The final : makes the key invalid.
|
||||
:cl1 mode %channel% -k+k foo :::badkey
|
||||
:cl1 expect %srv1-name% 525 %channel% :Key is not well-formed
|
||||
:cl2 expect %cl1-nick% mode %channel% -k foo
|
||||
|
||||
# Non-ASCII characters should be accepted in the key, and colons after the first character.
|
||||
:cl1 mode %channel% +k mötör:head
|
||||
:cl2 expect %cl1-nick% mode %channel% \\+k mötör:head
|
||||
|
||||
# We need to have a key, too.
|
||||
:cl1 mode %channel% -k+k mötör:head
|
||||
:cl1 expect %srv1-name% 461 MODE \\+k :Not enough parameters
|
||||
|
||||
# Are spaces accepted anywhere in the key?
|
||||
:cl1 mode %channel% +k :: spaced key
|
||||
:cl1 expect %srv1-name% 525 %channel% :Key is not well-formed
|
||||
|
||||
# What about commas?
|
||||
:cl1 mode %channel% +k foo,bar
|
||||
:cl1 expect %srv1-name% 525 %channel% :Key is not well-formed
|
||||
|
||||
# Is the key too long?
|
||||
:cl1 mode %channel% +k 123456789012345678901234567890
|
||||
:cl1 expect %srv1-name% 525 %channel% :Key is not well-formed
|
||||
@@ -0,0 +1,330 @@
|
||||
define srv1 localhost:7601
|
||||
define srv1-name irc.example.net
|
||||
define srv2 localhost:7611
|
||||
define srv2-name irc-2.example.net
|
||||
define cl1-nick Op3rm4n
|
||||
define cl2-nick Monitor
|
||||
|
||||
# Connect a client, oper it up and force G-line server notices on (0x8200).
|
||||
connect cl1 %cl1-nick% oper %srv1% :Some IRC Operator
|
||||
:cl1 oper oper oper
|
||||
:cl1 mode %cl1-nick% +s +33280
|
||||
|
||||
# Do the same for the second server, for monitoring snotices.
|
||||
# This is useful while debugging the remote operations in this script.
|
||||
connect cl2 %cl2-nick% oper %srv2% :Some IRC Operator
|
||||
:cl2 oper oper oper
|
||||
:cl2 mode %cl2-nick% +s +33280
|
||||
|
||||
# For an operator, the syntax is:
|
||||
# GLINE [[!][+|-|>|<]<mask> [<target>] [<expiration> [:<reason>]]]
|
||||
# By itself, that's 2 * 5 * 3 (target missing/self, other or global)
|
||||
# * 3 = 90 possibilities.
|
||||
#
|
||||
# In each case, we would want to try it with various combinations:
|
||||
# - Local gline for <mask> absent or present
|
||||
# - Global gline for <mask> absent, or present but locally and/or globally activated or deactivated (5 combinations)
|
||||
# So ten pre-existing states for each syntax variant.
|
||||
# For sanity's sake, we don't do all 900 combinations.
|
||||
#
|
||||
# Perl code to generate a fairly complete list:
|
||||
# foreach my $operator (split(//, ' +-><')) {
|
||||
# foreach my $mask ('test@example.com') {
|
||||
# foreach my $target ('', '%srv1-name%', '%srv2-name%', '*') {
|
||||
# foreach my $expiration ('', '100000') {
|
||||
# foreach my $reason ('', ':foo') {
|
||||
# my $str = "GLINE ${operator}${mask} ${target} ${expiration} ${reason}";
|
||||
# $str =~ s/ +/ /g;
|
||||
# $str =~ s/ +$//;
|
||||
# print "$str\n";
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
# print "\n";
|
||||
# }
|
||||
# }
|
||||
|
||||
# Initial query: verify that our target G-line does not exist.
|
||||
:cl1 raw :GLINE test@example.com
|
||||
:cl1 expect %srv1-name% 512 test@example.com :No such gline
|
||||
|
||||
# Try a bunch of operations, only one of which should generate an actual G-line.
|
||||
:cl1 raw :GLINE test@example.com :foo
|
||||
:cl1 expect %srv1-name% 461 GLINE :Not enough parameters
|
||||
:cl1 raw :GLINE test@example.com 100000
|
||||
:cl1 expect %srv1-name% 461 GLINE :Not enough parameters
|
||||
:cl1 raw :GLINE test@example.com 100000 :foo
|
||||
:cl1 expect %srv1-name% 515 foo :Bad expire time
|
||||
:cl1 raw :GLINE test@example.com %srv1-name%
|
||||
:cl1 expect %srv1-name% 461 GLINE :Not enough parameters
|
||||
:cl1 raw :GLINE test@example.com %srv1-name% :foo
|
||||
:cl1 expect %srv1-name% 515 foo :Bad expire time
|
||||
:cl1 raw :GLINE test@example.com %srv1-name% 100000
|
||||
:cl1 expect %srv1-name% 461 GLINE :Not enough parameters
|
||||
|
||||
# Check that we still have no G-line, and that we create it as expected.
|
||||
:cl1 raw :GLINE test@example.com
|
||||
:cl1 expect %srv1-name% 512 test@example.com :No such gline
|
||||
:cl1 raw :GLINE test@example.com %srv1-name% 100000 :foo
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% adding local GLINE for test@example.com, expiring at \\d+: foo
|
||||
:cl1 raw :GLINE test@example.com
|
||||
:cl1 expect %srv1-name% 280 test@example.com \\d+ 0 \\d+ %srv1-name% \\+ :foo
|
||||
:cl1 expect %srv1-name% 281 :End of G-line List
|
||||
# Now remove it (and verify removal).
|
||||
:cl1 raw :GLINE -test@example.com 100000 :foo
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% removing local GLINE for test@example.com
|
||||
:cl1 raw :GLINE test@example.com
|
||||
:cl1 expect %srv1-name% 512 test@example.com :No such gline
|
||||
|
||||
# Try doing remote operations.
|
||||
:cl1 raw :GLINE test@example.com %srv2-name%
|
||||
:cl1 expect %srv1-name% 461 GLINE :Not enough parameters
|
||||
:cl1 raw :GLINE test@example.com %srv2-name% :foo
|
||||
:cl1 expect %srv1-name% 515 foo :Bad expire time
|
||||
:cl1 raw :GLINE test@example.com %srv2-name% 100000
|
||||
:cl1 expect %srv1-name% 461 GLINE :Not enough parameters
|
||||
:cl1 raw :GLINE test@example.com
|
||||
:cl1 expect %srv1-name% 512 test@example.com :No such gline
|
||||
:cl1 raw :GLINE test@example.com %srv2-name% 100000 :foo
|
||||
# No response expected for remote commands; do a remote stats query to check.
|
||||
:cl1 raw :STATS g %srv2-name%
|
||||
:cl1 expect %srv2-name% 247 G test@example.com \\d+ 0 \\d+ \\+ :foo
|
||||
:cl1 expect %srv2-name% 219 g :End of /STATS report
|
||||
:cl1 raw :GLINE -test@example.com %srv2-name% 100000 :foo
|
||||
:cl1 raw :STATS g %srv2-name%
|
||||
:cl1 expect %srv2-name% 219 g :End of /STATS report
|
||||
|
||||
# Try doing network-wide operations.
|
||||
:cl1 raw :GLINE test@example.com *
|
||||
:cl1 expect %srv1-name% 461 GLINE :Not enough parameters
|
||||
# These should fail because no existing G-line matches.
|
||||
:cl1 raw :GLINE test@example.com * :foo
|
||||
:cl1 expect %srv1-name% 515 foo :Bad expire time
|
||||
:cl1 raw :GLINE test@example.com * 100000
|
||||
:cl1 expect %srv1-name% 512 test@example.com :No such gline
|
||||
:cl1 raw :GLINE test@example.com * 100000 :foo
|
||||
:cl1 expect %srv1-name% 512 test@example.com :No such gline
|
||||
|
||||
# Try explicit create/activate operations.
|
||||
:cl1 raw :GLINE +test@example.com
|
||||
:cl1 expect %srv1-name% 461 GLINE :Not enough parameters
|
||||
:cl1 raw :GLINE +test@example.com :foo
|
||||
:cl1 expect %srv1-name% 461 GLINE :Not enough parameters
|
||||
:cl1 raw :GLINE +test@example.com 100000
|
||||
:cl1 expect %srv1-name% 461 GLINE :Not enough parameters
|
||||
# This next one should create the G-line.
|
||||
:cl1 raw :GLINE test@example.com
|
||||
:cl1 expect %srv1-name% 512 test@example.com :No such gline
|
||||
:cl1 raw :GLINE +test@example.com 100000 :foo
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% adding local GLINE for test@example.com, expiring at \\d+: foo
|
||||
:cl1 raw :GLINE test@example.com
|
||||
:cl1 expect %srv1-name% 280 test@example.com \\d+ 0 \\d+ %srv1-name% \\+ :foo
|
||||
:cl1 expect %srv1-name% 281 :End of G-line List
|
||||
:cl1 raw :GLINE -test@example.com 100000 :foo
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% removing local GLINE for test@example.com
|
||||
|
||||
# Local create/activate operations?
|
||||
:cl1 raw :GLINE +test@example.com %srv1-name%
|
||||
:cl1 expect %srv1-name% 461 GLINE :Not enough parameters
|
||||
:cl1 raw :GLINE +test@example.com %srv1-name% :foo
|
||||
:cl1 expect %srv1-name% 515 .+ :Bad expire time
|
||||
:cl1 raw :GLINE +test@example.com %srv1-name% 100000
|
||||
:cl1 expect %srv1-name% 515 .+ :Bad expire time
|
||||
:cl1 raw :GLINE +test@example.com %srv1-name% 100000 :foo
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% adding local GLINE for test@example.com, expiring at \\d+: foo
|
||||
:cl1 raw :GLINE test@example.com
|
||||
:cl1 expect %srv1-name% 280 test@example.com \\d+ 0 \\d+ %srv1-name% \\+ :foo
|
||||
:cl1 expect %srv1-name% 281 :End of G-line List
|
||||
:cl1 raw :GLINE -test@example.com 100000 :foo
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% removing local GLINE for test@example.com
|
||||
:cl1 raw :GLINE +test@example.com %srv1-name% 100000 :foo
|
||||
:cl1 raw :GLINE -test@example.com 100000 :foo
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% removing local GLINE for test@example.com
|
||||
:cl1 raw :GLINE +test@example.com %srv1-name% 100000 :foo
|
||||
:cl1 raw :GLINE -test@example.com %srv1-name% 100000 :foo
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% removing local GLINE for test@example.com
|
||||
|
||||
# Remote create/activate operations?
|
||||
:cl1 raw :GLINE +test@example.com %srv2-name%
|
||||
:cl1 expect %srv1-name% 461 GLINE :Not enough parameters
|
||||
:cl1 raw :GLINE +test@example.com %srv2-name% :foo
|
||||
:cl1 expect %srv1-name% 515 .+ :Bad expire time
|
||||
:cl1 raw :GLINE +test@example.com %srv2-name% 100000
|
||||
:cl1 expect %srv1-name% 515 .+ :Bad expire time
|
||||
:cl1 raw :GLINE +test@example.com %srv2-name% 100000 :foo
|
||||
# No response expected for remote commands; do a remote stats query to check.
|
||||
:cl1 raw :STATS g %srv2-name%
|
||||
:cl1 expect %srv2-name% 247 G test@example.com \\d+ 0 \\d+ \\+ :foo
|
||||
:cl1 expect %srv2-name% 219 g :End of /STATS report
|
||||
:cl1 raw :GLINE -test@example.com %srv2-name% 100000 :foo
|
||||
:cl1 raw :STATS g %srv2-name%
|
||||
:cl1 expect %srv2-name% 219 g :End of /STATS report
|
||||
|
||||
# Global create/activate operations?
|
||||
:cl1 raw :GLINE +test@example.com *
|
||||
:cl1 expect %srv1-name% 512 test@example.com :No such gline
|
||||
:cl1 raw :GLINE +test@example.com * :foo
|
||||
:cl1 expect %srv1-name% 515 .+ :Bad expire time
|
||||
:cl1 raw :GLINE +test@example.com * 100000
|
||||
:cl1 expect %srv1-name% 515 .+ :Bad expire time
|
||||
|
||||
# Local G-line deactivation?
|
||||
:cl1 raw :GLINE -test@example.com
|
||||
:cl1 expect %srv1-name% 461 GLINE :Not enough parameters
|
||||
:cl1 raw :GLINE -test@example.com :foo
|
||||
:cl1 expect %srv1-name% 461 GLINE :Not enough parameters
|
||||
:cl1 raw :GLINE -test@example.com 100000
|
||||
:cl1 expect %srv1-name% 461 GLINE :Not enough parameters
|
||||
:cl1 raw :GLINE -test@example.com 100000 :foo
|
||||
:cl1 expect %srv1-name% 512 test@example.com :No such gline
|
||||
|
||||
# .. with a specified server?
|
||||
:cl1 raw :GLINE -test@example.com %srv1-name%
|
||||
:cl1 expect %srv1-name% 461 GLINE :Not enough parameters
|
||||
:cl1 raw :GLINE -test@example.com %srv1-name% :foo
|
||||
:cl1 expect %srv1-name% 515 %srv1-name% :Bad expire time
|
||||
:cl1 raw :GLINE -test@example.com %srv1-name% 100000
|
||||
:cl1 expect %srv1-name% 515 %srv1-name% :Bad expire time
|
||||
:cl1 raw :GLINE -test@example.com %srv1-name% 100000 :foo
|
||||
:cl1 expect %srv1-name% 512 test@example.com :No such gline
|
||||
:cl1 raw :GLINE -test@example.com %srv2-name%
|
||||
:cl1 expect %srv1-name% 461 GLINE :Not enough parameters
|
||||
:cl1 raw :GLINE -test@example.com %srv2-name% :foo
|
||||
:cl1 expect %srv1-name% 515 %srv2-name% :Bad expire time
|
||||
:cl1 raw :GLINE -test@example.com %srv2-name% 100000
|
||||
:cl1 expect %srv1-name% 515 %srv2-name% :Bad expire time
|
||||
:cl1 raw :GLINE -test@example.com %srv2-name% 100000 :foo
|
||||
:cl1 expect %srv2-name% 512 test@example.com :No such gline
|
||||
|
||||
# Global deactivations?
|
||||
:cl1 raw :GLINE -test@example.com *
|
||||
:cl1 expect %srv1-name% 512 test@example.com :No such gline
|
||||
:cl1 raw :GLINE -test@example.com * :foo
|
||||
:cl1 expect %srv1-name% 515 \\* :Bad expire time
|
||||
:cl1 raw :GLINE -test@example.com * 100000
|
||||
:cl1 expect %srv1-name% 515 \\* :Bad expire time
|
||||
:cl1 raw :GLINE -test2@example.com * 100000 :foo
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% adding deactivated global GLINE for test2@example.com
|
||||
|
||||
# Now start with the operations that create or need a global G-line.
|
||||
|
||||
# Global activations and deactivations?
|
||||
:cl1 raw :GLINE +test@example.com * 100000 :foo
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% adding global GLINE for test@example.com
|
||||
:cl1 raw :GLINE test@example.com
|
||||
:cl1 expect %srv1-name% 280 test@example.com \\d+ \\d+ \\d+ \\* \\+ :foo
|
||||
:cl1 raw :GLINE test@example.com * 100000
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% modifying global GLINE for test@example.com: changing expiration time to \\d+; and extending record lifetime to \\d+
|
||||
:cl1 raw :GLINE test@example.com * 100000 :food
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% modifying global GLINE for test@example.com: changing expiration time to \\d+; extending record lifetime to \\d+; and changing reason to "food"
|
||||
:cl1 raw :GLINE -test@example.com *
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% modifying global GLINE for test@example.com: globally deactivating G-line
|
||||
:cl1 raw :GLINE -test@example.com * 100000 :foo
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% modifying global GLINE for test@example.com: changing expiration time to \\d+; extending record lifetime to \\d+; and changing reason to "foo"
|
||||
:cl1 raw :GLINE test@example.com
|
||||
:cl1 expect %srv1-name% 280 test@example.com \\d+ \\d+ \\d+ \\* - :foo
|
||||
|
||||
# Failed local activations and deactivations?
|
||||
:cl1 raw :GLINE >test@example.com
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% modifying global GLINE for test@example.com: locally activating G-line
|
||||
:cl1 raw :GLINE <test@example.com
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% modifying global GLINE for test@example.com: locally deactivating G-line
|
||||
:cl1 raw :GLINE >test@example.com :foo
|
||||
:cl1 expect %srv1-name% 402 foo :No such server
|
||||
:cl1 raw :GLINE <test@example.com :foo
|
||||
:cl1 expect %srv1-name% 402 foo :No such server
|
||||
:cl1 raw :GLINE >test@example.com 100000
|
||||
:cl1 expect %srv1-name% 402 100000 :No such server
|
||||
:cl1 raw :GLINE <test@example.com 100000 :foo
|
||||
:cl1 expect %srv1-name% 402 100000 :No such server
|
||||
:cl1 raw :GLINE <test@example.com 100000 :foo
|
||||
:cl1 expect %srv1-name% 402 100000 :No such server
|
||||
:cl1 raw :GLINE >test@2.example.com
|
||||
:cl1 expect %srv1-name% 512 test@2.example.com :No such gline
|
||||
:cl1 raw :GLINE >test@example.com %srv1-name%
|
||||
|
||||
# What about successes for the local server?
|
||||
# (For simplicity, single-server activations and deactivations are not
|
||||
# allowed to change any other parameters.)
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% modifying global GLINE for test@example.com: locally activating G-line
|
||||
:cl1 raw :GLINE <test@example.com %srv1-name%
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% modifying global GLINE for test@example.com: locally deactivating G-line
|
||||
:cl1 raw :GLINE >test@example.com %srv1-name% :foo
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% modifying global GLINE for test@example.com: locally activating G-line
|
||||
:cl1 raw :GLINE <test@example.com %srv1-name% :foo
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% modifying global GLINE for test@example.com: locally deactivating G-line
|
||||
:cl1 raw :GLINE >test@example.com %srv1-name% 100000
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% modifying global GLINE for test@example.com: locally activating G-line
|
||||
:cl1 raw :GLINE <test@example.com %srv1-name% 100000
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% modifying global GLINE for test@example.com: locally deactivating G-line
|
||||
:cl1 raw :GLINE >test@example.com %srv1-name% 100000 :foo
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% modifying global GLINE for test@example.com: locally activating G-line
|
||||
:cl1 raw :GLINE <test@example.com %srv1-name% 100000 :foo
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% modifying global GLINE for test@example.com: locally deactivating G-line
|
||||
:cl1 raw :GLINE >test@example.com %srv1-name% 100000 :foo
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% modifying global GLINE for test@example.com: locally activating G-line
|
||||
:cl1 raw :GLINE <test@example.com %srv1-name% 100000 :foo
|
||||
:cl1 expect %srv1-name% NOTICE :\\*\\*\\* Notice -- %cl1-nick% modifying global GLINE for test@example.com: locally deactivating G-line
|
||||
|
||||
# And successful activations/deactiations for a (single) remote server?
|
||||
# First make sure the global G-line is globally activated.
|
||||
:cl1 raw :GLINE +test@example.com * 100000 :foo
|
||||
# Form: "GLINE <gline@mask server.name"
|
||||
:cl1 raw :STATS g %srv2-name%
|
||||
:cl1 expect %srv2-name% 247 G test@example.com \\d+ \\d+ \\d+ \\+ :foo
|
||||
:cl1 expect %srv2-name% 219 g :End of /STATS report
|
||||
:cl1 raw :GLINE <test@example.com %srv2-name%
|
||||
:cl1 raw :STATS g %srv2-name%
|
||||
:cl1 expect %srv2-name% 247 G test@example.com \\d+ \\d+ \\d+ <\\+ :foo
|
||||
:cl1 expect %srv2-name% 219 g :End of /STATS report
|
||||
:cl1 raw :GLINE >test@example.com %srv2-name%
|
||||
:cl1 raw :STATS g %srv2-name%
|
||||
:cl1 expect %srv2-name% 247 G test@example.com \\d+ \\d+ \\d+ >\\+ :foo
|
||||
:cl1 expect %srv2-name% 219 g :End of /STATS report
|
||||
# Form: "GLINE <gline@mask server.name :foo"
|
||||
:cl1 raw :GLINE <test@example.com %srv2-name% :foo
|
||||
:cl1 raw :STATS g %srv2-name%
|
||||
:cl1 expect %srv2-name% 247 G test@example.com \\d+ \\d+ \\d+ <\\+ :foo
|
||||
:cl1 expect %srv2-name% 219 g :End of /STATS report
|
||||
:cl1 raw :GLINE >test@example.com %srv2-name% :foo
|
||||
:cl1 raw :STATS g %srv2-name%
|
||||
:cl1 expect %srv2-name% 247 G test@example.com \\d+ \\d+ \\d+ >\\+ :foo
|
||||
:cl1 expect %srv2-name% 219 g :End of /STATS report
|
||||
# Form: "GLINE <gline@mask server.name 100000"
|
||||
:cl1 raw :GLINE <test@example.com %srv2-name% 100000
|
||||
:cl1 raw :STATS g %srv2-name%
|
||||
:cl1 expect %srv2-name% 247 G test@example.com \\d+ \\d+ \\d+ <\\+ :foo
|
||||
:cl1 expect %srv2-name% 219 g :End of /STATS report
|
||||
:cl1 raw :GLINE >test@example.com %srv2-name% 100000
|
||||
:cl1 raw :STATS g %srv2-name%
|
||||
:cl1 expect %srv2-name% 247 G test@example.com \\d+ \\d+ \\d+ >\\+ :foo
|
||||
:cl1 expect %srv2-name% 219 g :End of /STATS report
|
||||
# Form: "GLINE <gline@mask server.name 100000 :foo"
|
||||
:cl1 raw :GLINE <test@example.com %srv2-name% 100000 :foo
|
||||
:cl1 raw :STATS g %srv2-name%
|
||||
:cl1 expect %srv2-name% 247 G test@example.com \\d+ \\d+ \\d+ <\\+ :foo
|
||||
:cl1 expect %srv2-name% 219 g :End of /STATS report
|
||||
:cl1 raw :GLINE >test@example.com %srv2-name% 100000 :foo
|
||||
:cl1 raw :STATS g %srv2-name%
|
||||
:cl1 expect %srv2-name% 247 G test@example.com \\d+ \\d+ \\d+ >\\+ :foo
|
||||
:cl1 expect %srv2-name% 219 g :End of /STATS report
|
||||
|
||||
# What about activations/deactivations that might go across the whole network?
|
||||
# (These are not permitted because "global local [de]activation" does not
|
||||
# make sense: just globally [de]activate the G-line.)
|
||||
:cl1 raw :GLINE >test@example.com *
|
||||
:cl1 expect %srv1-name% 402 \\* :No such server
|
||||
:cl1 raw :GLINE <test@example.com *
|
||||
:cl1 expect %srv1-name% 402 \\* :No such server
|
||||
:cl1 raw :GLINE >test@example.com * :foo
|
||||
:cl1 expect %srv1-name% 402 \\* :No such server
|
||||
:cl1 raw :GLINE <test@example.com * :foo
|
||||
:cl1 expect %srv1-name% 402 \\* :No such server
|
||||
:cl1 raw :GLINE >test@example.com * 100000
|
||||
:cl1 expect %srv1-name% 402 \\* :No such server
|
||||
:cl1 raw :GLINE <test@example.com * 100000
|
||||
:cl1 expect %srv1-name% 402 \\* :No such server
|
||||
:cl1 raw :GLINE >test@example.com * 100000 :foo
|
||||
:cl1 expect %srv1-name% 402 \\* :No such server
|
||||
:cl1 raw :GLINE <test@example.com * 100000 :foo
|
||||
:cl1 expect %srv1-name% 402 \\* :No such server
|
||||
@@ -0,0 +1,66 @@
|
||||
#! /usr/bin/perl
|
||||
# iauth-test: test script for IRC authorization (iauth) protocol
|
||||
# Copyright 2006-2007 Michael Poole
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License version 2 as
|
||||
# published by the Free Software Foundation.
|
||||
|
||||
require 5.008; # We assume deferred signal handlers, new in 5.008.
|
||||
use strict;
|
||||
use warnings;
|
||||
use vars qw(%pending);
|
||||
|
||||
use FileHandle; # for autoflush method on file handles
|
||||
|
||||
# This script is an iauth helper script to help check for bugs in
|
||||
# ircu's IAuth handling.
|
||||
|
||||
sub dolog ($) {
|
||||
print LOG "$_[0]\n";
|
||||
}
|
||||
|
||||
sub reply ($;$$) {
|
||||
my ($msg, $client, $extra) = @_;
|
||||
|
||||
if (not defined $msg) {
|
||||
# Accept this for easier handling of client reply messages.
|
||||
return;
|
||||
} elsif (ref $msg eq '') {
|
||||
$msg =~ s/^(.) ?/$1 $client->{id} $client->{ip} $client->{port} / if $client;
|
||||
dolog "< $msg";
|
||||
print "$msg\n";
|
||||
} elsif (ref $msg eq 'ARRAY') {
|
||||
grep { reply($_, $client, $extra); } @$msg;
|
||||
} elsif (ref $msg eq 'CODE') {
|
||||
&$msg($client, $extra);
|
||||
} else {
|
||||
die "Unknown reply message type.";
|
||||
}
|
||||
}
|
||||
|
||||
open LOG, ">> iauth.log";
|
||||
autoflush LOG 1;
|
||||
autoflush STDOUT 1;
|
||||
autoflush STDERR 1;
|
||||
dolog "IAuth starting at " . scalar(localtime(time));
|
||||
reply("O ARU");
|
||||
|
||||
while (<>) {
|
||||
# Chomp newline and log incoming message.
|
||||
s/\r?\n?\r?$//;
|
||||
dolog "> $_";
|
||||
|
||||
# If there's an ID at the start of the line, parse it out.
|
||||
my $client = $pending{my $id = $1} if s/^(\d+) //;
|
||||
|
||||
# Figure out how to handle the command.
|
||||
if (/^C (\S+) (\S+) (.+)$/) {
|
||||
$pending{$id} = { id => $id, ip => $1, port => $2 };
|
||||
} elsif (/^([DT])/ and $client) {
|
||||
delete $pending{$id};
|
||||
} elsif (/^n (.+)$/ and $client) {
|
||||
reply("C $client->{id} :Do not choke on missing parameters.") if $1 eq 'Bug1685648';
|
||||
reply("D", $client);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
General {
|
||||
name = "irc-2.example.net";
|
||||
vhost = "127.0.0.1";
|
||||
description = "Test IRC server";
|
||||
numeric = 2;
|
||||
};
|
||||
|
||||
Admin {
|
||||
Location = "Right Here, Right Now";
|
||||
Location = "Testbench IRC server";
|
||||
Contact = "root@localhost";
|
||||
};
|
||||
|
||||
Class {
|
||||
name = "Server";
|
||||
pingfreq = 90 seconds;
|
||||
connectfreq = 5 minutes;
|
||||
sendq = 9 megabytes;
|
||||
maxlinks = 10;
|
||||
};
|
||||
|
||||
Connect { name = "irc.example.net"; host = "127.0.0.1"; port = 7600; password = "password"; class = "Server"; hub; autoconnect = yes; };
|
||||
|
||||
Class {
|
||||
name = "Local";
|
||||
pingfreq = 1 minutes 30 seconds;
|
||||
sendq = 160000;
|
||||
maxlinks = 100;
|
||||
};
|
||||
|
||||
Client { ip = "127.*"; class = "Local"; };
|
||||
Operator { local = no; class = "Local"; host = "*@127.*"; password = "$PLAIN$oper"; name = "oper"; };
|
||||
Port { server = yes; port = 7610; };
|
||||
Port { port = 7611; };
|
||||
|
||||
Features {
|
||||
"PPATH" = "ircd-2.pid";
|
||||
"CONFIG_OPERCMDS" = "TRUE";
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
General {
|
||||
name = "irc-3.example.net";
|
||||
vhost = "127.0.0.1";
|
||||
description = "Test IRC server";
|
||||
numeric = 3;
|
||||
};
|
||||
|
||||
Admin {
|
||||
Location = "Right Here, Right Now";
|
||||
Location = "Testbench IRC server";
|
||||
Contact = "root@localhost";
|
||||
};
|
||||
|
||||
Class {
|
||||
name = "Server";
|
||||
pingfreq = 90 seconds;
|
||||
connectfreq = 5 minutes;
|
||||
sendq = 9 megabytes;
|
||||
maxlinks = 10;
|
||||
};
|
||||
|
||||
Connect { name = "irc.example.net"; host = "127.0.0.1"; port = 7600; password = "password"; class = "Server"; hub; autoconnect = yes; };
|
||||
|
||||
Class {
|
||||
name = "Local";
|
||||
pingfreq = 1 minutes 30 seconds;
|
||||
sendq = 160000;
|
||||
maxlinks = 100;
|
||||
};
|
||||
|
||||
Client { ip = "127.*"; class = "Local"; };
|
||||
Operator { local = no; class = "Local"; host = "*@127.*"; password = "$PLAIN$oper"; name = "oper"; };
|
||||
Port { server = yes; port = 7620; };
|
||||
Port { port = 7621; };
|
||||
|
||||
Features {
|
||||
"PPATH" = "ircd-3.pid";
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
General {
|
||||
name = "irc.example.net";
|
||||
vhost = "127.0.0.1";
|
||||
description = "Test IRC server";
|
||||
numeric = 1;
|
||||
};
|
||||
|
||||
Admin {
|
||||
Location = "Right Here, Right Now";
|
||||
Location = "Testbench IRC server";
|
||||
Contact = "root@localhost";
|
||||
};
|
||||
|
||||
Class {
|
||||
name = "Server";
|
||||
pingfreq = 90 seconds;
|
||||
connectfreq = 5 minutes;
|
||||
sendq = 9 megabytes;
|
||||
maxlinks = 10;
|
||||
};
|
||||
|
||||
Connect { name = "irc-2.example.net"; host = "127.0.0.1"; port = 7610; password = "password"; class = "Server"; autoconnect = no; };
|
||||
Connect { name = "irc-3.example.net"; host = "127.0.0.1"; port = 7620; password = "password"; class = "Server"; autoconnect = no; };
|
||||
|
||||
Class {
|
||||
name = "Local";
|
||||
pingfreq = 1 minutes 30 seconds;
|
||||
sendq = 160000;
|
||||
maxlinks = 100;
|
||||
};
|
||||
|
||||
Client { ip = "127.*"; class = "Local"; };
|
||||
Operator { local = no; class = "Local"; host = "*@127.*"; password = "$PLAIN$oper"; name = "oper"; };
|
||||
Port { server = yes; port = 7600; };
|
||||
Port { port = 7601; };
|
||||
IAuth { program = "../tests/iauth-test"; };
|
||||
|
||||
Features {
|
||||
"HUB" = "TRUE";
|
||||
"CONFIG_OPERCMDS" = "TRUE";
|
||||
"CHANNELLEN" = "50";
|
||||
"MAXCHANNELSPERUSER" = "20";
|
||||
};
|
||||
@@ -0,0 +1,107 @@
|
||||
ircu Test Framework
|
||||
===================
|
||||
|
||||
This directory contains a simple test driver for ircu, supporting
|
||||
files, and test scripts. test-driver.pl requires the POE and
|
||||
POE::Component::IRC modules for Perl; they are available from CPAN.
|
||||
|
||||
The test scripts assume that an instance of ircu has been started
|
||||
using the ircd.conf file in this directory (e.g. by running
|
||||
"../ircd/ircd -f `pwd`/ircd.conf"), and that IPv4 support is enabled
|
||||
on the system.
|
||||
|
||||
The test-driver.pl script accepts several command-line options:
|
||||
|
||||
-D enables POE::Component::IRC debugging output
|
||||
-V enables test-driver.pl debugging output
|
||||
-Hipaddr sets the IPv4 address to use for connections to the server
|
||||
one or more script names to interpret and execute
|
||||
|
||||
The normal output is one dot for each line that is executed. Using
|
||||
the -D and -V options generates much more output.
|
||||
|
||||
Command Syntax
|
||||
==============
|
||||
|
||||
A test script typically starts with a set of variable definitions for
|
||||
strings that are used throughout the script or that may be changed to
|
||||
match changes ircu's configuration file. These have the syntax:
|
||||
define <variable> <replacement text>
|
||||
|
||||
A variable is expanded by writing %variablename% in later commands.
|
||||
If a variable is dereferenced without a definition, the test will
|
||||
abort.
|
||||
|
||||
Following the variable definitions is usually one or more "connect"
|
||||
statements. These have the syntax:
|
||||
connect <tag> <nickname> <username> <server:port> :<Real Name or GECOS>
|
||||
This creates a client and starts a connection to an IRC server. The
|
||||
tag is used to issue commands for that client in the rest of the file.
|
||||
The remaining fields have their usual meanings for IRC.
|
||||
|
||||
A number of IRC commands are supported natively, including:
|
||||
:<tag> join <channel>
|
||||
:<tag> mode <nick/channel> [<modes> ...]
|
||||
:<tag> nick <nickname>
|
||||
:<tag> notice <target> :<text>
|
||||
:<tag> oper <name> <password>
|
||||
:<tag> part <channel> [:<message>]
|
||||
:<tag> privmsg <target> :<text>
|
||||
:<tag> quit [:<message>]
|
||||
:<tag> raw :<irc line to send>
|
||||
|
||||
Other commands are used to implement tests:
|
||||
:<tag> expect <irc line contents>
|
||||
:<tag> sleep <seconds>
|
||||
:<tag> wait <tag2,tag3>
|
||||
|
||||
The test commands are discussed at more length below.
|
||||
|
||||
expect Syntax
|
||||
=============
|
||||
|
||||
The command to look for data coming from the irc server is "expect":
|
||||
:<tag> expect <irc line contents>
|
||||
|
||||
The contents are treated as a regular expression and matched against
|
||||
the start of the line. If the line from the IRC server began with
|
||||
':', that is removed before the match is performed.
|
||||
|
||||
Because the contents are a regular expression, and because \ is used
|
||||
as an escape character both in parsing both the script line and the
|
||||
regular expression, some common things become awkward to match:
|
||||
:cl1 mode %channel% +D
|
||||
:cl1 expect %cl1-nick% mode %channel% \\+D
|
||||
or a more drastic example:
|
||||
:cl1 mode %channel% +b *!*@*.bar.example.*
|
||||
:cl1 mode %channel% +b
|
||||
:cl1 expect %srv1-name% 367 %channel% \\*!\\*@\\*\\.bar\\.example\\.* %cl1-nick% \\d+
|
||||
|
||||
sleep Syntax
|
||||
============
|
||||
|
||||
The command to make a client stop operating for a fixed period of time
|
||||
is "sleep":
|
||||
:<tag> sleep <seconds>
|
||||
|
||||
This will deactivate the identified client for at least <seconds>
|
||||
seconds (which may be a floating point number). Other clients will
|
||||
continue to process commands, but if another command for the
|
||||
identified client is encountered, it will block execution until the
|
||||
time expires.
|
||||
|
||||
wait Syntax
|
||||
===========
|
||||
|
||||
The command to synchronize one client to another is "wait":
|
||||
:<tag> wait <tag2[,tag3...]>
|
||||
|
||||
This is syntactic sugar for something like this:
|
||||
:<tag> expect <nick2> NOTICE <nick> :SYNC
|
||||
:<nick2> notice <nick> :SYNC
|
||||
:<tag> expect <nick3> NOTICE <nick> :SYNC
|
||||
:<nick3> notice <nick> :SYNC
|
||||
|
||||
In other words, the wait command uses in-IRC messages to make sure
|
||||
that other clients have already executed commands up to a certain
|
||||
point in the test script.
|
||||
@@ -0,0 +1,516 @@
|
||||
#! /usr/bin/perl -wT
|
||||
|
||||
# If you edit this file, please check carefully that the garbage
|
||||
# collection isn't broken. POE is sometimes too clever for our good
|
||||
# in finding references to sessions, and keeps running even after we
|
||||
# want to stop.
|
||||
|
||||
require 5.006;
|
||||
|
||||
use warnings;
|
||||
use strict;
|
||||
use vars;
|
||||
use constant DELAY => 2;
|
||||
use constant EXPECT_TIMEOUT => 15;
|
||||
use constant RECONNECT_TIMEOUT => 5;
|
||||
use constant THROTTLED_TIMEOUT => 90;
|
||||
|
||||
use FileHandle;
|
||||
# sub POE::Kernel::ASSERT_DEFAULT () { 1 }
|
||||
# sub POE::Kernel::TRACE_DEFAULT () { 1 }
|
||||
use POE v0.35;
|
||||
use POE::Component::IRC v5.00;
|
||||
|
||||
# this defines commands that take "zero time" to execute
|
||||
# (specifically, those which do not send commands from the issuing
|
||||
# client to the server)
|
||||
our $zero_time = {
|
||||
expect => 1,
|
||||
sleep => 1,
|
||||
wait => 1,
|
||||
};
|
||||
|
||||
# Create the main session and start POE.
|
||||
# All the empty anonymous subs are just to make POE:Session::ASSERT_STATES happy.
|
||||
POE::Session->create(inline_states =>
|
||||
{
|
||||
# POE kernel interaction
|
||||
_start => \&drv_start,
|
||||
_child => sub {},
|
||||
_stop => sub {
|
||||
my $heap = $_[HEAP];
|
||||
print "\nThat's all, folks!";
|
||||
print "(exiting at line $heap->{lineno}: $heap->{line})"
|
||||
if $heap->{line};
|
||||
print "\n";
|
||||
},
|
||||
_default => \&drv_default,
|
||||
# generic utilities or miscellaneous functions
|
||||
heartbeat => \&drv_heartbeat,
|
||||
timeout_expect => \&drv_timeout_expect,
|
||||
reconnect => \&drv_reconnect,
|
||||
enable_client => sub { $_[ARG0]->{ready} = 1; },
|
||||
disable_client => sub { $_[ARG0]->{ready} = 0; },
|
||||
die => sub { $_[KERNEL]->signal($_[SESSION], 'TERM'); },
|
||||
# client-based command issuers
|
||||
cmd_expect => \&cmd_expect,
|
||||
cmd_join => \&cmd_generic,
|
||||
cmd_mode => \&cmd_generic,
|
||||
cmd_nick => \&cmd_generic,
|
||||
cmd_notice => \&cmd_message,
|
||||
cmd_oper => \&cmd_generic,
|
||||
cmd_part => \&cmd_generic,
|
||||
cmd_privmsg => \&cmd_message,
|
||||
cmd_quit => \&cmd_generic,
|
||||
cmd_raw => \&cmd_raw,
|
||||
cmd_sleep => \&cmd_sleep,
|
||||
cmd_wait => \&cmd_wait,
|
||||
# handlers for messages from IRC
|
||||
irc_001 => \&irc_connected, # Welcome to ...
|
||||
irc_snotice => sub {}, # notice from a server (anonymous/our uplink)
|
||||
irc_notice => \&irc_notice, # NOTICE to self or channel
|
||||
irc_msg => \&irc_msg, # PRIVMSG to self
|
||||
irc_public => \&irc_public, # PRIVMSG to channel
|
||||
irc_connected => sub {},
|
||||
irc_ctcp_action => sub {},
|
||||
irc_ctcp_ping => sub {},
|
||||
irc_ctcp_time => sub {},
|
||||
irc_ctcpreply_ping => sub {},
|
||||
irc_ctcpreply_time => sub {},
|
||||
irc_invite => sub {},
|
||||
irc_isupport => sub {},
|
||||
irc_join => sub {},
|
||||
irc_kick => sub {},
|
||||
irc_kill => sub {},
|
||||
irc_mode => \&irc_mode, # MODE change on client or channel
|
||||
irc_nick => sub {},
|
||||
irc_part => sub {},
|
||||
irc_ping => sub {},
|
||||
irc_quit => sub {},
|
||||
irc_registered => sub {},
|
||||
irc_topic => sub {},
|
||||
irc_plugin_add => sub {},
|
||||
irc_error => \&irc_error,
|
||||
irc_disconnected => \&irc_disconnected,
|
||||
irc_socketerr => \&irc_socketerr,
|
||||
},
|
||||
args => [@ARGV]);
|
||||
|
||||
$| = 1;
|
||||
$poe_kernel->run();
|
||||
exit;
|
||||
|
||||
# Core/bookkeeping test driver functions
|
||||
|
||||
sub drv_start {
|
||||
my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];
|
||||
|
||||
# initialize heap
|
||||
$heap->{clients} = {}; # session details, indexed by (short) session name
|
||||
$heap->{sessions} = {}; # session details, indexed by session ref
|
||||
$heap->{servers} = {}; # server addresses, indexed by short names
|
||||
$heap->{macros} = {}; # macros
|
||||
|
||||
# Parse arguments
|
||||
foreach my $arg (@_[ARG0..$#_]) {
|
||||
if ($arg =~ /^-D$/) {
|
||||
$heap->{irc_debug} = 1;
|
||||
} elsif ($arg =~ /^-V$/) {
|
||||
$heap->{verbose} = 1;
|
||||
} elsif ($arg =~ /^-H(.+)$/) {
|
||||
$heap->{local_address} = $1;
|
||||
} else {
|
||||
die "Extra command-line argument $arg\n" if $heap->{script};
|
||||
$heap->{script} = new FileHandle($arg, 'r')
|
||||
or die "Unable to open $arg for reading: $!\n";
|
||||
}
|
||||
}
|
||||
die "No test name specified\n" unless $heap->{script};
|
||||
|
||||
# hook in to POE
|
||||
$kernel->alias_set('control');
|
||||
$kernel->yield('heartbeat');
|
||||
}
|
||||
|
||||
sub drv_heartbeat {
|
||||
my ($kernel, $sender, $heap) = @_[KERNEL, SENDER, HEAP];
|
||||
my $script = $heap->{script};
|
||||
my $used = {};
|
||||
my $delay = DELAY;
|
||||
|
||||
while (1) {
|
||||
my ($line, $lineno);
|
||||
if ($heap->{line}) {
|
||||
$line = delete $heap->{line};
|
||||
} elsif (defined($line = <$script>)) {
|
||||
$heap->{lineno} = $.;
|
||||
print "." unless $heap->{irc_debug};
|
||||
} else {
|
||||
# close all connections
|
||||
foreach my $client (values %{$heap->{clients}}) {
|
||||
$kernel->call($client->{irc}, 'quit', "I fell off the end of my script");
|
||||
$client->{quitting} = 1;
|
||||
}
|
||||
# unalias the control session
|
||||
$kernel->alias_remove('control');
|
||||
# die in a few seconds
|
||||
$kernel->delay_set('die', 5);
|
||||
return;
|
||||
}
|
||||
|
||||
chomp $line;
|
||||
# ignore comments and blank lines
|
||||
next if $line =~ /^\#/ or $line !~ /\S/;
|
||||
|
||||
# expand any macros in the line
|
||||
$line =~ s/(?<=[^\\])%(\S+?)%/$heap->{macros}->{$1}
|
||||
or die "Use of undefined macro $1 at line $heap->{lineno}\n"/eg;
|
||||
# remove any \-escapes
|
||||
$line =~ s/\\(.)/$1/g;
|
||||
# figure out the type of line
|
||||
if ($line =~ /^define (\S+) (.+)$/i) {
|
||||
# define a new macro
|
||||
$heap->{macros}->{$1} = $2;
|
||||
} elsif ($line =~ /^undef (\S+)$/i) {
|
||||
# remove the macro
|
||||
delete $heap->{macros}->{$1};
|
||||
} elsif ($line =~ /^connect (\S+) (\S+) (\S+) (\S+) :(.+)$/i) {
|
||||
# connect a new session (named $1) to server $4
|
||||
my ($name, $nick, $ident, $server, $userinfo, $port) = ($1, $2, $3, $4, $5, 6667);
|
||||
$server = $heap->{servers}->{$server} || $server;
|
||||
if ($server =~ /(.+):(\d+)/) {
|
||||
$server = $1;
|
||||
$port = $2;
|
||||
}
|
||||
die "Client with nick $nick already exists (line $heap->{lineno})" if $heap->{clients}->{$nick};
|
||||
my $alias = "client_$name";
|
||||
my $client = {
|
||||
name => $name,
|
||||
nick => $nick,
|
||||
ready => 0,
|
||||
expect => [],
|
||||
expect_alarms => [],
|
||||
params => { Nick => $nick,
|
||||
Server => $server,
|
||||
Port => $port,
|
||||
Username => $ident,
|
||||
Ircname => $userinfo,
|
||||
Debug => $heap->{irc_debug},
|
||||
}
|
||||
};
|
||||
$client->{params}->{LocalAddr} = $heap->{local_address}
|
||||
if $heap->{local_address};
|
||||
my $irc = POE::Component::IRC->spawn
|
||||
(
|
||||
alias => $alias,
|
||||
nick => $nick,
|
||||
) or die "Unable to create new user $nick (line $heap->{lineno}): $!";
|
||||
$client->{irc} = $irc->session_id();
|
||||
$heap->{clients}->{$client->{name}} = $client;
|
||||
$heap->{sessions}->{$irc} = $client;
|
||||
$kernel->call($client->{irc}, 'register', 'all');
|
||||
$kernel->call($client->{irc}, 'connect', $client->{params});
|
||||
$used->{$name} = 1;
|
||||
} elsif ($line =~ /^sync (.+)$/i) {
|
||||
# do multi-way synchronization between every session named in $1
|
||||
my @synced = split(/,|\s/, $1);
|
||||
# first, check that they exist and are ready
|
||||
foreach my $clnt (@synced) {
|
||||
die "Unknown session name $clnt (line $heap->{lineno})" unless $heap->{clients}->{$clnt};
|
||||
goto REDO unless $heap->{clients}->{$clnt}->{ready};
|
||||
}
|
||||
# next we actually send the synchronization signals
|
||||
foreach my $clnt (@synced) {
|
||||
my $client = $heap->{clients}->{$clnt};
|
||||
$client->{sync_wait} = [map { $_ eq $clnt ? () : $heap->{clients}->{$_}->{nick} } @synced];
|
||||
$kernel->call($client->{irc}, 'notice', $client->{sync_wait}, 'SYNC');
|
||||
$kernel->call($sender, 'disable_client', $client);
|
||||
}
|
||||
} elsif ($line =~ /^:(\S+) (\S+)(.*)$/i) {
|
||||
# generic command handler
|
||||
my ($names, $cmd, $args) = ($1, lc($2), $3);
|
||||
my (@avail, @unavail);
|
||||
# figure out whether each listed client is available or not
|
||||
foreach my $c (split ',', $names) {
|
||||
my $client = $heap->{clients}->{$c};
|
||||
if (not $client) {
|
||||
print "ERROR: Unknown session name $c (line $heap->{lineno}; ignoring)\n";
|
||||
} elsif (($used->{$c} and not $zero_time->{$cmd}) or ($cmd ne 'expect' and not $client->{ready})) {
|
||||
push @unavail, $c;
|
||||
} else {
|
||||
push @avail, $c;
|
||||
}
|
||||
}
|
||||
# redo command with unavailable clients
|
||||
if (@unavail) {
|
||||
# This will break if the command can cause a redo for
|
||||
# available clients.. this should be fixed sometime
|
||||
$line = ':'.join(',', @unavail).' '.$cmd.$args;
|
||||
$heap->{redo} = 1;
|
||||
}
|
||||
# do command with available clients
|
||||
if (@avail) {
|
||||
# split up the argument part of the line
|
||||
$args =~ /^((?:(?: [^:])|[^ ])+)?(?: :(.+))?$/;
|
||||
$args = [($1 ? split(' ', $1) : ()), ($2 ? $2 : ())];
|
||||
# find the client and figure out if we need to wait
|
||||
foreach my $c (@avail) {
|
||||
my $client = $heap->{clients}->{$c};
|
||||
die "Client $c used twice as source (line $heap->{lineno})" if $used->{c} and not $zero_time->{$cmd};
|
||||
$kernel->call($sender, 'cmd_' . $cmd, $client, $args);
|
||||
$used->{$c} = 1 unless $zero_time->{$cmd};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
die "Unrecognized input line $heap->{lineno}: $line";
|
||||
}
|
||||
if ($heap->{redo}) {
|
||||
REDO:
|
||||
delete $heap->{redo};
|
||||
$heap->{line} = $line;
|
||||
last;
|
||||
}
|
||||
}
|
||||
# issue new heartbeat with appropriate delay
|
||||
$kernel->delay_set('heartbeat', $delay);
|
||||
}
|
||||
|
||||
sub drv_timeout_expect {
|
||||
my ($kernel, $session, $client, $heap) = @_[KERNEL, SESSION, ARG0, HEAP];
|
||||
print "\nERROR: Dropping timed-out expectation by $client->{name} (line $heap->{expect_lineno}): ".join(',', @{$client->{expect}->[0]})."\n";
|
||||
$client->{expect_alarms}->[0] = undef;
|
||||
unexpect($kernel, $session, $client);
|
||||
}
|
||||
|
||||
sub drv_reconnect {
|
||||
my ($kernel, $session, $client) = @_[KERNEL, SESSION, ARG0];
|
||||
$kernel->call($client->{irc}, 'connect', $client->{params});
|
||||
}
|
||||
|
||||
sub drv_default {
|
||||
my ($kernel, $heap, $sender, $session, $state, $args) = @_[KERNEL, HEAP, SENDER, SESSION, ARG0, ARG1];
|
||||
if ($state =~ /^irc_(\d\d\d)$/) {
|
||||
my $client = $heap->{sessions}->{$sender->get_heap()};
|
||||
if (@{$client->{expect}}
|
||||
and $args->[0] eq $client->{expect}->[0]->[0]
|
||||
and $client->{expect}->[0]->[1] eq "$1") {
|
||||
my $expect = $client->{expect}->[0];
|
||||
my $mismatch;
|
||||
$args = $args->[2]; # ->[1] is the entire string, ->[2] is split
|
||||
for (my $x=0; ($x+2<=$#$expect) and ($x<=$#$args) and not $mismatch; $x++) {
|
||||
my $expectation = $expect->[$x+2];
|
||||
if ($args->[$x] !~ /$expectation/i) {
|
||||
$mismatch = 1;
|
||||
print "Mismatch in arg $x: $args->[$x] !~ $expectation\n";
|
||||
}
|
||||
}
|
||||
unexpect($kernel, $session, $client) unless $mismatch;
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
print "ERROR: Unexpected event $state to test driver (from ".$sender->ID.")\n";
|
||||
return undef;
|
||||
}
|
||||
|
||||
# client-based command issuers
|
||||
|
||||
sub cmd_message {
|
||||
my ($kernel, $heap, $event, $client, $args) = @_[KERNEL, HEAP, STATE, ARG0, ARG1];
|
||||
die "Missing arguments" unless $#$args >= 1;
|
||||
# translate each target as appropriate (e.g. *sessionname)
|
||||
my @targets = split(/,/, $args->[0]);
|
||||
foreach my $target (@targets) {
|
||||
if ($target =~ /^\*(.+)$/) {
|
||||
my $other = $heap->{clients}->{$1} or die "Unknown session name $1 (line $heap->{lineno})\n";
|
||||
$target = $other->{nick};
|
||||
}
|
||||
}
|
||||
$kernel->call($client->{irc}, substr($event, 4), \@targets, $args->[1]);
|
||||
}
|
||||
|
||||
sub cmd_generic {
|
||||
my ($kernel, $event, $client, $args) = @_[KERNEL, STATE, ARG0, ARG1];
|
||||
$kernel->call($client->{irc}, substr($event, 4), @$args);
|
||||
}
|
||||
|
||||
sub cmd_raw {
|
||||
my ($kernel, $heap, $client, $args) = @_[KERNEL, HEAP, ARG0, ARG1];
|
||||
die "Missing argument" unless $#$args >= 0;
|
||||
$kernel->call($client->{irc}, 'sl', $args->[0]);
|
||||
}
|
||||
|
||||
sub cmd_sleep {
|
||||
my ($kernel, $session, $heap, $client, $args) = @_[KERNEL, SESSION, HEAP, ARG0, ARG1];
|
||||
die "Missing argument" unless $#$args >= 0;
|
||||
$kernel->call($session, 'disable_client', $client);
|
||||
$kernel->delay_set('enable_client', $args->[0], $client);
|
||||
}
|
||||
|
||||
sub cmd_wait {
|
||||
my ($kernel, $session, $heap, $client, $args) = @_[KERNEL, SESSION, HEAP, ARG0, ARG1];
|
||||
die "Missing argument" unless $#$args >= 0;
|
||||
# if argument was comma-delimited, split it up (space-delimited is split by generic parser)
|
||||
$args = [split(/,/, $args->[0])] if $args->[0] =~ /,/;
|
||||
# make sure we only wait if all the other clients are ready
|
||||
foreach my $other (@$args) {
|
||||
if (not $heap->{clients}->{$other}->{ready}) {
|
||||
$heap->{redo} = 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
# disable this client, make the others send SYNC to it
|
||||
$kernel->call($session, 'disable_client', $client);
|
||||
$client->{sync_wait} = [map { $heap->{clients}->{$_}->{nick} } @$args];
|
||||
foreach my $other (@$args) {
|
||||
die "Cannot wait on self" if $other eq $client->{name};
|
||||
$kernel->call($heap->{clients}->{$other}->{irc}, 'notice', $client->{nick}, 'SYNC');
|
||||
}
|
||||
}
|
||||
|
||||
sub cmd_expect {
|
||||
my ($kernel, $session, $heap, $client, $args) = @_[KERNEL, SESSION, HEAP, ARG0, ARG1];
|
||||
die "Missing argument" unless $#$args >= 0;
|
||||
$heap->{expect_lineno} = $heap->{lineno};
|
||||
push @{$client->{expect}}, $args;
|
||||
push @{$client->{expect_alarms}}, $kernel->delay_set('timeout_expect', EXPECT_TIMEOUT, $client);
|
||||
$kernel->call($session, 'disable_client', $client);
|
||||
}
|
||||
|
||||
# handlers for messages from IRC
|
||||
|
||||
sub unexpect {
|
||||
my ($kernel, $session, $client) = @_;
|
||||
shift @{$client->{expect}};
|
||||
my $alarm_id = shift @{$client->{expect_alarms}};
|
||||
$kernel->alarm_remove($alarm_id) if $alarm_id;
|
||||
$kernel->call($session, 'enable_client', $client) unless @{$client->{expect}};
|
||||
}
|
||||
|
||||
sub check_expect {
|
||||
my ($kernel, $session, $heap, $poe_sender, $sender, $text) = @_[KERNEL, SESSION, HEAP, SENDER, ARG0, ARG1];
|
||||
my $client = $heap->{sessions}->{$poe_sender->get_heap()};
|
||||
my $expected = $client->{expect}->[0];
|
||||
|
||||
# check sender
|
||||
return 0 unless $sender =~ /^:?\Q$expected->[0]\E/i;
|
||||
|
||||
# compare text
|
||||
return 0 unless $text =~ /$expected->[2]/i;
|
||||
|
||||
# drop expectation of event
|
||||
unexpect($kernel, $session, $client);
|
||||
}
|
||||
|
||||
sub irc_connected {
|
||||
my ($kernel, $session, $heap, $sender) = @_[KERNEL, SESSION, HEAP, SENDER];
|
||||
my $client = $heap->{sessions}->{$sender->get_heap()};
|
||||
print "Client $client->{name} connected to server $_[ARG0]\n"
|
||||
if $heap->{verbose};
|
||||
$kernel->call($session, 'enable_client', $client);
|
||||
}
|
||||
|
||||
sub handle_irc_disconnect ($$$$$) {
|
||||
my ($kernel, $session, $heap, $sender, $client) = @_;
|
||||
if ($client->{quitting}) {
|
||||
$kernel->call($sender, 'unregister', 'all');
|
||||
delete $heap->{sessions}->{$sender->get_heap()};
|
||||
delete $heap->{clients}->{$client->{name}};
|
||||
} else {
|
||||
if ($client->{disconnect_expected}) {
|
||||
delete $client->{disconnect_expected};
|
||||
} else {
|
||||
print "Got unexpected disconnect for $client->{name} (nick $client->{nick})\n";
|
||||
}
|
||||
$kernel->call($session, 'disable_client', $client);
|
||||
$kernel->delay_set('reconnect', $client->{throttled} ? THROTTLED_TIMEOUT : RECONNECT_TIMEOUT, $client);
|
||||
delete $client->{throttled};
|
||||
}
|
||||
}
|
||||
|
||||
sub irc_disconnected {
|
||||
my ($kernel, $session, $heap, $sender, $server) = @_[KERNEL, SESSION, HEAP, SENDER, ARG0];
|
||||
my $client = $heap->{sessions}->{$sender->get_heap()};
|
||||
print "Client $client->{name} disconnected from server $_[ARG0]\n" if $heap->{verbose};
|
||||
handle_irc_disconnect($kernel, $session, $heap, $sender, $client);
|
||||
}
|
||||
|
||||
sub irc_socketerr {
|
||||
my ($kernel, $session, $heap, $sender, $msg) = @_[KERNEL, SESSION, HEAP, SENDER, ARG0];
|
||||
my $client = $heap->{sessions}->{$sender->get_heap()};
|
||||
print "Client $client->{name} (re-)connect error: $_[ARG0]\n";
|
||||
handle_irc_disconnect($kernel, $session, $heap, $sender, $client);
|
||||
}
|
||||
|
||||
sub irc_notice {
|
||||
my ($kernel, $session, $heap, $sender, $from, $to, $text) = @_[KERNEL, SESSION, HEAP, SENDER, ARG0, ARG1, ARG2];
|
||||
my $client = $heap->{sessions}->{$sender->get_heap()};
|
||||
if ($client->{sync_wait} and $text eq 'SYNC') {
|
||||
$from =~ s/!.+$//;
|
||||
my $x;
|
||||
# find who sent it..
|
||||
for ($x=0; $x<=$#{$client->{sync_wait}}; $x++) {
|
||||
last if $from eq $client->{sync_wait}->[$x];
|
||||
}
|
||||
# exit if we don't expect them
|
||||
if ($x>$#{$client->{sync_wait}}) {
|
||||
print "Got unexpected SYNC from $from to $client->{name} ($client->{nick})\n";
|
||||
return;
|
||||
}
|
||||
# remove from the list of people we're waiting for
|
||||
splice @{$client->{sync_wait}}, $x, 1;
|
||||
# re-enable client if we're done waiting
|
||||
if ($#{$client->{sync_wait}} == -1) {
|
||||
delete $client->{sync_wait};
|
||||
$kernel->call($session, 'enable_client', $client);
|
||||
}
|
||||
} elsif (@{$client->{expect}}
|
||||
and $client->{expect}->[0]->[1] =~ /notice/i) {
|
||||
check_expect(@_[0..ARG0], $text);
|
||||
}
|
||||
}
|
||||
|
||||
sub irc_msg {
|
||||
my ($kernel, $session, $heap, $sender, $from, $to, $text) = @_[KERNEL, SESSION, HEAP, SENDER, ARG0, ARG1, ARG2];
|
||||
my $client = $heap->{sessions}->{$sender->get_heap()};
|
||||
if (@{$client->{expect}}
|
||||
and $client->{expect}->[0]->[1] =~ /msg/i) {
|
||||
check_expect(@_[0..ARG0], $text);
|
||||
}
|
||||
}
|
||||
|
||||
sub irc_public {
|
||||
my ($kernel, $session, $heap, $sender, $from, $to, $text) = @_[KERNEL, SESSION, HEAP, SENDER, ARG0, ARG1, ARG2];
|
||||
my $client = $heap->{sessions}->{$sender->get_heap()};
|
||||
if (@{$client->{expect}}
|
||||
and $client->{expect}->[0]->[1] =~ /public/i
|
||||
and grep($client->{expect}->[0]->[2], @$to)) {
|
||||
splice @{$client->{expect}->[0]}, 2, 1;
|
||||
check_expect(@_[0..ARG0], $text);
|
||||
}
|
||||
}
|
||||
|
||||
sub irc_mode {
|
||||
my ($kernel, $session, $heap, $sender, $from, $to) = @_[KERNEL, SESSION, HEAP, SENDER, ARG0, ARG1];
|
||||
my $client = $heap->{sessions}->{$sender->get_heap()};
|
||||
if (@{$client->{expect}}
|
||||
and $client->{expect}->[0]->[1] =~ /mode/i
|
||||
and grep($client->{expect}->[0]->[2], $to)) {
|
||||
splice @{$client->{expect}->[0]}, 2, 1;
|
||||
splice(@_, ARG1, 1);
|
||||
check_expect(@_);
|
||||
}
|
||||
}
|
||||
|
||||
sub irc_error {
|
||||
my ($kernel, $session, $heap, $sender, $what) = @_[KERNEL, SESSION, HEAP, SENDER, ARG0];
|
||||
my $client = $heap->{sessions}->{$sender->get_heap()};
|
||||
if (@{$client->{expect}}
|
||||
and $client->{expect}->[0]->[1] =~ /error/i) {
|
||||
splice @{$client->{expect}->[0]}, 2, 1;
|
||||
unexpect($kernel, $session, $client);
|
||||
$client->{disconnect_expected} = 1;
|
||||
} else {
|
||||
print "ERROR: From server to $client->{name}: $what\n";
|
||||
}
|
||||
$client->{throttled} = 1 if $what =~ /throttled/i;
|
||||
}
|
||||
Reference in new issue
Block a user