Commit graph

1,588 commits

Author SHA1 Message Date
Vitor Mattos
54f73ed475
refactor: add centralized reset in getMockAppConfig for test isolation
- Add reset() method to AppConfigOverwrite that clears overWrite and deleted arrays and returns self
- Integrate reset() directly into getMockAppConfig() to ensure clean state on every call
- All tests now automatically get clean AppConfig state without explicit reset calls
- Prevents state pollution across test suites by resetting at the source
- Simplifies test code by removing need for separate reset wrapper method

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-15 19:11:06 -03:00
Vitor Mattos
3d4bdf0294
fix: filter CA ID from OU only when certificate not generated
The CA ID (libresign-ca-id:...) in OrganizationalUnit should only be
filtered out when the certificate is not generated (isSetupOk() returns
false). When the certificate is successfully generated, the CA ID must
be preserved in the API response.

This ensures:
- Generated certificates: CA ID is visible (expected behavior)
- Failed/not generated: CA ID is filtered to prevent stale data in form

Integration tests validated:
- features/account/signature.feature:2 (OpenSSL)
- features/account/signature.feature:23 (CFSSL)
- features/admin/certificate_openssl.feature:2
- features/admin/certificate_openssl.feature:35

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-15 17:39:24 -03:00
Vitor Mattos
65ac52b309
test: clean up config_path in AEngineHandlerTest setUp
Prevent test state pollution by ensuring config_path is deleted
in setUp(). This fixes failures in OpenSslHandlerTest where the
temporary config path from AEngineHandlerTest was persisting
through the shared appConfig mock, causing tests that expect
properly formatted PKI directory names to fail.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-15 17:20:48 -03:00
Vitor Mattos
249f0837b0
fix: prevent stale configPath and CA ID exposure in root certificate API
Filter configPath from API response when certificate is not generated to prevent
form pre-population with outdated generation numbers that cause validation errors.

Filter CA ID (libresign-ca-id:*) from OrganizationalUnit field to prevent users
from submitting stale generation values that conflict with certificate validation.

Refactor toArray() method by extracting logic into dedicated methods:
- getConfigPathForApi(): Returns empty string for non-generated certificates
- removeCaIdFromOrganizationalUnit(): Filters CA IDs from OU arrays

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-15 16:57:17 -03:00
Vitor Mattos
c8e9a2d4b1
fix: year
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-15 15:56:34 -03:00
Vitor Mattos
77dfe0a49c
fix: cs
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-15 15:56:28 -03:00
Vitor Mattos
80ab7e6560
chore: add REUSE headers to catalog.yaml
Add SPDX license and copyright headers to comply with REUSE specification.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-15 15:56:06 -03:00
Vitor Mattos
4d23cd91aa
chore(test): remove old PDF fixtures
Delete PDFs from root fixtures directory.
Files now organized in tests/php/fixtures/pdfs/ with catalog.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-15 15:52:53 -03:00
Vitor Mattos
7bc88482a8
feat(test): add PdfFixtureCatalog for real signed PDFs
Create catalog system for managing real-world signed PDFs:
- PdfFixtureCatalog class with YAML-based metadata
- Filter by DocMDP level, TSA, signature tool, count
- Provides expected validation results for tests
- Includes PdfFixture wrapper for easy access
- Store real PDFs in tests/php/fixtures/pdfs/ directory

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-15 15:52:45 -03:00
Vitor Mattos
3f26b2bc24
test: reduce verbosity in Pkcs12HandlerTest
Clean up test code by:
- Removing verbose docblocks and obvious comments
- Simplifying assertion messages
- Deleting 2 redundant tests (extraction and validation)
- Reducing file size from 180 to 46 lines (74% reduction)

All 21 tests still pass with maintained coverage.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-15 15:52:35 -03:00
Vitor Mattos
04f393b9a6
refactor(test): migrate API controller tests to PdfGenerator
Replace PdfFixtureTrait with PdfGenerator in API tests:
- FileControllerTest
- FileElementControllerTest
- IdDocsControllerTest
- NotifyControllerTest
- RequestSignatureControllerTest
- SignFileControllerTest

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-15 15:52:25 -03:00
Vitor Mattos
819eca3ab1
refactor(test): migrate Unit tests to use PdfGenerator
Replace PdfFixtureTrait usage with PdfGenerator static methods:
- Remove 'use PdfFixtureTrait' statements
- Add 'use OCA\Libresign\Tests\Fixtures\PdfGenerator' imports
- Change trait method calls to static PdfGenerator:: calls
- Fix incorrect PdfGenerator::createMock() to $this->createMock()

