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

MyPy CI failures #1488

Merged
merged 23 commits into from
Jul 25, 2023
Merged

MyPy CI failures #1488

merged 23 commits into from
Jul 25, 2023

Conversation

yoonthegoon
Copy link
Contributor

@yoonthegoon yoonthegoon commented Jul 24, 2023

  • File: theHarvester/lib/stash.py

    • Line: 197 - Error: Incompatible types in assignment (expression has type "Iterable[Row]", variable has type "list[Any]") [assignment]
    • Line: 218 - Error: Value of type "Optional[Row]" is not indexable [index]
    • Line: 223 - Error: Incompatible types in assignment (expression has type "Iterable[Row]", variable has type "list[Any]") [assignment]
    • Line: 328 - Error: Incompatible types in assignment (expression has type "Iterable[Row]", variable has type "list[Any]") [assignment]
  • File: theHarvester/screenshot/screenshot.py

    • Line: 56 - Error: Value of type "Sized" is not indexable [index]
  • File: theHarvester/lib/core.py

    • Line: 112 - Error: Incompatible return value type (got "tuple[Any, Any]", expected "str") [return-value]
    • Line: 290 - Error: Argument "headers" to "ClientSession" has incompatible type "Sized"; expected "Union[Mapping[Union[str, istr], str], CIMultiDict[str], CIMultiDictProxy[str], None]" [arg-type]
    • Line: 303 - Error: Argument "headers" to "ClientSession" has incompatible type "Sized"; expected "Union[Mapping[Union[str, istr], str], CIMultiDict[str], CIMultiDictProxy[str], None]" [arg-type]
    • Line: 316 - Error: Argument "headers" to "ClientSession" has incompatible type "Sized"; expected "Union[Mapping[Union[str, istr], str], CIMultiDict[str], CIMultiDictProxy[str], None]" [arg-type]
    • Line: 325 - Error: Argument "headers" to "ClientSession" has incompatible type "Sized"; expected "Union[Mapping[Union[str, istr], str], CIMultiDict[str], CIMultiDictProxy[str], None]" [arg-type]
    • Line: 445 - Error: Argument "headers" to "ClientSession" has incompatible type "Sized"; expected "Union[Mapping[Union[str, istr], str], CIMultiDict[str], CIMultiDictProxy[str], None]" [arg-type]
    • Line: 465 - Error: Argument "headers" to "ClientSession" has incompatible type "Sized"; expected "Union[Mapping[Union[str, istr], str], CIMultiDict[str], CIMultiDictProxy[str], None]" [arg-type]
    • Line: 488 - Error: Argument "headers" to "ClientSession" has incompatible type "Sized"; expected "Union[Mapping[Union[str, istr], str], CIMultiDict[str], CIMultiDictProxy[str], None]" [arg-type]
    • Line: 496 - Error: Argument 3 to "fetch" of "AsyncFetcher" has incompatible type "Sized"; expected "str" [arg-type]
  • File: theHarvester/discovery/takeover.py

    • Line: 15 - Error: Need type annotation for "fingerprints" (hint: "fingerprints: Dict[, ] = ...") [var-annotated]
    • Line: 17 - Error: Need type annotation for "results" [var-annotated]
    • Line: 99 - Error: Incompatible types in assignment (expression has type "list[Any]", variable has type "tuple[Any, ...]") [assignment]
  • File: theHarvester/discovery/dnsdumpster.py

    • Line: 28 - Error: Incompatible types in assignment (expression has type "list[str]", variable has type "str") [assignment]
    • Line: 33 - Error: Incompatible types in assignment (expression has type "list[str]", variable has type "str") [assignment]
  • File: theHarvester/discovery/constants.py

    • Line: 92 - Error: Argument "data" to "post_fetch" of "AsyncFetcher" has incompatible type "dict[str, str]"; expected "str" [arg-type]
  • File: theHarvester/discovery/zoomeyesearch.py

    • Line: 58 - Error: Incompatible types in assignment (expression has type "Pattern[str]", variable has type "str") [assignment]
  • File: theHarvester/discovery/securitytrailssearch.py

    • Line: 57 - Error: Incompatible types in assignment (expression has type "Union[list[Any], tuple[Any, ...]]", variable has type "tuple[]") [assignment]
    • Line: 62 - Error: Tuple index out of range [misc]
    • Line: 65 - Error: Tuple index out of range [misc]
  • File: theHarvester/discovery/intelxsearch.py

    • Line: 63 - Error: Incompatible types in assignment (expression has type "tuple[Any, ...]", variable has type "None") [assignment]
    • Line: 71 - Error: Incompatible types in assignment (expression has type "tuple[Any, ...]", variable has type "tuple[]") [assignment]
    • Line: 71 - Error: Argument 1 to "parse_dictionaries" of "Parser" has incompatible type "None"; expected "dict[Any, Any]" [arg-type]
  • File: theHarvester/discovery/githubcode.py

    • Line: 111 - Error: Incompatible return value type (got "Optional[Any]", expected "int") [return-value]
  • File: theHarvester/discovery/bingsearch.py

    • Line: 51 - Error: Incompatible types in assignment (expression has type "tuple[Any, ...]", variable has type "str") [assignment]
  • File: theHarvester/discovery/censysearch.py

    • Line: 8 - Error: Module "censys.search" has no attribute "CensysCertificates"; maybe "CensysCerts"? [attr-defined]

