Adding a app_id field to applications database which must remain unique.

This commit is contained in:
sergiotarxz 2022-03-29 18:47:25 +02:00
parent cd17423eb5
commit 20b74912fa
11 changed files with 101 additions and 75 deletions

View File

@ -38,6 +38,8 @@ use Peace::Test::Mock::Model::Application;
$application->developer($developer);
my $application_dao = Peace::DAO::Application->new( dbh => $dbh );
$application->app_id("com.example.desfronificator@{[int(rand(10000000))]}");
## WHEN
$application_dao->create( application => $application );
@ -67,6 +69,7 @@ use Peace::Test::Mock::Model::Application;
my $application_dao = Peace::DAO::Application->new( dbh => $dbh );
$application->app_id("com.example.desfronificator@{[int(rand(10000000))]}");
$application_dao->create( application => $application );
$developer->{dbh} = $dbh;

View File

@ -41,6 +41,7 @@ use Peace::Test::Mock::Model::Release;
my $application_dao = Peace::DAO::Application->new( dbh => $dbh );
$application->app_id("com.example.desfronificator@{[int(rand(10000000))]}");
$application_dao->create( application => $application );
my $release = Peace::Test::Mock::Model::Release->new;

View File

@ -28,6 +28,7 @@
<li><a href="#description">description</a></li>
<li><a href="#url">url</a></li>
<li><a href="#developer">developer</a></li>
<li><a href="#app_id">app_id</a></li>
<li><a href="#price">price</a></li>
<li><a href="#git_repo">git_repo</a></li>
<li><a href="#flatpak_builder_file">flatpak_builder_file</a></li>
@ -132,6 +133,14 @@ $application-&gt;developer($developer);</code></pre>
<p>Allows to retrieve and set the application&#39;s developer which is a <a href="Developer.pm.html">Peace::Model::Developer</a>.</p>
<h2 id="app_id">app_id</h2>
<pre><code>my $app_id = $application-&gt;app_id;
$application-&gt;app_id($app_id);</code></pre>
<p>Allows to retrieve and set the application&#39;s id which represents the flatpak identifier.</p>
<h2 id="price">price</h2>
<pre><code>my $price = $application-&gt;price;

View File

@ -44,18 +44,18 @@ use Types::Standard qw/HasMethods InstanceOf Str HashRef/;
my $insert = <<'EOF';
INSERT INTO applications
(name, description, url,
developer, price, git_repo,
developer, app_id, price, git_repo,
flatpak_builder_file, flatpak_repo, verified)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
RETURNING uuid;
EOF
my $result = $dbh->selectrow_hashref(
$insert, undef,
$application->name, $application->description,
$application->url, $application->developer->uuid,
$application->price, $application->git_repo,
$application->flatpak_builder_file, $application->flatpak_repo,
$application->verified
$insert, undef,
$application->name, $application->description,
$application->url, $application->developer->uuid,
$application->app_id, $application->price,
$application->git_repo, $application->flatpak_builder_file,
$application->flatpak_repo, $application->verified
);
my $uuid = $result->{uuid};
my $new_application = $self->recover_by_uuid( uuid => $uuid );
@ -88,7 +88,7 @@ EOF
$dbh->selectall_arrayref(
<<'EOF', { Slice => {} }, $developer->uuid );
SELECT uuid, date_creation, name,
description, url, developer,
description, url, developer, app_id,
price, git_repo, flatpak_builder_file,
flatpak_repo, verified
FROM applications
@ -114,7 +114,7 @@ EOF
my $uuid = $params{uuid};
my $result = $dbh->selectrow_hashref( <<'EOF', undef, $uuid );
SELECT uuid, date_creation, name,
description, url, developer,
description, url, developer, app_id,
price, git_repo, flatpak_builder_file,
flatpak_repo, verified
FROM applications

View File

