Skip to content

Commit

Permalink
Update mypy and remove some "type: ignore"
Browse files Browse the repository at this point in the history
  • Loading branch information
nabla-c0d3 committed Aug 28, 2023
1 parent 7ad09f3 commit fb07deb
Show file tree
Hide file tree
Showing 30 changed files with 173 additions and 114 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ on:
push:
branches: [ release ]
pull_request:
branches: [ release ]
branches: [ release, dev ]
workflow_dispatch:

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mypy==0.981
mypy==1.4.1
flake8
invoke>=2,<3
pytest==7.2.2
Expand Down
1 change: 1 addition & 0 deletions sslyze/cli/console_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def server_scan_completed(self, server_scan_result: ServerScanResult) -> None:
if server_scan_result.scan_status != ServerScanStatusEnum.COMPLETED:
# Nothing to print here if the scan was not completed
return
assert server_scan_result.scan_result # Must be set if scan_status == ServerScanStatusEnum.COMPLETED

# Generate the console output for each scan command
scan_command_results_str = ""
Expand Down
14 changes: 9 additions & 5 deletions sslyze/json/json_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ def from_orm(cls, tls_probing_result: ServerTlsProbingResult) -> "_ServerTlsProb
)


_ServerTlsProbingResultAsJson.__doc__ = ServerTlsProbingResult.__doc__ # type: ignore
assert ServerTlsProbingResult.__doc__
_ServerTlsProbingResultAsJson.__doc__ = ServerTlsProbingResult.__doc__


class _ServerNetworkConfigurationAsJson(BaseModelWithOrmModeAndForbid):
Expand All @@ -152,18 +153,20 @@ class _ServerNetworkConfigurationAsJson(BaseModelWithOrmModeAndForbid):
network_max_retries: int = 3


_ServerNetworkConfigurationAsJson.__doc__ = ServerNetworkConfiguration.__doc__ # type: ignore
assert ServerNetworkConfiguration.__doc__
_ServerNetworkConfigurationAsJson.__doc__ = ServerNetworkConfiguration.__doc__


class _ServerNetworkLocationAsJson(BaseModelWithOrmModeAndForbid):
hostname: str
port: int
connection_type: ConnectionTypeEnum
ip_address: Optional[str] = None
http_proxy_settings: Optional[_HttpProxySettingsAsJson] = None # type: ignore
http_proxy_settings: Optional[_HttpProxySettingsAsJson] = None


_ServerNetworkLocationAsJson.__doc__ = ServerNetworkLocation.__doc__ # type: ignore
assert ServerNetworkLocation.__doc__
_ServerNetworkLocationAsJson.__doc__ = ServerNetworkLocation.__doc__


class ServerScanResultAsJson(BaseModelWithOrmModeAndForbid):
Expand Down Expand Up @@ -210,7 +213,8 @@ def from_orm(cls, server_scan_result: ServerScanResult) -> "ServerScanResultAsJs
)


ServerScanResultAsJson.__doc__ = ServerScanResult.__doc__ # type: ignore
assert ServerScanResult.__doc__
ServerScanResultAsJson.__doc__ = ServerScanResult.__doc__


class InvalidServerStringAsJson(BaseModelWithOrmModeAndForbid):
Expand Down
15 changes: 10 additions & 5 deletions sslyze/plugins/certificate_info/json_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class CertificateInfoExtraArgumentAsJson(BaseModelWithOrmMode):
custom_ca_file: Path


CertificateInfoExtraArgumentAsJson.__doc__ = CertificateInfoExtraArgument.__doc__ # type: ignore
assert CertificateInfoExtraArgument.__doc__
CertificateInfoExtraArgumentAsJson.__doc__ = CertificateInfoExtraArgument.__doc__


class _PublicKeyAsJson(BaseModelWithOrmMode):
Expand Down Expand Up @@ -232,7 +233,8 @@ class _TrustStoreAsJson(BaseModelWithOrmMode):
ev_oids: Optional[List[_ObjectIdentifierAsJson]]


_TrustStoreAsJson.__doc__ = TrustStore.__doc__ # type: ignore
assert TrustStore.__doc__
_TrustStoreAsJson.__doc__ = TrustStore.__doc__


