summaryrefslogtreecommitdiff
path: root/orbsvcs/tests/Security/BiDirectional/run_test.pl
blob: d3e18164e16393e2c7a7ecb69dccaa329dc1c4d9 (plain)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
     & eval 'exec perl -S $0 $argv:q'
     if 0;

# $Id$
# -*- perl -*-

use lib "$ENV{ACE_ROOT}/bin";
use PerlACE::TestTarget;
use Getopt::Long;

$status = 0;

$status = 0;
$opt = "";
$conf_client = "";
$conf_server = "";
$iter = 10;

sub options () { 
    my $help = 0;       # handled locally 
    my $man = 0;        # handled locally
    my $ssl = 1;        # handled locally
    my $dotdec = 0;     # handled locally
    my $debug;        # handled locally
    my $shost;        # handled locally
    my $chost;        # handled locally

    # Process options.
    if ( @ARGV > 0 ) { 
        GetOptions ('help|?' => \$help, 
                'manual' => \$man, 
                'iter=i' => \$iter, 
                'ssl' => \$ssl, 
                'dd=s' => \$dotdec, 
                'shost=s' => \$shost, 
                'chost=s' => \$chost, 
                'debug=i' => \$debug) or pod2usage(2); 
    }

    if ($ssl) {
        $conf_client = " -ORBSvcConf client.conf";
        $conf_server = " -ORBSvcConf server.conf";
    }

    if ($debug) {
        $opt = "$opt -ORBDebugLevel $debug";
    }

    if ($dotdec) {
        if ($dotdec =~ /client/) {
            $conf_client = "$conf_client -ORBDottedDecimalAddresses 1";
        }
        if ($dotdec =~ /server/) {
            $conf_server = "$conf_server -ORBDottedDecimalAddresses 1";
        }
    }

    if ($shost) {
        $conf_server = "$conf_server -ORBListenEndpoints iiop:///hostname_in_ior=$shost";
    }

    if ($chost) {
       $conf_client = "$conf_client -ORBListenEndpoints iiop:///hostname_in_ior=$chost";
    }

    if ( $man or $help ) {
        # Load Pod::Usage only if needed.
        require "Pod/Usage.pm"; 
        import Pod::Usage; 
        pod2usage(1) if $help;
        pod2usage(VERBOSE => 2) if $man; 
        return 0;
    } 
    return 1;
}


# Make sure OpenSSL knows where to find the trust store
$ENV{'SSL_CERT_DIR'} = './ssl'; 

options () or die "Error: Nothing executed";

my $server = PerlACE::TestTarget::create_target (1) || die "Create target 1 failed\n";
my $client = PerlACE::TestTarget::create_target (2) || die "Create target 2 failed\n";

my $iorbase = "test.ior";
my $server_iorfile = $server->LocalFile ($iorbase);
my $client_iorfile = $client->LocalFile ($iorbase);
$server->DeleteFile($iorbase);
$client->DeleteFile($iorbase);

print STDERR "Executing: server $conf_server $opt -o $iorbase -i $iter\n";

$SV = $server->CreateProcess ("server", 
                              "$conf_server " .
                              "$opt " .
                              "-o $server_iorfile " .
                              "-i $iter");

$CL = $client->CreateProcess ("client", 
                              "$conf_client " .
                              "$opt " .
                              "-k file://$client_iorfile");
$server_status = $SV->Spawn ();

if ($server_status != 0) {
    print STDERR "ERROR: server returned $server_status\n";
    exit 1;
}

if ($server->WaitForFileTimed ($iorbase,
                               $server->ProcessStartWaitInterval()) == -1) {
    print STDERR "ERROR: cannot find file <$server_iorfile>\n";
    $SV->Kill (); $SV->TimedWait (1);
    exit 1;
}

print STDERR "Executing: server find file\n";

if ($server->GetFile ($iorbase) == -1) {
    print STDERR "ERROR: cannot retrieve file <$server_iorfile>\n";
    $SV->Kill (); $SV->TimedWait (1);
    exit 1;
}
if ($client->PutFile ($iorbase) == -1) {
    print STDERR "ERROR: cannot set file <$client_iorfile>\n";
    $SV->Kill (); $SV->TimedWait (1);
    exit 1;
}

$client_status = $CL->SpawnWaitKill ($client->ProcessStartWaitInterval());

if ($client_status != 0) {
    print STDERR "ERROR: client returned $client_status\n";
    $status = 1;
}

$server_status = $SV->WaitKill ($server->ProcessStopWaitInterval());

if ($server_status != 0) {
    print STDERR "ERROR: server returned $server_status\n";
    $status = 1;
}

$server->DeleteFile($iorbase);
$client->DeleteFile($iorbase);

exit $status;

__END__

=head1 NAME

run_test.pl - A driver to run the test

=head1 SYNOPSIS

B<run_test.pl> [B<-help|?>] [B<-iter iterations>] [B<-chost host>]
               [B<-dd who>] [B<-shost host>] [B<-man>] [B<-ssl>] 
               [B<-debug level>]


=head1 DESCRIPTION

This is a test that exercises the birectional GIOP connection
implementation in TAO over SSLIOP connection. Start the server like this

    $ server -ORBSvcConf server.conf -o <file.ior> -i <no_iterations>
    $ client -ORBSvcConf client.conf -k file://<file.ior> -x 

Or, simply

    $ ./run_test.pl

The server starts up writing the IOR to the file. The client then starts
up, creates its own object and passes the reference to the server. Then
it invokes a method on the server to indicate that it is ready for
callback. The server then callsback the client on the same connection
<no_iterations> times. If the server creates a new connection the server
would crash itself.

Basicaly, the test is a copy of the $TAO_ROOT/tests/BiDirectional with
added support for SSLIOP.

=head1 OPTIONS

[B<-help|?>]
    Print a short help message

[B<-iter iterations>] 
    The number of iterations to make. Default is 10.

[B<-chost hostname>] 
    The hostname_in_ior for the client. Used only if specified.

[B<-shost hostname>] 
    The hostname_in_ior for the server. Used only if specified.

[B<-man>]
    Prints this nice manual page

[B<-dd who>]
    Request the usage of -ORBDottedDecimalAddresses 1" for the client, the
    server or both. Values of who can be "client", "server" or
    "client,server".

[B<-ssl>] 
    Enables the use of SSLIOP instead of IIOP. Default.

[B<-debug level>]
    Enables debugging. Values for level are 1-10. Default is 0.

=cut