diff options
author | Mark Wells <mark@freeside.biz> | 2015-08-04 11:16:41 -0700 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2015-08-04 11:52:57 -0700 |
commit | ce1a26f5033acf26ccf0c922b2fc43cc2baa2bb9 (patch) | |
tree | e146ac70e272749658fe146e522931ad83a79269 /FS | |
parent | 908d425750365b7a2bf59334ccfc41adc9d61a17 (diff) |
de-randomization fixes for testing, #37340
Conflicts:
FS/FS/Conf.pm
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/Conf.pm | 7 | ||||
-rw-r--r-- | FS/FS/Mason.pm | 2 | ||||
-rw-r--r-- | FS/FS/Record.pm | 1 | ||||
-rw-r--r-- | FS/FS/UI/Web.pm | 33 |
4 files changed, 41 insertions, 2 deletions
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index c93608266..53459c721 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -5922,6 +5922,13 @@ and customer address. Include units.', 'type' => 'text', }, + { + 'key' => 'no_random_ids', + 'section' => '', + 'description' => 'Replace random identifiers in UI code with a static string, for repeatable testing. Don\'t use in production.', + 'type' => 'checkbox', + }, + ); 1; diff --git a/FS/FS/Mason.pm b/FS/FS/Mason.pm index 3d577f6d2..ae4f07cdb 100644 --- a/FS/FS/Mason.pm +++ b/FS/FS/Mason.pm @@ -136,7 +136,7 @@ if ( -e $addl_handler_use_file ) { use FS::Conf; use FS::CGI qw(header menubar table itable ntable idiot eidiot myexit http_header); - use FS::UI::Web qw(svc_url); + use FS::UI::Web qw(svc_url random_id); use FS::UI::Web::small_custview qw(small_custview); use FS::UI::bytecount; use FS::UI::REST qw( rest_auth rest_uri_remain encode_rest ); diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index 70d4f672e..d6892a96c 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -527,6 +527,7 @@ sub qsearch { # Check for encrypted fields and decrypt them. ## only in the local copy, not the cached object + no warnings 'deprecated'; # XXX silence the warning for now if ( $conf_encryption && eval '@FS::'. $table . '::encrypted_fields' ) { foreach my $record (@return) { diff --git a/FS/FS/UI/Web.pm b/FS/FS/UI/Web.pm index 6655f270f..13b2e2dc0 100644 --- a/FS/FS/UI/Web.pm +++ b/FS/FS/UI/Web.pm @@ -15,11 +15,13 @@ use FS::cust_main; # are sql_balance and sql_date_balance in the right module? #@ISA = qw( FS::UI ); @ISA = qw( Exporter ); -@EXPORT_OK = qw( svc_url ); +@EXPORT_OK = qw( svc_url random_id ); $DEBUG = 0; $me = '[FS::UID::Web]'; +our $NO_RANDOM_IDS; + ### # date parsing ### @@ -608,6 +610,35 @@ sub is_mobile { return 0; } +=item random_id [ DIGITS ] + +Returns a random number of length DIGITS, or if unspecified, a long random +identifier consisting of the timestamp, process ID, and a random number. +Anything in the UI that needs a random identifier should use this. + +=cut + +sub random_id { + my $digits = shift; + if (!defined $NO_RANDOM_IDS) { + my $conf = FS::Conf->new; + $NO_RANDOM_IDS = $conf->exists('no_random_ids') ? 1 : 0; + } + if ( $NO_RANDOM_IDS ) { + if ( $digits > 0 ) { + return 0; + } else { + return '0000000000-0000-000000000.000000'; + } + } else { + if ($digits > 0) { + return int(rand(10 ** $digits)); + } else { + return time . "-$$-" . rand() * 2**32; + } + } +} + =back =cut |