class _PathValidationResultAsJson(BaseModelWithOrmMode):
Expand All @@ -242,7 +244,8 @@ class _PathValidationResultAsJson(BaseModelWithOrmMode):
was_validation_successful: bool


_PathValidationResultAsJson.__doc__ = PathValidationResult.__doc__ # type: ignore
assert PathValidationResult.__doc__
_PathValidationResultAsJson.__doc__ = PathValidationResult.__doc__


class _CertificateDeploymentAnalysisResultAsJson(BaseModelWithOrmMode):
Expand All @@ -264,15 +267,17 @@ class _CertificateDeploymentAnalysisResultAsJson(BaseModelWithOrmMode):
verified_certificate_chain: Optional[List[_CertificateAsJson]]


_CertificateDeploymentAnalysisResultAsJson.__doc__ = CertificateDeploymentAnalysisResult.__doc__ # type: ignore
assert CertificateDeploymentAnalysisResult.__doc__
_CertificateDeploymentAnalysisResultAsJson.__doc__ = CertificateDeploymentAnalysisResult.__doc__


class CertificateInfoScanResultAsJson(BaseModelWithOrmMode):
hostname_used_for_server_name_indication: str
certificate_deployments: List[_CertificateDeploymentAnalysisResultAsJson]


CertificateInfoScanResultAsJson.__doc__ = CertificateInfoScanResult.__doc__ # type: ignore
assert CertificateInfoScanResult.__doc__
CertificateInfoScanResultAsJson.__doc__ = CertificateInfoScanResult.__doc__


class CertificateInfoScanAttemptAsJson(ScanCommandAttemptAsJson):
Expand Down
2 changes: 1 addition & 1 deletion sslyze/plugins/compression_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CompressionScanResultAsJson(BaseModelWithOrmModeAndForbid):


class CompressionScanAttemptAsJson(ScanCommandAttemptAsJson):
result: Optional[CompressionScanResultAsJson] # type: ignore
result: Optional[CompressionScanResultAsJson]


class _CompressionCliConnector(ScanCommandCliConnector[CompressionScanResult, None]):
Expand Down
2 changes: 1 addition & 1 deletion sslyze/plugins/early_data_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class EarlyDataScanResultAsJson(BaseModelWithOrmModeAndForbid):


class EarlyDataScanAttemptAsJson(ScanCommandAttemptAsJson):
result: Optional[EarlyDataScanResultAsJson] # type: ignore
result: Optional[EarlyDataScanResultAsJson]


class _EarlyDataCliConnector(ScanCommandCliConnector[EarlyDataScanResult, None]):
Expand Down
6 changes: 4 additions & 2 deletions sslyze/plugins/elliptic_curves_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class _EllipticCurveAsJson(pydantic.BaseModel):
openssl_nid: int


_EllipticCurveAsJson.__doc__ = EllipticCurve.__doc__ # type: ignore
assert EllipticCurve.__doc__
_EllipticCurveAsJson.__doc__ = EllipticCurve.__doc__


class SupportedEllipticCurvesScanResultAsJson(pydantic.BaseModel):
Expand Down Expand Up @@ -92,7 +93,8 @@ def from_orm(cls, result: SupportedEllipticCurvesScanResult) -> "SupportedEllipt
)


SupportedEllipticCurvesScanResultAsJson.__doc__ = SupportedEllipticCurvesScanResult.__doc__ # type: ignore
assert SupportedEllipticCurvesScanResult.__doc__
SupportedEllipticCurvesScanResultAsJson.__doc__ = SupportedEllipticCurvesScanResult.__doc__


class SupportedEllipticCurvesScanAttemptAsJson(ScanCommandAttemptAsJson):
Expand Down
2 changes: 1 addition & 1 deletion sslyze/plugins/fallback_scsv_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FallbackScsvScanResultAsJson(BaseModelWithOrmModeAndForbid):


class FallbackScsvScanAttemptAsJson(ScanCommandAttemptAsJson):
result: Optional[FallbackScsvScanResultAsJson] # type: ignore
result: Optional[FallbackScsvScanResultAsJson]


class _FallbackScsvCliConnector(ScanCommandCliConnector[FallbackScsvScanResult, None]):
Expand Down
2 changes: 1 addition & 1 deletion sslyze/plugins/heartbleed_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class HeartbleedScanResultAsJson(BaseModelWithOrmModeAndForbid):


