summaryrefslogtreecommitdiffstats
path: root/qa/t/webservice_group_create.t
blob: 8622621a13332b071d36aa3f881e2dd848a91503 (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
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
# 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 Group.create() #
##########################################

use strict;
use warnings;
use lib qw(lib ../../lib ../../local/lib/perl5);
use Test::More tests => 77;
use QA::Util;

use constant DESCRIPTION => 'Group created by Group.create';

sub post_success {
  my $call = shift;
  my $gid  = $call->result->{id};
  ok($gid, "Got a non-zero group ID: $gid");
}

my ($config, $xmlrpc, $jsonrpc, $jsonrpc_get) = get_rpc_clients();

my @tests = (
  {
    args  => {name => random_string(20), description => DESCRIPTION},
    error => 'You must log in',
    test  => 'Logged-out user cannot call Group.create',
  },
  {
    user  => 'unprivileged',
    args  => {name => random_string(20), description => DESCRIPTION},
    error => 'you are not authorized',
    test  => 'Unprivileged user cannot call Group.create',
  },
  {
    user  => 'admin',
    args  => {description => DESCRIPTION},
    error => 'You must enter a name',
    test  => 'Missing name to Group.create',
  },
  {
    user  => 'admin',
    args  => {name => random_string(20)},
    error => 'You must enter a description',
    test  => 'Missing description to Group.create',
  },
  {
    user  => 'admin',
    args  => {name => '', description => DESCRIPTION},
    error => 'You must enter a name',
    test  => 'Name to Group.create cannot be empty',
  },
  {
    user  => 'admin',
    args  => {name => random_string(20), description => ''},
    error => 'You must enter a description',
    test  => 'Description to Group.create cannot be empty',
  },
  {
    user  => 'admin',
    args  => {name => 'canconfirm', description => DESCRIPTION},
    error => 'already exists',
    test  => 'Name to Group.create already exists',
  },
  {
    user  => 'admin',
    args  => {name => 'caNConFIrm', description => DESCRIPTION},
    error => 'already exists',
    test  => 'Name to Group.create already exists but with a different case',
  },
  {
    user => 'admin',
    args =>
      {name => random_string(20), description => DESCRIPTION, user_regexp => '\\'},
    error => 'The regular expression you entered is invalid',
    test  => 'The regular expression passed to Group.create is invalid',
  },
);

$jsonrpc_get->bz_call_fail(
  'Group.create',
  {name => random_string(20), description => 'Created with JSON-RPC via GET'},
  'must use HTTP POST',
  'Group.create fails over GET'
);

foreach my $rpc ($xmlrpc, $jsonrpc) {

  # Tests which work must be called from here,
  # to avoid creating twice the same group.
  my @all_tests = (
    @tests,
    {
      user => 'admin',
      args => {name => random_string(20), description => DESCRIPTION},
      test => 'Passing the name and description only works',
    },
    {
      user => 'admin',
      args => {
        name        => random_string(20),
        description => DESCRIPTION,
        user_regexp => '\@foo.com$',
        is_active   => 1,
        icon_url    => 'https://www.bugzilla.org/favicon.ico'
      },
      test => 'Passing all arguments works',
    },
  );
  $rpc->bz_run_tests(
    tests        => \@all_tests,
    method       => 'Group.create',
    post_success => \&post_success
  );
}