Peace/t/00009-release-model.t

173 lines
6.0 KiB
Perl
Raw Normal View History

use v5.30.0;
use strict;
use warnings;
use Test::Most tests => 6;
use Test::MockModule;
use Peace::Model::Application;
use Peace::Model::Developer;
use Peace::Test::Mock::Model::Developer;
use DBI;
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';
my $app_flatpak_repo =
'https://nightly.gnome.org/gnome-nightly.flatpakrepo';
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,
);
my $app_id = 'com.example.desfronificator';
### 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,
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';
## WHEN
my $release = Peace::Model::Release->new(
name => $release_name,
application => $release_application,
tag => $release_tag
);
## THEN
ok $release->isa('Peace::Model::Release'),
'Instanced release is made of Peace::Model::Release.';
is $release->name, $release_name, 'Name is correctly setup';
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';
my $app_flatpak_repo =
'https://nightly.gnome.org/gnome-nightly.flatpakrepo';
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,
);
my $app_id = 'com.example.desfronificator';
### 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,
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';
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.';
}
{
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,
app_id => 'com.example.desfronificator',
);
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' );
ok !$result->{success},
'Build ends fail if flatpak_builder_file contains a .. component to avoid a directory escape vulnerability..';
}