Skip to content

Commit d0554b8

Browse files
committed
feat: add unit tests for SMB brute force module
1 parent 500a299 commit d0554b8

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/core/lib/test_smb.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from unittest.mock import patch
2+
from tests.common import TestCase
3+
from nettacker.core.lib.smb import (
4+
SmbLibrary,
5+
create_connection
6+
)
7+
8+
9+
SMB_SESSION_PORT = 445
10+
11+
class MockSmbConnectionObject:
12+
def __init__(self, remoteName='', remoteHost='', sess_port=SMB_SESSION_PORT):
13+
self._sess_port = sess_port
14+
self._remoteHost = remoteHost
15+
self._remoteName = remoteName
16+
17+
def login(self, user, password, domain = '', lmhash = '', nthash = ''):
18+
return None
19+
20+
21+
22+
class TestSmbMethod(TestCase):
23+
@patch("nettacker.core.lib.smb.create_connection")
24+
def test_brute_force_password(self, mock_smb_connection):
25+
library = SmbLibrary()
26+
HOST = "dc-01"
27+
PORT = 445
28+
USERNAME = "Administrator"
29+
PASSWORD = "Password@123"
30+
31+
mock_smb_connection.return_value = MockSmbConnectionObject(HOST, remoteHost=HOST, sess_port=PORT)
32+
self.assertEqual(
33+
library.brute_force(
34+
host=HOST,
35+
port=PORT,
36+
username=USERNAME,
37+
password=PASSWORD,
38+
),
39+
{
40+
'host': HOST,
41+
'port': PORT,
42+
'username': USERNAME,
43+
'password': PASSWORD,
44+
},
45+
)

0 commit comments

Comments
 (0)