|
| 1 | +#!/usr/bin/env perl |
| 2 | +# This Source Code Form is subject to the terms of the Mozilla Public |
| 3 | +# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 | +# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 | +# |
| 6 | +# This Source Code Form is "Incompatible With Secondary Licenses", as |
| 7 | +# defined by the Mozilla Public License, v. 2.0. |
| 8 | + |
| 9 | +use 5.10.1; |
| 10 | +use strict; |
| 11 | +use warnings; |
| 12 | +use lib qw(. lib local/lib/perl5 qa/t/lib); |
| 13 | + |
| 14 | +use Bugzilla; |
| 15 | +BEGIN { Bugzilla->extensions } |
| 16 | + |
| 17 | +use Mojo::Util qw(dumper); |
| 18 | +use QA::Util; |
| 19 | +use Test::More "no_plan"; |
| 20 | +use Test::Mojo; |
| 21 | + |
| 22 | +my ($sel, $config) = get_selenium(); |
| 23 | + |
| 24 | +log_in($sel, $config, 'admin'); |
| 25 | +set_parameters( |
| 26 | + $sel, |
| 27 | + { |
| 28 | + 'Webhooks' => { |
| 29 | + 'webhooks_enabled-on' => undef, |
| 30 | + 'webhooks_group' => {type => 'select', value => 'editbugs'}, |
| 31 | + }, |
| 32 | + 'Jira Webhook Sync' => { |
| 33 | + 'jira_webhook_sync_hostname' => {type => 'text', value => 'externalapi.test'}, |
| 34 | + 'jira_webhook_sync_config' => { |
| 35 | + type => 'text', |
| 36 | + value => '{"BZFF": {"product": "Firefox", "component": "General"}}' |
| 37 | + }, |
| 38 | + }, |
| 39 | + } |
| 40 | +); |
| 41 | + |
| 42 | +# Enable global push daemon support |
| 43 | +go_to_admin($sel); |
| 44 | +$sel->click_ok('link=Configuration'); |
| 45 | +$sel->title_is('Push Administration: Configuration', 'Push configuration'); |
| 46 | +$sel->select_ok('global_enabled', 'label=Enabled'); |
| 47 | +$sel->click_ok('//input[@type="submit" and @value="Submit Changes"]'); |
| 48 | +$sel->is_text_present_ok('Changes to the configuration have been saved'); |
| 49 | +logout($sel); |
| 50 | + |
| 51 | +# Login as editbugs user add a new webhook |
| 52 | +log_in($sel, $config, 'editbugs'); |
| 53 | +$sel->click_ok('header-account-menu-button'); |
| 54 | +$sel->click_ok("//a[./span[contains(text(), 'Preferences')]]"); |
| 55 | +$sel->wait_for_page_to_load_ok(WAIT_TIME); |
| 56 | +$sel->title_is('User Preferences', 'User preferences'); |
| 57 | +$sel->click_ok('link=Webhooks'); |
| 58 | +$sel->type_ok('name', 'Jira Sync Webhook'); |
| 59 | +$sel->type_ok('url', 'http://externalapi.test:8001/webhooks/store_payload'); |
| 60 | +$sel->check_ok('create_event'); |
| 61 | +$sel->select_ok('product', 'value=Firefox'); |
| 62 | +$sel->click_ok('add_webhook'); |
| 63 | +$sel->is_text_present_ok('Jira Sync Webhook'); |
| 64 | +$sel->is_text_present_ok('create'); |
| 65 | + |
| 66 | +# File a new bug in the Firefox product and General component |
| 67 | +# The BZFF whiteboard tag should be added to the bug. |
| 68 | +file_bug_in_product($sel, 'Firefox'); |
| 69 | +my $bug_summary = 'Test bug for webhooks 1'; |
| 70 | +$sel->select_ok('component', 'value=General'); |
| 71 | +$sel->type_ok('short_desc', $bug_summary); |
| 72 | +$sel->type_ok('comment', $bug_summary); |
| 73 | +my $bug_id_1 = create_bug($sel, $bug_summary); |
| 74 | + |
| 75 | +# Give run push extension to pick up the new events |
| 76 | +Bugzilla->push_ext->push(); |
| 77 | + |
| 78 | +# Call the endpoint to get back the json that was sent |
| 79 | +my $t = Test::Mojo->new(); |
| 80 | +$t->get_ok('http://externalapi.test:8001/webhooks/last_payload') |
| 81 | + ->status_is(200) |
| 82 | + ->json_is('/event/routing_key', 'bug.create') |
| 83 | + ->json_is('/bug/id', $bug_id_1) |
| 84 | + ->json_is('/bug/summary', $bug_summary) |
| 85 | + ->json_is('/bug/product', 'Firefox') |
| 86 | + ->json_is('/bug/component', 'General') |
| 87 | + ->json_is('/bug/whiteboard', '[BZFF]'); |
| 88 | + |
| 89 | +# File a new bug in the Firefox product and Install component |
| 90 | +# The BZFF whiteboard tag should not be added to the bug. |
| 91 | +file_bug_in_product($sel, 'Firefox'); |
| 92 | +$bug_summary = 'Test bug for webhooks 2'; |
| 93 | +$sel->select_ok('component', 'value=Installer'); |
| 94 | +$sel->type_ok('short_desc', $bug_summary); |
| 95 | +$sel->type_ok('comment', $bug_summary); |
| 96 | +my $bug_id_2 = create_bug($sel, $bug_summary); |
| 97 | +logout($sel); |
| 98 | + |
| 99 | +# Give run push extension to pick up the new events |
| 100 | +Bugzilla->push_ext->push(); |
| 101 | + |
| 102 | +# Call the endpoint to get back the json that was sent |
| 103 | +$t->get_ok('http://externalapi.test:8001/webhooks/last_payload') |
| 104 | + ->status_is(200) |
| 105 | + ->json_is('/event/routing_key', 'bug.create') |
| 106 | + ->json_is('/bug/id', $bug_id_2) |
| 107 | + ->json_is('/bug/summary', $bug_summary) |
| 108 | + ->json_is('/bug/product', 'Firefox') |
| 109 | + ->json_is('/bug/component', 'Installer') |
| 110 | + ->json_is('/bug/whiteboard', ''); |
| 111 | + |
| 112 | +# Turn off webhooks |
| 113 | +log_in($sel, $config, 'admin'); |
| 114 | +set_parameters($sel, {'Webhooks' => {'webhooks_enabled-off' => undef,}}); |
| 115 | +logout($sel); |
| 116 | + |
| 117 | +done_testing(); |
| 118 | + |
| 119 | +1; |
0 commit comments