Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Doing dirty (but extremely useful) things with equals.
Documentation: dirty-equals.helpmanual.io
Source Code: github.com/samuelcolvin/dirty-equals
dirty-equals is a python library that (mis)uses the __eq__
method to make python code (generally unit tests)
more declarative and therefore easier to read and write.
dirty-equals can be used in whatever context you like, but it comes into its own when writing unit tests for applications where you're commonly checking the response to API calls and the contents of a database.
Here's a trivial example of what dirty-equals can do:
from dirty_equals import IsPositive
assert 1 == IsPositive
assert -2 == IsPositive # this will fail!
That doesn't look very useful yet!, but consider the following unit test code using dirty-equals:
from dirty_equals import IsJson, IsNow, IsPositiveInt, IsStr
...
# user_data is a dict returned from a database or API which we want to test
assert user_data == {
# we want to check that id is a positive int
'id': IsPositiveInt,
# we know avatar_file should be a string, but we need a regex as we don't know whole value
'avatar_file': IsStr(regex=r'/[a-z0-9\-]{10}/example\.png'),
# settings_json is JSON, but it's more robust to compare the value it encodes, not strings
'settings_json': IsJson({'theme': 'dark', 'language': 'en'}),
# created_ts is datetime, we don't know the exact value, but we know it should be close to now
'created_ts': IsNow(delta=3),
}
Without dirty-equals, you'd have to compare individual fields and/or modify some fields before comparison - the test would not be declarative or as clear.
dirty-equals can do so much more than that, for example:
IsPartialDict
lets you compare a subset of a dictionaryIsStrictDict
lets you confirm order in a dictionaryIsList
and
IsTuple
lets you compare partial lists and tuples, with or without order constraintsIsInstance
lets you simply confirm the type of an object|
and &
to combine multiple conditionsSimply:
pip install dirty-equals
dirty-equals requires Python 3.8+.
FAQs
Doing dirty (but extremely useful) things with equals.
We found that dirty-equals demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.