@ -45,6 +45,7 @@ my @migrations = (
developer UUID NOT NULL,
price INTEGER NOT NULL,
git_repo TEXT NOT NULL,
app_id TEXT NOT NULL UNIQUE,
flatpak_builder_file TEXT NOT NULL,
flatpak_repo TEXT NOT NULL,
verified BOOL DEFAULT false,
@ -64,6 +65,8 @@ my @migrations = (
uuid UUID NOT NULL DEFAULT gen_random_uuid(),
release UUID NOT NULL,
date_creation timestamp DEFAULT NOW(),
success BOOLEAN NOT NULL,
log TEXT NOT NULL,
arch TEXT NOT NULL,
PRIMARY KEY (uuid),
FOREIGN KEY (release) REFERENCES releases (uuid)

View File

@ -24,6 +24,7 @@ use DateTime;
{ type => InstanceOf ['Peace::Model::Developer'], optional => 1 },
developer_uuid => { type => Str, optional => 1 },
dbh => { type => HasMethods ['selectrow_hashref'], optional => 1 },
app_id => { type => Str },
price => { type => Num },
git_repo => { type => Str },
flatpak_builder_file => { type => Str },
@ -137,6 +138,26 @@ use DateTime;
}
}
{
my $validator = validation_for(
params => [
{
type => Str,
optional => 1,
}
]
);
sub app_id {
my $self = shift;
if (@_) {
my ($new_app_id) = $validator->(@_);
$self->{app_id} = $new_app_id;
}
return $self->{app_id};
}
}
{
my $validator =
validation_for( params => [ { type => Num, optional => 1 } ] );
@ -310,6 +331,15 @@ Allows to retrieve and set the application's url.
Allows to retrieve and set the application's developer which
is a L<Peace::Model::Developer>.
=head2 app_id
my $app_id = $application->app_id;
$application->app_id($app_id);
Allows to retrieve and set the application's id which represents
the flatpak identifier.
=head2 price
my $price = $application->price;

View File

@ -15,6 +15,7 @@ sub new {
name => 'Desfronificator',
description => 'Desfronifies the files.',
url => 'desfronificator.example.com',
app_id => 'com.example.desfronificator',
developer => Peace::Test::Mock::Model::Developer->new,
price => 0,
flatpak_builder_file => './resources/com.example.desfronificator.yml',
@ -25,6 +26,7 @@ sub new {
);
}
1;
=encoding utf8
=head1 NAME

View File

@ -9,6 +9,7 @@ use Test::MockModule;
use DBI;
use Peace::Model::Application;
use Peace::Test::Mock::Model::Application;
BEGIN {
use_ok 'Peace::Model::Developer';
@ -78,21 +79,6 @@ BEGIN {
my $verified = 0;
my $dbh = DBI->connect( 'DBI:Mock:', '', '' );
### Application data
my $app_name0 = 'Desfronificator';
my $app_name1 = 'Desfronificator 1.0';
my $app_description = 'Desfronifies the files.';
my $app_url = 'https://desfronificator.example.com';
my $app_price = '4.20';
my $app_git_repo =
'https://git.desfronificator.example.com/larry/desfronificator.git';
my $app_flatpak_builder_file =
'./resources/com.example.desfronificator.yml';
my $app_flatpak_repo =
'https://nightly.gnome.org/gnome-nightly.flatpakrepo';
my $app_verified = 0;
my $developer = Peace::Model::Developer->new(
secret_bcrypt => $secret_bcrypt,
name => $name,
@ -104,29 +90,8 @@ BEGIN {
);
my $applications = [
Peace::Model::Application->new(
name => $app_name0,
description => $app_description,
url => $app_url,
price => $app_price,
git_repo => $app_git_repo,
flatpak_builder_file => $app_flatpak_builder_file,
flatpak_repo => $app_flatpak_repo,
verified => $app_verified,
developer => $developer,
),
Peace::Model::Application->new(
name => $app_name1,
description => $app_description,
url => $app_url,
price => $app_price,
git_repo => $app_git_repo,
flatpak_builder_file => $app_flatpak_builder_file,
flatpak_repo => $app_flatpak_repo,
verified => $app_verified,
developer => $developer,
),
Peace::Test::Mock::Model::Application->new,
Peace::Test::Mock::Model::Application->new,
];
$application_dao_mock->mock(
recover_by_developer => sub {

View File

@ -46,10 +46,12 @@ BEGIN {
country => $country,
verified => $verified,
);
my $app_id = 'com.example.desfronificator';
## WHEN
my $application = Peace::Model::Application->new(
developer => $developer,
app_id => $app_id,
name => $app_name,
description => $app_description,
url => $app_url,
@ -96,6 +98,7 @@ BEGIN {
country => $country,
verified => $verified,
);
my $app_id = 'com.example.desfronificator';
my $developer_dao = Test::MockModule->new('Peace::DAO::Developer');
$developer_dao->mock(
@ -116,6 +119,7 @@ BEGIN {
verified => $app_verified,
git_repo => $app_git_repo,
dbh => $dbh,
app_id => $app_id,
);
## THEN

View File

@ -22,19 +22,18 @@ BEGIN {
my $sql = <<'EOF';
INSERT INTO applications
(name, description, url,
developer, price, git_repo,
developer, app_id, price, git_repo,
flatpak_builder_file, flatpak_repo, verified)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
RETURNING uuid;
EOF
my $dbh = DBI->connect( 'DBI:Mock:', '', '' );
my $dbh = DBI->connect( 'DBI:Mock:', '', '' );
my $developer = Peace::Test::Mock::Model::Developer->new;
$developer->uuid('hola');
my $application = Peace::Test::Mock::Model::Application->new;
my $uuid = 'hola';
my $uuid = 'hola';
my $application_dao = Peace::DAO::Application->new( dbh => $dbh );
@ -44,7 +43,7 @@ EOF
};
$sql = <<'EOF';
SELECT uuid, date_creation, name,
description, url, developer,
description, url, developer, app_id,
price, git_repo, flatpak_builder_file,
flatpak_repo, verified
FROM applications
@ -56,12 +55,12 @@ EOF
sql => $sql,
results => [
[
'uuid', 'date_creation',
'name', 'description',
'url', 'developer',
'price', 'git_repo',
'flatpak_builder_file', 'flatpak_repo',
'verified',
'uuid', 'date_creation',
'name', 'description',
'url', 'developer',
'app_id', 'price',
'git_repo', 'flatpak_builder_file',
'flatpak_repo', 'verified',
],
[
$uuid,
@ -70,6 +69,7 @@ EOF
$application->description,
$application->url,
$developer->uuid,
$application->app_id,
$application->price,
$application->git_repo,
$application->flatpak_builder_file,
@ -87,17 +87,17 @@ EOF
}
{
my $dbh = DBI->connect( 'DBI:Mock:', '', '' );
my $developer = Peace::Test::Mock::Model::Developer->new;
my $dbh = DBI->connect( 'DBI:Mock:', '', '' );
my $developer = Peace::Test::Mock::Model::Developer->new;
my $application_mock = Peace::Test::Mock::Model::Application->new;
my $uuid = 'hola';
my $uuid = 'hola';
my $application_dao = Peace::DAO::Application->new( dbh => $dbh );
$application_mock->developer->uuid('hola');
my $sql = <<'EOF';
SELECT uuid, date_creation, name,
description, url, developer,
description, url, developer, app_id,
price, git_repo, flatpak_builder_file,
flatpak_repo, verified
FROM applications
@ -109,12 +109,12 @@ EOF
sql => $sql,
results => [
[
'uuid', 'date_creation',
'name', 'description',
'url', 'developer',
'price', 'git_repo',
'flatpak_builder_file', 'flatpak_repo',
'verified',
'uuid', 'date_creation',
'name', 'description',
'url', 'developer',
'app_id', 'price',
'git_repo', 'flatpak_builder_file',
'flatpak_repo', 'verified',
],
[
$uuid,
@ -123,6 +123,7 @@ EOF
$application_mock->description,
$application_mock->url,
$application_mock->developer->uuid,
$application_mock->app_id,
$application_mock->price,
$application_mock->git_repo,
$application_mock->flatpak_builder_file,
@ -142,15 +143,15 @@ EOF
## GIVEN
my $sql = <<'EOF';
SELECT uuid, date_creation, name,
description, url, developer,
description, url, developer, app_id,
price, git_repo, flatpak_builder_file,
flatpak_repo, verified
FROM applications
WHERE developer = ?;
EOF
my $dbh = DBI->connect( 'DBI:Mock:', '', '' );
my $developer = Peace::Test::Mock::Model::Developer->new;
my $dbh = DBI->connect( 'DBI:Mock:', '', '' );
my $developer = Peace::Test::Mock::Model::Developer->new;
$developer->uuid('hola');
### Application data
@ -168,6 +169,7 @@ EOF
'https://nightly.gnome.org/gnome-nightly.flatpakrepo';
my $app_verified = 0;
my $iso8601 = DateTime::Format::Pg->new;
my $app_id = 'com.example.desfronificator';
$dbh->{mock_add_resultset} = {
sql => $sql,
results => [
@ -177,7 +179,7 @@ EOF
'url', 'price',
'git_repo', 'flatpak_builder_file',
'flatpak_repo', 'verified',
'developer'
'developer', 'app_id',
],
[
$app_uuid,
@ -191,6 +193,7 @@ EOF
$app_flatpak_repo,
$app_verified,
$developer->uuid,
$app_id,
],
]
};

View File

@ -47,6 +47,7 @@ BEGIN {
country => $developer_country,
verified => $developer_verified,
);
my $app_id = 'com.example.desfronificator';
### Release data.
my $release_application = Peace::Model::Application->new(
developer => $app_developer,
@ -58,6 +59,7 @@ BEGIN {
flatpak_repo => $app_flatpak_repo,
verified => $app_verified,
git_repo => $app_git_repo,
app_id => $app_id,
);
my $release_name = '0.0.1';
my $release_tag = 'v0.0.1';
@ -105,6 +107,7 @@ BEGIN {
country => $developer_country,
verified => $developer_verified,
);
my $app_id = 'com.example.desfronificator';
### Release data.
my $release_application = Peace::Model::Application->new(
developer => $app_developer,
@ -116,6 +119,7 @@ BEGIN {
flatpak_repo => $app_flatpak_repo,
verified => $app_verified,
git_repo => $app_git_repo,
app_id => $app_id,
);
my $release_application_uuid = 'exampleuuid';
my $release_name = '0.0.1';
@ -153,6 +157,7 @@ BEGIN {
flatpak_builder_file => '../me.sergiotarxz.openmg.json',
flatpak_repo => 'https://nightly.gnome.org/gnome-nightly.flatpakrepo',
verified => 1,
app_id => 'com.example.desfronificator',
);
my $uuid = 'random-uuid';
my $release = Peace::Model::Release->new(
@ -162,5 +167,6 @@ BEGIN {
name => 'test',
);
my $result = $release->generate_build( arch => 'x86_64' );
ok !$result->{success}, 'Build ends fail if flatpak_builder_file contains a .. component to avoid a directory escape vulnerability..';
ok !$result->{success},
'Build ends fail if flatpak_builder_file contains a .. component to avoid a directory escape vulnerability..';
}