Affected test files:
- DocMdpHandlerTest
- FileServiceTest (3 createMock fixes)
- SignFileServiceTest (20+ createMock fixes)
- PdfParseServiceTest
- PdfSignatureDetectionServiceTest
- RequestSignatureServiceTest
- ValidateHelperTest
- AEnvironmentPageAwareControllerTest

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-15 15:52:16 -03:00
Vitor Mattos
a7de549cdf
refactor(test): remove PdfFixtureTrait
Delete trait after migrating all methods to PdfGenerator.
The trait pattern was unnecessary for stateless utility methods.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-15 15:52:05 -03:00
Vitor Mattos
6f8d4111cc
feat(test): create PdfGenerator class with static methods
Consolidate PDF fixture generation into a single static class:
- Migrate all methods from PdfFixtureTrait to PdfGenerator
- Convert trait methods to public static methods
- Maintain all existing functionality
- Includes 20+ methods for ISO 32000-1 edge case testing

This improves code organization and eliminates trait usage.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-15 15:49:35 -03:00
Vitor Mattos
50b66c4f79
fix: unit tests
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-14 16:38:34 -03:00
Vitor Mattos
d23ae7b51c
fix: cs
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-14 16:38:34 -03:00
Vitor Mattos
114b4eabd1
test: fix unit tests for DocMDP per-file feature
- Add docmdpLevel to LibresignValidateFile schema in ResponseDefinitions
- Add DocMdpConfigService mock to RequestSignatureServiceTest
- Fix constructor parameter order in RequestSignatureServiceTest
- Mock validateDocMdpAllowsSignatures in SignFileServiceTest
- Mock getDocmdpLevelEnum to return NOT_CERTIFIED in test scenarios
- Fixes OpenAPI schema validation errors
- Fixes ArgumentCountError in RequestSignatureService tests
- Fixes enum mocking issues in SignFileService tests

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-14 16:38:34 -03:00
Vitor Mattos
3d9652487c
test: update SequentialSigningServiceTest after IAppConfig removal
Removed IAppConfig mock from test setup to match updated
service constructor signature.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-14 14:00:30 -03:00
Vitor Mattos
30c4612419
fix: cs
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-14 13:53:52 -03:00
Vitor Mattos
911af0d300
test: update RequestSignatureService tests for new architecture
Updated tests to inject FileStatusService and SignRequestStatusService
mocks. Added specific tests validating parallel and ordered flow
behavior with correct parameter ordering for determineInitialStatus.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-14 13:53:33 -03:00
Vitor Mattos
dfe40d40a9
test: add comprehensive tests for SignRequestStatusService
Created test suite with 53 tests validating business rules for sign
request status determination. Covers notification scenarios, status
updates, and initial status calculation based on file status, signer
status, signing order, and flow type. Uses PHP 8 DataProvider
attributes for parameterized testing.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-14 13:53:24 -03:00
Vitor Mattos
60bcd04419
test: add comprehensive tests for FileStatusService
Created test suite with 23 tests covering all file status upgrade
scenarios and notification validation. Uses PHP 8 DataProvider
attributes for parameterized testing.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-14 13:53:16 -03:00
Vitor Mattos
21aee754ad
test: add missing IEventDispatcher parameter to RequestSignatureServiceTest
The RequestSignatureService constructor was updated to require 18 parameters
including IEventDispatcher, but the test was only passing 17 parameters.
This commit adds the missing mock dependency to fix all failing tests.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-14 12:51:34 -03:00
Vitor Mattos
650d26e2af
test: add integration tests for signature request cancellation
Adds Behat tests covering three scenarios:
1. Deleting pending request sends cancellation notification
2. Deleting draft request does not send notification
3. Deletion removes signer from file list

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-13 17:17:17 -03:00
Vitor Mattos
90536362d8
test: Add tests for parallel and ordered flow status determination
Added two unit tests to validate status determination logic:

1. testParallelFlowIgnoresSignerDraftStatusWhenFileIsAbleToSign:
   Validates that in parallel flow, all signers are set to ABLE_TO_SIGN
   when file status is ABLE_TO_SIGN, ignoring individual DRAFT status
   sent by frontend.