@yoonthegoon
Copy link
Contributor Author

I need to take a look at page_from_response later.
My brain tells me that last_page should never be None, but I'd need to dig through the logic some more.
If anyone has any input, please let me know.

I run pytest and everything is passing locally.
If there are any other tests I need to run, I didn't 🤷

@yoonthegoon
Copy link
Contributor Author

Also damn, I tried to do a quiet commit for formatting. You can review with shift + click over the other commits when reviewing though.

@L1ghtn1ng
Copy link
Collaborator

I need to take a look at page_from_response later.

My brain tells me that last_page should never be None, but I'd need to dig through the logic some more.

If anyone has any input, please let me know.

I run pytest and everything is passing locally.

If there are any other tests I need to run, I didn't 🤷

As far as I understand it that is to know when to stop iterating, I could be wrong on that but would need Matt to chime in.

@L1ghtn1ng
Copy link
Collaborator

With regards to more checks to run, can you fix the flake8 ci failures from this PR please?

@yoonthegoon
Copy link
Contributor Author

I think it might be appropriate to also add E203, W503 to .flake8 ignore.
They are both whitespace before ':' and line break before binary operator respectively.
Both of those make for more readable code when slicing with an expression and long binary sequences like in some conditionals.

theHarvester/lib/core.py Fixed Show resolved Hide resolved
@L1ghtn1ng
Copy link
Collaborator

L1ghtn1ng commented Jul 24, 2023 via email

@yoonthegoon
Copy link
Contributor Author

I wouldn't be too worried about running these workflows yet; I still haven't fixed theHarvester/discovery/githubcode.py.
I'll take a look at that a bit later.

@@ -848,7 +848,6 @@ async def handler(lst):
print('\n[*] Virtual hosts:')
print('------------------')
for data in host_ip:
from theHarvester.discovery import bingsearch
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from theHarvester.discovery import * already exists at the top of the file.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some times it's needed as it does not actually work without that, if you tested it and it still works then am happy for it to be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested it out myself after making this change yet, only ran pytest after. I'll give it a shot tomorrow. There's still more I've got to go through it looks like.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LMK if you got a command I can run that results in some vhosts. I tried a few stuff with keeping and removing the import, but both resulsts didn't have any vhosts to show. I can experiment with harvesting more a bit later.

theHarvester/lib/core.py Fixed Show resolved Hide resolved
@yoonthegoon
Copy link
Contributor Author

Looks like the workflow isn't pointing to .flake8.

░▒▓    ~/repos/theHarvester    MyPy-CI-failures *1 ··········· theHarvester   22:39:19  ▓▒░
❯ flake8 --config .flake8 theHarvester                    

░▒▓    ~/repos/theHarvester    MyPy-CI-failures *1 ··········· theHarvester   22:39:23  ▓▒░
❯ flake8 theHarvester                                     
theHarvester/discovery/constants.py:47:13: W503 line break before binary operator
theHarvester/discovery/constants.py:48:13: W503 line break before binary operator
theHarvester/discovery/constants.py:69:13: W503 line break before binary operator
theHarvester/discovery/constants.py:70:13: W503 line break before binary operator
theHarvester/discovery/constants.py:106:9: W503 line break before binary operator
theHarvester/discovery/constants.py:107:9: W503 line break before binary operator
theHarvester/discovery/takeover.py:34:21: W503 line break before binary operator
theHarvester/discovery/zoomeyesearch.py:171:21: W503 line break before binary operator
theHarvester/discovery/zoomeyesearch.py:172:21: W503 line break before binary operator
theHarvester/discovery/zoomeyesearch.py:173:21: W503 line break before binary operator
theHarvester/discovery/zoomeyesearch.py:174:21: W503 line break before binary operator
theHarvester/screenshot/screenshot.py:57:26: E203 whitespace before ':'

@L1ghtn1ng
Copy link
Collaborator

