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
|
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.
#############################################
# Test for xmlrpc call to Bug.add_comment() #
#############################################
use strict;
use warnings;
use lib qw(lib ../../lib ../../local/lib/perl5);
use QA::Util;
use Test::More tests => 141;
my ($config, $xmlrpc, $jsonrpc, $jsonrpc_get) = get_rpc_clients();
use constant INVALID_BUG_ID => -1;
use constant INVALID_BUG_ALIAS => 'aaaaaaa12345';
use constant PRIVS_USER => 'QA_Selenium_TEST';
use constant TIMETRACKING_USER => 'admin';
use constant TEST_COMMENT => '--- Test Comment From QA Tests ---';
use constant TOO_LONG_COMMENT => 'a' x 100000;
my @tests = (
# Permissions
{ args => { id => 'public_bug', comment => TEST_COMMENT },
error => 'You must log in',
test => 'Logged-out user cannot comment on a public bug',
},
{ args => { id => 'private_bug', comment => TEST_COMMENT },
error => "You must log in",
test => 'Logged-out user cannot comment on a private bug',
},
{ user => 'unprivileged',
args => { id => 'private_bug', comment => TEST_COMMENT },
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 => "It does not seem like 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',
args => { id => 'public_bug' },
error => 'a comment argument',
test => 'Failing to pass the "comment" parameter fails',
},
{ user => 'unprivileged',
args => { id => 'public_bug', comment => '' },
error => "a comment argument",
test => 'Passing an empty comment fails',
},
{ user => 'unprivileged',
args => { id => 'public_bug', comment => ' ' },
error => 'a comment argument',
test => 'Passing only a space for comment fails',
},
{ user => 'unprivileged',
args => { id => 'public_bug', comment => " \t\n\n\r\n\r\n\r " },
error => 'a comment argument',
test => 'Passing only whitespace (including newlines) fails',
},
{ user => 'unprivileged',
args => { id => 'public_bug', comment => TOO_LONG_COMMENT },
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
# FIXME: 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',
args => { id => 'public_bug', comment => TEST_COMMENT,
work_time => 'aaa' },
error => "is not a numeric value",
test => "Passing a non-numeric work_time fails",
},
{ user => 'admin',
args => { id => 'public_bug', comment => TEST_COMMENT,
work_time => '1234567890' },
error => 'more than the maximum',
test => 'Passing too large of a work_time fails',
},
{ user => 'admin',
args => { id => 'public_bug', comment => '',
work_time => '1.0' },
error => 'a comment argument',
test => 'Passing a work_time with an empty comment fails',
},
# Success tests
{ user => 'unprivileged',
args => { id => 'public_bug', comment => TEST_COMMENT },
test => 'Unprivileged user can add a comment to a public bug',
},
{ user => 'unprivileged',
args => { id => 'public_bug', comment => " \n" . TEST_COMMENT },
test => 'Can add a comment to a bug where the first line is whitespace',
},
{ user => 'QA_Selenium_TEST',
args => { id => 'private_bug', comment => TEST_COMMENT },
test => 'Privileged user can add a comment to a private bug',
check_privacy => 1,
},
{ user => 'QA_Selenium_TEST',
args => { id => 'public_bug', comment => TEST_COMMENT,
is_private => 1 },
test => 'Insidergroup user can add a private comment',
check_privacy => 1,
},
{ user => 'admin',
args => { id => 'public_bug', comment => TEST_COMMENT,
work_time => '1.5' },
test => 'Timetracking user can add work_time to a bug',
},
# FIXME: Need to verify that the comment added actually has work_time.
);
$jsonrpc_get->bz_call_fail('Bug.add_comment',
{ id => 'public_bug', comment => TEST_COMMENT },
'must use HTTP POST', 'add_comment fails over GET');
foreach my $rpc ($jsonrpc, $xmlrpc) {
$rpc->bz_run_tests(tests => \@tests, method => 'Bug.add_comment',
post_success => \&post_success);
}
sub post_success {
my ($call, $t, $rpc) = @_;
return unless $t->{check_privacy};
my $comment_id = $call->result->{id};
my $result = $rpc->bz_call_success('Bug.comments', {comment_ids => [$comment_id]});
if ($t->{args}->{is_private}) {
ok($result->result->{comments}->{$comment_id}->{is_private},
$rpc->TYPE . ": Comment $comment_id is private");
}
else {
ok(!$result->result->{comments}->{$comment_id}->{is_private},
$rpc->TYPE . ": Comment $comment_id is NOT private");
}
}
|