2. testOrderedFlowRespectsSigningOrderWhenFileIsAbleToSign:
   Validates that in ordered flow, only the first signer (order 1)
   gets ABLE_TO_SIGN status, while subsequent signers remain DRAFT
   until their turn.

Also updated getService() method to accept optional
SequentialSigningService parameter for testing different flows.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-13 10:07:04 -03:00
Vitor Mattos
c468f3a15f
test: add unit tests for signature flow feature
Add comprehensive unit tests for the signature flow implementation.

- SequentialSigningServiceTest: Test flow detection and order assignment
- FileTest: Test enum conversion methods in File entity
- RequestSignatureServiceTest: Fix constructor to include IAppConfig mock

Tests validate the core logic without focusing on coverage metrics.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-12 17:21:52 -03:00
Vitor Mattos
1d62e46b5c
refactor: move signature flow constants to enum
Move database value constants from File entity to SignatureFlow enum
where they belong as the single source of truth.

- Add SignatureFlow::NUMERIC_PARALLEL and NUMERIC_ORDERED_NUMERIC
- Remove circular dependency between File and SignatureFlow
- Update all references to use enum constants
- Use descriptive names instead of abbreviations

This follows single responsibility principle: the enum owns its
database representation.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-12 17:14:12 -03:00
Vitor Mattos
adc396d52e
test: update sequential signing test to validate DRAFT filter
Split the sequential signing test into two separate scenarios to better
validate the DRAFT status filtering behavior:

1. First scenario: Tests that signer1 can see and sign the document
   (simpler flow without multiple user switches)

2. Second scenario: Tests that signer2 does NOT see the document when
   their sign_request is in DRAFT status

