adding duplicate test
[freeside.git] / test / cgi-test
1 #!/usr/bin/perl -Tw
2 #
3 # $Id: cgi-test,v 1.3 2001-08-21 02:32:54 ivan Exp $
4 #
5 # This is the beginning of a test suite for the web interface.
6 # It's also excellent for populating your database with some meaningful test
7 # data.  (a derivative is used by the web demo)
8 # It only works on an empty database (probably need empty counters too, and
9 # no arbirary RADIUS attributes).
10 # Usage: cgi-test http://base.freeside.url/with/path/ username password
11 # (Yes, if you were properly paranoid and are using SSL, you'll need to get
12 #  libwww-perl working with SSL to use this.)
13
14 use strict;
15 #use diagnostics;
16 use subs qw( big_ugly_data_structure );
17 use CGI;
18 use LWP::UserAgent;
19
20 my ( $base_url, $username, $password ) = ( shift, shift, shift );
21 #trust 'em
22 $base_url =~ /^(.*)$/; $base_url = $1;
23 $username =~ /^(.*)$/; $username = $1;
24 $password =~ /^(.*)$/; $password = $1;
25
26 my @data = &big_ugly_data_structure;
27
28 my $ua = new LWP::UserAgent;
29 {
30   local $^W = 0;
31   eval '
32     sub LWP::UserAgent::get_basic_credentials {
33       #my $self = shift;
34       ( $username, $password );
35     }
36   ';
37 }
38
39 my $data;
40 while ( $data = shift @data ) {
41   my $cgi = new CGI ( $data->{'params'} );
42   my $full_url = $base_url. $data->{'url'}. '?'. $cgi->query_string;
43   #my $request = new HTTP::Request( 'POST', $full_url );
44   my $request = new HTTP::Request( 'GET', $full_url );
45   my $response = $ua->request( $request );
46   if ( $response->is_redirect ) {
47     die "Unexpected redirect!\n".
48            "URL: $full_url\n".
49            "To: ". $response->base. "\n"
50     ;
51   } elsif ( $response->is_success ) {
52     my $location = $response->base;
53     my $expected_location = $data->{'location'};
54     #if ( $location =~ /^$base_url$expected_location$/ ) {
55     if ( $location eq $base_url. $expected_location ) {
56       #warn "cool, got expected response $location from $full_url\n";
57     } else {
58       die "Strange, regular response, but unexpected base!\n".
59         "URL: $full_url\n".
60         "Base    : ". $response->base. "\n".
61         "Expected: $base_url$expected_location\n".
62         "Output: ". $response->content. "\n"
63       ;
64     }
65   } elsif ( $response->is_error ) {
66     die "Strange, I got an error\n".
67         "URL: $full_url\n".
68         "Error: ". $response->error_as_HTML. "\n".
69         "Output: ". $response->content. "\n"
70     ;
71   } elsif ( $response->is_info ) {
72     die "Strange, I got an info reponse\n".
73         "URL: $full_url\n".
74         "Output: ". $response->content. "\n"
75     ;
76   } else {
77     die "Really strange, got an unrecognized response from LWP::UserAgent!\n";
78   }
79 }
80
81 #---
82
83 sub big_ugly_data_structure {
84
85   (
86     { 'url'      => 'edit/process/part_svc.cgi',
87       'params'   => {
88                       'svcpart' => '',
89                       'svc'     => 'Shell',
90                       'svcdb'   => 'svc_acct',
91                       'svc_acct__popnum_flag' => '',
92                       'svc_acct__popnum' => '',
93                       'svc_acct__dir_flag' => '',
94                       'svc_acct__dir' => '',
95                       'svc_acct__username_flag' => '',
96                       'svc_acct__username' => '',
97                       'svc_acct__uid_flag' => '',
98                       'svc_acct__uid' => '',
99                       'svc_acct__quota_flag' => 'F',
100                       'svc_acct__quota' => '10',
101                       'svc_acct__slipip_flag' => 'F',
102                       'svc_acct__slipip' => '',
103                       'svc_acct___password_flag' => '',
104                       'svc_acct___password' => '',
105                       'svc_acct__gid_flag' => '',
106                       'svc_acct__gid' => '',
107                       'svc_acct__shell_flag' => 'D',
108                       'svc_acct__shell' => '/bin/sh',
109                       'svc_acct__finger_flag' => '',
110                       'svc_acct__finger' => '',
111                       'svc_domain__domain_flag' => '',
112                       'svc_domain__domain' => '',
113                       'svc_acct_sm__domuser_flag' => '',
114                       'svc_acct_sm__domuser' => '',
115                       'svc_acct_sm__domuid_flag' => '',
116                       'svc_acct_sm__domuid' => '',
117                       'svc_acct_sm__domsvc_flag' => '',
118                       'svc_acct_sm__domsvc' => '',
119                     },
120       'location' => 'browse/part_svc.cgi',
121     },
122     { 'url'      => 'edit/process/part_svc.cgi',
123       'params'   => {
124                       'svcpart' => '',
125                       'svc'     => 'SLIP/PPP',
126                       'svcdb'   => 'svc_acct',
127                       'svc_acct__popnum_flag' => '',
128                       'svc_acct__popnum' => '',
129                       'svc_acct__dir_flag' => '',
130                       'svc_acct__dir' => '',
131                       'svc_acct__username_flag' => '',
132                       'svc_acct__username' => '',
133                       'svc_acct__uid_flag' => '',
134                       'svc_acct__uid' => '',
135                       'svc_acct__quota_flag' => 'F',
136                       'svc_acct__quota' => '10',
137                       'svc_acct__slipip_flag' => 'D',
138                       'svc_acct__slipip' => '0.0.0.0',
139                       'svc_acct___password_flag' => '',
140                       'svc_acct___password' => '',
141                       'svc_acct__gid_flag' => '',
142                       'svc_acct__gid' => '',
143                       'svc_acct__shell_flag' => 'D',
144                       'svc_acct__shell' => '/bin/sh',
145                       'svc_acct__finger_flag' => '',
146                       'svc_acct__finger' => '',
147                       'svc_domain__domain_flag' => '',
148                       'svc_domain__domain' => '',
149                       'svc_acct_sm__domuser_flag' => '',
150                       'svc_acct_sm__domuser' => '',
151                       'svc_acct_sm__domuid_flag' => '',
152                       'svc_acct_sm__domuid' => '',
153                       'svc_acct_sm__domsvc_flag' => '',
154                       'svc_acct_sm__domsvc' => '',
155                     },
156       'location' => 'browse/part_svc.cgi',
157     },
158     { 'url'      => 'edit/process/part_svc.cgi',
159       'params'   => {
160                       'svcpart' => '',
161                       'svc'     => 'POP Mailbox',
162                       'svcdb'   => 'svc_acct',,
163                       'svc_acct__popnum_flag' => 'F',
164                       'svc_acct__popnum' => '',
165                       'svc_acct__dir_flag' => '',
166                       'svc_acct__dir' => '',
167                       'svc_acct__username_flag' => '',
168                       'svc_acct__username' => '',
169                       'svc_acct__uid_flag' => '',
170                       'svc_acct__uid' => '',
171                       'svc_acct__quota_flag' => 'F',
172                       'svc_acct__quota' => '10',
173                       'svc_acct__slipip_flag' => 'F',
174                       'svc_acct__slipip' => '',
175                       'svc_acct___password_flag' => '',
176                       'svc_acct___password' => '',
177                       'svc_acct__gid_flag' => '',
178                       'svc_acct__gid' => '',
179                       'svc_acct__shell_flag' => 'F',
180                       'svc_acct__shell' => '/bin/passwd',
181                       'svc_acct__finger_flag' => '',
182                       'svc_acct__finger' => '',
183                       'svc_domain__domain_flag' => '',
184                       'svc_domain__domain' => '',
185                       'svc_acct_sm__domuser_flag' => '',
186                       'svc_acct_sm__domuser' => '',
187                       'svc_acct_sm__domuid_flag' => '',
188                       'svc_acct_sm__domuid' => '',
189                       'svc_acct_sm__domsvc_flag' => '',
190                       'svc_acct_sm__domsvc' => '',
191                     },
192       'location' => 'browse/part_svc.cgi',
193     },
194     { 'url'      => 'edit/process/part_svc.cgi',
195       'params'   => {
196                       'svcpart' => '',
197                       'svc'     => 'Domain',
198                       'svcdb'   => 'svc_domain',,
199                       'svc_acct__popnum_flag' => '',
200                       'svc_acct__popnum' => '',
201                       'svc_acct__dir_flag' => '',
202                       'svc_acct__dir' => '',
203                       'svc_acct__username_flag' => '',
204                       'svc_acct__username' => '',
205                       'svc_acct__uid_flag' => '',
206                       'svc_acct__uid' => '',
207                       'svc_acct__quota_flag' => '',
208                       'svc_acct__quota' => '',
209                       'svc_acct__slipip_flag' => '',
210                       'svc_acct__slipip' => '',
211                       'svc_acct___password_flag' => '',
212                       'svc_acct___password' => '',
213                       'svc_acct__gid_flag' => '',
214                       'svc_acct__gid' => '',
215                       'svc_acct__shell_flag' => '',
216                       'svc_acct__shell' => '',
217                       'svc_acct__finger_flag' => '',
218                       'svc_acct__finger' => '',
219                       'svc_domain__domain_flag' => '',
220                       'svc_domain__domain' => '',
221                       'svc_acct_sm__domuser_flag' => '',
222                       'svc_acct_sm__domuser' => '',
223                       'svc_acct_sm__domuid_flag' => '',
224                       'svc_acct_sm__domuid' => '',
225                       'svc_acct_sm__domsvc_flag' => '',
226                       'svc_acct_sm__domsvc' => '',
227                     },
228       'location' => 'browse/part_svc.cgi',
229     },
230     { 'url'      => 'edit/process/part_svc.cgi',
231       'params'   => {
232                       'svcpart' => '',
233                       'svc'     => 'Domain email alias',
234                       'svcdb'   => 'svc_acct_sm',,
235                       'svc_acct__popnum_flag' => '',
236                       'svc_acct__popnum' => '',
237                       'svc_acct__dir_flag' => '',
238                       'svc_acct__dir' => '',
239                       'svc_acct__username_flag' => '',
240                       'svc_acct__username' => '',
241                       'svc_acct__uid_flag' => '',
242                       'svc_acct__uid' => '',
243                       'svc_acct__quota_flag' => '',
244                       'svc_acct__quota' => '',
245                       'svc_acct__slipip_flag' => '',
246                       'svc_acct__slipip' => '',
247                       'svc_acct___password_flag' => '',
248                       'svc_acct___password' => '',
249                       'svc_acct__gid_flag' => '',
250                       'svc_acct__gid' => '',
251                       'svc_acct__shell_flag' => '',
252                       'svc_acct__shell' => '',
253                       'svc_acct__finger_flag' => '',
254                       'svc_acct__finger' => '',
255                       'svc_domain__domain_flag' => '',
256                       'svc_domain__domain' => '',
257                       'svc_acct_sm__domuser_flag' => '',
258                       'svc_acct_sm__domuser' => '',
259                       'svc_acct_sm__domuid_flag' => '',
260                       'svc_acct_sm__domuid' => '',
261                       'svc_acct_sm__domsvc_flag' => '',
262                       'svc_acct_sm__domsvc' => '',
263                     },
264       'location' => 'browse/part_svc.cgi',
265     },
266
267     { 'url'      => 'edit/process/part_pkg.cgi',
268       'params'   => {
269                       'pkgpart' => '',
270                       'pkg' => 'Personal SLIP/PPP',
271                       'comment' => '$30/setup, $19.99/month',
272                       'setup' => '30',
273                       'recur' => '19.99',
274                       'freq' => '1',
275                       'pkg_svc1' => '0',
276                       'pkg_svc2' => '1',
277                       'pkg_svc3' => '0',
278                       'pkg_svc4' => '0',
279                       'pkg_svc5' => '0',
280                     },
281       'location' => 'browse/part_pkg.cgi',
282     },
283     { 'url'      => 'edit/process/part_pkg.cgi',
284       'params'   => {
285                       'pkgpart' => '',
286                       'pkg' => 'Personal SLIP/PPP',
287                       'comment' => '$0/setup, $179.88/year',
288                       'setup' => '0',
289                       'recur' => '179.88',
290                       'freq' => '12',
291                       'pkg_svc1' => '0',
292                       'pkg_svc2' => '1',
293                       'pkg_svc3' => '0',
294                       'pkg_svc4' => '0',
295                       'pkg_svc5' => '0',
296                     },
297       'location' => 'browse/part_pkg.cgi',
298     },
299     { 'url'      => 'edit/process/part_pkg.cgi',
300       'params'   => {
301                       'pkgpart' => '',
302                       'pkg' => 'Personal POP mailbox',
303                       'comment' => '$10/setup, $5/month',
304                       'setup' => '10',
305                       'recur' => '5',
306                       'freq' => '1',
307                       'pkg_svc1' => '0',
308                       'pkg_svc2' => '0',
309                       'pkg_svc3' => '1',
310                       'pkg_svc4' => '0',
311                       'pkg_svc5' => '0',
312                     },
313       'location' => 'browse/part_pkg.cgi',
314     },
315     { 'url'      => 'edit/process/part_pkg.cgi',
316       'params'   => {
317                       'pkgpart' => '',
318                       'pkg' => 'Business SLIP/PPP',
319                       'comment' => '$30/setup, $29.99/month',
320                       'setup' => '30',
321                       'recur' => '29.99',
322                       'freq' => '1',
323                       'pkg_svc1' => '0',
324                       'pkg_svc2' => '1',
325                       'pkg_svc3' => '0',
326                       'pkg_svc4' => '1',
327                       'pkg_svc5' => '1',
328                     },
329       'location' => 'browse/part_pkg.cgi',
330     },
331     { 'url'      => 'edit/process/part_pkg.cgi',
332       'params'   => {
333                       'pkgpart' => '',
334                       'pkg' => 'Business SLIP/PPP',
335                       'comment' => '$0/setup, $299.88/year',
336                       'setup' => '0',
337                       'recur' => '299.88',
338                       'freq' => '12',
339                       'pkg_svc1' => '0',
340                       'pkg_svc2' => '1',
341                       'pkg_svc3' => '0',
342                       'pkg_svc4' => '1',
343                       'pkg_svc5' => '1',
344                     },
345       'location' => 'browse/part_pkg.cgi',
346     },
347     { 'url'      => 'edit/process/part_pkg.cgi',
348       'params'   => {
349                       'pkgpart' => '',
350                       'pkg' => 'Business POP mailbox',
351                       'comment' => '$10/setup, $5/month',
352                       'setup' => '10',
353                       'recur' => '5',
354                       'freq' => '1',
355                       'pkg_svc1' => '0',
356                       'pkg_svc2' => '0',
357                       'pkg_svc3' => '1',
358                       'pkg_svc4' => '0',
359                       'pkg_svc5' => '1',
360                     },
361       'location' => 'browse/part_pkg.cgi',
362     },
363     { 'url'      => 'edit/process/part_pkg.cgi',
364       'params'   => {
365                       'pkgpart' => '',
366                       'pkg' => 'UNIX shell',
367                       'comment' => '$20/setup, $9.99/month',
368                       'setup' => '20',
369                       'recur' => '9.99',
370                       'freq' => '1',
371                       'pkg_svc1' => '1',
372                       'pkg_svc2' => '0',
373                       'pkg_svc3' => '0',
374                       'pkg_svc4' => '0',
375                       'pkg_svc5' => '0',
376                     },
377       'location' => 'browse/part_pkg.cgi',
378     },
379     { 'url'      => 'edit/process/part_pkg.cgi',
380       'params'   => {
381                       'pkgpart' => '',
382                       'pkg' => 'Point-to-point T1',
383                       'comment' => '$1000/setup, $1000/month',
384                       'setup' => '1000',
385                       'recur' => '1000',
386                       'freq' => '1',
387                       'pkg_svc1' => '0',
388                       'pkg_svc2' => '0',
389                       'pkg_svc3' => '5',
390                       'pkg_svc4' => '1',
391                       'pkg_svc5' => '5',
392                     },
393       'location' => 'browse/part_pkg.cgi',
394     },
395     { 'url'      => 'edit/process/part_pkg.cgi',
396       'params'   => {
397                       'pkgpart' => '',
398                       'pkg' => 'Cisco 2501 Router',
399                       'comment' => '$2500',
400                       'setup' => '2500',
401                       'recur' => '0',
402                       'freq' => '0',
403                       'pkg_svc1' => '0',
404                       'pkg_svc2' => '0',
405                       'pkg_svc3' => '0',
406                       'pkg_svc4' => '0',
407                       'pkg_svc5' => '0',
408                     },
409       'location' => 'browse/part_pkg.cgi',
410     },
411
412     { 'url'      => 'edit/process/agent_type.cgi',
413       'params'   => {
414                       'typenum' => '',
415                       'atype' => 'Internal Sales',
416                       'pkgpart1' => 'ON',
417                       'pkgpart2' => 'ON',
418                       'pkgpart3' => 'ON',
419                       'pkgpart4' => 'ON',
420                       'pkgpart5' => 'ON',
421                       'pkgpart6' => 'ON',
422                       'pkgpart7' => 'ON',
423                       'pkgpart8' => 'ON',
424                       'pkgpart9' => 'ON',
425                     },
426       'location' => 'browse/agent_type.cgi',
427     },
428
429     { 'url'      => 'edit/process/agent.cgi',
430       'params'   => {
431                       'agentnum' => '',
432                       'agent' => 'Internal Sales',
433                       'typenum' => '1',
434                       'freq' => '',
435                       'prog' => '',
436                     },
437       'location' => 'browse/agent.cgi',
438     },
439
440     { 'url'      => 'edit/process/part_referral.cgi',
441       'params'   => {
442                       'refnum' => '',
443                       'referral' => 'Another customer',
444                     },
445       'location' => 'browse/part_referral.cgi',
446     },
447     { 'url'      => 'edit/process/part_referral.cgi',
448       'params'   => {
449                       'refnum' => '',
450                       'referral' => 'Newspaper ad',
451                     },
452       'location' => 'browse/part_referral.cgi',
453     },
454
455     { 'url'      => 'edit/process/svc_acct_pop.cgi',
456       'params'   => {
457                       'popnum' => '',
458                       'city' => 'Line Lexington',
459                       'state' => 'PA',
460                       'ac' => '215',
461                       'exch' => '996',
462                     },
463       'location' => 'browse/svc_acct_pop.cgi',
464     },
465     { 'url'      => 'edit/process/svc_acct_pop.cgi',
466       'params'   => {
467                       'popnum' => '',
468                       'city' => 'Oakland',
469                       'state' => 'CA',
470                       'ac' => '510',
471                       'exch' => '208',
472                     },
473       'location' => 'browse/svc_acct_pop.cgi',
474     },
475
476     { 'url'      => 'edit/process/cust_main.cgi',
477       'params'   => {
478                       'custnum' => '',
479                       'agentnum' => '1',
480                       'refnum' => '1',
481                       'last' => 'Hogan',
482                       'first' => 'Shawn D.',
483                       'ss' => '',
484                       'company' => 'Digital Point Solutions',
485                       'address1' => '3570 Tony Drive',
486                       'address2' => '',
487                       'city' => 'San Diego',
488                       'state' => 'CA / US',
489                       'zip' => '92122-2307',
490                       'daytime' => '',
491                       'night' => '',
492                       'fax' => '',
493                       'tax' => '',
494                       'invoicing_list_POST' => '',
495                       'invoicing_list' => '',
496                       'payby' => 'BILL',
497                       'CARD_payinfo' => '',
498                       'CARD_month' => '1',
499                       'CARD_year' => '1999',
500                       'CARD_payname' => '',
501                       'BILL_payinfo' => '',
502                       'BILL_month' => '12',
503                       'BILL_year' => '2037',
504                       'BILL_payname' => 'Accounts Payable',
505                       'COMP_payinfo' => '',
506                       'COMP_month' => '1',
507                       'COMP_year' => '1999',
508                       'pkgpart_svcpart' => '1_2',
509                       'username' => 'cyborg',
510                       '_password' => '',
511                       'popnum' => '1',
512                       'otaker' => 'example',
513                     },
514       'location' => 'view/cust_main.cgi?1',
515     },
516     { 'url'      => 'edit/process/cust_main.cgi',
517       'params'   => {
518                       'custnum' => '',
519                       'agentnum' => '1',
520                       'refnum' => '2',
521                       'last' => 'Ford',
522                       'first' => 'Bill',
523                       'ss' => '',
524                       'company' => 'Boardtown Corporation',
525                       'address1' => '116 East Main Street',
526                       'address2' => '',
527                       'city' => 'Starkville',
528                       'state' => 'MS / US',
529                       'zip' => '39759',
530                       'daytime' => '',
531                       'night' => '',
532                       'fax' => '',
533                       'tax' => '',
534                       'invoicing_list_POST' => '',
535                       'invoicing_list' => '',
536                       'payby' => 'BILL',
537                       'CARD_payinfo' => '',
538                       'CARD_month' => '1',
539                       'CARD_year' => '1999',
540                       'CARD_payname' => '',
541                       'BILL_payinfo' => '',
542                       'BILL_month' => '12',
543                       'BILL_year' => '2037',
544                       'BILL_payname' => 'Accounts Payable',
545                       'COMP_payinfo' => '',
546                       'COMP_month' => '1',
547                       'COMP_year' => '1999',
548                       'pkgpart_svcpart' => '3_3',
549                       'username' => 'billf',
550                       '_password' => '',
551                       'popnum' => '',
552                       'otaker' => 'example',
553                     },
554       'location' => 'view/cust_main.cgi?2',
555     },
556
557            
558   );
559 }
560