Skip to content

Commit

Permalink
Upgrade to PHP8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
santiagolizardo committed Jun 8, 2024
1 parent d19ccdd commit 47f7747
Show file tree
Hide file tree
Showing 14 changed files with 139 additions and 77 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "reconmap/rest-api",
"description": "Reconmap REST API",
"license": "Apache-2.0",
"minimum-stability": "dev",
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
"php": "^8.2",
"php": "^8.3",
"ext-curl": "*",
"ext-dom": "*",
"ext-gd": "*",
Expand Down Expand Up @@ -47,7 +47,7 @@
}
},
"require-dev": {
"phpunit/phpunit": "^11",
"phpunit/phpunit": "^10",
"icanhazstring/composer-unused": "^0.8.2"
},
"autoload-dev": {
Expand Down
18 changes: 9 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ services:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: reconmuppet
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 20s
retries: 10

keycloak:
image: quay.io/reconmap/keycloak-custom:latest
Expand Down Expand Up @@ -58,8 +62,8 @@ services:
ports:
- "8080:8080"
depends_on:
- mysql

mysql:
condition: service_healthy
api:
container_name: rmap-api
image: quay.io/reconmap/rest-api:latest
Expand Down
16 changes: 9 additions & 7 deletions docker/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM debian:bullseye-slim
FROM debian:bookworm-slim

ARG PHP_VERSION=8.3

ARG DEBIAN_FRONTEND=noninteractive

Expand All @@ -7,26 +9,26 @@ RUN apt-get install -y wget unzip lsb-release
RUN wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
RUN echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list
RUN apt-get update
RUN apt-get install -y php8.2 php8.2-cli php8.2-fpm php8.2-mysqlnd php8.2-dom php8.2-mbstring php8.2-intl php8.2-xdebug php8.2-curl php8.2-gd php8.2-zip
RUN apt-get install -y php${PHP_VERSION} php${PHP_VERSION}-cli php${PHP_VERSION}-fpm php${PHP_VERSION}-mysqlnd php${PHP_VERSION}-dom php${PHP_VERSION}-mbstring php${PHP_VERSION}-intl php${PHP_VERSION}-xdebug php${PHP_VERSION}-curl php${PHP_VERSION}-gd php${PHP_VERSION}-zip
RUN apt-get install -y nginx

RUN apt-get update && apt-get install -y php8.2-dev php-pear && \
RUN apt-get update && apt-get install -y php${PHP_VERSION}-dev php-pear && \
pecl channel-update pecl.php.net && \
pecl install redis && \
bash -c "echo extension=redis.so | tee /etc/php/8.2/{fpm,cli}/conf.d/30-redis.ini > /dev/null"
bash -c "echo extension=redis.so | tee /etc/php/${PHP_VERSION}/{fpm,cli}/conf.d/30-redis.ini > /dev/null"

RUN wget --no-verbose https://getcomposer.org/installer -O - -q | php -- --install-dir=/usr/local/bin/ --filename=composer --quiet

RUN apt-get install -y cron
COPY docker/api/crontab.txt /tmp/crontab
RUN crontab /tmp/crontab && rm /tmp/crontab

RUN sed -i "s/;clear_env = no/clear_env = no/" /etc/php/8.2/fpm/pool.d/www.conf
RUN sed -i "s/;clear_env = no/clear_env = no/" /etc/php/${PHP_VERSION}/fpm/pool.d/www.conf
RUN rm /etc/nginx/sites-enabled/default
COPY docker/api/nginx/sites-enabled/* /etc/nginx/sites-enabled/

RUN sed -i 's/upload_max_filesize = [[:digit:]]\+M/upload_max_filesize = 20M/' /etc/php/8.2/fpm/php.ini
RUN sed -i 's/post_max_size = [[:digit:]]\+M/post_max_size = 28M/' /etc/php/8.2/fpm/php.ini
RUN sed -i 's/upload_max_filesize = [[:digit:]]\+M/upload_max_filesize = 20M/' /etc/php/${PHP_VERSION}/fpm/php.ini
RUN sed -i 's/post_max_size = [[:digit:]]\+M/post_max_size = 28M/' /etc/php/${PHP_VERSION}/fpm/php.ini

WORKDIR /var/www/webapp
COPY composer.json /var/www/webapp
Expand Down
4 changes: 2 additions & 2 deletions docker/api/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
printenv | grep "REDIS_" > /etc/environment
service cron start

# 'service php8.2-fpm start' does not pass env variables to process.
/etc/init.d/php8.2-fpm start
# 'service php-fpm start' does not pass env variables to process.
/etc/init.d/php8.3-fpm start

# Hand off to the CMD
exec "$@"
2 changes: 1 addition & 1 deletion docker/api/nginx/sites-enabled/webapp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ server {

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
}
}

2 changes: 1 addition & 1 deletion docker/mysql/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mysql:8.0
FROM mysql:8.4

LABEL maintainer="Reconmap engineering" \
org.opencontainers.image.title="Reconmap Rest API database" \
Expand Down
4 changes: 2 additions & 2 deletions docker/mysql/overrides.cnf
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ default-character-set=utf8mb4
init_connect='SET collation_connection = utf8mb4_unicode_ci'
init_connect='SET NAMES utf8mb4'
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
skip-character-set-client-handshake
collation-server=utf8mb4_unicode_ci

9 changes: 6 additions & 3 deletions src/Database/TestDataGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(
{
}

public function generate()
public function generate(): void
{
$contact = new Contact();
$contact->kind = 'billing';
Expand Down Expand Up @@ -74,10 +74,13 @@ public function generate()
$document->title = 'Thing';
$this->documentRepository->insert($document);

$notification = new Notification(toUserId: 1, title: 'Command completed', content: '100 vulnerabilities have been found');
$notification = new Notification();
$notification->toUserId = 1;
$notification->title = 'Command completed';
$notification->content = '100 vulnerabilities have been found';
$this->notificationsRepository->insert($notification);

$this->projectTestDataGenerator->run();;
$this->projectTestDataGenerator->run();
$target = new Target();
$target->project_id = 1;
$target->name = 'https://test.com';
Expand Down
27 changes: 19 additions & 8 deletions src/Models/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@
/**
* Autogenerated file, do not edit manually. @see https://github.com/reconmap/model-definitions
*/
class Client {
class Client
{

public ?int $id;
public ?int $creator_uid;
public ?string $name;
public ?string $address;
public ?string $url;
public ?int $logo_attachment_id = null;
public ?int $small_logo_attachment_id = null;
public ?int $id;
public ?int $creator_uid;
public ?string $name;
public ?string $address;
public ?string $url;
public ?int $logo_attachment_id = null;
public ?int $small_logo_attachment_id = null;

public function getId(): int
{
return $this->id;
}

public function getName(): string
{
return $this->name;
}
}
24 changes: 17 additions & 7 deletions src/Models/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@
/**
* Autogenerated file, do not edit manually. @see https://github.com/reconmap/model-definitions
*/
class Document {
class Document
{

public ?int $user_id;
public string $visibility = 'private';
public ?int $parent_id;
public ?string $parent_type;
public ?string $content;
public ?string $title;
public ?int $user_id;
public string $visibility = 'private';
public ?int $parent_id;
public ?string $parent_type;
public ?string $content;
public ?string $title;

static public function fromObject(object $object): static
{
$self = new static();
$other = new \ReflectionObject($object);
$props = array_filter($other->getProperties(), fn($prop) => property_exists($self, $prop->getName()));
array_walk($props, fn($prop) => $self->{$prop->getName()} = $prop->getValue($object));
return $self;
}
}
84 changes: 55 additions & 29 deletions src/Models/Vulnerability.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,60 @@
/**
* Autogenerated file, do not edit manually. @see https://github.com/reconmap/model-definitions
*/
class Vulnerability {
class Vulnerability implements Cleanable
{

public ?int $id = null;
public ?string $insert_ts = null;
public ?string $update_ts = null;
public ?int $creator_uid = null;
public bool $is_template = false;
public ?int $external_id = null;
public ?int $project_id = null;
public ?int $target_id = null;
public ?int $category_id = null;
public string $summary;
public ?string $description;
public ?string $external_refs = null;
public ?string $visibility = 'public';
public string $risk;
public ?string $proof_of_concept = null;
public ?string $impact = null;
public ?string $remediation = null;
public ?string $remediation_complexity = null;
public ?string $remediation_priority = null;
public ?float $cvss_score = null;
public ?string $cvss_vector = null;
public ?string $status;
public ?string $substatus;
public mixed $tags;
public ?string $owasp_vector = null;
public ?float $owasp_likehood = null;
public ?float $owasp_impact = null;
public ?string $owasp_overall = null;
public ?int $id = null;
public ?string $insert_ts = null;
public ?string $update_ts = null;
public ?int $creator_uid = null;
public bool $is_template = false;
public ?int $external_id = null;
public ?int $project_id = null;
public ?int $target_id = null;
public ?int $category_id = null;
public string $summary;
public ?string $description;
public ?string $external_refs = null;
public ?string $visibility = 'public';
public string $risk;
public ?string $proof_of_concept = null;
public ?string $impact = null;
public ?string $remediation = null;
public ?string $remediation_complexity = null;
public ?string $remediation_priority = null;
public ?float $cvss_score = null;
public ?string $cvss_vector = null;
public ?string $status;
public ?string $substatus;
public mixed $tags;
public ?string $owasp_vector = null;
public ?float $owasp_likehood = null;
public ?float $owasp_impact = null;
public ?string $owasp_overall = null;

public function toArray(?array $properties = null): array
{
$array = (array)$this;

if (is_null($properties)) {
return $array;
}

return array_filter(
$array,
fn(string $key) => in_array($key, $properties),
ARRAY_FILTER_USE_KEY
);
}

public function clean(): void
{
if ($this->is_template) {
$this->project_id = null;
}
if (0 === $this->target_id) {
$this->target_id = null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Reconmap\Models\Attachment;
use Reconmap\Repositories\AttachmentRepository;
use Reconmap\Repositories\CommandRepository;
use Reconmap\Repositories\CommandUsageRepository;
use Reconmap\Services\Filesystem\AttachmentFilePath;
use Reconmap\Services\RedisServer;

Expand Down Expand Up @@ -63,9 +64,14 @@ public function testHappyPath()
->method('findById')
->willReturn(['id' => 5]);

$mockCommandUsageRepository = $this->createMock(CommandUsageRepository::class);
$mockCommandUsageRepository->expects($this->once())
->method('findById')
->willReturn(['command_id' => 5]);

$args = ['attachmentId' => $fakeAttachmentId];

$controller = $this->injectController(new UploadCommandOutputController($mockAttachmentRepository, $mockAttachmentFilePath, $mockRedisServer, $mockCommandRepository));
$controller = $this->injectController(new UploadCommandOutputController($mockAttachmentRepository, $mockAttachmentFilePath, $mockRedisServer, $mockCommandRepository, $mockCommandUsageRepository));
$response = $controller($mockRequest, $args);

$this->assertTrue($response['success']);
Expand Down
Loading

0 comments on commit 47f7747

Please sign in to comment.