class HeartbleedScanAttemptAsJson(ScanCommandAttemptAsJson):
result: Optional[HeartbleedScanResultAsJson] # type: ignore
result: Optional[HeartbleedScanResultAsJson]


class _HeartbleedCliConnector(ScanCommandCliConnector[HeartbleedScanResult, None]):
Expand Down
12 changes: 6 additions & 6 deletions sslyze/plugins/http_headers_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# TODO: Fix type annotations in nassl
from nassl._nassl import SslError # type: ignore

from sslyze.json.pydantic_utils import BaseModelWithOrmMode
from sslyze.json.scan_attempt_json import ScanCommandAttemptAsJson
from sslyze.plugins.plugin_base import (
ScanCommandImplementation,
Expand Down Expand Up @@ -90,20 +91,18 @@ class _StrictTransportSecurityHeaderAsJson(pydantic.BaseModel):
include_subdomains: bool


_StrictTransportSecurityHeaderAsJson.__doc__ = StrictTransportSecurityHeader.__doc__ # type: ignore
assert StrictTransportSecurityHeader.__doc__
_StrictTransportSecurityHeaderAsJson.__doc__ = StrictTransportSecurityHeader.__doc__


class HttpHeadersScanResultAsJson(pydantic.BaseModel):
class HttpHeadersScanResultAsJson(BaseModelWithOrmMode):
http_request_sent: str
http_error_trace: Optional[str]

http_path_redirected_to: Optional[str]
strict_transport_security_header: Optional[_StrictTransportSecurityHeaderAsJson]
expect_ct_header: None = None # TODO(6.0.0): Remove as this is a deprecated field

class Config:
orm_mode = True

@classmethod
def from_orm(cls, result: HttpHeadersScanResult) -> "HttpHeadersScanResultAsJson":
http_error_trace_as_str = None
Expand All @@ -124,7 +123,8 @@ def from_orm(cls, result: HttpHeadersScanResult) -> "HttpHeadersScanResultAsJson
)


HttpHeadersScanResultAsJson.__doc__ = HttpHeadersScanResult.__doc__ # type: ignore
assert HttpHeadersScanResult.__doc__
HttpHeadersScanResultAsJson.__doc__ = HttpHeadersScanResult.__doc__


class HttpHeadersScanAttemptAsJson(ScanCommandAttemptAsJson):
Expand Down
2 changes: 1 addition & 1 deletion sslyze/plugins/openssl_ccs_injection_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class OpenSslCcsInjectionScanResultAsJson(BaseModelWithOrmModeAndForbid):


class OpenSslCcsInjectionScanAttemptAsJson(ScanCommandAttemptAsJson):
result: Optional[OpenSslCcsInjectionScanResultAsJson] # type: ignore
result: Optional[OpenSslCcsInjectionScanResultAsJson]


class _OpenSslCcsInjectionCliConnector(ScanCommandCliConnector[OpenSslCcsInjectionScanResult, None]):
Expand Down
6 changes: 4 additions & 2 deletions sslyze/plugins/openssl_cipher_suites/json_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class _CipherSuiteAcceptedByServerAsJson(BaseModelWithOrmMode):
ephemeral_key: Optional[_EphemeralKeyInfoAsJson]


_CipherSuiteAcceptedByServerAsJson.__doc__ = CipherSuiteAcceptedByServer.__doc__ # type: ignore
assert CipherSuiteAcceptedByServer.__doc__
_CipherSuiteAcceptedByServerAsJson.__doc__ = CipherSuiteAcceptedByServer.__doc__


class _CipherSuiteRejectedByServerAsJson(BaseModelWithOrmMode):
Expand All @@ -98,7 +99,8 @@ def from_orm(cls, scan_result: CipherSuitesScanResult) -> "CipherSuitesScanResul
)


CipherSuitesScanResultAsJson.__doc__ = CipherSuitesScanResult.__doc__ # type: ignore
assert CipherSuitesScanResult.__doc__
CipherSuitesScanResultAsJson.__doc__ = CipherSuitesScanResult.__doc__


