#!/usr/bin/perl -w use strict; # har har ### ### ### conf ### ### ### my $BASE_ADDRESS = "http://localhost/JHB/"; my $JABBER_SERVER = "localhost"; my $RID = 3197423130; my $USER = "user01"; my $UPW = "topSecret"; my $DEBUG = 1; # create an agent we can use for our requests use LWP::UserAgent; my $ua = new LWP::UserAgent(); ### ### ### subs ### ### ### sub doSend() { my $content = shift; print STDERR "\n\n" if ($DEBUG); # create a request my $req = new HTTP::Request(POST => $BASE_ADDRESS); $req->content_type('text/xml; charset=utf-8'); $req->content($content); print STDERR "<< Request\n", $req->as_string, "<<\n" if ($DEBUG); # send request my $res = $ua->request($req); print STDERR ">> Response\n" if ($DEBUG); if ($res->is_success) { print STDERR $res->as_string if ($DEBUG); } else { print STDERR $res->status_line if ($DEBUG); } print STDERR "\n>>\n" if ($DEBUG); return $res; } ### ### ### main ### ### ### $| = 1; # set streaming output # no body print "Sending some 'foo': "; my $res = &doSend("foo"); if ($res->code == 400) { print "OK.\n"; } else { print "Failed!\n"; print $res->as_string, "\n"; } # no body print "Sending some '': "; $res = &doSend(""); if ($res->code == 400) { print "OK.\n"; } else { print "Failed!\n"; print $res->as_string, "\n"; } # empty body print "Sending empty body: "; $res = &doSend(""); if ($res->code == 400) { print "OK.\n"; } else { print "Failed!\n"; print $res->as_string, "\n"; } # fake a sid print "Sending wrong sid: "; $res = &doSend(""); if ($res->code == 401) { print "OK.\n"; } else { print "Failed!\n"; print $res->as_string, "\n"; } # forget to send 'to' print "Missing 'to' attribute at session creation request: "; $res = &doSend(""); if ($res->is_success && $res->content =~ /content =~/as_string, "\n"; } # sending empty 'to' attribute with initialization element print "Empty 'to' attribute at session creation request: "; $res = &doSend(""); if ($res->is_success && $res->content =~ /content =~/as_string, "\n"; } # forget to send a rid print "Missing 'rid' attribute at session creation request: "; $res = &doSend(""); if ($res->code == 400) { print "OK.\n"; } else { print "Failed!\n"; print $res->as_string, "\n"; } # trying to connect to non-existent domain print "Connecting to non-existent domain: "; $res = &doSend(""); if ($res->is_success && $res->content =~ /content =~/as_string, "\n"; } # trying to connect to non-existent jabber server print "Connecting to non-existent jabber server: "; $res = &doSend(""); if ($res->is_success && $res->content =~ /content =~/as_string, "\n"; } # try to get a real sid print "Create a new session: "; $res = &doSend(""); my ($sid,$authid); if ($res->is_success) { if ($res->content =~ //) { $sid = $1; } if ($res->content =~ //) { $authid = $1; } } if (defined($sid) && $sid ne "") { print "OK"; print " [$authid]" if (defined($authid) && $authid ne ""); print ".\n" } else { print "Failed!\n"; print $res->as_string, "\n"; print "Aborting.\n"; exit(1); } # query auth $RID++; $res = &doSend("$USER"); print $res->content, "\n"; # send auth $RID++; $res = &doSend("$USERtest$UPW"); print $res->content, "\n"; # get roster $RID++; $res = &doSend(""); print $res->content, "\n"; # send presence $RID++; $res = &doSend(""); print $res->content, "\n"; # sending bullshit $RID++; $res = &doSend("sending bullshit"); print $res->content, "\n"; # send presence $RID++; $res = &doSend("xa"); print $res->content, "\n"; # disconnect sleep 3; $RID++; $res = &doSend(""); print $res->content, "\n";