-
Notifications
You must be signed in to change notification settings - Fork 581
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
DodgyBear.py: Add bear implementation #2246
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to add tests, always see the coverage before submitting the PR.
@newbazz I've added the tests. |
@newbazz Yeah, I did see that. But these are the only lines that do the required work in DodgyBear. |
bears/python/DodgyBear.py
Outdated
|
||
from coalib.bearlib.abstractions.Linter import linter | ||
from coalib.results.Result import Result | ||
from dependency_management.requirements.PipRequirement import PipRequirement |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import sud be in alphabetical order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made the changes ;)
Initially I imported them alphabetically according to the package the imports were made from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar changes in DodgyBearTest.py
too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed the import order in the test file too
bears/python/DodgyBear.py
Outdated
return [] | ||
|
||
def process_output(self, output, filename, file): | ||
for issue in json.loads(output)['warnings']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a docstring to explain what you are doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's needed. Just reading the JSON stdout call from dodgy
and following what https://api.coala.io/en/latest/Developers/Linter_Bears_Advanced.html#custom-processing-functions-with-process-output has. Do you still want me to add it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup not everyones gonna read this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added the docstring.
c56e4a4
to
371dc7a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have tests failing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't dodgy a npm package? I think you need to add it in package.json
in case it is a npm package. ;)
@newbazz No. What you're talking about is https://www.npmjs.com/package/dodgy I guess. |
I dont think so, in that case the appveyor should also fail but it is not the case here. |
@newbazz If you look at the build, I'm getting this error |
If you want this issue to be closed you can close the PR or else ping @Makman2 for clarification, i am also not able to find what is going wrong ;) |
This bear checks Python code for possible dodgy looking values such as secret keys or passwords. Closes coala#836
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bear is there for windows system as well right?
@newbazz Yes, I guess. But I haven't tested it on windows. |
|
||
@linter(executable='dodgy', | ||
use_stdout=True, | ||
use_stderr=False, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is default, you can just omit use_stdout
and use_stderr
args ;)
AUTHORS_EMAILS = {'[email protected]'} | ||
LICENSE = 'AGPL-3.0' | ||
CAN_DETECT = {'Security', 'Hardcoded Secret', | ||
'SCM Diff Check-in', 'SSH Keys'} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SCM Diff Check-in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, pushing a code diff
|
||
@staticmethod | ||
def create_arguments(config_file): | ||
return [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather return an empty tuple, then Python will reference always the same object and we save a little bit of memory and performance (minimal, but still :D)
|
||
@staticmethod | ||
def create_arguments(config_file): | ||
return [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't pass files to dodgy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly, no. You cannot specify a path. It just runs for all the .py
files in the current directory.
We've discussed this before, I guess.
prospector-dev/dodgy#5
Parses JSON stdout call and yields results | ||
according to the executable output. | ||
:param output: | ||
string output from the executable i.e. dodgy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My opinion: These variables and API here are all described in the linter docs already, so I would only document additional parameters that are settings.
:param output: | ||
string output from the executable i.e. dodgy | ||
""" | ||
print(output) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
debugging remains ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was trying to catch some stdout when the tests fail. No output is being returned by dodgy. But locally, it works fine.
#2246 (comment)
""" | ||
print(output) | ||
issues = json.loads(output) | ||
for issue in issues['warnings']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about other types of issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dodgy just returns a JSON string as output
kinda like this for every type of issue found:
{
"warnings": {.....}
}
issues['warnings']
is used for that here.
I'm wondering why appveyor skips the test... dodgy is a pip package and it gets installed :/ |
'na6d1dBmrQ3ly0B6g+pEf8ObaBriu0Fest0yZhyF8hsgueGu' | ||
'gZFXzjaAu68ib99nP17w111cbej9jUNnyfseykl5ngqrvsP3' | ||
'mGKw739z+p0vIIchHYa3jn6xW8fim/PH4gtcWC8mUXlv6XT ' | ||
'random@123') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should use test files :) See other tests that have functions like get_testfile_name
/get_testfile_path
and load_testfile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same thing - #2246 (comment)
'secrets.py', 'ssh_private_key.py', 'ssh_public_key.py'] | ||
for f in test_files: | ||
if f in current: | ||
os.remove(f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah properly using test files makes this unnecessary^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Btw you should always remove temp files where you created them in a test function, best is using context managers for this, having a tearDown
should be rather avoided if possible.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Makman2 We did discuss this before.
The problem was that dodgy only runs for files in the current directory. No files can be specified. It doesn't accept absolute/relative paths to a file which should be checked.
So, we cannot use test files here. But rather create test files in the pwd, test dodgy and then remove the created files.
:(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh I remember now... Yeah sorry it's been a while. Can you maybe execute coala / the bear inside a different working directory? Maybe patching some variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya, we have a decorator which changes directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've emailed the maintainer to ask them whether we can implement prospector-dev/dodgy#5 for them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't like dodgy
. The regexes included only adhere to a certain kind of checks.
For example: If your file contains PASSWORD=123@xyz
, it is detected; if it contains password=123@xyz
, it does not. 👎
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does gitleaks
support individual files? if not, it is still not ideal. Create a new issue for gitleaks if you like.
Anyway, dodgy maintainer replied and said they are happy to review PRs for prospector-dev/dodgy#5 .
That gets it usable, and then this PR can be finished.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gitleaks
doesn't support individual files, but does accept a path to a directory which dodgy
isn't capable of. Although it works only if it's a path to a git repo, and unlike dodgy
, it runs checks on the whole commit history.
Also, it is capable of running on remote repositories, and on all of the repositories of a particular user/organization at once.
@Makman2 But the appveyor build passes. |
Yeah because the tests are skipped for dodgy :3
Weird, some bad installation happens maybe in the CI? |
Oh 😄
but whenever I synchronize my PR, it gets installed again, right? |
Because some tests are skipped on Windows, we don't require 100% coverage there. In the end we
Yeah every new PR sync triggers a new build that runs on a clean environment. Still seems |
But I believe we have fixed that somehow in linter... |
This bear checks Python code for possible
dodgy looking values such as secret keys or
passwords.
Closes #836
For short term contributors: we understand that getting your commits well
defined like we require is a hard task and takes some learning. If you
look to help without wanting to contribute long term there's no need
for you to learn this. Just drop us a message and we'll take care of brushing
up your stuff for merge!
Checklist
them.
individually. It is not sufficient to have "fixup commits" on your PR,
our bot will still report the issues for the previous commit.) You will
likely receive a lot of bot comments and build failures if coala does not
pass on every single commit!
After you submit your pull request, DO NOT click the 'Update Branch' button.
When asked for a rebase, consult coala.io/rebase
instead.
Please consider helping us by reviewing other peoples pull requests as well:
cobot mark wip <URL>
to get it outof the review queue.
The more you review, the more your score will grow at coala.io and we will
review your PRs faster!