2010-05-28 22:33:11 +04:00
|
|
|
#############################################
|
|
|
|
# Test for xmlrpc call to Bug.add_comment() #
|
|
|
|
#############################################
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use lib qw(lib);
|
|
|
|
use QA::Util;
|
2010-06-09 19:10:11 +04:00
|
|
|
use Test::More 'no_plan';
|
2010-05-28 22:33:11 +04:00
|
|
|
my ($xmlrpc, $jsonrpc, $config) = get_rpc_clients();
|
|
|
|
|
|
|
|
use constant INVALID_BUG_ID => -1;
|
|
|
|
use constant INVALID_BUG_ALIAS => 'aaaaaaa12345';
|
2010-06-09 19:10:11 +04:00
|
|
|
use constant PRIVATE_BUG => 40933;
|
|
|
|
use constant PUBLIC_BUG => 58878;
|
2010-05-28 22:33:11 +04:00
|
|
|
|
|
|
|
use constant TEST_COMMENT => '--- Test Comment From QA Tests ---';
|
|
|
|
use constant TOO_LONG_COMMENT => 'a' x 100000;
|
|
|
|
|
|
|
|
my @tests = (
|
|
|
|
# Permissions
|
2010-06-09 19:10:11 +04:00
|
|
|
{ args => { id => PUBLIC_BUG, comment => TEST_COMMENT },
|
2010-05-28 22:33:11 +04:00
|
|
|
error => 'You must log in',
|
|
|
|
test => 'Logged-out user cannot comment on a public bug',
|
|
|
|
},
|
2010-06-09 19:10:11 +04:00
|
|
|
{ args => { id => PRIVATE_BUG, comment => TEST_COMMENT },
|
2010-05-28 22:33:11 +04:00
|
|
|
error => "You must log in",
|
|
|
|
test => 'Logged-out user cannot comment on a private bug',
|
|
|
|
},
|
|
|
|
{ user => 'unprivileged',
|
2010-06-09 19:10:11 +04:00
|
|
|
args => { id => PRIVATE_BUG, comment => TEST_COMMENT },
|
2010-05-28 22:33:11 +04:00
|
|
|
error => "not authorized to access",
|
|
|
|
test => "Unprivileged user can't comment on a private bug",
|
|
|
|
},
|
|
|
|
|
|
|
|
# Test ID parameter
|
|
|
|
{ user => 'unprivileged',
|
|
|
|
args => { comment => TEST_COMMENT },
|
|
|
|
error => 'a id argument',
|
|
|
|
test => 'Failing to pass the "id" param fails',
|
|
|
|
},
|
|
|
|
{ user => 'unprivileged',
|
|
|
|
args => { id => INVALID_BUG_ID, comment => TEST_COMMENT },
|
|
|
|
error => "not a valid bug number",
|
|
|
|
test => 'Passing invalid bug id returns error "Invalid Bug ID"',
|
|
|
|
},
|
|
|
|
{ user => 'unprivileged',
|
|
|
|
args => { id => '', comment => TEST_COMMENT },
|
|
|
|
error => "You must enter a valid bug number",
|
|
|
|
test => 'Passing empty bug id param returns error "Invalid Bug ID"',
|
|
|
|
},
|
|
|
|
{ user => 'unprivileged',
|
|
|
|
args => { id => INVALID_BUG_ALIAS, comment => TEST_COMMENT },
|
|
|
|
error => "nor an alias to a bug",
|
|
|
|
test => 'Passing invalid bug alias returns error "Invalid Bug Alias"',
|
|
|
|
},
|
|
|
|
|
|
|
|
# Test Comment parameter
|
|
|
|
{ user => 'unprivileged',
|
2010-06-09 19:10:11 +04:00
|
|
|
args => { id => PUBLIC_BUG },
|
2010-05-28 22:33:11 +04:00
|
|
|
error => 'a comment argument',
|
|
|
|
test => 'Failing to pass the "comment" parameter fails',
|
|
|
|
},
|
|
|
|
{ user => 'unprivileged',
|
2010-06-09 19:10:11 +04:00
|
|
|
args => { id => PUBLIC_BUG, comment => '' },
|
2010-05-28 22:33:11 +04:00
|
|
|
error => "a comment argument",
|
|
|
|
test => 'Passing an empty comment fails',
|
|
|
|
},
|
|
|
|
{ user => 'unprivileged',
|
2010-06-09 19:10:11 +04:00
|
|
|
args => { id => PUBLIC_BUG, comment => ' ' },
|
2010-05-28 22:33:11 +04:00
|
|
|
error => 'a comment argument',
|
|
|
|
test => 'Passing only a space for comment fails',
|
|
|
|
},
|
|
|
|
{ user => 'unprivileged',
|
2010-06-09 19:10:11 +04:00
|
|
|
args => { id => PUBLIC_BUG, comment => " \t\n\n\r\n\r\n\r " },
|
2010-05-28 22:33:11 +04:00
|
|
|
error => 'a comment argument',
|
|
|
|
test => 'Passing only whitespace (including newlines) fails',
|
|
|
|
},
|
|
|
|
{ user => 'unprivileged',
|
2010-06-09 19:10:11 +04:00
|
|
|
args => { id => PUBLIC_BUG, comment => TOO_LONG_COMMENT },
|
2010-05-28 22:33:11 +04:00
|
|
|
error => "cannot be longer than",
|
|
|
|
test => "Passing a comment that's too long fails",
|
|
|
|
},
|
|
|
|
|
|
|
|
# Testing the "private" parameter happens in the tests for Bug.comments
|
|
|
|
|
|
|
|
# Test work_time parameter
|
|
|
|
# XXX Should be testing permissions on the work_time parameter,
|
|
|
|
# but we currently have no way to verify whether or not time was
|
|
|
|
# added to the bug, and there's no error thrown if you lack perms.
|
|
|
|
{ user => 'admin',
|
2010-06-09 19:10:11 +04:00
|
|
|
args => { id => PUBLIC_BUG, comment => TEST_COMMENT,
|
2010-05-28 22:33:11 +04:00
|
|
|
work_time => 'aaa' },
|
|
|
|
error => "is not a numeric value",
|
|
|
|
test => "Passing a non-numeric work_time fails",
|
|
|
|
},
|
|
|
|
{ user => 'admin',
|
2010-06-09 19:10:11 +04:00
|
|
|
args => { id => PUBLIC_BUG, comment => TEST_COMMENT,
|
2010-05-28 22:33:11 +04:00
|
|
|
work_time => '1234567890' },
|
|
|
|
error => 'more than the maximum',
|
|
|
|
test => 'Passing too large of a work_time fails',
|
|
|
|
},
|
|
|
|
{ user => 'admin',
|
2010-06-09 19:10:11 +04:00
|
|
|
args => { id => PUBLIC_BUG, comment => '',
|
2010-05-28 22:33:11 +04:00
|
|
|
work_time => '1.0' },
|
|
|
|
error => 'a comment argument',
|
|
|
|
test => 'Passing a work_time with an empty comment fails',
|
|
|
|
},
|
|
|
|
|
|
|
|
# Success tests
|
|
|
|
{ user => 'unprivileged',
|
2010-06-09 19:10:11 +04:00
|
|
|
args => { id => PUBLIC_BUG, comment => TEST_COMMENT },
|
2010-05-28 22:33:11 +04:00
|
|
|
test => 'Unprivileged user can add a comment to a public bug',
|
|
|
|
},
|
|
|
|
{ user => 'unprivileged',
|
2010-06-09 19:10:11 +04:00
|
|
|
args => { id => PUBLIC_BUG, comment => " \n" . TEST_COMMENT },
|
2010-05-28 22:33:11 +04:00
|
|
|
test => 'Can add a comment to a bug where the first line is whitespace',
|
|
|
|
},
|
2010-06-09 19:10:11 +04:00
|
|
|
{ user => 'admin',
|
|
|
|
args => { id => PRIVATE_BUG, comment => TEST_COMMENT },
|
2010-05-28 22:33:11 +04:00
|
|
|
test => 'Privileged user can add a comment to a private bug',
|
|
|
|
},
|
|
|
|
{ user => 'admin',
|
2010-06-09 19:10:11 +04:00
|
|
|
args => { id => PUBLIC_BUG, comment => TEST_COMMENT,
|
2010-05-28 22:33:11 +04:00
|
|
|
work_time => '1.5' },
|
|
|
|
test => 'Timetracking user can add work_time to a bug',
|
|
|
|
},
|
|
|
|
# XXX Need to verify that the comment added actually has work_time.
|
|
|
|
{ user => 'admin',
|
2010-06-09 19:10:11 +04:00
|
|
|
args => { id => PUBLIC_BUG, comment => TEST_COMMENT,
|
2010-05-28 22:33:11 +04:00
|
|
|
isprivate => 1 },
|
|
|
|
test => 'Insidergroup user can add a private comment',
|
|
|
|
},
|
|
|
|
# XXX Need to verify that the comment added was actually private.
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach my $rpc ($jsonrpc, $xmlrpc) {
|
|
|
|
$rpc->bz_run_tests(tests => \@tests, method => 'Bug.add_comment');
|
|
|
|
}
|