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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
|
# 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.
use strict;
use warnings;
use lib qw(lib);
use Data::Dumper;
use QA::Util;
use QA::Tests qw(PRIVATE_BUG_USER STANDARD_BUG_TESTS);
use Storable qw(dclone);
use Test::More tests => 927;
use constant NONEXISTANT_BUG => 12_000_000;
###############
# Subroutines #
###############
# We have to generate different values for each RPC client, so we
# have a function to generate the tests for each client.
sub get_tests {
my ($config, $rpc) = @_;
# update doesn't support logged-out users.
my @tests = grep { $_->{user} } @{ STANDARD_BUG_TESTS() };
my ($public_bug, $second_bug) = $rpc->bz_create_test_bugs();
my ($public_id, $second_id) = ($public_bug->{id}, $second_bug->{id});
my $comment_call = $rpc->bz_call_success(
'Bug.comments', { ids => [$public_id, $second_id] });
$public_bug->{comment} =
$comment_call->result->{bugs}->{$public_id}->{comments}->[0];
$second_bug->{comment} =
$comment_call->result->{bugs}->{$second_id}->{comments}->[0];
push(@tests, (
{ args => { ids => [$public_id] },
error => 'You must log in',
test => 'Logged-out users cannot call update' },
# FIXME: We need a permissions test for canedit, but it's so uncommonly
# used that it's not a high priority.
));
my %valid = valid_values($config, $public_bug, $second_bug);
my $valid_value_tests = valid_values_to_tests(\%valid, $public_bug);
push(@tests, @$valid_value_tests);
my %invalid = invalid_values($public_bug, $second_bug);
my $invalid_value_tests = invalid_values_to_tests(\%invalid, $public_bug);
push(@tests, @$invalid_value_tests);
return \@tests;
}
sub valid_values {
my ($config, $public_bug, $second_bug) = @_;
my $admin = $config->{'admin_user_login'};
my $second_id = $second_bug->{id};
my $comment_id = $public_bug->{comment}->{id};
my $bug_uri = $config->{browser_url} . '/'
. $config->{bugzilla_installation} . '/show_bug.cgi?id=';
my %values = (
alias => [
{ value => random_string(20) },
],
assigned_to => [
{ value => $config->{'unprivileged_user_login'} }
],
blocks => [
{ value => { set => [$second_id] },
added => $second_id,
test => 'set to second bug' },
{ value => { remove => [$second_id] },
added => '', removed => $second_id,
test => 'remove second bug' },
{ value => { add => [$second_id] },
added => $second_id, removed => '',
test => 'add second bug' },
{ value => { set => [] },
added => '', removed => $second_id,
test => 'set to nothing' },
],
cc => [
{ value => { add => [$admin] },
added => $admin, removed => '',
test => 'add admin' },
{ value => { remove => [$admin] },
added => '', removed => $admin,
test => 'remove admin' },
{ value => { remove => [$admin] },
test => "removing user who isn't on the list works",
no_changes => 1 },
],
is_cc_accessible => [
{ value => 0, test => 'set to 0' },
{ value => 1, test => 'set to 1' },
],
comment => [
{ value => { body => random_string(100) }, test => 'public' },
{ value => { body => random_string(100), is_private => 1 },
user => PRIVATE_BUG_USER, test => 'private' },
],
comment_is_private => [
{ value => { $comment_id => 1 },
user => PRIVATE_BUG_USER, test => 'make description private' },
{ value => { $comment_id => 0 },
user => PRIVATE_BUG_USER, test => 'make description public' },
],
component => [
{ value => 'c2' }
],
deadline => [
{ value => '2037-01-01' },
{ value => '', removed => '2037-01-01', test => 'remove' },
],
dupe_of => [
{ value => $second_id },
],
estimated_time => [
{ value => '10.0' },
{ value => '0.0', removed => '10.0', test => 'set to zero' },
],
groups => [
{ value => { add => ['Master'] },
user => 'admin', added => 'Master', test => 'add Master' },
{ value => { remove => ['Master'] },
user => 'admin', added => '', removed => 'Master',
test => 'remove Master' },
],
keywords => [
{ value => { add => ['test-keyword-1'] },
test => 'add one', added => 'test-keyword-1' },
{ value => { set => ['test-keyword-1', 'test-keyword-2'] },
test => 'set two', added => 'test-keyword-2' },
{ value => { remove => ['test-keyword-1'] },
removed => 'test-keyword-1', added => '',
test => 'remove one' },
{ value => { set => [] },
removed => 'test-keyword-2', added => '',
test => 'set to empty' },
{ value => { remove => ['test-keyword-2'] },
test => 'removing removed keyword does nothing',
no_changes => 1 },
],
op_sys => [
{ value => 'All' },
],
platform => [
{ value => 'All' },
],
priority => [
{ value => 'Normal' },
],
product => [
{ value => 'C2 Forever',
extra => {
component => 'Helium', version => 'unspecified',
target_milestone => '---',
},
test => 'move to C2 Forever'
},
# This also tests that the extra fields transfer over properly
# when they have identical names in both products.
{ value => $public_bug->{product},
extra => { component => $public_bug->{component} },
test => 'move back to original product' },
],
qa_contact => [
{ value => $admin },
{ value => '', test => 'set blank', removed => $admin },
# Reset to the original so that reset_qa_contact can also be tested.
{ value => $public_bug->{qa_contact} },
],
remaining_time => [
{ value => '1000.50' },
{ value => 0 },
],
reset_assigned_to => [
{ value => 1, field => 'assigned_to',
added => $config->{permanent_user} },
],
reset_qa_contact => [
{ value => 1, field => 'qa_contact', added => '' },
],
resolution => [
{ value => 'FIXED', extra => { status => 'RESOLVED' },
test => 'to RESOLVED FIXED' },
{ value => 'INVALID', test => 'just resolution' },
],
see_also => [
{ value => { add => [$bug_uri . $second_id] },
added => $bug_uri . $second_id, removed => '',
test => 'add local bug URI' },
{ value => { remove => [$bug_uri . $second_id] },
removed => $bug_uri . $second_id, added => '',
test => 'remove local bug URI' },
{ value => { remove => ['http://landfill.bugzilla.org/bugzilla-tip/show_bug.cgi?id=1'] },
no_changes => 1,
test => 'removing non-existent URI works' },
{ value => { add => [''] },
no_changes => 1,
test => 'adding an empty string to see_also does nothing' },
{ value => { add => [undef] },
no_changes => 1,
test => 'adding a null to see_also does nothing' },
],
status => [
# At this point, due to previous tests, the status is RESOLVED,
# so changing to CONFIRMED is our only real option if we want to
# test a simple open status.
{ value => 'CONFIRMED' },
],
severity => [
{ value => 'critical' },
],
summary => [
{ value => random_string(100) },
],
target_milestone => [
{ value => 'AnotherMS2' },
],
url => [
{ value => 'http://' . random_string(20) . '/' },
],
version => [
{ value => 'Another2' },
],
whiteboard => [
{ value => random_string(1000) },
],
work_time => [
# FIXME: work_time really needs to start showing up in the changes hash.
{ value => '1.2', no_changes => 1 },
{ value => '-1.2', test => 'negative value', no_changes => 1 },
],
);
$values{depends_on} = $values{blocks};
$values{is_creator_accessible} = $values{is_cc_accessible};
return %values;
};
sub valid_values_to_tests {
my ($valid_values, $public_bug) = @_;
my @tests;
foreach my $field (sort keys %$valid_values) {
my @tests_valid = @{ $valid_values->{$field} };
foreach my $item (@tests_valid) {
my $desc = $item->{test} || 'valid value';
my %args = (
ids => [$public_bug->{id}],
$field => $item->{value},
%{ $item->{extra} || {} },
);
my %test = ( user => 'editbugs', args => \%args, field => $field,
test => "$field: $desc" );
foreach my $item_field (qw(no_changes added removed field user)) {
next if !exists $item->{$item_field};
$test{$item_field} = $item->{$item_field};
}
push(@tests, \%test);
}
}
return \@tests;
}
sub invalid_values {
my ($public_bug, $second_bug) = @_;
my $public_id = $public_bug->{id};
my $second_id = $second_bug->{id};
my $comment_id = $public_bug->{comment}->{id};
my $second_comment_id = $second_bug->{comment}->{id};
my %values = (
alias => [
{ value => random_string(41),
error => 'aliases cannot be longer than',
test => 'alias cannot be too long' },
{ value => $second_bug->{alias},
error => 'has already taken the alias',
test => 'duplicate alias fails' },
{ value => 123456,
error => 'at least one letter',
test => 'numeric alias fails' },
{ value => random_string(20), ids => [$public_id, $second_id],
error => 'aliases when modifying multiple',
test => 'setting alias on multiple bugs fails' },
],
assigned_to => [
{ value => random_string(20),
error => 'There is no user named',
test => 'changing assigned_to to invalid user fails' },
# FIXME: Also check strict_isolation at some point in the future, perhaps.
],
blocks => [
{ value => { add => [NONEXISTANT_BUG] },
error => 'does not exist',
test => 'Non-existent bug number fails in deps' },
{ value => { add => [$public_id] },
error => 'block itself or depend on itself',
test => "can't add this bug itself in a dep field" },
# FIXME: Could use strict_isolation checks at some point.
# FIXME: Could use a dependency_loop_multi test.
],
cc => [
{ value => { add => [random_string(20)] },
error => 'There is no user named',
test => 'adding invalid user to cc fails' },
{ value => { remove => [random_string(20)] },
error => 'There is no user named',
test => 'removing invalid user from cc fails' },
],
comment => [
{ value => { body => random_string(100_000) },
error => 'cannot be longer',
test => 'comment too long' },
{ value => { body => random_string(100), is_private => 1 },
error => 'comments or attachments as private',
test => 'normal user cannot add private comments' },
],
comment_is_private => [
{ value => { $comment_id => 1 },
error => 'comments or attachments as private',
test => 'normal user cannot make a comment private' },
{ value => { $second_comment_id => 1 },
error => 'You tried to modify the privacy of comment',
user => PRIVATE_BUG_USER,
test => 'cannot change privacy on a comment on another bug' },
],
component => [
{ value => '',
error => 'you must first choose a component',
test => 'empty component fails' },
{ value => random_string(20),
error => 'There is no component named',
test => 'invalid component fails' },
],
deadline => [
{ value => random_string(20),
error => 'is not a legal date',
test => 'Non-date fails in deadline' },
{ value => '2037',
error => 'is not a legal date',
test => 'year alone fails in deadline' },
],
dupe_of => [
{ value => undef,
error => 'dup_id was not defined',
test => 'undefined dupe_of fails' },
{ value => NONEXISTANT_BUG,
error => 'does not exist',
test => 'Cannot dup to a nonexistant bug' },
{ value => $public_id,
error => 'as a duplicate of itself',
test => 'Cannot dup bug to itself' },
],
estimated_time => [
{ value => -1,
error => 'less than the minimum allowable value',
test => 'negative estimated_time fails' },
{ value => 100_000_000,
error => 'more than the maximum allowable value',
test => 'too-large estimated_time fails' },
{ value => random_string(20),
error => 'is not a numeric value',
test => 'non-numeric estimated_time fails' },
# We use PRIVATE_BUG_USER because he can modify the bug, but
# can't change time-tracking fields.
{ value => '100', user => PRIVATE_BUG_USER,
error => 'only a user with the required permissions',
test => 'non-timetracker can not set estimated_time' },
],
groups => [
{ value => { add => ['Master'] },
error => 'either this group does not exist, or you are not allowed to restrict bugs to this group',
test => "adding group we don't have access to but is valid fails" },
{ value => { add => ['QA-Selenium-TEST'] },
error => 'either this group does not exist, or you are not allowed to restrict bugs to this group',
test => 'adding valid group that is not in this product fails' },
{ value => { add => [random_string(20)] },
error => 'either this group does not exist, or you are not allowed to restrict bugs to this group',
test => 'adding non-existent group fails' },
{ value => { remove => [random_string(20)] },
error => 'either this group does not exist, or you are not allowed to remove bugs from this group',
test => 'removing non-existent group fails' },
],
keywords => [
{ value => { add => [random_string(20)] },
error => 'The legal keyword names are listed here',
test => 'adding invalid keyword fails' },
{ value => { remove => [random_string(20)] },
error => 'The legal keyword names are listed here',
test => 'removing invalid keyword fails' },
{ value => { set => [random_string(20)] },
error => 'The legal keyword names are listed here',
test => 'setting invalid keyword fails' },
],
op_sys => [
{ value => random_string(20),
error => 'There is no',
test => 'invalid op_sys fails' },
{ value => '',
error => 'You must select/enter',
test => 'blank op_sys fails' },
],
product => [
{ value => random_string(60),
error => "does not exist or you aren't authorized",
test => 'invalid product fails' },
{ value => '',
error => 'You must select/enter a product',
test => 'moving to blank product fails' },
{ value => 'TestProduct',
error => 'There is no component named',
test => 'moving products without other fields fails' },
{ value => 'QA-Selenium-TEST',
extra => { component => 'QA-Selenium-TEST' },
error => "does not exist or you aren't authorized",
test => 'moving to inaccessible product fails' },
{ value => 'QA Entry Only',
error => "does not exist or you aren't authorized",
test => 'moving to product where ENTRY is denied fails' },
],
qa_contact => [
{ value => random_string(20),
error => 'There is no user named',
test => 'changing qa_contact to invalid user fails' },
],
remaining_time => [
{ value => -1,
error => 'less than the minimum allowable value',
test => 'negative remaining_time fails' },
{ value => 100_000_000,
error => 'more than the maximum allowable value',
test => 'too-large remaining_time fails' },
{ value => random_string(20),
error => 'is not a numeric value',
test => 'non-numeric remaining_time fails' },
# We use PRIVATE_BUG_USER because he can modify the bug, but
# can't change time-tracking fields.
{ value => '100', user => PRIVATE_BUG_USER,
error => 'only a user with the required permissions',
test => 'non-timetracker can not set remaining_time' },
],
# We do all the failing resolution tests on the second bug,
# because we want to be sure that we're starting from an open
# status.
resolution => [
{ value => random_string(20), ids => [$second_id],
extra => { status => 'RESOLVED' },
error => 'There is no Resolution named',
test => 'invalid resolution fails' },
{ value => 'FIXED', ids => [$second_id],
error => 'You cannot set a resolution for open bugs',
test => 'setting resolution on open bug fails' },
{ value => 'DUPLICATE', ids => [$second_id],
extra => { status => 'RESOLVED' },
error => 'id to mark this bug as a duplicate',
test => 'setting DUPLICATE without dup_id fails' },
{ value => '', ids => [$second_id],
extra => { status => 'RESOLVED' },
error => 'A valid resolution is required',
test => 'blank resolution fails with closed status' },
],
see_also => [
{ value => { add => [random_string(20)] },
error => 'is not a valid bug number nor an alias',
test => 'random string fails in see_also' },
{ value => { add => ['http://landfill.bugzilla.org/'] },
error => 'See Also URLs should point to one of',
test => 'no show_bug.cgi in see_also URI' },
],
status => [
{ value => random_string(20),
error => 'There is no status named',
test => 'invalid status fails' },
{ value => '',
error => 'You must select/enter a status',
test => 'blank status fails' },
# We use the second bug for this because we can guarantee that
# it is open.
{ value => 'VERIFIED', ids => [$second_id],
extra => { resolution => 'FIXED' },
error => 'You are not allowed to change the bug status from',
test => 'invalid transition fails' },
],
summary => [
{ value => random_string(300),
error => 'The text you entered in the Summary field is too long',
test => 'too-long summary fails' },
{ value => '',
error => 'You must enter a summary for this bug',
test => 'blank summary fails' },
],
work_time => [
{ value => 100_000_000,
error => 'more than the maximum allowable value',
test => 'too-large work_time fails' },
{ value => random_string(20),
error => 'is not a numeric value',
test => 'non-numeric work_time fails' },
# We use PRIVATE_BUG_USER because he can modify the bug, but
# can't change time-tracking fields.
{ value => '10', user => PRIVATE_BUG_USER,
error => 'only a user with the required permissions',
test => 'non-timetracker can not set work_time' },
],
);
$values{depends_on} = $values{blocks};
foreach my $field (qw(platform priority severity target_milestone version))
{
my $tests = dclone($values{op_sys});
foreach my $test (@$tests) {
$test->{test} =~ s/op_sys/$field/g;
}
$values{$field} = $tests;
}
return %values;
}
sub invalid_values_to_tests {
my ($invalid_values, $public_bug) = @_;
my @tests;
foreach my $field (sort keys %$invalid_values) {
my @tests_invalid = @{ $invalid_values->{$field} };
foreach my $item (@tests_invalid) {
my %args = (
ids => $item->{ids} || [$public_bug->{id}],
$field => $item->{value},
%{ $item->{extra} || {} },
);
push(@tests, { user => $item->{user} || 'editbugs',
args => \%args,
error => $item->{error},
test => $item->{test} });
}
}
return \@tests;
}
###############
# Main Script #
###############
my ($config, $xmlrpc, $jsonrpc, $jsonrpc_get) = get_rpc_clients();
$jsonrpc_get->bz_call_fail('Bug.update',
{ ids => ['public_bug'] },
'must use HTTP POST', 'update fails over GET');
sub post_success {
my ($call, $t, $rpc) = @_;
return if $t->{no_changes};
my $field = $t->{field};
return if !$field;
my @bugs = @{ $call->result->{bugs} };
foreach my $bug (@bugs) {
if ($field =~ /^comment/) {
_check_comment($bug, $field, $t, $rpc);
}
else {
_check_changes($bug, $field, $t);
}
}
}
sub _check_changes {
my ($bug, $field, $t) = @_;
my $changes = $bug->{changes}->{$field};
ok(defined $changes, "$field was changed")
or diag Dumper($bug, $t);
my $new_value = $t->{added};
$new_value = $t->{args}->{$field} if !defined $new_value;
_test_value($changes->{added}, $new_value, $field, 'added');
if (defined $t->{removed}) {
_test_value($changes->{removed}, $t->{removed}, $field, 'removed');
}
}
sub _test_value {
my ($got, $expected, $field, $type) = @_;
if ($field eq 'estimated_time' or $field eq 'remaining_time') {
cmp_ok($got, '==', $expected, "$field: $type is correct");
}
else {
is($got, $expected, "$field: $type is correct");
}
}
sub _check_comment {
my ($bug, $field, $t, $rpc) = @_;
my $bug_id = $bug->{id};
my $call = $rpc->bz_call_success('Bug.comments', { ids => [$bug_id] });
my $comments = $call->result->{bugs}->{$bug_id}->{comments};
if ($field eq 'comment_is_private') {
my $first_private = $comments->[0]->{is_private};
my ($expected) = values %{ $t->{args}->{comment_is_private} };
cmp_ok($first_private, '==', $expected,
'description privacy is correct');
}
else {
my $last_comment = $comments->[-1];
my $expected = $t->{args}->{comment}->{body};
is($last_comment->{text}, $expected, 'comment added correctly');
}
}
foreach my $rpc ($jsonrpc, $xmlrpc) {
$rpc->bz_run_tests(tests => get_tests($config, $rpc),
method => 'Bug.update', post_success => \&post_success);
}
|