3 use RT::Test tests => 17;
5 my $ticket = RT::Ticket->new(RT->SystemUser);
8 Subject => 'blue lines',
13 my $attacker = RT::User->new(RT->SystemUser);
22 my $template_as_attacker = RT::Template->new($attacker);
24 # can't create templates without ModifyTemplate
25 my ($ok, $msg) = $template_as_attacker->Create(
26 Name => 'Harmless, honest!',
27 Content => "\nhello ;)",
30 ok(!$ok, 'permission to create denied');
33 # permit modifying templates but they must be simple
34 $attacker->PrincipalObj->GrantRight(Right => 'ShowTemplate', Object => $RT::System);
35 $attacker->PrincipalObj->GrantRight(Right => 'ModifyTemplate', Object => $RT::System);
37 ($ok, $msg) = $template_as_attacker->Create(
38 Name => 'Harmless, honest!',
39 Content => "\nhello ;)",
42 ok(!$ok, 'permission to create denied');
45 ($ok, $msg) = $template_as_attacker->Create(
46 Name => 'Harmless, honest!',
47 Content => "\nhello ;)",
50 ok($ok, 'created template now that we have ModifyTemplate');
52 ($ok, $msg) = $template_as_attacker->SetType('Perl');
53 ok(!$ok, 'permission to update type to Perl denied');
55 my $template_as_root = RT::Template->new(RT->SystemUser);
56 $template_as_root->Load('Harmless, honest!');
57 is($template_as_root->Content, "\nhello ;)");
58 is($template_as_root->Type, 'Simple');
60 $template_as_root->Parse(TicketObj => $ticket);
61 is($template_as_root->MIMEObj->stringify_body, "hello ;)");
64 # update the content to include code (even though Simple won't parse it)
66 ($ok, $msg) = $template_as_attacker->SetContent("\nYou are { (my \$message = 'bjarq') =~ tr/a-z/n-za-m/; \$message }!");
67 ok($ok, 'updating Content permitted since the template is Simple');
69 $template_as_root = RT::Template->new(RT->SystemUser);
70 $template_as_root->Load('Harmless, honest!');
72 is($template_as_root->Content, "\nYou are { (my \$message = 'bjarq') =~ tr/a-z/n-za-m/; \$message }!");
73 is($template_as_root->Type, 'Simple');
75 $template_as_root->Parse(TicketObj => $ticket);
76 is($template_as_root->MIMEObj->stringify_body, "You are { (my \$message = 'bjarq') =~ tr/a-z/n-za-m/; \$message }!");
80 ($ok, $msg) = $template_as_attacker->SetType('Perl');
81 ok(!$ok, 'permission to update type to Perl denied');
84 # now root will change the template to genuine code
85 $template_as_root = RT::Template->new(RT->SystemUser);
86 $template_as_root->Load('Harmless, honest!');
87 $template_as_root->SetType('Perl');
88 $template_as_root->SetContent("\n{ scalar reverse \$Ticket->Subject }");
90 $template_as_root->Parse(TicketObj => $ticket);
91 is($template_as_root->MIMEObj->stringify_body, "senil eulb");
94 # see if we can update anything
95 $template_as_attacker = RT::Template->new($attacker);
96 $template_as_attacker->Load('Harmless, honest!');
98 ($ok, $msg) = $template_as_attacker->SetContent("\nYou are { (my \$message = 'bjarq') =~ tr/a-z/n-za-m/; \$message }!");
99 ok(!$ok, 'updating Content forbidden since the template is Perl');
101 # try again just to be absolutely sure it doesn't work
102 $template_as_root = RT::Template->new(RT->SystemUser);
103 $template_as_root->Load('Harmless, honest!');
104 $template_as_root->SetType('Perl');
105 $template_as_root->SetContent("\n{ scalar reverse \$Ticket->Subject }");
107 $template_as_root->Parse(TicketObj => $ticket);
108 is($template_as_root->MIMEObj->stringify_body, "senil eulb");