2022-03-24 18:52:35 +01:00
|
|
|
use v5.30.0;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2022-03-29 01:03:02 +02:00
|
|
|
use Test::Most tests => 6;
|
2022-03-24 19:06:01 +01:00
|
|
|
use Test::MockModule;
|
2022-03-24 18:52:35 +01:00
|
|
|
|
|
|
|
use Peace::Model::Application;
|
|
|
|
use Peace::Model::Developer;
|
|
|
|
|
2022-03-28 03:23:17 +02:00
|
|
|
use Peace::Test::Mock::Model::Developer;
|
|
|
|
|
2022-03-24 19:06:01 +01:00
|
|
|
use DBI;
|
|
|
|
|
2022-03-24 18:52:35 +01:00
|
|
|
BEGIN {
|
|
|
|
use_ok 'Peace::Model::Release';
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
## GIVEN
|
|
|
|
### Developer data.
|
|
|
|
my $developer_secret_bcrypt = 'hola';
|
|
|
|
my $developer_name = 'Larry';
|
|
|
|
my $developer_surname = 'Wall';
|
|
|
|
my $developer_email = 'larry@perl.org';
|
|
|
|
my $developer_country = 'US';
|
|
|
|
my $developer_verified = 0;
|
|
|
|
|
|
|
|
### Application data.
|
|
|
|
my $app_name = 'Desfronificator';
|
|
|
|
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';
|
2022-03-24 23:57:09 +01:00
|
|
|
my $app_flatpak_repo =
|
|
|
|
'https://nightly.gnome.org/gnome-nightly.flatpakrepo';
|
2022-03-24 18:52:35 +01:00
|
|
|
my $app_verified = 0;
|
|
|
|
my $app_developer = Peace::Model::Developer->new(
|
|
|
|
secret_bcrypt => $developer_secret_bcrypt,
|
|
|
|
name => $developer_name,
|
|
|
|
surname => $developer_surname,
|
|
|
|
email => $developer_email,
|
|
|
|
country => $developer_country,
|
|
|
|
verified => $developer_verified,
|
|
|
|
);
|
2022-03-29 18:47:25 +02:00
|
|
|
my $app_id = 'com.example.desfronificator';
|
2022-03-24 18:52:35 +01:00
|
|
|
### Release data.
|
|
|
|
my $release_application = Peace::Model::Application->new(
|
|
|
|
developer => $app_developer,
|
|
|
|
name => $app_name,
|
|
|
|
description => $app_description,
|
|
|
|
url => $app_url,
|
|
|
|
price => $app_price,
|
|
|
|
flatpak_builder_file => $app_flatpak_builder_file,
|
2022-03-24 23:57:09 +01:00
|
|
|
flatpak_repo => $app_flatpak_repo,
|
2022-03-24 18:52:35 +01:00
|
|
|
verified => $app_verified,
|
|
|
|
git_repo => $app_git_repo,
|
2022-03-29 18:47:25 +02:00
|
|
|
app_id => $app_id,
|
2022-03-24 18:52:35 +01:00
|
|
|
);
|
|
|
|
my $release_name = '0.0.1';
|
2022-03-24 19:06:01 +01:00
|
|
|
my $release_tag = 'v0.0.1';
|
2022-03-24 18:52:35 +01:00
|
|
|
|
|
|
|
## WHEN
|
|
|
|
my $release = Peace::Model::Release->new(
|
|
|
|
name => $release_name,
|
|
|
|
application => $release_application,
|
|
|
|
tag => $release_tag
|
|
|
|
);
|
|
|
|
## THEN
|
|
|
|
ok $release->isa('Peace::Model::Release'),
|
2022-03-24 19:06:01 +01:00
|
|
|
'Instanced release is made of Peace::Model::Release.';
|
2022-03-24 18:52:35 +01:00
|
|
|
is $release->name, $release_name, 'Name is correctly setup';
|
2022-03-24 19:06:01 +01:00
|
|
|
is $release->uuid, undef, 'Uuid is undef.';
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
## GIVEN
|
|
|
|
### Developer data.
|
|
|
|
my $developer_secret_bcrypt = 'hola';
|
|
|
|
my $developer_name = 'Larry';
|
|
|
|
my $developer_surname = 'Wall';
|
|
|
|
my $developer_email = 'larry@perl.org';
|
|
|
|
my $developer_country = 'US';
|
|
|
|
my $developer_verified = 0;
|
|
|
|
|
|
|
|
### Application data.
|
|
|
|
my $app_name = 'Desfronificator';
|
|
|
|
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';
|
2022-03-24 23:57:09 +01:00
|
|
|
my $app_flatpak_repo =
|
|
|
|
'https://nightly.gnome.org/gnome-nightly.flatpakrepo';
|
2022-03-24 19:06:01 +01:00
|
|
|
my $app_verified = 0;
|
|
|
|
my $app_developer = Peace::Model::Developer->new(
|
|
|
|
secret_bcrypt => $developer_secret_bcrypt,
|
|
|
|
name => $developer_name,
|
|
|
|
surname => $developer_surname,
|
|
|
|
email => $developer_email,
|
|
|
|
country => $developer_country,
|
|
|
|
verified => $developer_verified,
|
|
|
|
);
|
2022-03-29 18:47:25 +02:00
|
|
|
my $app_id = 'com.example.desfronificator';
|
2022-03-24 19:06:01 +01:00
|
|
|
### Release data.
|
|
|
|
my $release_application = Peace::Model::Application->new(
|
|
|
|
developer => $app_developer,
|
|
|
|
name => $app_name,
|
|
|
|
description => $app_description,
|
|
|
|
url => $app_url,
|
|
|
|
price => $app_price,
|
|
|
|
flatpak_builder_file => $app_flatpak_builder_file,
|
2022-03-24 23:57:09 +01:00
|
|
|
flatpak_repo => $app_flatpak_repo,
|
2022-03-24 19:06:01 +01:00
|
|
|
verified => $app_verified,
|
|
|
|
git_repo => $app_git_repo,
|
2022-03-29 18:47:25 +02:00
|
|
|
app_id => $app_id,
|
2022-03-24 19:06:01 +01:00
|
|
|
);
|
|
|
|
my $release_application_uuid = 'exampleuuid';
|
|
|
|
my $release_name = '0.0.1';
|
|
|
|
my $release_tag = 'v0.0.1';
|
|
|
|
my $release_dbh = DBI->connect('dbi:Mock:');
|
|
|
|
my $application_dao_mock_module =
|
|
|
|
Test::MockModule->new('Peace::DAO::Application');
|
|
|
|
$application_dao_mock_module->mock(
|
|
|
|
recover_by_uuid => sub {
|
|
|
|
return $release_application;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
## WHEN
|
|
|
|
my $release = Peace::Model::Release->new(
|
|
|
|
name => $release_name,
|
|
|
|
application_uuid => $release_application_uuid,
|
|
|
|
tag => $release_tag,
|
|
|
|
dbh => $release_dbh,
|
|
|
|
);
|
|
|
|
## THEN
|
|
|
|
is $release->application, $release_application, 'Uuid is undef.';
|
2022-03-24 18:52:35 +01:00
|
|
|
}
|
2022-03-29 01:03:02 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
my $developer = Peace::Test::Mock::Model::Developer->new;
|
|
|
|
my $application = Peace::Model::Application->new(
|
|
|
|
name => 'OpenMG',
|
|
|
|
description => 'Stub',
|
|
|
|
url => 'https://gitea.sergiotarxz.freemyip.com/sergiotarxz/mangareader',
|
|
|
|
developer => $developer,
|
|
|
|
price => '99',
|
|
|
|
git_repo =>
|
|
|
|
'https://gitea.sergiotarxz.freemyip.com/sergiotarxz/mangareader',
|
|
|
|
flatpak_builder_file => '../me.sergiotarxz.openmg.json',
|
|
|
|
flatpak_repo => 'https://nightly.gnome.org/gnome-nightly.flatpakrepo',
|
|
|
|
verified => 1,
|
2022-03-29 18:47:25 +02:00
|
|
|
app_id => 'com.example.desfronificator',
|
2022-03-29 01:03:02 +02:00
|
|
|
);
|
|
|
|
my $uuid = 'random-uuid';
|
|
|
|
my $release = Peace::Model::Release->new(
|
|
|
|
uuid => $uuid,
|
|
|
|
application => $application,
|
|
|
|
tag => 'main',
|
|
|
|
name => 'test',
|
|
|
|
);
|
|
|
|
my $result = $release->generate_build( arch => 'x86_64' );
|
2022-03-29 18:47:25 +02:00
|
|
|
ok !$result->{success},
|
|
|
|
'Build ends fail if flatpak_builder_file contains a .. component to avoid a directory escape vulnerability..';
|
2022-03-29 01:03:02 +02:00
|
|
|
}
|