Looks like the workflow isn't pointing to .flake8.


░▒▓    ~/repos/theHarvester    MyPy-CI-failures *1 ··········· theHarvester   22:39:19  ▓▒░

❯ flake8 --config .flake8 theHarvester                    



░▒▓    ~/repos/theHarvester    MyPy-CI-failures *1 ··········· theHarvester   22:39:23  ▓▒░

❯ flake8 theHarvester                                     

theHarvester/discovery/constants.py:47:13: W503 line break before binary operator

theHarvester/discovery/constants.py:48:13: W503 line break before binary operator

theHarvester/discovery/constants.py:69:13: W503 line break before binary operator

theHarvester/discovery/constants.py:70:13: W503 line break before binary operator

theHarvester/discovery/constants.py:106:9: W503 line break before binary operator

theHarvester/discovery/constants.py:107:9: W503 line break before binary operator

theHarvester/discovery/takeover.py:34:21: W503 line break before binary operator

theHarvester/discovery/zoomeyesearch.py:171:21: W503 line break before binary operator

theHarvester/discovery/zoomeyesearch.py:172:21: W503 line break before binary operator

theHarvester/discovery/zoomeyesearch.py:173:21: W503 line break before binary operator

theHarvester/discovery/zoomeyesearch.py:174:21: W503 line break before binary operator

theHarvester/screenshot/screenshot.py:57:26: E203 whitespace before ':'

Ah can you update it please and give it the --config flag as that is what is missing, thanks for pointing that out

@yoonthegoon
Copy link
Contributor Author

It looks like expected behavior of method next_page_or_end is to return None if next_page and last_page are both None.
Therefore, I will have to change the return type of the method, and the type of the variables that call it.

@yoonthegoon
Copy link
Contributor Author

yoonthegoon commented Jul 24, 2023

❯ flake8 --config .flake8 theHarvester

❯ mypy --pretty theHarvester/*/*.py              
Success: no issues found in 51 source files

❯ pytest                                         
====================================== test session starts ======================================
platform darwin -- Python 3.9.6, pytest-7.4.0, pluggy-1.2.0
rootdir: /Users/yunis/repos/theHarvester
configfile: pytest.ini
testpaths: tests
plugins: asyncio-0.21.1, anyio-3.7.1, typeguard-2.13.3
asyncio: mode=auto
collected 16 items                                                                              

tests/test_myparser.py .                                                                  [  6%]
tests/discovery/test_anubis.py ...                                                        [ 25%]
tests/discovery/test_certspotter.py ...                                                   [ 43%]
tests/discovery/test_githubcode.py .....                                                  [ 75%]
tests/discovery/test_otx.py ..                                                            [ 87%]
tests/discovery/test_threatminer.py ..                                                    [100%]

====================================== 16 passed in 46.83s ======================================

Hopefully all checks pass this time around.
I have just once concern about removing import shadowed by loop variable.
When I run python3 theHarvester.py -v -d google.com -b all, my output is

...
zxkitk.feedproxy.ghs.google.com:142.250.204.83
zyy53f.feedproxy.ghs.google.com

[*] Virtual hosts:
------------------

❯ 

both with and without the looped import.
It's great that it doesn't give me a NameError from removing the import.
However, I'd like to ensure that a source and domain that result in virtual hosts also result in those same virtual hosts with the looped import removed.
Otherwise, LGTM 🤷

@L1ghtn1ng
Copy link
Collaborator

L1ghtn1ng commented Jul 24, 2023 via email

@yoonthegoon
Copy link
Contributor Author

yoonthegoon commented Jul 24, 2023

No luck with either domain.
It should be fine as bingsearch is brought into the namespace here.
Everything is passing locally and we'll have to see how the workflows look.
I think the near future, I'll probably write an issue to clean up __main__.py and probably the rest of the repo to properly order the imports and to not use import * as that can cause confusion as to where certain modules are coming from.

@yoonthegoon
Copy link
Contributor Author

I see #1341 but I cannot reproduce the reference before assignment.
I imagine this may also be something cause by having imports throughout the script in conditionals rather than all at the top of the file.
This goes along with my last comment about cleaning this up.
Practically all these modules are already being imported and brought into the namespace by import *, so a refactor to have explicit imports of all of these modules would be better and less likely to cause these issues.

@L1ghtn1ng
Copy link
Collaborator

Yeah sounds good to me ☺️ major big thanks for this very much appreciated you fixing these issues

@L1ghtn1ng L1ghtn1ng merged commit 4f0e3bc into laramies:master Jul 25, 2023
@yoonthegoon yoonthegoon deleted the MyPy-CI-failures branch July 25, 2023 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants