use Bugzilla::Flag;
use Bugzilla::Hook;
use Bugzilla::Install::Localconfig qw(read_localconfig);
+use Bugzilla::Localconfig;
use Bugzilla::Install::Util qw(init_console include_languages);
use Bugzilla::Memcached;
use Bugzilla::Template;
}
sub localconfig {
- return $_[0]->process_cache->{localconfig} ||= read_localconfig();
+ return $_[0]->process_cache->{localconfig} ||= Bugzilla::Localconfig->new(read_localconfig());
}
+
sub params {
return request_cache->{params} ||= Bugzilla::Config::read_param_file();
}
sub get_param_with_override {
my ($class, $name) = @_;
- return $class->localconfig->{param_override}{$name} // $class->params->{$name};
+ return $class->localconfig->param_override->{$name} // $class->params->{$name};
}
sub user {
sub jwt {
my ($class, @args) = @_;
require Mojo::JWT;
- return Mojo::JWT->new(@args, secret => $class->localconfig->{jwt_secret});
+ return Mojo::JWT->new(@args, secret => $class->localconfig->jwt_secret);
}
sub dbh {
# Connector to the Datadog metrics collection daemon.
sub datadog {
my ($class, $namespace) = @_;
- my $host = $class->localconfig->{datadog_host};
- my $port = $class->localconfig->{datadog_port};
+ my $host = $class->localconfig->datadog_host;
+ my $port = $class->localconfig->datadog_port;
$namespace //= '';
}
);
- $app->secrets([Bugzilla->localconfig->{side_wide_secret}]);
+ $app->secrets([Bugzilla->localconfig->site_wide_secret]);
$app->renderer->add_handler(
'bugzilla' => sub {
my ($c, $type) = @_;
if ($type == LOGIN_REQUIRED) {
- $c->redirect_to(Bugzilla->localconfig->{basepath} . 'login');
+ $c->redirect_to(Bugzilla->localconfig->basepath . 'login');
return undef;
}
else {
'url_is_attachment_base' => sub {
my ($c, $id) = @_;
return 0 unless Bugzilla::Util::use_attachbase();
- my $attach_base = Bugzilla->localconfig->{'attachment_base'};
+ my $attach_base = Bugzilla->localconfig->attachment_base;
# If we're passed an id, we only want one specific attachment base
# for a particular bug. If we're not passed an ID, we just want to
sub _before_routes {
my ($c) = @_;
- state $urlbase = Bugzilla->localconfig->{urlbase};
+ state $urlbase = Bugzilla->localconfig->urlbase;
state $urlbase_uri = URI->new($urlbase);
state $urlbase_host = $urlbase_uri->host;
state $urlbase_host_regex = qr/^bug(\d+)\.\Q$urlbase_host\E$/;
- state $attachment_base = Bugzilla->localconfig->{attachment_base};
+ state $attachment_base = Bugzilla->localconfig->attachment_base;
state $attachment_root = _attachment_root($attachment_base);
state $attachment_host_regex = _attachment_host_regex($attachment_base);
$conf->{verify_auth_code} = \&_verify_auth_code;
$conf->{store_access_token} = \&_store_access_token;
$conf->{verify_access_token} = \&_verify_access_token;
- $conf->{jwt_secret} = Bugzilla->localconfig->{jwt_secret};
+ $conf->{jwt_secret} = Bugzilla->localconfig->jwt_secret;
$conf->{jwt_claims} = sub {
my $args = shift;
if (!$args->{user_id}) {
my ($self, $app, $conf) = @_;
if (HAVE_BSD_RESOURCE) {
- my $setrlimit = decode_json(Bugzilla->localconfig->{setrlimit});
+ my $setrlimit = decode_json(Bugzilla->localconfig->setrlimit);
# This trick means the master process will not a size limit.
Mojo::IOLoop->next_tick(sub {
}
if (HAVE_LINUX_SMAPS_TINY) {
- my $size_limit = Bugzilla->localconfig->{size_limit};
+ my $size_limit = Bugzilla->localconfig->size_limit;
return unless $size_limit;
if ($size_limit < MIN_SIZE_LIMIT) {
# Add in cvs context if we have the necessary info to do it
if ( $context ne 'patch'
- && Bugzilla->localconfig->{cvsbin}
+ && Bugzilla->localconfig->cvsbin
&& Bugzilla->params->{'cvsroot_get'})
{
require Bugzilla::PatchReader::AddCVSContext;
# We need to set $cvsbin as global, because PatchReader::CVSClient
# needs it in order to find 'cvs'.
- $main::cvsbin = Bugzilla->localconfig->{cvsbin};
+ $main::cvsbin = Bugzilla->localconfig->cvsbin;
$last_reader->sends_data_to(new Bugzilla::PatchReader::AddCVSContext(
$context, Bugzilla->params->{'cvsroot_get'}
));
$vars->{'collapsed'} = $cgi->param('collapsed');
$vars->{'context'} = $context;
$vars->{'do_context'}
- = Bugzilla->localconfig->{cvsbin}
+ = Bugzilla->localconfig->cvsbin
&& Bugzilla->params->{'cvsroot_get'}
&& !$vars->{'newid'};
# Attachments are served from a separate host (ideally), and so
# an evil attachment cannot abuse this check with a redirect.
elsif (my $referer = $cgi->referer) {
- my $urlbase = Bugzilla->localconfig->{urlbase};
+ my $urlbase = Bugzilla->localconfig->urlbase;
$valid = 1 if $referer =~ /^\Q$urlbase\E/;
}
sub _parse_see_also {
my (@links) = @_;
- my $urlbase = Bugzilla->localconfig->{urlbase};
+ my $urlbase = Bugzilla->localconfig->urlbase;
my $bug_link_re = qr/^\Q$urlbase\Eshow_bug\.cgi\?id=(\d+)$/;
return grep { /^\d+$/ } map { /$bug_link_re/ ? int($1) : () } @links;
sub local_uri {
my ($self, $bug_id) = @_;
$bug_id ||= '';
- return Bugzilla->localconfig->{urlbase} . "show_bug.cgi?id=$bug_id";
+ return Bugzilla->localconfig->urlbase . "show_bug.cgi?id=$bug_id";
}
sub bug {
sub target_uri {
my ($self) = @_;
- my $base = Bugzilla->localconfig->{urlbase};
+ my $base = Bugzilla->localconfig->urlbase;
if (my $request_uri = $self->request_uri) {
my $base_uri = URI->new($base);
$base_uri->path('');
# Note that urlbase must end with a /.
# It almost certainly does, but let's be extra careful.
- my $urlbase = Bugzilla->localconfig->{urlbase};
+ my $urlbase = Bugzilla->localconfig->urlbase;
$urlbase =~ s{/$}{};
qr{
# Begins with literal urlbase
}
# Add the default path and the domain in.
- state $uri = URI->new(Bugzilla->localconfig->{urlbase});
+ state $uri = URI->new(Bugzilla->localconfig->urlbase);
$paramhash{'-path'} = $uri->path;
# we don't set the domain.
sub redirect_to_https {
my $self = shift;
- my $urlbase = Bugzilla->localconfig->{'urlbase'};
+ my $urlbase = Bugzilla->localconfig->urlbase;
# If this is a POST, we don't want ?POSTDATA in the query string.
# We expect the client to re-POST, which may be a violation of
sub redirect_to_urlbase {
my $self = shift;
my $path = $self->url('-path_info' => 1, '-query' => 1, '-relative' => 1);
- print $self->redirect('-location' => Bugzilla->localconfig->{urlbase} . $path);
+ print $self->redirect('-location' => Bugzilla->localconfig->urlbase . $path);
exit;
}
sub base_redirect {
my ($self, $path, $is_perm) = @_;
print $self->redirect(
- -location => Bugzilla->localconfig->{basepath} . ($path || ''),
+ -location => Bugzilla->localconfig->basepath . ($path || ''),
-status => $is_perm ? '301 Moved Permanently' : '302 Found'
);
exit;
local $Data::Dumper::Sortkeys = 1;
my %params = %$param_data;
- $params{urlbase} = Bugzilla->localconfig->{urlbase};
+ $params{urlbase} = Bugzilla->localconfig->urlbase;
__PACKAGE__->_write_file(Data::Dumper->Dump([\%params], ['*param']));
# And now we have to reset the params cache so that Bugzilla will re-read
# Because show_bug code lives in many different .cgi files,
# we needed a centralized place to define the policy.
# normally the policy would just live in one .cgi file.
-# Additionally, Bugzilla->localconfig->{urlbase} cannot be called at compile time, so this can't be a constant.
+# Additionally, Bugzilla->localconfig->urlbase cannot be called at compile time, so this can't be a constant.
sub SHOW_BUG_MODAL_CSP {
my ($bug_id) = @_;
my %policy = (
worker_src => ['none',],
);
if (Bugzilla::Util::use_attachbase() && $bug_id) {
- my $attach_base = Bugzilla->localconfig->{'attachment_base'};
+ my $attach_base = Bugzilla->localconfig->attachment_base;
$attach_base =~ s/\%bugid\%/$bug_id/g;
push @{$policy{img_src}}, $attach_base;
push @{$policy{media_src}}, $attach_base;
$connect_params->{db_port} = Bugzilla->get_param_with_override('shadowdbport');
$connect_params->{db_sock} = Bugzilla->get_param_with_override('shadowdbsock');
- if ( Bugzilla->localconfig->{'shadowdb_user'}
- && Bugzilla->localconfig->{'shadowdb_pass'})
+ if ( Bugzilla->localconfig->shadowdb_user
+ && Bugzilla->localconfig->shadowdb_pass)
{
- $connect_params->{db_user} = Bugzilla->localconfig->{'shadowdb_user'};
- $connect_params->{db_pass} = Bugzilla->localconfig->{'shadowdb_pass'};
+ $connect_params->{db_user} = Bugzilla->localconfig->shadowdb_user;
+ $connect_params->{db_pass} = Bugzilla->localconfig->shadowdb_pass;
}
return $shadow_dbh = _connect($connect_params);
}
# See if we can connect to the actual Bugzilla database.
my $conn_success = eval { $dbh = connect_main() };
- my $db_name = Bugzilla->localconfig->{db_name};
+ my $db_name = Bugzilla->localconfig->db_name;
if (!$conn_success) {
$dbh = _get_no_db_connection();
sub bz_last_key {
my ($self, $table, $column) = @_;
- return $self->last_insert_id(Bugzilla->localconfig->{db_name},
+ return $self->last_insert_id(Bugzilla->localconfig->db_name,
undef, $table, $column);
}
my $self = shift;
my $lc = Bugzilla->localconfig;
- if (lc(Bugzilla->localconfig->{db_name}) eq 'mysql') {
+ if (lc(Bugzilla->localconfig->db_name) eq 'mysql') {
die "It is not safe to run Bugzilla inside a database named 'mysql'.\n"
. " Please pick a different value for \$db_name in localconfig.\n";
}
}
# Upgrade tables from MyISAM to InnoDB
- my $db_name = Bugzilla->localconfig->{db_name};
+ my $db_name = Bugzilla->localconfig->db_name;
my $myisam_tables = $self->selectcol_arrayref(
'SELECT TABLE_NAME FROM information_schema.TABLES
WHERE TABLE_SCHEMA = ? AND ENGINE = ?', undef, $db_name, 'MyISAM'
sub _alter_db_charset_to_utf8 {
my $self = shift;
- my $db_name = Bugzilla->localconfig->{db_name};
+ my $db_name = Bugzilla->localconfig->db_name;
my $charset = $self->utf8_charset;
my $collate = $self->utf8_collate;
$self->do("ALTER DATABASE $db_name CHARACTER SET $charset COLLATE $collate");
# You can never connect to Oracle without a DB name,
# and there is no default DB.
- $dbname ||= Bugzilla->localconfig->{db_name};
+ $dbname ||= Bugzilla->localconfig->db_name;
# Set the language enviroment
$ENV{'NLS_LANG'} = '.AL32UTF8' if Bugzilla->params->{'utf8'};
# Create a WORLD_LEXER named BZ_LEX for multilingual fulltext search
my $lexer = $self->selectcol_arrayref(
"SELECT pre_name FROM CTXSYS.CTX_PREFERENCES WHERE pre_name = ? AND
- pre_owner = ?", undef, 'BZ_LEX', uc(Bugzilla->localconfig->{db_user})
+ pre_owner = ?", undef, 'BZ_LEX', uc(Bugzilla->localconfig->db_user)
);
if (!@$lexer) {
$self->do(
###############
# Used by the permissions "constants" below.
-sub _suexec { Bugzilla->localconfig->{'use_suexec'} }
-sub _group { Bugzilla->localconfig->{'webservergroup'} }
+sub _suexec { Bugzilla->localconfig->use_suexec }
+sub _group { Bugzilla->localconfig->webservergroup }
# Writeable by the owner only.
use constant OWNER_WRITE => 0600;
sub _check_web_server_group {
my ($output) = @_;
- my $group = Bugzilla->localconfig->{'webservergroup'};
+ my $group = Bugzilla->localconfig->webservergroup;
my $filename = bz_locations()->{'localconfig'};
my $group_id;
our @EXPORT_OK = qw(
read_localconfig
update_localconfig
+ LOCALCONFIG_VARS
);
# might want to change this for upstream
{name => 'memcached_servers', default => '',},
{name => 'memcached_namespace', default => "bugzilla:",},
{name => 'urlbase', default => '',},
- {name => 'canonical_urlbase', default => '',},
+ {name => 'canonical_urlbase', lazy => 1},
{name => 'attachment_base', default => '',},
{name => 'ses_username', default => '',},
{name => 'ses_password', default => '',},
? _read_localconfig_from_env()
: _read_localconfig_from_file($include_deprecated);
- # Use the site's URL as the default Canonical URL
- $config->{canonical_urlbase} //= $config->{urlbase};
-
- # Get the absolute path of the URLBase value
- $config->{basepath} = do {
- my $path = $config->{urlbase};
- $path =~ s/^https?:\/\/.*?\//\//;
- $path;
- };
-
return $config;
}
}
}
- if (!$localconfig->{'interdiffbin'} && $output) {
+ if (!$localconfig->{interdiffbin} && $output) {
print "\n", install_string('patchutils_missing'), "\n";
}
sub check_webdotbase {
my ($output) = @_;
- my $webdotbase = Bugzilla->localconfig->{'webdotbase'};
+ my $webdotbase = Bugzilla->localconfig->webdotbase;
return 1 if $webdotbase =~ /^https?:/;
my $return;
sub check_font_file {
my ($output) = @_;
- my $font_file = Bugzilla->localconfig->{'font_file'};
+ my $font_file = Bugzilla->localconfig->font_file;
my $readable;
$readable = 1 if -r $font_file;
--- /dev/null
+# 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::Localconfig;
+use 5.10.1;
+use Moo;
+use MooX::StrictConstructor;
+
+use Bugzilla::Install::Localconfig qw(LOCALCONFIG_VARS);
+
+foreach my $var (LOCALCONFIG_VARS) {
+ if ($var->{lazy}) {
+ has $var->{name} => (is => 'lazy');
+ }
+ else {
+ has $var->{name} => (is => 'ro', required => 1);
+ }
+}
+
+has 'basepath' => (is => 'lazy');
+
+# Use the site's URL as the default Canonical URL
+sub _build_canonical_urlbase {
+ my ($self) = @_;
+ $self->urlbase;
+}
+
+sub _build_basepath {
+ my ($self) = @_;
+ my $path = $self->urlbase;
+ $path =~ s/^https?:\/\/.*?\//\//;
+ return $path;
+}
+
+1;
# We add this header to uniquely identify all email that we
# send as coming from this Bugzilla installation.
#
- $email->header_set('X-Bugzilla-URL', Bugzilla->localconfig->{urlbase});
+ $email->header_set('X-Bugzilla-URL', Bugzilla->localconfig->urlbase);
# We add this header to mark the mail as "auto-generated" and
# thus to hopefully avoid auto replies.
else {
# Sendmail will automatically append our hostname to the From
# address, but other mailers won't.
- my $urlbase = Bugzilla->localconfig->{urlbase};
+ my $urlbase = Bugzilla->localconfig->urlbase;
$urlbase =~ m|//([^:/]+)[:/]?|;
$hostname = $1;
$from .= "\@$hostname" if $from !~ /@/;
$user_id = Bugzilla->user->id;
}
- my $sitespec = '@' . Bugzilla->localconfig->{urlbase};
+ my $sitespec = '@' . Bugzilla->localconfig->urlbase;
$sitespec =~ s/:\/\//\./; # Make the protocol look like part of the domain
$sitespec =~ s/^([^:\/]+):(\d+)/$1/; # Remove a port number, to relocate
if ($2) {
# always return an object to simplify calling code when memcached is
# disabled.
- my $servers = Bugzilla->localconfig->{memcached_servers};
+ my $servers = Bugzilla->localconfig->memcached_servers;
if (Bugzilla->feature('memcached') && $servers) {
- $self->{namespace} = Bugzilla->localconfig->{memcached_namespace};
+ $self->{namespace} = Bugzilla->localconfig->memcached_namespace;
TRACE("connecting servers: $servers, namespace: $self->{namespace}");
$self->{memcached} = Cache::Memcached::Fast->new({
servers => [_parse_memcached_server_list($servers)],
if ($bug_id && Bugzilla->user->can_see_bug($bug_id) && !i_am_webservice()) {
$alias = url_quote($alias);
print Bugzilla->cgi->redirect(
- -uri => Bugzilla->localconfig->{urlbase} . "show_bug.cgi?id=$alias");
+ -uri => Bugzilla->localconfig->urlbase . "show_bug.cgi?id=$alias");
exit;
}
}
}
# Provide tooltips for full bug links (Bug 74355)
- my $urlbase_re = '(' . quotemeta(Bugzilla->localconfig->{urlbase}) . ')';
+ my $urlbase_re = '(' . quotemeta(Bugzilla->localconfig->urlbase) . ')';
$text =~ s~\b(${urlbase_re}\Qshow_bug.cgi?id=\E([0-9]+)(\#c([0-9]+))?)\b
~($things[$count++] = $bug_link_func->($3, $1, { comment_num => $5, user => $user })) &&
("\x{FDD2}" . ($count-1) . "\x{FDD3}")
$link_text =~ s/ \[details\]$//;
$link_text =~ s/ \[diff\]$//;
- state $basepath = Bugzilla->localconfig->{basepath};
+ state $basepath = Bugzilla->localconfig->basepath;
my $linkval = "${basepath}attachment.cgi?id=$attachid";
# If the attachment is a patch and patch_viewer feature is
sub version_filter {
my ($file_url) = @_;
return
- Bugzilla->localconfig->{basepath}
+ Bugzilla->localconfig->basepath
. "static/v"
. Bugzilla->VERSION
. "/$file_url";
'sudoer' => sub { return Bugzilla->sudoer; },
# Allow templates to access the "corect" URLBase value
- 'urlbase' => sub { return Bugzilla->localconfig->{urlbase}; },
+ 'urlbase' => sub { return Bugzilla->localconfig->urlbase; },
# Allow templates to get the absolute path of the URLBase value
- 'basepath' => sub { return Bugzilla->localconfig->{basepath}; },
+ 'basepath' => sub { return Bugzilla->localconfig->basepath; },
# Allow templates to access docs url with users' preferred language
'docs_urlbase' => sub {
return '' unless @sigs;
# use a URI object to encode the query string part.
- my $uri = URI->new(Bugzilla->localconfig->{urlbase} . 'page.cgi');
+ my $uri = URI->new(Bugzilla->localconfig->urlbase . 'page.cgi');
$uri->query_form({'id' => 'socorro-lens.html', 's' => join("\\", @sigs)});
return $uri;
},
my $dbh = Bugzilla->dbh;
my $user = Bugzilla->user;
my $checksum = hmac_sha256_base64($user->id, $uri,
- Bugzilla->localconfig->{'site_wide_secret'});
+ Bugzilla->localconfig->site_wide_secret);
return _create_token($user->id, 'auth_delegation', $checksum);
}
if ($eventdata) {
my $checksum = hmac_sha256_base64($user->id, $uri,
- Bugzilla->localconfig->{'site_wide_secret'});
+ Bugzilla->localconfig->site_wide_secret);
if ($eventdata eq $checksum) {
delete_token($token);
return 1;
$salt //= generate_random_password(16);
my $hmac = hmac_sha256_base64($salt, $type, $data,
- Bugzilla->localconfig->{site_wide_secret});
+ Bugzilla->localconfig->site_wide_secret);
return sprintf("%s|%s|%x", $salt, $hmac, length($data));
}
# $token needs to be a byte string.
utf8::encode($token);
$token
- = hmac_sha256_base64($token, Bugzilla->localconfig->{'site_wide_secret'});
+ = hmac_sha256_base64($token, Bugzilla->localconfig->site_wide_secret);
$token =~ s/\+/-/g;
$token =~ s/\//_/g;
state $web_server_gid;
if (!defined $web_server_gid) {
- my $web_server_group = Bugzilla->localconfig->{webservergroup};
+ my $web_server_group = Bugzilla->localconfig->webservergroup;
if ($web_server_group eq '' || ON_WINDOWS) {
$web_server_gid = $effective_gids[0];
# (doing so can mess up XML-RPC).
sub do_ssl_redirect_if_required {
return if !i_am_cgi();
- my $uri = URI->new(Bugzilla->localconfig->{'urlbase'});
+ my $uri = URI->new(Bugzilla->localconfig->urlbase);
return if $uri->scheme ne 'https';
# If we're already running under SSL, never redirect.
}
sub use_attachbase {
- my $attachbase = Bugzilla->localconfig->{'attachment_base'};
- my $urlbase = Bugzilla->localconfig->{'urlbase'};
+ my $attachbase = Bugzilla->localconfig->attachment_base;
+ my $urlbase = Bugzilla->localconfig->urlbase;
return ($attachbase ne '' && $attachbase ne $urlbase);
}
# Functions that tell you about your environment
my $is_cgi = i_am_cgi();
my $is_webservice = i_am_webservice();
- my $urlbase = Bugzilla->localconfig->{urlbase};
+ my $urlbase = Bugzilla->localconfig->urlbase;
# Data manipulation
($removed, $added) = diff_arrays(\@old, \@new);
# order to throw proper errors. We use the installation's urlbase as
# the id, in this case.
else {
- $id = Bugzilla->localconfig->{urlbase};
+ $id = Bugzilla->localconfig->urlbase;
}
# Setting _bz_request_id here is required in case we throw errors early,
# also set up the correct handler method
my $obj = {
version => '1.1',
- id => Bugzilla->localconfig->{urlbase},
+ id => Bugzilla->localconfig->urlbase,
method => $self->bz_method_name,
params => $params
};
# make sure we were not going to request credentials on the
# alternate host.
Bugzilla->login();
- my $attachbase = Bugzilla->localconfig->{'attachment_base'};
+ my $attachbase = Bugzilla->localconfig->attachment_base;
# Replace %bugid% by the ID of the bug the attachment
# belongs to, if present.
my $current_module;
my @panels = ();
my $param_panels = Bugzilla::Config::param_panels();
-my $override = Bugzilla->localconfig->{param_override};
+my $override = Bugzilla->localconfig->param_override;
foreach my $panel (keys %$param_panels) {
my $module = $param_panels->{$panel};
require_module($module);
my $uri = URI->new($url);
$uri->query(undef);
$uri->fragment(undef);
- if ($uri->as_string ne Bugzilla->localconfig->{urlbase} . 'buglist.cgi') {
+ if ($uri->as_string ne Bugzilla->localconfig->urlbase . 'buglist.cgi') {
ThrowUserError('bitly_unsupported');
}
# form a bug_id only url, sanity check the length
$uri
- = URI->new(Bugzilla->localconfig->{urlbase}
+ = URI->new(Bugzilla->localconfig->urlbase
. 'buglist.cgi?bug_id='
. join(',', map { $_->[0] } @$data));
if (length($uri->as_string) > CGI_URI_LIMIT) {
# split see-also
if ($change->{fieldname} eq 'see_also') {
- my $url_base = Bugzilla->localconfig->{urlbase};
+ my $url_base = Bugzilla->localconfig->urlbase;
foreach my $f (qw( added removed )) {
my @values;
foreach my $value (split(/, /, $change->{$f})) {
sub get_empty {
my ($self) = @_;
return {
- ref => $self->type('string', Bugzilla->localconfig->{urlbase} . "bzapi/"),
+ ref => $self->type('string', Bugzilla->localconfig->urlbase . "bzapi/"),
documentation => $self->type('string', BZAPI_DOC),
version => $self->type('string', BUGZILLA_VERSION)
};
# Return an URL base appropriate for constructing a ref link
# normally required by REST API calls.
sub ref_urlbase {
- return Bugzilla->localconfig->{urlbase} . "bzapi";
+ return Bugzilla->localconfig->urlbase . "bzapi";
}
# convert certain fields within a bug object
sub login_uri {
my ($class, $target_uri) = @_;
- my $uri = URI->new(Bugzilla->localconfig->{urlbase} . "github.cgi");
+ my $uri = URI->new(Bugzilla->localconfig->urlbase . "github.cgi");
$uri->query_form(target_uri => $target_uri);
return $uri;
}
client_id => Bugzilla->params->{github_client_id},
scope => 'user:email',
state => $state,
- redirect_uri => Bugzilla->localconfig->{urlbase} . "github.cgi",
+ redirect_uri => Bugzilla->localconfig->urlbase . "github.cgi",
);
return $uri;
$digest->add(remote_ip());
$digest->add($cgi->cookie('Bugzilla_github_token')
// Bugzilla->request_cache->{github_token} // '');
- $digest->add(Bugzilla->localconfig->{site_wide_secret});
+ $digest->add(Bugzilla->localconfig->site_wide_secret);
return $digest->hexdigest;
}
return sub {
my $email = shift;
- my $uri = URI->new(Bugzilla->localconfig->{urlbase} . "github.cgi");
+ my $uri = URI->new(Bugzilla->localconfig->urlbase . "github.cgi");
$uri->query_form(state => $state, email => $email);
return $uri;
};
# split see-also
if ($change->{fieldname} eq 'see_also') {
- my $url_base = Bugzilla->localconfig->{urlbase};
+ my $url_base = Bugzilla->localconfig->urlbase;
foreach my $f (qw( added removed )) {
my @values;
foreach my $value (split(/, /, $change->{$f})) {
sub _cipher {
my ($self) = @_;
$self->{_cipher} ||= Crypt::CBC->new(
- -key => Bugzilla->localconfig->{'site_wide_secret'},
+ -key => Bugzilla->localconfig->site_wide_secret,
-cipher => 'DES_EDE3'
);
return $self->{_cipher};
$self->{queue_name} = $self->config->{queue};
}
else {
- my $queue_name = Bugzilla->localconfig->{'urlbase'};
+ my $queue_name = Bugzilla->localconfig->urlbase;
$queue_name =~ s#^https?://##;
$queue_name =~ s#/$#|#;
$queue_name .= generate_random_password(16);
$request->authorization_basic($self->config->{service_now_user},
$self->config->{service_now_pass});
- $self->{lwp} ||= LWP::UserAgent->new(agent => Bugzilla->localconfig->{urlbase});
+ $self->{lwp} ||= LWP::UserAgent->new(agent => Bugzilla->localconfig->urlbase);
my $result = $self->{lwp}->request($request);
# http level errors
}
}
}
- $text .= Bugzilla->localconfig->{urlbase} . "show_bug.cgi?id=" . $bug->id;
+ $text .= Bugzilla->localconfig->urlbase . "show_bug.cgi?id=" . $bug->id;
my $room_id = $self->config->{spark_room_id};
my $message_uri = $self->_spark_uri('messages');
# PGP keys must be ASCII-armoured.
my $tct = Bugzilla::Extension::SecureMail::TCT->new(
public_key => $value,
- command => Bugzilla->localconfig->{tct_bin},
+ command => Bugzilla->localconfig->tct_bin,
);
unless ($tct->is_valid->get) {
ThrowUserError('securemail_invalid_key',
my $tct = Bugzilla::Extension::SecureMail::TCT->new(
public_key => $key,
- command => Bugzilla->localconfig->{tct_bin},
+ command => Bugzilla->localconfig->tct_bin,
);
if (scalar $email->parts > 1) {
my $message;
my $email_type = $email->header('X-Bugzilla-Type');
my $vars = {
- 'urlbase' => Bugzilla->localconfig->{urlbase},
+ 'urlbase' => Bugzilla->localconfig->urlbase,
'bug_id' => $bug_id,
'maintainer' => Bugzilla->params->{'maintainer'},
'email_type' => $email_type
sub _tct_encrypt {
my ($tct, $text, $bug_id) = @_;
- my $comment = Bugzilla->localconfig->{urlbase}
+ my $comment = Bugzilla->localconfig->urlbase
. ($bug_id ? 'show_bug.cgi?id=' . $bug_id : '');
my $encrypted;
my $ok = eval { $encrypted = $tct->encrypt($text, $comment)->get; 1 };
sub install_before_final_checks {
my ($self) = @_;
- if (!Bugzilla->localconfig->{urlbase}) {
+ if (!Bugzilla->localconfig->urlbase) {
print STDERR get_text('sitemap_no_urlbase'), "\n";
return;
}
return;
}
- return if (Bugzilla->localconfig->{urlbase} ne 'https://bugzilla.mozilla.org/');
+ return if (Bugzilla->localconfig->urlbase ne 'https://bugzilla.mozilla.org/');
}
sub install_filesystem {
sub before_robots_txt {
my ($self, $args) = @_;
- $args->{vars}{SITEMAP_URL} = Bugzilla->localconfig->{urlbase} . SITEMAP_URL;
+ $args->{vars}{SITEMAP_URL} = Bugzilla->localconfig->urlbase . SITEMAP_URL;
}
__PACKAGE__->NAME;
$index_xml .= "
<sitemap>
<loc>"
- . Bugzilla->localconfig->{urlbase} . "data/$extension_name/$filename</loc>
+ . Bugzilla->localconfig->urlbase . "data/$extension_name/$filename</loc>
<lastmod>$timestamp</lastmod>
</sitemap>
";
sub _generate_sitemap_file {
my ($extension_name, $filecount, $products, $bugs) = @_;
- my $bug_url = Bugzilla->localconfig->{urlbase} . 'show_bug.cgi?id=';
+ my $bug_url = Bugzilla->localconfig->urlbase . 'show_bug.cgi?id=';
my $product_url
- = Bugzilla->localconfig->{urlbase} . 'describecomponents.cgi?product=';
+ = Bugzilla->localconfig->urlbase . 'describecomponents.cgi?product=';
my $sitemap_xml = <<END;
<?xml version="1.0" encoding="UTF-8"?>
use Bugzilla::Extension::GitHubAuth::Client;
my $cgi = Bugzilla->cgi;
-my $urlbase = Bugzilla->localconfig->{urlbase};
+my $urlbase = Bugzilla->localconfig->urlbase;
if (lc($cgi->request_method) eq 'post') {
if ($user_id && $user->in_group('admin')) {
# If 'urlbase' is not set, display the Welcome page.
- unless (Bugzilla->localconfig->{'urlbase'}) {
+ unless (Bugzilla->localconfig->urlbase) {
$template->process('welcome-admin.html.tmpl')
or ThrowTemplateError($template->error());
exit;
# the same product names.
my $project = bz_locations()->{'project'} || '';
my $image_file = join(':', ($project, $prod_id, @datasets));
- my $key = Bugzilla->localconfig->{'site_wide_secret'};
+ my $key = Bugzilla->localconfig->site_wide_secret;
$image_file = hmac_sha256_base64($image_file, $key) . '.png';
$image_file =~ s/\+/-/g;
$image_file =~ s/\//_/g;
});
print "Done!\n";
-my $urlbase = Bugzilla->localconfig->{urlbase};
+my $urlbase = Bugzilla->localconfig->urlbase;
print
"Please visit ${urlbase}editfields.cgi?action=edit&name=$name to finish setting up this field.\n";
defined $root_mysql_pw || die "MySQL root password required.\n";
my $mysql_dbh = Bugzilla::DB::_connect({
- db_driver => $localconfig->{db_driver},
- db_host => $localconfig->{db_host},
+ db_driver => $localconfig->db_driver,
+ db_host => $localconfig->db_host,
db_name => 'mysql',
db_user => 'root',
db_pass => $root_mysql_pw
"SELECT TABLE_NAME, COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = ?
- AND DATA_TYPE='datetime'", undef, Bugzilla->localconfig->{db_name}
+ AND DATA_TYPE='datetime'", undef, Bugzilla->localconfig->db_name
);
my $total = scalar @$rows;
#
-my $db_name = Bugzilla->localconfig->{db_name};
+my $db_name = Bugzilla->localconfig->db_name;
print <<EOF;
WARNING
} keys %$teams;
my $vars = {
- urlbase => Bugzilla->localconfig->{urlbase},
+ urlbase => Bugzilla->localconfig->urlbase,
report_week => $report_week,
teams => \@sorted_team_names,
sec_keywords => $sec_keywords,
sub build_bugs_link {
my ($arr, $product) = @_;
- my $uri = URI->new(Bugzilla->localconfig->{urlbase} . 'buglist.cgi');
+ my $uri = URI->new(Bugzilla->localconfig->urlbase . 'buglist.cgi');
$uri->query_param(bug_id => (join ',', @$arr));
$uri->query_param(product => $product) if $product;
return $uri->as_string;
chmod Bugzilla::Install::Filesystem::CGI_WRITE, $filename
or warn install_string('chmod_failed', {path => $filename, error => $!});
-my $urlbase = Bugzilla->localconfig->{urlbase};
+my $urlbase = Bugzilla->localconfig->urlbase;
print $fh "digraph G {";
print $fh qq(
my $webdotbase = Bugzilla->params->{'webdotbase'};
if ($webdotbase =~ /^https?:/) {
- $webdotbase =~ s/%(?:sslbase|urlbase)%/Bugzilla->localconfig->{urlbase}/eg;
+ $webdotbase =~ s/%(?:sslbase|urlbase)%/Bugzilla->localconfig->urlbase/eg;
my $url = $webdotbase . $filename;
$vars->{'image_url'} = $url . ".gif";
$vars->{'map_url'} = $url . ".map";
});
ok($bug_1->id, "got a new bug");
-my $urlbase = Bugzilla->localconfig->{urlbase};
+my $urlbase = Bugzilla->localconfig->urlbase;
my $bug_1_id = $bug_1->id;
my $bug_2 = Bugzilla::Bug->create({
short_desc => 'A bug that references another bug',
use lib qw( . lib local/lib/perl5 );
use Bugzilla::Util qw(generate_random_password);
use Bugzilla::Token qw(issue_hash_sig check_hash_sig);
-use Test::More;
+use Bugzilla::Localconfig;
+use Test2::V0;
+use Test2::Mock qw(mock);
-my $localconfig = {site_wide_secret => generate_random_password(256)};
-{
+my $site_wide_secret = generate_random_password(256);
+my $Localconfig = mock 'Bugzilla::Localconfig' => (
+ add_constructor => [fake_new => 'ref_copy'],
+ override => [
+ site_wide_secret => sub { $site_wide_secret },
+ ]
+);
+{
package Bugzilla;
- sub localconfig {$localconfig}
+ sub localconfig { Bugzilla::Localconfig->fake_new({}) }
}
my $sig = issue_hash_sig("hero", "batman");
my $oauth_login = 'oauth@mozilla.bugs';
my $oauth_password = 'password123456789!';
-my $referer = Bugzilla->localconfig->{urlbase};
+my $referer = Bugzilla->localconfig->urlbase;
my $stash = {};
# Create user to use as OAuth2 resource owner
# Determine the numeric GID of $webservergroup
my $webgroupnum = 0;
-my $webservergroup = Bugzilla->localconfig->{webservergroup};
+my $webservergroup = Bugzilla->localconfig->webservergroup;
if ($webservergroup =~ /^(\d+)$/) {
$webgroupnum = $1;
}
That is a very insecure practice. Please refer to the
Bugzilla documentation.\n";
}
- elsif ($webgroupnum == $sgid || Bugzilla->localconfig->{use_suexec}) {
+ elsif ($webgroupnum == $sgid || Bugzilla->localconfig->use_suexec) {
print "TEST-OK Webserver is running under group id in \$webservergroup.\n";
}
else {