class CipherSuitesScanAttemptAsJson(ScanCommandAttemptAsJson):
Expand Down
2 changes: 1 addition & 1 deletion sslyze/plugins/robot/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class RobotScanResultAsJson(BaseModelWithOrmModeAndForbid):


class RobotScanAttemptAsJson(ScanCommandAttemptAsJson):
result: Optional[RobotScanResultAsJson] # type: ignore
result: Optional[RobotScanResultAsJson]


class _RobotCliConnector(ScanCommandCliConnector[RobotScanResult, None]):
Expand Down
2 changes: 1 addition & 1 deletion sslyze/plugins/session_renegotiation_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SessionRenegotiationScanResultAsJson(BaseModelWithOrmModeAndForbid):


class SessionRenegotiationScanAttemptAsJson(ScanCommandAttemptAsJson):
result: Optional[SessionRenegotiationScanResultAsJson] # type: ignore
result: Optional[SessionRenegotiationScanResultAsJson]


class _ScanJobResultEnum(Enum):
Expand Down
4 changes: 3 additions & 1 deletion sslyze/plugins/session_resumption/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ def _process_resumption_attempt_results(
return result, successful_attempts_count, total_attempts_count


class SessionResumptionSupportImplementation(ScanCommandImplementation[SessionResumptionSupportScanResult, None]):
class SessionResumptionSupportImplementation(
ScanCommandImplementation[SessionResumptionSupportScanResult, SessionResumptionSupportExtraArgument]
):
"""Test a server for session resumption support using session IDs and TLS tickets."""

cli_connector_cls = _SessionResumptionSupportCliConnector
Expand Down
6 changes: 4 additions & 2 deletions sslyze/plugins/session_resumption/json_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class SessionResumptionSupportExtraArgumentAsJson(BaseModelWithOrmModeAndForbid)
number_of_resumptions_to_attempt: int


SessionResumptionSupportExtraArgumentAsJson.__doc__ = SessionResumptionSupportExtraArgument.__doc__ # type: ignore
assert SessionResumptionSupportExtraArgument.__doc__
SessionResumptionSupportExtraArgumentAsJson.__doc__ = SessionResumptionSupportExtraArgument.__doc__


class SessionResumptionSupportScanResultAsJson(BaseModelWithOrmModeAndForbid):
Expand All @@ -22,7 +23,8 @@ class SessionResumptionSupportScanResultAsJson(BaseModelWithOrmModeAndForbid):
tls_ticket_successful_resumptions_count: int


SessionResumptionSupportScanResultAsJson.__doc__ = SessionResumptionSupportScanResult.__doc__ # type: ignore
assert SessionResumptionSupportScanResult.__doc__
SessionResumptionSupportScanResultAsJson.__doc__ = SessionResumptionSupportScanResult.__doc__


class SessionResumptionSupportScanAttemptAsJson(ScanCommandAttemptAsJson):
Expand Down
17 changes: 13 additions & 4 deletions sslyze/scanner/_jobs_worker_thread.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import threading
from dataclasses import dataclass
import queue
from typing import Optional, Any, Callable, Sequence
from typing import Optional, Any, Callable, Sequence, Union
from uuid import UUID

from sslyze.plugins.scan_commands import ScanCommand


try:
# Python 3.10+
from typing import TypeAlias # type: ignore
except ImportError:
# Python 3.9 and before
from typing_extensions import TypeAlias # type: ignore


@dataclass(frozen=True)
class CompletedScanJob:
parent_server_scan_request_uuid: UUID
Expand All @@ -29,10 +37,11 @@ class WorkerThreadNoMoreJobsSentinel:
pass


WorkerQueueType: TypeAlias = "queue.Queue[Union[WorkerThreadNoMoreJobsSentinel, QueuedScanJob]]"


class JobsWorkerThread(threading.Thread):
def __init__(
self, jobs_queue_in: "queue.Queue[QueuedScanJob]", completed_jobs_queue_out: "queue.Queue[CompletedScanJob]"
):
def __init__(self, jobs_queue_in: WorkerQueueType, completed_jobs_queue_out: "queue.Queue[CompletedScanJob]"):
super().__init__()
self._jobs_queue_in = jobs_queue_in
self._completed_jobs_queue_out = completed_jobs_queue_out
Expand Down
Loading

0 comments on commit fb07deb

Please sign in to comment.