summaryrefslogtreecommitdiffstats
path: root/qa/t/webservice_bug_update_see_also.t
blob: 3bdc3dc25e0bb8f55ab3d0e1a9f8bae769028856 (plain)
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
# 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.update_see_also() #
#################################################

use strict;
use warnings;
use lib qw(lib);
use QA::Util;
use QA::Tests qw(PRIVATE_BUG_USER STANDARD_BUG_TESTS);
use Test::More tests => 117;
my ($config, $xmlrpc, $jsonrpc, $jsonrpc_get) = get_rpc_clients();

my $bug_url = 'http://landfill.bugzilla.org/bugzilla-tip/show_bug.cgi?id=100';

# update_see_also doesn't support logged-out users.
my @tests = grep { $_->{user} } @{ STANDARD_BUG_TESTS() };
foreach my $t (@tests) {
    $t->{args}->{add} = $t->{args}->{remove} = [];
}

push(@tests, (
    { user  => 'unprivileged',
      args  => { ids => ['public_bug'], add => [$bug_url] },
      error => 'only the assignee or reporter of the bug, or a user',
      test  => 'Unprivileged user cannot add a URL to a bug',
    },

    { user  => 'admin',
      args  => { ids => ['public_bug'], add => ['asdfasdfasdf'] },
      error => 'asdf',
      test  => 'Admin cannot add an invalid URL',
    },
    { user => 'admin',
      args => { ids => ['public_bug'], remove => ['asdfasdfasdf'] },
      test => 'Invalid URL silently ignored',
    },

    { user => 'admin',
      args => { ids => ['public_bug'], add => [$bug_url] },
      test => 'Admin can add a URL to a public bug',
    },
    { user  => 'unprivileged',
      args  => { ids => ['public_bug'], remove => [$bug_url] },
      error => 'only the assignee or reporter of the bug, or a user',
      test  => 'Unprivileged user cannot remove a URL from a bug',
    },
    { user => 'admin',
      args => { ids => ['public_bug'], remove => [$bug_url] },
      test => 'Admin can remove a URL from a public bug',
    },

    { user => PRIVATE_BUG_USER,
      args => { ids => ['private_bug'], add => [$bug_url] },
      test => PRIVATE_BUG_USER . ' can add a URL to a private bug',
    },
    { user => PRIVATE_BUG_USER,
      args => { ids => ['private_bug'], remove => [$bug_url] },
      test => PRIVATE_BUG_USER . ' can remove a URL from a private bug',
    },

));

sub post_success {
    my ($call, $t) = @_;
    isa_ok($call->result->{changes}, 'HASH', "Changes");
}

$jsonrpc_get->bz_call_fail('Bug.update_see_also',
    { ids => ['public_bug'], add => [$bug_url] },
    'must use HTTP POST', 'update_see_also fails over GET');

foreach my $rpc ($jsonrpc, $xmlrpc) {
    $rpc->bz_run_tests(tests => \@tests, method => 'Bug.update_see_also',
                       post_success => \&post_success);
}