Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/unit-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: "Unit Testing"
on: [push]
jobs:
test:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: sudo apt-get update && sudo apt-get install -y python3-pymysql python3-requests
Expand Down
6 changes: 5 additions & 1 deletion wordfence/cli/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,11 @@ def get_io_manager(self) -> IoManager:

def open_output_file(self) -> Optional[IO]:
mode = 'w+' if self.will_email() else 'w'
return open(resolve_path(self.config.output_path), mode) \
return open(
resolve_path(self.config.output_path),
mode,
encoding='utf-8'
) \
if self.config.output_path is not None \
else nullcontext()

Expand Down
41 changes: 41 additions & 0 deletions wordfence/cli/test_reporting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import unittest
from types import SimpleNamespace
from unittest import mock

from wordfence.cli.reporting import ReportManager
from wordfence.cli.dbscan.reporting import (
DatabaseScanReportFormat,
DatabaseScanReportColumn
)


class ReportManagerEncodingTest(unittest.TestCase):

def test_open_output_file_uses_utf8_encoding(self):
config = SimpleNamespace(
output=None,
output_path='/tmp/out.csv',
email=None
)
context = SimpleNamespace(config=config)
manager = ReportManager(
DatabaseScanReportFormat,
DatabaseScanReportColumn,
context,
read_stdin=None,
input_delimiter='\0'
)

patcher = mock.patch(
'wordfence.cli.reporting.open',
mock.mock_open()
)
with patcher as mock_open:
manager.open_output_file()

_, kwargs = mock_open.call_args
self.assertEqual('utf-8', kwargs.get('encoding'))


if __name__ == '__main__':
unittest.main()