RT 4.0.22
[freeside.git] / rt / t / security / CVE-2011-4458-verp.t
1 use strict;
2 use warnings;
3
4 use RT::Test tests => undef;
5
6 RT->Config->Set( MailCommand  => 'sendmailpipe' );
7 RT->Config->Set( VERPPrefix   => "verp-" );
8 RT->Config->Set( VERPDomain   => "example.com" );
9
10 # Ensure that the fake sendmail knows where to write to
11 $ENV{RT_MAILLOGFILE} = RT::Test->temp_directory . "/sendmailpipe.log";
12 my $fake = File::Spec->rel2abs( File::Spec->catfile(
13         't', 'security', 'fake-sendmail' ) );
14 RT->Config->Set( SendmailPath => $fake);
15
16 ok(
17     RT::Test->set_rights(
18         { Principal => 'Everyone',  Right => [qw/CreateTicket/] },
19     ),
20     'set rights'
21 );
22
23 my $bad = RT::Test->load_or_create_user(
24     EmailAddress => 'danger-$USER@example.com',
25 );
26 ok( $bad, "Got a user object back" );
27 ok( $bad->id, "Successfully created a user" );
28
29 my $current_user = RT::CurrentUser->new(RT->SystemUser);
30 my ($id, $msg) = $current_user->Load($bad->Id);
31 ok( $id, "Loaded the user successfully" );
32
33 my $ticket = RT::Ticket->new( $current_user );
34 ($id, $msg) = $ticket->Create(
35     Requestor => $bad->Id,
36     Subject   => "Danger, Will Robinson!",
37     Queue     => "General"
38 );
39 ok( $id, "Created a ticket: $msg" );
40
41 open(LOG, "<", $ENV{RT_MAILLOGFILE}) or die "Can't open log file: $!";
42 while (my $line = <LOG>) {
43     next unless $line =~ /^-f/;
44     like($line, qr/\$USER/, "Contains uninterpolated \$USER");
45 }
46 close(LOG);
47
48 done_testing;