Skip to content

Commit

Permalink
rollback "pydriller"-related code
Browse files Browse the repository at this point in the history
  • Loading branch information
babenek committed Oct 16, 2023
1 parent 9a3fc09 commit 4eaa3df
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 51 deletions.
9 changes: 1 addition & 8 deletions credsweeper/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,11 @@ def _use_ml_validation(self) -> bool:

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

@property
def is_ml_validator_inited(self) -> bool:
"""method to check whether ml_validator was inited without creation"""
return bool(self.__ml_validator)

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

@property
def ml_validator(self) -> MlValidator:
"""ml_validator getter"""
from credsweeper.ml_model import MlValidator
if not self.is_ml_validator_inited:
if not self.__ml_validator:
self.__ml_validator: MlValidator = MlValidator(threshold=self.ml_threshold)
assert self.__ml_validator, "self.__ml_validator was not initialized"
return self.__ml_validator
Expand Down
43 changes: 0 additions & 43 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,49 +360,6 @@ def test_find_by_ext_and_not_ignore_p(self) -> None:

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

def test_multiple_invocation_p(self) -> None:
# test whether ml_validator is created once
self.maxDiff = None
cred_sweeper = CredSweeper()
self.assertFalse(cred_sweeper.is_ml_validator_inited)
# found candidate is not ML validated
provider = StringContentProvider(["qpF8Q~PCM5MhMoyTFc5TYEomnzRUKim9UJhe8a6E"])
candidates = cred_sweeper.file_scan(provider)
self.assertEqual(1, len(candidates))
self.assertEqual("Azure Secret Value", candidates[0].rule_name)
self.assertFalse(cred_sweeper.is_ml_validator_inited)
cred_sweeper.credential_manager.set_credentials(candidates)
cred_sweeper.post_processing()
self.assertFalse(cred_sweeper.is_ml_validator_inited)

# found candidate is ML validated

provider = StringContentProvider(['"nonce": "qPRjfoZWaBPH0KbXMCicm5v1VdG5Hj0DUFMHdSxPOiS"'])
candidates = cred_sweeper.file_scan(provider)
self.assertEqual(1, len(candidates))
self.assertEqual("Nonce", candidates[0].rule_name)
self.assertFalse(cred_sweeper.is_ml_validator_inited)
cred_sweeper.credential_manager.set_credentials(candidates)
cred_sweeper.post_processing()
self.assertTrue(cred_sweeper.is_ml_validator_inited)
# remember id of the validator
validator_id = id(cred_sweeper.ml_validator)

# found candidate is ML validated also
provider = StringContentProvider(["password = Xdj@jcN834b"])
candidates = cred_sweeper.file_scan(provider)
self.assertEqual(1, len(candidates))
self.assertEqual("Password", candidates[0].rule_name)
# the ml_validator still initialized
self.assertTrue(cred_sweeper.is_ml_validator_inited)
cred_sweeper.credential_manager.set_credentials(candidates)
cred_sweeper.post_processing()
self.assertTrue(cred_sweeper.is_ml_validator_inited)
# the same id of the validator
self.assertEqual(validator_id, id(cred_sweeper.ml_validator))

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

def test_multi_jobs_p(self) -> None:
# real result might be shown in code coverage
content_provider: FilesProvider = TextProvider([SAMPLES_PATH])
Expand Down

0 comments on commit 4eaa3df

Please sign in to comment.