File: plain.t

package info (click to toggle)
libauthen-sasl-cyrus-perl 0.13-server-10
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 348 kB
  • ctags: 43
  • sloc: perl: 241; makefile: 13
file content (97 lines) | stat: -rwxr-xr-x 1,886 bytes parent folder | download | duplicates (4)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97

use strict;
use Authen::SASL;
use Test::Simple tests => 5;

our $me;
require "t/common.pl";

pipe (FROM_CLIENT,TO_PARENT) or die "pipe failed.";
pipe (FROM_PARENT,TO_CLIENT) or die "pipe failed.";

my $pid = fork();
my $mech = "PLAIN";
my $service = "arc";
my $host = "hyade11.ifh.de";

if ($pid) { # parent
sleep(1);
	close FROM_PARENT;
	close TO_PARENT;
	$me = "server";


	my $sasl = Authen::SASL->new (
		mechanism => $mech,
		callback => {
			canonuser => \&canonuser,		
			authorize => \&authorize,
			getsecret => \&getsecret,
			checkpass => \&checkpass,
		}
	) or ok(0);
	ok(1);
	
	my $conn = $sasl->server_new($service) or die "Authen::SASL::Cyrus failed." or
		ok(0);
	ok(1);

	print $conn->listmech("","|",""),"\n";

	sendreply( $conn->server_start( getreply(\*FROM_CLIENT)  ),\*TO_CLIENT );
	ok(1);
	
	while ($conn->need_step) {
		sendreply( $conn->server_step( &getreply(\*FROM_CLIENT) ) ,\*TO_CLIENT );
	}

	if ($conn->code == 0) {
		ok(1);
		print "Server: Test successful Negotiation succeeded.\n";
	} else {
		ok(0);
		warn "Server: Negotiation failed.\n",$conn->error(),"\n";
	}

	close FROM_CLIENT;
	close TO_CLIENT;
	wait();
} elsif ($pid == 0) {
	close FROM_CLIENT;
	close TO_CLIENT;
	$me = "client";

	my $sasl = Authen::SASL->new (
		mechanism => $mech,
		callback => {
			user => \&getusername,
			pass => \&getpassword,
			auth => \&getauthname,
		}
	) or die "Authen::SASL failed.";

	my $conn = $sasl->client_new($service, $host)
		or die "Authen::SASL::Cyrus failed.";

	sendreply($conn->client_start(),*TO_PARENT);

	while ($conn->need_step) {
		sendreply($conn->client_step( &getreply(*FROM_PARENT) ),*TO_PARENT );
	}
					   
	if ($conn->code == 0) {
		print "Client: Negotiation succeeded.\n";
	} else { 
		warn "Client: Negotiation failed.\n",$conn->error,"\n";
	}
	
	close FROM_PARENT;
	close TO_PARENT;
	exit 0;
} else {
	exit 1;
}

ok(1);

exit 0;