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

Add ignoring password entires in auditing #36

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
39 changes: 37 additions & 2 deletions pass_audit/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import os
import sys
import re

from argparse import ArgumentParser, RawDescriptionHelpFormatter

from pass_audit import __version__
Expand Down Expand Up @@ -81,10 +83,43 @@ def setup():
if not store.isvalid():
msg.die('invalid user ID, password access aborted.')

paths = store.list(arg.paths, arg.name)
if not paths:
paths_raw = store.list(arg.paths, arg.name)
paths = []

if not paths_raw:
msg.die(f"{arg.paths} is not in the password store.")

ignore_paths_list = []
audit_ignore_path = os.path.join(store.prefix, ".pass-audit-ignore")

if not os.path.isfile(audit_ignore_path):
open(audit_ignore_path, "w").close()

with open(audit_ignore_path, "r") as f:
ignore_paths = f.read()

if len(ignore_paths) > 0:
ignore_paths_list = ignore_paths.split("\n")

for path in paths_raw:
add_path = False

for ignore_path in ignore_paths_list:
if ignore_path == "":
continue

if ignore_path.startswith("#"):
continue

if not re.search(ignore_path, path):
add_path = True
else:
add_path = False
break

if add_path or len(ignore_paths_list) <= 0:
paths.append(path)

return msg, store, paths


Expand Down
9 changes: 9 additions & 0 deletions tests/test_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
class TestPassAudit(tests.Test):
"""Test the PassAudit class."""
passwords_nb = 7
passwords_unignored = 4

@mock.patch('requests.get', tests.mock_request)
def test_password_notpwned(self):
Expand All @@ -36,6 +37,14 @@ def test_password_pwned(self):
ref_index = int(path[-1:]) - 1
self.assertTrue(ref_counts[ref_index] == count)

def test_password_ignore(self):
"""Testing: if .pass-audit-ignore works"""
data = tests.getdata('Password/ignore')
audit = pass_audit.audit.PassAudit(data, True)
passwords = audit.password()

self.assertTrue(len(passwords) == self.passwords_unignored)

def test_zxcvbn_weak(self):
"""Testing: pass audit for weak password with zxcvbn."""
data = tests.getdata('Password/pwned/1')
Expand Down