Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/libmagic dependency injection #23

Merged

Conversation

conitrade-as
Copy link
Contributor

This change set adds the magic description (as a payload) and mime type (as a header) to the classifier result.

Testing has been completely reworked and uses dependency injection to make libmagic results stable across various platforms.

@msm-code msm-code requested review from psrok1, msm-code, nazywam and chivay and removed request for nazywam May 17, 2021 13:12
@msm-code
Copy link
Contributor

Thanks!

I feel like there's a lot of duplication, and I'm a bit concerned by the big number of new lines of code. For example, this fragment:

m = MagicMock()
m.side_effect = [
    ', '.join([
        'PDF document',
        'version 1.4',
    ]),
    'application/pdf',
]
self.karton = Classifier(
    magic=m, config=self.config, backend=self.backend
)

with a good helper method could be shortened to:

self.karton = mock_classifier(['PDF document', 'version 1.4'], "application/pdf")

And this fragment:

resource = Resource('file.pdf', b'feeddecaf\n', sha256='sha256')
task = Task({
    'type': 'sample',
    'kind': 'raw',
})
task.add_payload('sample', resource)

res = self.run_task(task)

could be shortened to:

res = classify("file.pdf")

this will add up over all the repeated invocations. Do you think it makes sense?

Also do you mind running black and flake8 on your code? Looks like CI doesn't check tests/ directory, but we like the consistency black enforces.

tests/test_classifier.py Show resolved Hide resolved
@conitrade-as
Copy link
Contributor Author

Let me clean up the code just a bit more. As there seem to be some issues after merging in changes from @msm-code .

* add basic classifier test
* refactor archive tests
* refactor document tests
* refactor misc tests
* refactor runnable tests
* refactor script tests
@conitrade-as conitrade-as force-pushed the feature/libmagic-dependency-injection branch from 770f695 to f323bf4 Compare May 18, 2021 06:49
Copy link
Contributor

@msm-code msm-code left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests still feel a bit repetitive, but I think they're good - and I like the dependency injection approach here. LGTM.

@msm-code msm-code merged commit 3af5edb into CERT-Polska:master May 18, 2021
chivay added a commit that referenced this pull request Sep 15, 2021
chivay added a commit that referenced this pull request Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants