-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30673d4
commit f6c5665
Showing
5 changed files
with
82 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
venv/ | ||
evilurl.egg-info/ | ||
dist/ | ||
.eggs/ | ||
.eggs/ | ||
__pycache__/ | ||
*.pyc | ||
*.pyo | ||
*.pyd | ||
*.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import unittest | ||
from unittest.mock import patch | ||
|
||
from src.evilurl import (HomographAnalyzer, load_unicode_combinations_from_file, main) | ||
|
||
|
||
class TestHomographAnalyzer(unittest.TestCase): | ||
|
||
def setUp(self): | ||
unicode_combinations = [ | ||
{"latin": "a", "similar": ["а", "ɑ"]}, | ||
{"latin": "c", "similar": ["ϲ", "с", "ƈ"]}, | ||
{"latin": "e", "similar": ["е"]}, | ||
{"latin": "o", "similar": ["о", "ο", "o", "օ"]}, | ||
{"latin": "p", "similar": ["р"]}, | ||
{"latin": "s", "similar": ["ѕ"]}, | ||
{"latin": "i", "similar": ["і"]}, | ||
{"latin": "d", "similar": ["ԁ"]}, | ||
{"latin": "l", "similar": ["ɩ"]}, | ||
{"latin": "g", "similar": ["ɡ"]}, | ||
{"latin": "n", "similar": ["ո"]}, | ||
{"latin": "u", "similar": ["ս"]}, | ||
{"latin": "k", "similar": ["κ"]}, | ||
{"latin": "h", "similar": ["һ"]}, | ||
{"latin": "x", "similar": ["х"]}, | ||
{"latin": "y", "similar": ["у"]} | ||
] | ||
self.analyzer = HomographAnalyzer(unicode_combinations, show_domains_only=False) | ||
|
||
def test_convert_to_punycode(self): | ||
punycode = self.analyzer.convert_to_punycode("gіtһսb.com") | ||
self.assertEqual(punycode, "xn--gtb-jhd02cr1b.com") | ||
|
||
@patch('socket.gethostbyname') | ||
def test_check_domain_registration(self, mock_gethostbyname): | ||
mock_gethostbyname.return_value = "127.0.0.1" | ||
result = self.analyzer.check_domain_registration("example.com") | ||
self.assertEqual(result, "127.0.0.1") | ||
|
||
def test_extract_domain_parts(self): | ||
url = "example.com" | ||
result = self.analyzer.extract_domain_parts(url) | ||
self.assertEqual(result, ['example', 'com']) | ||
|
||
def test_generate_combinations(self): | ||
result = self.analyzer.generate_combinations('x') | ||
self.assertEqual(result, ([['x', 'х']], ['х'])) | ||
|
||
@patch('builtins.print') | ||
def test_analyze_domain(self, mock_print): | ||
domain = "r.com" | ||
self.analyzer.analyze_domain(domain) | ||
mock_print.assert_called_with("IDN homograph attack is not possible for this domain with the current character set") | ||
|
||
def test_load_unicode_combinations_from_file(self): | ||
with patch('builtins.open', create=True) as mock_open: | ||
mock_open.return_value.__enter__.return_value.read.return_value = '[{"latin": "a", "similar": ["а", "ɑ"]}]' | ||
result = load_unicode_combinations_from_file("fake_file.json") | ||
self.assertEqual(result, [{"latin": "a", "similar": ["а", "ɑ"]}]) | ||
|
||
def test_main(self): | ||
with patch('sys.argv', ['src.evilurl.py', 'example.com']): | ||
with patch('src.evilurl.HomographAnalyzer.analyze_domain') as mock_analyze_domain: | ||
main() | ||
mock_analyze_domain.assert_called_with('example.com') | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |