Koha-clms/Koha/File
Martin Renvoize ac64e18ce6
Bug 40811: (follow-up) Fix list context bug and add comprehensive tests
This patch fixes a critical bug where plain_text_password() was called
in list context during hash construction. When a transport has no
password, the method's bare 'return' statement returns an empty list ()
in list context rather than undef, causing all subsequent key-value
pairs to shift positions. This resulted in malformed connection
parameters being passed to Net::SFTP::Foreign and Net::FTP.

Example of the bug:
  my %hash = (
    user => 'john',
    password => $self->plain_text_password,  # Returns () when no password
    timeout => 10
  );
  # Results in: (user => 'john', timeout => 10) instead of
  # (user => 'john', password => undef, timeout => 10)

Changes to code:
- Wrap plain_text_password calls with scalar() to force scalar context
  in both FTP.pm and SFTP.pm
- Make SFTP key and password authentication mutually exclusive using
  ternary operator
- Prefer key-based auth over password when both are available (SFTP)

Test plan:
1. Run t/db_dependent/Koha/File/Transport/FTP.t - should pass
2. Run t/db_dependent/Koha/File/Transport/SFTP.t - should pass
3. Verify tests cover:
   - Scalar context behavior with no password
   - FTP authentication with proper parameter passing
   - SFTP password-only authentication
   - SFTP key-only authentication
   - SFTP key preference when both key and password exist

Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-01-21 15:28:17 -07:00
..
Transport Bug 40811: (follow-up) Fix list context bug and add comprehensive tests 2026-01-21 15:28:17 -07:00
Transport.pm Bug 40811: Implement dual API for file transports with simplified auto-management 2026-01-21 15:28:17 -07:00
Transports.pm Bug 38489: Add rename_file method to transport system and Local transport class 2025-10-14 14:51:47 -06:00