view mod_lib_ldap/dev/t/TestConnection.pm @ 4293:edde5905744a

mod_s2s_keepalive: Don't send whitespace keepalives before s2sin stream is open Could possibly result in whitespace before the XML and stream header, which isn't allowed by the parser. Don't think s2sout is affected, as the stream is opened early and doesn't have to wait for the other end. Thanks Ge0rG
author Kim Alvefur <zash@zash.se>
date Thu, 10 Dec 2020 11:57:03 +0100
parents 07582b8aaf84
children
line wrap: on
line source

package TestConnection;

use strict;
use warnings;
use parent 'AnyEvent::XMPP::IM::Connection';

use 5.010;

our $HOST         = 'localhost';
our $TIMEOUT      = 5;
our %PASSWORD_FOR = (
    one   => '12345',
    two   => '23451',
    three => '34512',
    four  => '45123',
    five  => '51234',
    six   => '123456',
    seven => '1234567',
);

sub new {
    my ( $class, $username, %options ) = @_;

    my $cond  = AnyEvent->condvar;
    my $timer = AnyEvent->timer(
        after => $TIMEOUT,
        cb    => sub {
            $cond->send('timeout');
        },
    );

    my $self = $class->SUPER::new(
        username => $username,
        domain   => $HOST,
        password => $options{'password'} // $PASSWORD_FOR{$username},
        resource => 'test bot',
    );

    $self->reg_cb(error => sub {
        my ( undef, $error ) = @_;

        $cond->send($error->string);
    });

    bless $self, $class;

    $self->{'condvar'}       = $cond;
    $self->{'timeout_timer'} = $timer;

    $self->connect;

    return $self;
}

sub cond {
    my ( $self ) = @_;

    return $self->{'condvar'};
}

1;