Skip to content

Commit

Permalink
Merge pull request #1047 from matsduf/merge-develop-into-master
Browse files Browse the repository at this point in the history
Merge develop into master (Backend)
  • Loading branch information
matsduf authored Jul 8, 2022
2 parents 5a1359a + 3344485 commit 8aacc32
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 74 deletions.
9 changes: 9 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
Release history for Zonemaster component Zonemaster-Backend


v9.0.1 2022-07-08 (public fix release)

[Fixes]
- Corrects a bug where Zonemaster-Backend does not respect the IPv4 or
IPV6 setting in a custom profile (#1046, #1039)
- Updates the Danish translation (#1034)


v9.0.0 2022-06-09 (public release release)

[Deprecation]
Expand Down
2 changes: 1 addition & 1 deletion Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ requires
'Starman' => 0,
'String::ShellQuote' => 0,
'Try::Tiny' => 0.12,
'Zonemaster::Engine' => 4.005,
'Zonemaster::Engine' => 4.005001,
'Zonemaster::LDNS' => 2.002002,
'Plack::Middleware::ReverseProxy' => 0,
'Locale::TextDomain' => 1.20,
Expand Down
2 changes: 1 addition & 1 deletion lib/Zonemaster/Backend.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package Zonemaster::Backend;

our $VERSION = '9.0.0';
our $VERSION = '9.0.1';

use strict;
use warnings;
Expand Down
46 changes: 45 additions & 1 deletion lib/Zonemaster/Backend/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use Zonemaster::Backend::DB;

Readonly my @SIG_NAME => split ' ', $Config{sig_name};

=head1 STATIC METHODS
=head1 CLASS METHODS
=head2 get_default_path
Expand Down Expand Up @@ -63,6 +63,50 @@ sub get_default_path {
return $path // croak "File not found: backend_config.ini\n";
}

=head2 load_profiles
Loads and returns a set of named profiles.
my %all_profiles = (
$config->PUBLIC_PROFILES,
$config->PRIVATE_PROFILES,
);
my %profiles = %{ Zonemaster::Backend::Config->load_profiles( %all_profiles ) };
Takes a hash mapping profile names to profile paths.
An `undef` path value means the default profile.
Returns a hashref mapping profile names to profile objects.
The returned profiles have omitted values filled in with defaults from the
default profile.
Dies if any of the given paths cannot be read or their contents cannot be parsed
as JSON.
=cut

sub load_profiles {
my ( $class, %profile_paths ) = @_;

my %profiles;
foreach my $name ( keys %profile_paths ) {
my $path = $profile_paths{$name};

my $full_profile = Zonemaster::Engine::Profile->default;
if ( defined $path ) {
my $json = eval { read_file( $path, err_mode => 'croak' ) } #
// die "Error loading profile '$name': $@";
my $named_profile = eval { Zonemaster::Engine::Profile->from_json( $json ) } #
// die "Error loading profile '$name' at '$path': $@";
$full_profile->merge( $named_profile );
}
$profiles{$name} = $full_profile;
}

return \%profiles;
}

=head1 CONSTRUCTORS
=head2 load_config
Expand Down
7 changes: 2 additions & 5 deletions lib/Zonemaster/Backend/DB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use Log::Any qw( $log );
use POSIX qw( strftime );
use Try::Tiny;

use Zonemaster::Engine::Profile;
use Zonemaster::Backend::Errors;

requires qw(
Expand Down Expand Up @@ -612,13 +611,11 @@ sub _normalize_domain {
sub _project_params {
my ( $self, $params ) = @_;

my $profile = Zonemaster::Engine::Profile->effective;

my %projection = ();

$projection{domain} = _normalize_domain( $$params{domain} // "" );
$projection{ipv4} = $$params{ipv4} // $profile->get( 'net.ipv4' );
$projection{ipv6} = $$params{ipv6} // $profile->get( 'net.ipv6' );
$projection{ipv4} = $$params{ipv4};
$projection{ipv6} = $$params{ipv6};
$projection{profile} = lc( $$params{profile} // "default" );

my $array_ds_info = $$params{ds_info} // [];
Expand Down
24 changes: 20 additions & 4 deletions lib/Zonemaster/Backend/RPCAPI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use Encode;

# Zonemaster Modules
use Zonemaster::Engine;
use Zonemaster::Engine::Profile;
use Zonemaster::Engine::Recursor;
use Zonemaster::Backend;
use Zonemaster::Backend::Config;
Expand Down Expand Up @@ -59,6 +60,11 @@ sub new {

$self->_init_db($dbtype);

$self->{_profiles} = Zonemaster::Backend::Config->load_profiles( #
$self->{config}->PUBLIC_PROFILES,
$self->{config}->PRIVATE_PROFILES,
);

return ( $self );
}

Expand Down Expand Up @@ -257,8 +263,13 @@ sub start_domain_test {

die "No domain in parameters\n" unless ( defined $params->{domain} && length($params->{domain}) );

$params->{priority} //= 10;
$params->{queue} //= 0;
$params->{profile} //= "default";
$params->{priority} //= 10;
$params->{queue} //= 0;

my $profile = $self->{_profiles}{ $params->{profile} };
$params->{ipv4} //= $profile->get( "net.ipv4" );
$params->{ipv6} //= $profile->get( "net.ipv6" );

$result = $self->{db}->create_new_test( $params->{domain}, $params, $self->{config}->ZONEMASTER_age_reuse_previous_test );
};
Expand Down Expand Up @@ -514,8 +525,13 @@ sub add_batch_job {

my $results;
eval {
$params->{test_params}->{priority} //= 5;
$params->{test_params}->{queue} //= 0;
$params->{test_params}{profile} //= "default";
$params->{test_params}{priority} //= 5;
$params->{test_params}{queue} //= 0;

my $profile = $self->{_profiles}{ $params->{test_params}{profile} };
$params->{test_params}{ipv4} //= $profile->get( "net.ipv4" );
$params->{test_params}{ipv6} //= $profile->get( "net.ipv6" );

$results = $self->{db}->add_batch_job( $params );
};
Expand Down
18 changes: 4 additions & 14 deletions lib/Zonemaster/Backend/TestAgent.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,10 @@ sub new {
my $dbclass = Zonemaster::Backend::DB->get_db_class( $dbtype );
$self->{_db} = $dbclass->from_config( $config );

my %all_profiles = ( $config->PUBLIC_PROFILES, $config->PRIVATE_PROFILES );
foreach my $name ( keys %all_profiles ) {
my $path = $all_profiles{$name};

my $full_profile = Zonemaster::Engine::Profile->default;
if ( defined $path ) {
my $json = eval { read_file( $path, err_mode => 'croak' ) } #
// die "Error loading profile '$name': $@";
my $named_profile = eval { Zonemaster::Engine::Profile->from_json( $json ) } #
// die "Error loading profile '$name' at '$path': $@";
$full_profile->merge( $named_profile );
}
$self->{_profiles}{$name} = $full_profile;
}
$self->{_profiles} = Zonemaster::Backend::Config->load_profiles( #
$config->PUBLIC_PROFILES,
$config->PRIVATE_PROFILES,
);

bless( $self, $class );
return $self;
Expand Down
84 changes: 44 additions & 40 deletions share/da.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,75 @@ msgid ""
msgstr ""
"Project-Id-Version: 1.0.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-12-07 15:34+0000\n"
"PO-Revision-Date: 2021-10-14 11:25+0200\n"
"POT-Creation-Date: 2022-06-08 14:31+0000\n"
"PO-Revision-Date: 2022-06-08 14:26+0000\n"
"Last-Translator: [email protected]\n"
"Language-Team: Zonemaster project\n"
"Language: da\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

msgid "Invalid method parameter(s)."
msgstr "Invalid metodeparametre"

msgid "Missing property"
msgstr "Manglende egenskab"

msgid ""
"Warning: Zonemaster::LDNS not compiled with IDN support, cannot handle non-"
"ASCII names correctly."
msgstr ""
"Advarsel: Zonemaster::LDNS ikke kompileret med IDN-support, og kan derfor "
"ikke håndtere ikke-ascii-navne korrekt"

msgid "Invalid digest format"
msgstr "Invalid digest-format"

msgid "Algorithm must be a positive integer"
msgstr "Algoritmen skal være et positivt heltal"

msgid "Digest type must be a positive integer"
msgstr "Digest type skal være et positivt heltal"

msgid "Keytag must be a positive integer"
msgstr "Keytag skal være et positivt heltal"

msgid "Domain name required"
msgstr "Domænenavn påkrævet"

msgid "The domain name is IDNA invalid"
msgstr "Domænenavnet er IDNA ugyldigt"

msgid ""
"The domain name is not a valid IDNA string and cannot be converted to an A-"
"label"
"The domain name contains non-ascii characters and IDNA support is not "
"installed"
msgstr ""
"Domænenavnet er ikke en valid IDNA-streng og kan ikke konverteres til en A-label"

msgid "The domain name contains non-ascii characters and IDNA is not installed"
msgstr "Domænenavnet indeholder ikke-ascii-tegn og IDNA er ikke installeret"
"Domænenavnet indeholder ikke-ascii-tegn og IDNA-support er ikke installeret"

msgid "The domain name character(s) are not supported"
msgstr "Domænenavnets tegn er ikke understøttet"

msgid "The domain name contains consecutive dots"
msgstr "Domænenavnet indeholder flere dots (.) efter hinanden"

msgid "The domain name or label is too long"
msgstr "Domænenavnet eller labelen er for lang"

msgid "Unknown profile"
msgstr "Ukendt profil"

msgid "Invalid IP address"
msgstr "Invalid IP-adresse"
msgid "Invalid language tag format"
msgstr "Invalidt sprogkode-format"

msgid "Unkown language string"
msgstr "Ukendt sprogstreng"

msgid "Language string not unique"
msgstr "Sprogstreng ikke unik"

msgid "Invalid method parameter(s)."
msgstr "Invalid metodeparametre"

msgid "Missing property"
msgstr "Manglende egenskab"

msgid ""
"Warning: Zonemaster::LDNS not compiled with libidn2, cannot handle non-ASCII "
"names correctly."
msgstr "Advarsel: Zonemaster::LDNS ikke kompileret med libidn2 - kan ikke "
"håndtere ikke-ascii-navne korrekt"

msgid "The domain name contains a character or characters not supported"
msgstr "Domænenavnet indeholder et eller flere ikke understøttede tegn"

msgid "Invalid digest format"
msgstr "Invalid digest format"

msgid "Algorithm must be a positive integer"
msgstr "Algoritmen skal være et positivt heltal"

msgid "Digest type must be a positive integer"
msgstr "Digest type skal være et positivt heltal"
msgid "Invalid IP address"
msgstr "Invalid IP-adresse"

msgid "Keytag must be a positive integer"
msgstr "Keytag skal være et positivt heltal"
msgid "Invalid profile format"
msgstr "Invalidt profil-format"

msgid "Invalid language tag format"
msgstr "Invalidt sprogkodeformat"
msgid "Unknown profile"
msgstr "Ukendt profil"
18 changes: 10 additions & 8 deletions t/db.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ sub encode_and_fingerprint {
subtest 'encoding and fingerprint' => sub {

subtest 'missing properties' => sub {
my $expected_encoded_params = '{"domain":"example.com","ds_info":[],"ipv4":true,"ipv6":true,"nameservers":[],"profile":"default"}';

my %params = ( domain => "example.com" );

my $expected_encoded_params = '{"domain":"example.com","ds_info":[],"ipv4":null,"ipv6":null,"nameservers":[],"profile":"default"}';
my ( $encoded_params, $fingerprint ) = encode_and_fingerprint( \%params );
is $encoded_params, $expected_encoded_params, 'domain only: the encoded strings should match';
#diag ($fingerprint);

my $expected_encoded_params_v4_true = '{"domain":"example.com","ds_info":[],"ipv4":true,"ipv6":null,"nameservers":[],"profile":"default"}';
$params{ipv4} = JSON::PP->true;
my ( $encoded_params_ipv4, $fingerprint_ipv4 ) = encode_and_fingerprint( \%params );
is $encoded_params_ipv4, $expected_encoded_params, 'add ipv4: the encoded strings should match';
is $fingerprint_ipv4, $fingerprint, 'fingerprints should match';
is $encoded_params_ipv4, $expected_encoded_params_v4_true, 'add ipv4: the encoded strings should match';
isnt $fingerprint_ipv4, $fingerprint, 'fingerprints should not match';
};

subtest 'array properties' => sub {
Expand Down Expand Up @@ -121,7 +121,7 @@ subtest 'encoding and fingerprint' => sub {
};

subtest 'garbage properties set' => sub {
my $expected_encoded_params = '{"client":"GUI v3.3.0","domain":"example.com","ds_info":[],"ipv4":true,"ipv6":true,"nameservers":[],"profile":"default"}';
my $expected_encoded_params = '{"client":"GUI v3.3.0","domain":"example.com","ds_info":[],"ipv4":null,"ipv6":null,"nameservers":[],"profile":"default"}';
my %params1 = (
domain => "example.com",
);
Expand Down Expand Up @@ -174,6 +174,8 @@ subtest 'encoding and fingerprint' => sub {
my $expected_fingerprint = '8c64f7feaa3f13b77e769720991f2a79';

my %params = ( domain => "café.example" );
$params{ipv4} = JSON::PP->true;
$params{ipv6} = JSON::PP->true;

my ( $encoded_params, $fingerprint ) = encode_and_fingerprint( \%params );
is $encoded_params, $expected_encoded_params, 'IDN domain: the encoded strings should match';
Expand All @@ -184,7 +186,7 @@ subtest 'encoding and fingerprint' => sub {
subtest 'in domain' => sub {
my %params1 = ( domain => "example.com" );
my %params2 = ( domain => "example.com." );
my $expected_encoded_params = encode_utf8( '{"domain":"example.com","ds_info":[],"ipv4":true,"ipv6":true,"nameservers":[],"profile":"default"}' );
my $expected_encoded_params = encode_utf8( '{"domain":"example.com","ds_info":[],"ipv4":null,"ipv6":null,"nameservers":[],"profile":"default"}' );

my ( $encoded_params1, $fingerprint1 ) = encode_and_fingerprint( \%params1 );
my ( $encoded_params2, $fingerprint2 ) = encode_and_fingerprint( \%params2 );
Expand All @@ -196,7 +198,7 @@ subtest 'encoding and fingerprint' => sub {
subtest 'in nameserver' => sub {
my %params1 = ( domain => "example.com", nameservers => [ { ns => "ns1.example.com." } ] );
my %params2 = ( domain => "example.com", nameservers => [ { ns => "ns1.example.com" } ] );
my $expected_encoded_params = encode_utf8( '{"domain":"example.com","ds_info":[],"ipv4":true,"ipv6":true,"nameservers":[{"ns":"ns1.example.com"}],"profile":"default"}' );
my $expected_encoded_params = encode_utf8( '{"domain":"example.com","ds_info":[],"ipv4":null,"ipv6":null,"nameservers":[{"ns":"ns1.example.com"}],"profile":"default"}' );

my ( $encoded_params1, $fingerprint1 ) = encode_and_fingerprint( \%params1 );
my ( $encoded_params2, $fingerprint2 ) = encode_and_fingerprint( \%params2 );
Expand All @@ -207,7 +209,7 @@ subtest 'encoding and fingerprint' => sub {

subtest 'root is not modified' => sub {
my %params = ( domain => "." );
my $expected_encoded_params = encode_utf8( '{"domain":".","ds_info":[],"ipv4":true,"ipv6":true,"nameservers":[],"profile":"default"}' );
my $expected_encoded_params = encode_utf8( '{"domain":".","ds_info":[],"ipv4":null,"ipv6":null,"nameservers":[],"profile":"default"}' );

my ( $encoded_params, $fingerprint ) = encode_and_fingerprint( \%params );
is $encoded_params, $expected_encoded_params, 'the encoded strings should match';
Expand Down

0 comments on commit 8aacc32

Please sign in to comment.