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

chore(test): modernise and skip db2 tests on arm64 #151

Open
wants to merge 4 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
13 changes: 7 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.3.0
rev: v4.6.0
hooks:
- id: check-builtin-literals
args: ["--no-allow-dict-kwargs"]
Expand All @@ -11,33 +11,34 @@ repos:
- id: double-quote-string-fixer
- id: end-of-file-fixer
- id: name-tests-test
exclude: "^tests/testing/.*$"
- id: trailing-whitespace
- repo: https://github.com/pycqa/flake8
rev: 3.9.2
rev: 7.0.0
hooks:
- id: flake8
args: ["--max-line-length", "100"]
exclude: ^test_data/|bumpity.py$
- repo: https://github.com/asottile/reorder_python_imports
rev: v2.3.6
rev: v3.12.0
hooks:
- id: reorder-python-imports
language_version: python3
exclude: bumpity.py$
- repo: https://github.com/asottile/add-trailing-comma
rev: v2.0.1
rev: v3.1.0
hooks:
- id: add-trailing-comma
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.5.4
rev: v2.0.4
hooks:
- id: autopep8
- repo: https://github.com/ibm/detect-secrets
# If you desire to use a specific version of detect-secrets, you can replace `master` with other git revisions such as branch, tag or commit sha.
# You are encouraged to use static refs such as tags, instead of branch name
#
# Running "pre-commit autoupdate" would automatically updates rev to latest tag
rev: 0.13.1+ibm.58.dss
rev: 0.13.1+ibm.62.dss
hooks:
- id: detect-secrets # pragma: whitelist secret
# Add options for detect-secrets-hook binary. You can run `detect-secrets-hook --help` to list out all possible options.
Expand Down
4 changes: 2 additions & 2 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"files": "test_data/.*|tests/.*|^.secrets.baseline$",
"lines": null
},
"generated_at": "2023-05-25T14:44:17Z",
"generated_at": "2024-05-15T12:41:39Z",
"plugins_used": [
{
"name": "AWSKeyDetector"
Expand Down Expand Up @@ -242,7 +242,7 @@
}
]
},
"version": "0.13.1+ibm.58.dss",
"version": "0.13.1+ibm.62.dss",
"word_list": {
"file": null,
"hash": null
Expand Down
2 changes: 1 addition & 1 deletion detect_secrets/plugins/artifactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ArtifactoryDetector(RegexBasedDetector):

def verify(self, token, *args, **kwargs):
try:
if type(token) == bytes:
if isinstance(token, bytes):
token = token.decode('UTF-8')
headers = {'X-JFrog-Art-API': token}
response = requests.get(
Expand Down
4 changes: 2 additions & 2 deletions detect_secrets/plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(
exclude_lines_regex=None,
should_verify=False,
false_positive_heuristics=None,
**kwargs
**kwargs,
):
"""
:type exclude_lines_regex: str|None
Expand Down Expand Up @@ -426,7 +426,7 @@ def secret_generator( # lgtm [py/inheritance/incorrect-overridden-signature]
self,
string,
*args,
**kwargs
**kwargs,
):
for regex in self.denylist:
for match in regex.findall(string):
Expand Down
6 changes: 3 additions & 3 deletions detect_secrets/plugins/common/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def from_parser_builder(
automaton=automaton,
should_verify_secrets=should_verify_secrets,
plugin_filenames=plugin_filenames,
**plugins_dict[plugin_name]
**plugins_dict[plugin_name],
),
)

Expand Down Expand Up @@ -200,7 +200,7 @@ def from_plugin_classname(
exclude_lines_regex=exclude_lines_regex,
automaton=automaton,
should_verify=should_verify_secrets,
**kwargs
**kwargs,
)
except TypeError:
log.warning('Unable to initialize plugin!')
Expand Down Expand Up @@ -248,5 +248,5 @@ def from_secret_type(secret_type, settings, plugin_filenames=None):
automaton=None,
should_verify_secrets=False,

**plugin_init_vars
**plugin_init_vars,
)
2 changes: 1 addition & 1 deletion detect_secrets/plugins/github_enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(self, ghe_instance=DEFAULT_GHE_INSTANCE, *args, **kwargs):

def verify(self, token, *args, **kwargs):
try:
if type(token) == bytes:
if isinstance(token, bytes):
token = token.decode('UTF-8')
headers = {'Authorization': 'token %s' % token}
response = requests.get(f'https://{self.ghe_instance}/api/v3', headers=headers)
Expand Down
4 changes: 2 additions & 2 deletions detect_secrets/plugins/high_entropy_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, charset, limit, exclude_lines_regex, automaton, *args, **kwar
exclude_lines_regex=exclude_lines_regex,
false_positive_heuristics=false_positive_heuristics,
*args,
**kwargs
**kwargs,
)

def analyze(self, file, filename, output_raw=False, output_verified_false=False):
Expand Down Expand Up @@ -337,7 +337,7 @@ def __init__(self, hex_limit, exclude_lines_regex=None, automaton=None, **kwargs
limit=hex_limit,
exclude_lines_regex=exclude_lines_regex,
automaton=automaton,
**kwargs
**kwargs,
)

@classproperty
Expand Down
2 changes: 1 addition & 1 deletion detect_secrets/plugins/ibm_cloud_iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def verify(self, token, *args, **kwargs):


def verify_cloud_iam_api_key(apikey): # pragma: no cover
if type(apikey) == bytes:
if isinstance(apikey, bytes):
apikey = apikey.decode('UTF-8')
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
Expand Down
2 changes: 1 addition & 1 deletion detect_secrets/plugins/keyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def __init__(self, keyword_exclude=None, exclude_lines_regex=None, automaton=Non
super(KeywordDetector, self).__init__(
exclude_lines_regex=exclude_lines_regex,
false_positive_heuristics=false_positive_heuristics,
**kwargs
**kwargs,
)

self.keyword_exclude = None
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ responses
tox-pip-extensions
tox>=3.8
unidiff
ibm_db
ibm_db; platform_machine == 'x86_64'
boxsdk[jwt]
pyahocorasick
tabulate
Expand Down
6 changes: 6 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ description-file = README.md

[wheel]
universal = True

[flake8]
max-line-length = 100

[tool:pytest]
norecursedirs=tests/testing
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import os
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), 'testing'))
6 changes: 3 additions & 3 deletions tests/core/audit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

import mock
import pytest

from detect_secrets.core import audit
from detect_secrets.core.constants import POTENTIAL_SECRET_DETECTED_NOTE
from testing.factories import potential_secret_factory
from testing.mocks import mock_open as mock_open_base
from testing.mocks import mock_printer as mock_printer_base
from testing.util import uncolor

from detect_secrets.core import audit
from detect_secrets.core.constants import POTENTIAL_SECRET_DETECTED_NOTE


@pytest.fixture(autouse=True)
def reset_file_cache():
Expand Down
8 changes: 4 additions & 4 deletions tests/core/baseline_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

import mock
import pytest
from testing.factories import secrets_collection_factory
from testing.mocks import mock_git_calls
from testing.mocks import mock_open
from testing.mocks import SubprocessMock

from detect_secrets.core import baseline
from detect_secrets.core.baseline import format_baseline_for_output
Expand All @@ -14,10 +18,6 @@
from detect_secrets.core.potential_secret import PotentialSecret
from detect_secrets.plugins.high_entropy_strings import Base64HighEntropyString
from detect_secrets.plugins.high_entropy_strings import HexHighEntropyString
from testing.factories import secrets_collection_factory
from testing.mocks import mock_git_calls
from testing.mocks import mock_open
from testing.mocks import SubprocessMock


class TestInitializeBaseline:
Expand Down
1 change: 0 additions & 1 deletion tests/core/potential_secret_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest

from testing.factories import potential_secret_factory


Expand Down
4 changes: 2 additions & 2 deletions tests/core/report/conditions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
from copy import deepcopy

import mock
from testing.baseline import baseline
from testing.baseline import baseline_filename

from detect_secrets.core import audit
from detect_secrets.core.report.conditions import fail_on_audited_real
from detect_secrets.core.report.conditions import fail_on_live
from detect_secrets.core.report.conditions import fail_on_unaudited
from detect_secrets.core.report.constants import ReportExitCode
from detect_secrets.core.report.constants import ReportSecretType
from testing.baseline import baseline
from testing.baseline import baseline_filename


class TestReportConditions:
Expand Down
4 changes: 2 additions & 2 deletions tests/core/report/output_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import mock
import pytest
from testing.baseline import baseline
from testing.baseline import baseline_filename

from detect_secrets.core import audit
from detect_secrets.core.color import AnsiColor
Expand All @@ -13,8 +15,6 @@
from detect_secrets.core.report.output import print_stats
from detect_secrets.core.report.output import print_summary
from detect_secrets.core.report.output import print_table_report
from testing.baseline import baseline
from testing.baseline import baseline_filename


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/core/report/report_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

import mock
import pytest
from testing.baseline import baseline

from detect_secrets.core import audit as audit_module
from detect_secrets.core.report.constants import ReportExitCode
from detect_secrets.main import main
from testing.baseline import baseline


@pytest.fixture
Expand Down
6 changes: 3 additions & 3 deletions tests/core/secrets_collection_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

import mock
import pytest
from testing.factories import secrets_collection_factory
from testing.mocks import mock_log as mock_log_base
from testing.mocks import mock_open as mock_open_base

from detect_secrets import VERSION
from detect_secrets.core.potential_secret import PotentialSecret
from detect_secrets.core.secrets_collection import SecretsCollection
from detect_secrets.plugins.base import BasePlugin
from detect_secrets.plugins.high_entropy_strings import HexHighEntropyString
from detect_secrets.plugins.private_key import PrivateKeyDetector
from testing.factories import secrets_collection_factory
from testing.mocks import mock_log as mock_log_base
from testing.mocks import mock_open as mock_open_base


@pytest.fixture
Expand Down
13 changes: 9 additions & 4 deletions tests/main_test.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import json
import platform
import shlex
import textwrap
from contextlib import contextmanager

import mock
import pytest
from testing.factories import secrets_collection_factory
from testing.mocks import Any
from testing.mocks import mock_printer
from testing.util import uncolor

from detect_secrets import main as main_module
from detect_secrets import VERSION
from detect_secrets.core import audit as audit_module
from detect_secrets.core.constants import POTENTIAL_SECRET_DETECTED_NOTE
from detect_secrets.main import main
from detect_secrets.plugins.common.util import import_plugins
from testing.factories import secrets_collection_factory
from testing.mocks import Any
from testing.mocks import mock_printer
from testing.util import uncolor


def get_list_of_plugins(include=None, exclude=None):
Expand Down Expand Up @@ -190,6 +191,10 @@ def test_scan_string_cli_overrides_stdin(self):
}, exclude=['Db2Detector'],
)

@pytest.mark.skipif(
platform.machine() not in ('x86_64', 'AMD64'),
reason='ibm_db2 only runs on x86_64',
)
def test_scan_string_cli_overrides_stdin_db2_enabled(self):
with mock_stdin(
'012345678ab',
Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/aws_key_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import mock
import pytest
from testing.mocks import mock_file_object

from detect_secrets.core.constants import VerifiedResult
from detect_secrets.core.potential_secret import PotentialSecret
from detect_secrets.plugins.aws import AWSKeyDetector
from detect_secrets.plugins.aws import get_secret_access_keys
from detect_secrets.plugins.aws import verify_aws_secret_access_key
from testing.mocks import mock_file_object


EXAMPLE_SECRET = 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'
Expand Down
4 changes: 2 additions & 2 deletions tests/plugins/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import mock
import pytest
from testing.factories import potential_secret_factory
from testing.mocks import mock_file_object

from detect_secrets.core.constants import VerifiedResult
from detect_secrets.plugins.base import BasePlugin
from testing.factories import potential_secret_factory
from testing.mocks import mock_file_object


@pytest.mark.parametrize(
Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/common/yaml_file_parser_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import mock
import pytest
from testing.mocks import mock_file_object

from detect_secrets.plugins.common.yaml_file_parser import YamlFileParser
from testing.mocks import mock_file_object


class TestYamlFileParser:
Expand Down
Loading
Loading