Skip to content

Commit ef04601

Browse files
Check nickname (#28)
* add main code * add __init__.py,__main__.py,module.py,test_module.py * fix module.py fix test_module.py * add test_module.py * add requirements.txt * fix tests,module.py add new lines in __main__.py and __init__.py * add test_module.py * delete get_title * add some tests to test_module.py fix social_networks.txt * fix styles modify social_networks.txt * fix module.py fix test_module.py * Cosmetic fixes Co-authored-by: manmolecular <regwebghost@yandex.ru>
1 parent 1634ac6 commit ef04601

File tree

3 files changed

+60
-5
lines changed

3 files changed

+60
-5
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
twitter.com/
21
vk.com/
32
ok.ru/
43
instagram.com/
54
github.com/
65
reddit.com/user/
7-
tiktok.com/@
86
mastodon.social/@
9-
blackplanet.com/
107
flickr.com/photos/
8+
gab.com/
9+
ficwad.com/a/
10+
www.opendiary.com/m/author/
1111

1212

src/scripts/osint/check_nickname/module.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import aiohttp
77
import requests
8-
8+
import string
99
from src.core.base.osint import OsintRunner
1010
from src.core.utils.response import ScriptResponse
1111

@@ -55,7 +55,7 @@ async def check_nickname_async(nickname: str, social) -> list:
5555
while not social.empty():
5656
url = await social.get()
5757
try:
58-
async with session.get(url) as response:
58+
async with session.get(url, timeout=5) as response:
5959
if response.status == 200:
6060
ans.append(url)
6161
except:
@@ -76,6 +76,11 @@ def __init__(self, logger: str = __name__):
7676
async def __run(*args, **kwargs):
7777
try:
7878
username = kwargs.get("username")
79+
bad_symbols = list(set(username).intersection(string.punctuation))
80+
if bad_symbols:
81+
return ScriptResponse.error(
82+
message=f"Invalid characters: {', '.join(bad_symbols)}"
83+
)
7984
social = asyncio.Queue()
8085
for site in Networks().net:
8186
await social.put(
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python3
2+
3+
import string
4+
from random import choice, randrange
5+
from unittest import TestCase
6+
7+
from .module import Runner
8+
9+
10+
class NicknameCheckTest(TestCase):
11+
def setUp(self):
12+
"""
13+
Setup something before each test function
14+
:return: None
15+
"""
16+
self.runner = Runner()
17+
18+
def test_create_runner(self) -> None:
19+
"""
20+
Test creation of the class instance
21+
:return: None
22+
"""
23+
self.assertIsNotNone(self.runner)
24+
self.assertIsInstance(self.runner, Runner)
25+
26+
def test_nicknames(self) -> None:
27+
"""
28+
Test different usernames with random acceptable
29+
characters
30+
:return: None
31+
"""
32+
response = self.runner.run(username="")
33+
self.assertEqual(response.get("status"), "success")
34+
for _ in range(5):
35+
nickname = "".join(choice(string.ascii_letters) for _ in range(randrange(5, 10)))
36+
response = self.runner.run(username=nickname)
37+
self.assertEqual(response.get("status"), "success")
38+
39+
def test_special_nicknames(self) -> None:
40+
"""
41+
Test not acceptable characters in username
42+
and not acceptable formats of the stdin
43+
:return:
44+
"""
45+
response = self.runner.run(username=None)
46+
self.assertEqual(response.get("status"), "error")
47+
for _ in range(5):
48+
nickname = "".join(choice(string.punctuation) for _ in range(randrange(3, 5)))
49+
response = self.runner.run(username=nickname)
50+
self.assertEqual(response.get("status"), "error")

0 commit comments

Comments
 (0)