This avoids multiple user context switches in the same scenario which
was causing authentication issues in the Behat tests, and better isolates
the behavior we want to validate.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-11 17:58:07 -03:00
Vitor Mattos
2ce6cd430e
test: add status and statusText fields to expected test output
The FileService now includes status and statusText fields in the signer
data structure when processing signed files outside LibreSign. This
update adjusts the test expectations to match the actual behavior.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-11 15:27:22 -03:00
dependabot[bot]
6546a901e6
chore(deps): Bump behat/behat in /tests/integration
Bumps [behat/behat](https://github.com/Behat/Behat) from 3.27.0 to 3.29.0.
- [Release notes](https://github.com/Behat/Behat/releases)
- [Changelog](https://github.com/Behat/Behat/blob/3.x/CHANGELOG.md)
- [Commits](https://github.com/Behat/Behat/compare/v3.27.0...v3.29.0)

---
updated-dependencies:
- dependency-name: behat/behat
  dependency-version: 3.29.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-12-11 16:13:27 +00:00
Vitor Mattos
a025bc90fd
test: add multibyte text wrapping test cases
Add test cases for Portuguese text with accents to verify that the
multibyte-safe wordwrap implementation correctly handles text with
diacritical marks and other Unicode characters in signature images.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-10 14:01:58 -03:00
Vitor Mattos
3a44e0a8df
test: fix signature-flow endpoint URL in integration test
Update Behat test to use correct endpoint URL and parameter name:
- Changed from '/api/v1/admin/signature-flow' to '/api/v1/admin/signature-flow/config'
- Changed parameter from 'flow' to 'mode'

This aligns with the actual AdminController endpoint implementation.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-10 12:11:29 -03:00
Vitor Mattos
fae11f133c
test: fix mock callbacks for testUpdateDatabaseWhenSign and testDispatchEventWhenSign
Add __call callbacks to SignRequest mocks in both tests to properly return
fileId and signingOrder values. Without these callbacks, the mocks were
returning null when these magic methods were called, causing
SequentialSigningService::releaseNextOrder() to fail with a TypeError.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-09 21:56:51 -03:00
Vitor Mattos
3e2a04dbf7
test: fix mock callbacks to include getFileId and getSigningOrder
- Add getFileId and getSigningOrder to __call callback mocks
- Return 1 for both methods in tests
- Fixes TypeError when releaseNextOrder is called with null fileId
- All 12 affected tests now pass

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-09 21:56:51 -03:00
Vitor Mattos
b14cc50915
test: fix unit tests to include SequentialSigningService mock
- Add SequentialSigningService mock in RequestSignatureServiceTest
- Add SequentialSigningService mock in SignFileServiceTest
- Update constructor calls in both test files to include new dependency

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-09 21:56:51 -03:00
Vitor Mattos
8d83fa7382
test: add Behat integration tests for sequential signing
- Test parallel signing: all signers can sign immediately
- Test sequential signing: order enforced, status transitions validated
- Verify status 422 when signer attempts to sign out of order
- Verify status changes from DRAFT to ABLE_TO_SIGN after previous signer completes

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-09 21:56:51 -03:00
Vitor Mattos
abd1a97d19
Merge pull request #6054 from LibreSign/feat/disable-identify-methods-none-engine
feat: disable identify methods none engine
2025-12-09 13:03:10 -03:00
Vitor Mattos
7258c3ca2c
test: add unit tests for setEngine method
Add comprehensive test coverage for configureIdentifyMethodsForEngine
including edge cases and data provider patterns.

Tests validate that 'none' engine correctly configures only account
identification with minimal configuration.

Related to #5145

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-09 12:43:32 -03:00
Vitor Mattos
c8bddd8f43
test: add integration tests for certificate engine switching
Add Behat integration tests to validate engine switch detection.
Tests verify that switching between OpenSSL and CFSSL certificate
engines without proper configuration is correctly detected and
reported.

Scenarios tested:
- Set OpenSSL engine, configure it, then switch to unconfigured CFSSL
- Delete engine configuration and verify error state

Fixes #5272

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-09 10:39:39 -03:00
Vitor Mattos
49db550cf3
test: add unit tests for Imagick extension check
Create ConfigureCheckServiceTest with namespace-based function mocking
to test checkImagick() behavior. Uses DataProvider to test both scenarios:
extension loaded and not loaded. Mock allows testing independently of
actual Imagick installation state.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-09 09:40:27 -03:00
Vitor Mattos
ff165bbfc5
Merge pull request #6035 from LibreSign/fix/prevent-footer-on-signed-pdfs
fix: prevent footer on signed pdfs
2025-12-08 22:13:21 -03:00
Vitor Mattos
27bf7283dd
fix: cs
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-08 22:05:27 -03:00
Vitor Mattos
b1a68dcdc2 test: update SignFileServiceTest to inject PdfSignatureDetectionService
Added PdfSignatureDetectionService as a new dependency in the
SignFileService constructor. Updated all test setup code to create
and inject a mock of this service.

This maintains test isolation while allowing the service to use the
new signature detection logic.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-09 00:44:16 +00:00
Vitor Mattos
409a53d5d7 refactor: make PdfFixtureTrait methods public for easier testing
Changed createMinimalPdf() and createPdfWithDocMdp() from protected
to public visibility. This simplifies test code by allowing direct
usage without wrapper methods or complex workarounds.

The methods are already designed for test usage only and making them
public improves usability in data providers and static contexts.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-09 00:43:54 +00:00
Vitor Mattos
cd7db4ea37 feat: add PdfSignatureDetectionService for detecting existing signatures
This service provides a dedicated, testable way to detect if a PDF
already contains signatures. It encapsulates the signature detection
logic that was previously scattered across multiple handlers.

The service creates a memory resource from PDF content and uses the
SignEngineFactory to check for existing certificate chains. It handles
exceptions gracefully and returns false for any detection failures.

Tests use real PDF fixtures (signed and unsigned) instead of mocks,
providing better confidence in the detection logic.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-09 00:43:43 +00:00
Vitor Mattos
ae273a01bc
chore: bump dependencies
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-08 18:15:19 -03:00
Vitor Mattos
9088d4fabf
test: refactor DocMDP level 1 exception test to use getService helper
Simplifies test setup and improves maintainability.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-08 17:16:17 -03:00
Vitor Mattos
0668e31e8b
test: update DocMDP level 1 exception test to only check exception type
Removes translated message assertion for robustness.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-08 17:09:47 -03:00
Vitor Mattos
0a578c23ca
test: remove exception message validation from DocMDP tests
Tests now only check for exception type, not message, for DocMDP-related logic.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-08 16:53:52 -03:00
Vitor Mattos
5fc98d4e75
Use php://memory instead of php://temp in SignFileServiceTest for in-memory resource creation
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-08 16:53:50 -03:00