File: 60cancel.t

package info (click to toggle)
libnet-ldap-perl 1%3A0.6500%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 1,660 kB
  • ctags: 731
  • sloc: perl: 15,059; sh: 76; makefile: 5
file content (76 lines) | stat: -rw-r--r-- 2,077 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!perl

use Test::More;

use Net::LDAP;
use Net::LDAP::Entry;
use Net::LDAP::Constant qw(LDAP_EXTENSION_CANCEL LDAP_CANCELED);
use Net::LDAP::Extension::Cancel;

BEGIN { require "t/common.pl" }


start_server()
? plan tests => 7
: plan skip_all => 'no server';


$ldap = client();
isa_ok($ldap, Net::LDAP, "client");

$rootdse = $ldap->root_dse;
isa_ok($rootdse, Net::LDAP::RootDSE, "root_dse");


SKIP: {
  skip("RootDSE does not offer cancel extension", 5)
    unless($rootdse->supported_extension(LDAP_EXTENSION_CANCEL)); 

  #$mesg = $ldap->start_tls;
  #ok(!$mesg->code, "start_tls: " . $mesg->code . ": " . $mesg->error);

  $mesg = $ldap->bind($MANAGERDN, password => $PASSWD);
  ok(!$mesg->code, "bind: " . $mesg->code . ": " . $mesg->error);

  ok(ldif_populate($ldap, "data/40-in.ldif"), "data/40-in.ldif");

  # cancel undef => should fail
  $cancel = $ldap->cancel(undef);
  ok($cancel->code, "cancel an undefined operation: " . $cancel->code . ": " . $cancel->error);

  # perform a search
  my $search = $ldap->search(
                       base     => $BASEDN,
                       filter   => '(objectclass=*)'
                     );

  # cancel the finished search => should fail
  $cancel = $ldap->cancel($search);
  ok($cancel->code, "cancel a finished operation: " . $cancel->code . ": " . $cancel->error);

  # switch to async mode
  $ldap->async(1);

  # perform a search (asynchronously)
  $search = $ldap->search(
                       base     => $BASEDN,
                       filter   => '(objectclass=*)',
                       callback => \&process_entry, # Call this sub for each entry
                     );

  # cancel the running search => should work [may fail, as it depends on the server's speed]
  $cancel = $ldap->cancel($search);
  ok(!$cancel->code, "cancel a running operation: " . $cancel->code . ": " . $cancel->error)
    or diag("This test may have failed because the server was too fast");
}


sub process_entry
{
  my $m = shift;
  my $e = shift;

  note($m->mesg_id.':'.$e->dn())  if ($ENV{TEST_VERBOSE} && ref($e));
}