diff --git a/db_tests/00003-application-dao.t b/db_tests/00003-application-dao.t index 51b7812..9fb532e 100644 --- a/db_tests/00003-application-dao.t +++ b/db_tests/00003-application-dao.t @@ -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; diff --git a/db_tests/00004-release-dao.t b/db_tests/00004-release-dao.t index 5ad0191..e90234d 100644 --- a/db_tests/00004-release-dao.t +++ b/db_tests/00004-release-dao.t @@ -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; diff --git a/doc/lib/Peace/Model/Application.pm.html b/doc/lib/Peace/Model/Application.pm.html index c0c695b..39227e9 100644 --- a/doc/lib/Peace/Model/Application.pm.html +++ b/doc/lib/Peace/Model/Application.pm.html @@ -28,6 +28,7 @@
Allows to retrieve and set the application's developer which is a Peace::Model::Developer.
+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.
+my $price = $application->price;
diff --git a/lib/Peace/DAO/Application.pm b/lib/Peace/DAO/Application.pm
index 48a811f..cfdd5ce 100644
--- a/lib/Peace/DAO/Application.pm
+++ b/lib/Peace/DAO/Application.pm
@@ -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
diff --git a/lib/Peace/DB.pm b/lib/Peace/DB.pm
index 7fea43e..413a672 100644
--- a/lib/Peace/DB.pm
+++ b/lib/Peace/DB.pm
@@ -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)
diff --git a/lib/Peace/Model/Application.pm b/lib/Peace/Model/Application.pm
index f429717..c1567af 100644
--- a/lib/Peace/Model/Application.pm
+++ b/lib/Peace/Model/Application.pm
@@ -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.
+=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;
diff --git a/lib/Peace/Test/Mock/Model/Application.pm b/lib/Peace/Test/Mock/Model/Application.pm
index 640b4be..f2d5ee7 100644
--- a/lib/Peace/Test/Mock/Model/Application.pm
+++ b/lib/Peace/Test/Mock/Model/Application.pm
@@ -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
diff --git a/t/00005-developer-model.t b/t/00005-developer-model.t
index 31f6dae..eb9b88f 100644
--- a/t/00005-developer-model.t
+++ b/t/00005-developer-model.t
@@ -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 {
diff --git a/t/00007-application-model.t b/t/00007-application-model.t
index 2b9c301..503c04f 100644
--- a/t/00007-application-model.t
+++ b/t/00007-application-model.t
@@ -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
diff --git a/t/00008-application-dao.t b/t/00008-application-dao.t
index 41eb6c9..0f1115f 100644
--- a/t/00008-application-dao.t
+++ b/t/00008-application-dao.t
@@ -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,
],
]
};
diff --git a/t/00009-release-model.t b/t/00009-release-model.t
index c24cc90..4c99208 100644
--- a/t/00009-release-model.t
+++ b/t/00009-release-model.t
@@ -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..';
}