]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
- Fixed API tests to work after login/email changes
authorDavid Lawrence <dkl@mozilla.com>
Wed, 31 Aug 2016 04:24:56 +0000 (00:24 -0400)
committerDavid Lawrence <dkl@mozilla.com>
Wed, 31 Aug 2016 04:24:56 +0000 (00:24 -0400)
xt/lib/QA/RPC.pm
xt/lib/QA/Util.pm
xt/webservice/bug_attachments.t
xt/webservice/bug_comments.t
xt/webservice/user_get.t

index e2f1f759777113fce3d09cb5957da8e6baae6fc8..93414e2313d5296981d8560d2149812d4523d6f1 100644 (file)
@@ -236,7 +236,9 @@ sub bz_run_tests {
 }
 
 sub bz_test_bug {
-    my ($self, $fields, $bug, $expect, $t, $creation_time) = @_;
+    my ($self, $fields, $bug, $orig_expect, $t, $creation_time) = @_;
+
+    my $expect = dclone($orig_expect);
 
     foreach my $field (sort @$fields) {
         # "description" is used by Bug.create but comments are not returned
@@ -253,6 +255,12 @@ sub bz_test_bug {
             next;
         }
 
+       foreach my $field (qw(assigned_to creator qa_contact)) {
+            if (!$t->{user}) {
+                $expect->{$field} = email_filter($expect->{$field});
+            }
+       }
+
         if ($field =~ /^is_/) {
             ok(defined $bug->{$field}, $self->TYPE . ": $field is not null");
             is($bug->{$field} ? 1 : 0, $expect->{$field} ? 1 : 0,
@@ -260,6 +268,7 @@ sub bz_test_bug {
         }
         elsif ($field eq 'cc') {
             foreach my $cc_item (@{ $expect->{cc} || [] }) {
+               $cc_item = email_filter($cc_item) if !$t->{user};
                 ok(grep($_ eq $cc_item, @{ $bug->{cc} }),
                    $self->TYPE . ": $field contains $cc_item");
             }
index 90a6902e58e270cd750931b153c94d31d6d96dd8..eb68a0b5bef2246948ef5ae8bf0490732e1e975b 100644 (file)
@@ -18,6 +18,7 @@ use lib "$RealBin/../../lib", "$RealBin/../../../local/lib/perl5";
 
 use autodie;
 use Data::Dumper;
+use Email::Address;
 use Test::More;
 
 use parent qw(Exporter);
@@ -25,6 +26,7 @@ use parent qw(Exporter);
     trim
     url_quote
     random_string
+    email_filter
 
     log_in
     logout
@@ -367,6 +369,18 @@ sub set_parameters {
     }
 }
 
+sub email_filter {
+    my ($toencode) = @_;
+    my @emails = Email::Address->parse($toencode);
+    if (scalar @emails) {
+        my @hosts = map { quotemeta($_->host) } @emails;
+        my $hosts_re = join('|', @hosts);
+        $toencode =~ s/\@(?:$hosts_re)//g;
+        return $toencode;
+    }
+    return $toencode;
+}
+
 1;
 
 __END__
index 2150a0ff831d3fef38e27cf7371e936cd967b931..b0e6af81c6d8db157cc6c26978a85c6a028d21fa 100644 (file)
@@ -141,8 +141,8 @@ sub post_success {
        "content_type is correct");
     cmp_ok($attachment->{file_name}, '=~', qr/^\w+\.pl$/,
            "filename is in the expected format");
-    is($attachment->{creator}, $config->{QA_Selenium_TEST_user_login},
-       "creator is the correct user");
+    is($attachment->{creator}, ($t->{user} ? $config->{QA_Selenium_TEST_user_login} : email_filter($config->{QA_Selenium_TEST_user_login})),
+                  "creator is the correct user");
     my $data = $attachment->{data};
     $data = decode_base64($data) if $rpc->isa('QA::RPC::JSONRPC');
     is($data, $content, 'data is correct');
index 2312083d64e4cfa95086745af8b63d926f8000fa..107f866c365a0118517a5130920988eea68db172 100644 (file)
@@ -47,6 +47,7 @@ sub test_comments {
         is($comment->{text}, $expected_text, "comment has the correct text");
 
         my $priv_login = $rpc->bz_config->{PRIVATE_BUG_USER . '_user_login'};
+        $priv_login = $t->{user} ? $priv_login : email_filter($priv_login);
         is($comment->{creator}, $priv_login, "comment creator is correct");
 
         my $creation_day;
index a31e957b46e6674e932215404219589bef6a801e..835b48153d65d3a9099e71f8436bcbe73f4456b3 100644 (file)
@@ -137,8 +137,8 @@ sub post_success {
            'Admin correctly gets all user fields');
     }
     elsif ($user) {
-        ok(exists $item->{email} && exists $item->{can_login},
-           'Logged-in user correctly gets email and can_login');
+        ok(exists $item->{can_login},
+           'Logged-in user correctly gets can_login');
         ok(!exists $item->{email_enabled}
            && !exists $item->{login_denied_text},
            "Non-admin user doesn't get email_enabled and login_denied_text");