diff options
author | dklawren <dklawren@users.noreply.github.com> | 2018-09-07 12:04:50 +0200 |
---|---|---|
committer | Dylan William Hardison <dylan@hardison.net> | 2018-09-07 12:04:50 +0200 |
commit | 2e6e3e13587ee526ba94faabd5551e67508518f5 (patch) | |
tree | d54e6a7bf25c0545ef23e4854f70d5a55589b2a7 /extensions/Push | |
parent | a68b0d94e176d37e1381f38f235f760ca0a1001d (diff) | |
download | bugzilla-2e6e3e13587ee526ba94faabd5551e67508518f5.tar.gz bugzilla-2e6e3e13587ee526ba94faabd5551e67508518f5.tar.xz |
Bug 1488292 - Remove MozReview extension from BMO code tree as MozReview is being decommissioned
Diffstat (limited to 'extensions/Push')
-rw-r--r-- | extensions/Push/lib/Connector/ReviewBoard.pm | 178 | ||||
-rw-r--r-- | extensions/Push/t/ReviewBoard.t | 225 |
2 files changed, 0 insertions, 403 deletions
diff --git a/extensions/Push/lib/Connector/ReviewBoard.pm b/extensions/Push/lib/Connector/ReviewBoard.pm deleted file mode 100644 index 1c657a728..000000000 --- a/extensions/Push/lib/Connector/ReviewBoard.pm +++ /dev/null @@ -1,178 +0,0 @@ -# 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. - -package Bugzilla::Extension::Push::Connector::ReviewBoard; - -use 5.10.1; -use strict; -use warnings; - -use base 'Bugzilla::Extension::Push::Connector::Base'; - -use Bugzilla::Bug; -use Bugzilla::BugMail; -use Bugzilla::Component; -use Bugzilla::Constants; -use Bugzilla::Extension::Push::Constants; -use Bugzilla::Extension::Push::Util; -use Bugzilla::Group; -use Bugzilla::Product; -use Bugzilla::User; -use Bugzilla::Util qw( trim ); - -use constant RB_CONTENT_TYPE => 'text/x-review-board-request'; -use constant AUTOMATION_USER => 'automation@bmo.tld'; - -sub options { - return ( - { - name => 'product', - label => 'Product to create bugs in', - type => 'string', - default => 'Developer Services', - required => 1, - validate => sub { - Bugzilla::Product->new({ name => $_[0] }) - || die "Invalid Product ($_[0])\n"; - }, - }, - { - name => 'component', - label => 'Component to create bugs in', - type => 'string', - default => 'MozReview', - required => 1, - validate => sub { - my ($component, $config) = @_; - my $product = Bugzilla::Product->new({ name => $config->{product} }) - || die "Invalid Product (" . $config->{product} . ")\n"; - Bugzilla::Component->new({ product => $product, name => $component }) - || die "Invalid Component ($component)\n"; - }, - }, - { - name => 'version', - label => "The bug's version", - type => 'string', - default => 'Production', - required => 1, - validate => sub { - my ($version, $config) = @_; - my $product = Bugzilla::Product->new({ name => $config->{product} }) - || die "Invalid Product (" . $config->{product} . ")\n"; - Bugzilla::Version->new({ product => $product, name => $version }) - || die "Invalid Version ($version)\n"; - }, - }, - { - name => 'group', - label => 'Security group', - type => 'string', - default => 'mozilla-employee-confidential', - required => 1, - validate => sub { - Bugzilla::Group->new({ name => $_[0] }) - || die "Invalid Group ($_[0])\n"; - }, - }, - { - name => 'cc', - label => 'Comma separated list of users to CC', - type => 'string', - default => '', - required => 1, - validate => sub { - foreach my $login (map { trim($_) } split(',', $_[0])) { - Bugzilla::User->new({ name => $login }) - || die "Invalid User ($login)\n"; - } - }, - }, - ); -} - -sub should_send { - my ($self, $message) = @_; - - if ($message->routing_key =~ /^(?:attachment|bug)\.modify:.*\bis_private\b/) { - my $payload = $message->payload_decoded(); - my $target = $payload->{event}->{target}; - - if ($target ne 'bug' && exists $payload->{$target}->{bug}) { - return 0 if $payload->{$target}->{bug}->{is_private}; - return 0 if $payload->{$target}->{content_type} ne RB_CONTENT_TYPE; - } - - return $payload->{$target}->{is_private} ? 1 : 0; - } - else { - # We're not interested in the message. - return 0; - } -} - -sub send { - my ($self, $message) = @_; - my $logger = Bugzilla->push_ext->logger; - my $config = $self->config; - - eval { - my $payload = $message->payload_decoded(); - my $target = $payload->{event}->{target}; - - # load attachments - my $bug_id = $target eq 'bug' ? $payload->{bug}->{id} : $payload->{attachment}->{bug}->{id}; - my $attach_id = $target eq 'attachment' ? $payload->{attachment}->{id} : undef; - Bugzilla->set_user(Bugzilla::User->super_user); - my $bug = Bugzilla::Bug->new({ id => $bug_id, cache => 1 }); - Bugzilla->logout; - - # create a bug if there are any mozreview attachments - my @reviews = grep { $_->contenttype eq RB_CONTENT_TYPE } @{ $bug->attachments }; - if (@reviews) { - - # build comment - my $comment = $target eq 'bug' - ? "Bug $bug_id has MozReview reviews and is no longer public." - : "MozReview attachment $attach_id on Bug $bug_id is no longer public."; - $comment .= "\n\n"; - foreach my $attachment (@reviews) { - $comment .= $attachment->data . "\n"; - } - - # create bug - my $user = Bugzilla::User->new({ name => AUTOMATION_USER, cache => 1 }); - die "Invalid User: " . AUTOMATION_USER . "\n" unless $user; - Bugzilla->set_user($user); - my $new_bug = Bugzilla::Bug->create({ - short_desc => "[SECURITY] Bug $bug_id is no longer public", - product => $config->{product}, - component => $config->{component}, - bug_severity => 'normal', - groups => [ map { trim($_) } split(',', $config->{group}) ], - op_sys => 'Unspecified', - rep_platform => 'Unspecified', - version => $config->{version}, - cc => [ map { trim($_) } split(',', $config->{cc}) ], - comment => $comment, - }); - Bugzilla::BugMail::Send($new_bug->id, { changer => Bugzilla->user }); - Bugzilla->logout; - - $logger->info("Created bug " . $new_bug->id); - } - }; - my $error = $@; - Bugzilla->logout; - if ($error) { - return (PUSH_RESULT_TRANSIENT, clean_error($error)); - } - - return PUSH_RESULT_OK; -} - -1; diff --git a/extensions/Push/t/ReviewBoard.t b/extensions/Push/t/ReviewBoard.t deleted file mode 100644 index c752e34ef..000000000 --- a/extensions/Push/t/ReviewBoard.t +++ /dev/null @@ -1,225 +0,0 @@ -#!/usr/bin/perl -T -# 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 local/lib/perl5 ); - -use Test::More; -use Bugzilla; -use Bugzilla::Extension; -use Bugzilla::Attachment; -use Scalar::Util 'blessed'; - -BEGIN { - eval { - require Test::LWP::UserAgent; - require Test::MockObject; - }; - if ($@) { - plan skip_all => - 'Tests require Test::LWP::UserAgent and Test::MockObject'; - exit; - } -} - -BEGIN { - Bugzilla->extensions; # load all of them - use_ok 'Bugzilla::Extension::Push::Connector::ReviewBoard::Client'; - use_ok 'Bugzilla::Extension::Push::Constants'; -} - -my ($push) = grep { blessed($_) eq 'Bugzilla::Extension::Push' } @{Bugzilla->extensions }; -my $connectors = $push->_get_instance->connectors; -my $con = $connectors->by_name('ReviewBoard'); - -my $ua_204 = Test::LWP::UserAgent->new; -$ua_204->map_response( - qr{https://reviewboard-dev\.allizom\.org/api/review-requests/\d+}, - HTTP::Response->new('204')); - -my $ua_404 = Test::LWP::UserAgent->new; -$ua_404->map_response( - qr{https://reviewboard-dev\.allizom\.org/api/review-requests/\d+}, - HTTP::Response->new('404', undef, undef, q[{ "err": { "code": 100, "msg": "Object does not exist" }, "stat": "fail" }])); - -# forbidden -my $ua_403 = Test::LWP::UserAgent->new; -$ua_403->map_response( - qr{https://reviewboard-dev\.allizom\.org/api/review-requests/\d+}, - HTTP::Response->new('403', undef, undef, q[ {"err":{"code":101,"msg":"You don't have permission for this"},"stat":"fail"}])); - -# not logged in -my $ua_401 = Test::LWP::UserAgent->new; -$ua_401->map_response( - qr{https://reviewboard-dev\.allizom\.org/api/review-requests/\d+}, - HTTP::Response->new('401', undef, undef, q[ { "err": { "code": 103, "msg": "You are not logged in" }, "stat": "fail" } ])); - -# not logged in -my $ua_500 = Test::LWP::UserAgent->new; -$ua_500->map_response( - qr{https://reviewboard-dev\.allizom\.org/api/review-requests/\d+}, - HTTP::Response->new('500')); - -$con->client->{useragent} = $ua_204; -$con->config->{base_uri} = 'https://reviewboard-dev.allizom.org'; -$con->client->{base_uri} = 'https://reviewboard-dev.allizom.org'; - -{ - my $msg = message( - event => { - routing_key => 'attachment.modify:is_private', - target => 'attachment', - }, - attachment => { - is_private => 1, - content_type => 'text/plain', - bug => { id => 1, is_private => 0 }, - }, - ); - - ok(not($con->should_send($msg)), "text/plain message should not be sent"); -} - -my $data = slurp("extensions/Push/t/rblink.txt"); -Bugzilla::User::DEFAULT_USER->{userid} = 42; -Bugzilla->set_user(Bugzilla::User->super_user); -diag " " . Bugzilla::User->super_user->id; - -my $dbh = Bugzilla->dbh; -$dbh->bz_start_transaction; -my $timestamp = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)'); -my $bug = Bugzilla::Bug->new({id => 9000}); -my $attachment = Bugzilla::Attachment->create({ - bug => $bug, - creation_ts => $timestamp, - data => $data, - attach_size => length($data), - description => "rblink.txt", - filename => "rblink.txt", - isprivate => 1, - ispatch => 0, - mimetype => 'text/x-review-board-request' -}); -diag "".$attachment->id; -$dbh->bz_commit_transaction; - -{ - my $msg = message( - event => { - routing_key => 'attachment.modify:cc,is_private', - target => 'attachment', - }, - attachment => { - id => $attachment->id, - is_private => 1, - content_type => 'text/x-review-board-request', - bug => { id => $bug->id, is_private => 0 }, - }, - ); - ok($con->should_send($msg), "rb attachment should be sent"); - - { - my ($rv, $err) = $con->send($msg); - is($rv, PUSH_RESULT_OK, "good push result"); - diag $err if $err; - } - - { - local $con->client->{useragent} = $ua_404; - my ($rv, $err) = $con->send($msg); - is($rv, PUSH_RESULT_OK, "good push result for 404"); - diag $err if $err; - } - - - { - local $con->client->{useragent} = $ua_403; - my ($rv, $err) = $con->send($msg); - is($rv, PUSH_RESULT_TRANSIENT, "transient error on 403"); - diag $err if $err; - } - - - { - local $con->client->{useragent} = $ua_401; - my ($rv, $err) = $con->send($msg); - is($rv, PUSH_RESULT_TRANSIENT, "transient error on 401"); - diag $err if $err; - } - - { - local $con->client->{useragent} = $ua_500; - my ($rv, $err) = $con->send($msg); - is($rv, PUSH_RESULT_TRANSIENT, "transient error on 500"); - diag $err if $err; - } -} - -{ - my $msg = message( - event => { - routing_key => 'bug.modify:is_private', - target => 'bug', - }, - bug => { - is_private => 1, - id => $bug->id, - }, - ); - - ok($con->should_send($msg), "rb attachment should be sent"); - my ($rv, $err) = $con->send($msg); - is($rv, PUSH_RESULT_OK, "good push result"); - - { - local $con->client->{useragent} = $ua_404; - my ($rv, $err) = $con->send($msg); - is($rv, PUSH_RESULT_OK, "good push result for 404"); - } - - { - local $con->client->{useragent} = $ua_403; - my ($rv, $err) = $con->send($msg); - is($rv, PUSH_RESULT_TRANSIENT, "transient error on 404"); - diag $err if $err; - } - - - { - local $con->client->{useragent} = $ua_401; - my ($rv, $err) = $con->send($msg); - is($rv, PUSH_RESULT_TRANSIENT, "transient error on 401"); - diag $err if $err; - } - - { - local $con->client->{useragent} = $ua_401; - my ($rv, $err) = $con->send($msg); - is($rv, PUSH_RESULT_TRANSIENT, "transient error on 401"); - diag $err if $err; - } -} - -sub message { - my $msg_data = { @_ }; - - return Test::MockObject->new - ->set_always( routing_key => $msg_data->{event}{routing_key} ) - ->set_always( payload_decoded => $msg_data ); -} - -sub slurp { - my $file = shift; - local $/ = undef; - open my $fh, '<', $file or die "unable to open $file"; - my $s = readline $fh; - close $fh; - return $s; -} - -done_testing; |