forked from alpadalar/ActiveDirectoryMCP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick_ldap_test.py
More file actions
executable file
·131 lines (102 loc) · 3.81 KB
/
quick_ldap_test.py
File metadata and controls
executable file
·131 lines (102 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python3
"""Hızlı LDAP bağlantı testi"""
import ldap3
from ldap3 import Server, Connection, ALL, SUBTREE
def test_openldap():
print("🔍 OpenLDAP Bağlantı Testi")
print("=" * 50)
try:
# Server bağlantısı
server = Server('192.168.1.100', port=389, get_info=ALL)
print(f"✅ Server: {server}")
# Bağlantı
conn = Connection(
server,
user='cn=admin,dc=test,dc=local',
password='Admin123!',
auto_bind=True
)
print(f"✅ Connected: {conn}")
# Root DSE bilgileri
print(f"✅ Naming contexts: {server.info.naming_contexts}")
print(f"✅ Supported schemas: {len(server.info.schema.object_classes)} object classes")
# Basit arama
result = conn.search(
search_base='dc=test,dc=local',
search_filter='(objectClass=*)',
search_scope=SUBTREE,
attributes=['dn', 'objectClass'],
size_limit=10
)
print(f"✅ Search result: {result}")
print(f"✅ Found {len(conn.entries)} entries")
# Entries'leri listele
for i, entry in enumerate(conn.entries[:5]):
print(f" {i+1}. {entry.entry_dn}")
# Connection kapat
conn.unbind()
return True
except Exception as e:
print(f"❌ Error: {e}")
return False
def test_with_mcp_config():
print("\n🔧 ActiveDirectoryMCP Config ile Test")
print("=" * 50)
try:
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
from active_directory_mcp.config.loader import load_config
from active_directory_mcp.core.ldap_manager import LDAPManager
# Config yükle
config = load_config('ad-config/samba-ad-config.json')
print(f"✅ Config loaded: {config.active_directory.server}")
# LDAP Manager
ldap_manager = LDAPManager(
config.active_directory,
config.security,
config.performance
)
print("✅ LDAP Manager created")
# Connection test
result = ldap_manager.test_connection()
print(f"✅ Connection test: {result}")
return result.get('connected', False)
except Exception as e:
print(f"❌ MCP Config Error: {e}")
return False
def test_http_api():
print("\n🌐 HTTP API Testi")
print("=" * 50)
try:
import requests
# Health check
response = requests.get('http://localhost:8813', timeout=5)
print(f"✅ HTTP Status: {response.status_code}")
print(f"✅ Response: {response.text[:200]}...")
return True
except Exception as e:
print(f"❌ HTTP Error: {e}")
return False
if __name__ == "__main__":
print("🧪 ActiveDirectoryMCP + OpenLDAP Test Suite")
print("=" * 60)
# Test 1: Direct LDAP
ldap_ok = test_openldap()
# Test 2: MCP Config
mcp_ok = test_with_mcp_config()
# Test 3: HTTP API
http_ok = test_http_api()
# Summary
print("\n📊 Test Sonuçları")
print("=" * 50)
print(f"🔍 Direct LDAP: {'✅ SUCCESS' if ldap_ok else '❌ FAILED'}")
print(f"🔧 MCP Config: {'✅ SUCCESS' if mcp_ok else '❌ FAILED'}")
print(f"🌐 HTTP API: {'✅ SUCCESS' if http_ok else '❌ FAILED'}")
if ldap_ok and mcp_ok and http_ok:
print("\n🎉 Tüm testler başarılı!")
print("💡 Web arayüzleri:")
print(" - LDAP Admin: http://localhost:8080")
print(" - ActiveDirectoryMCP: http://localhost:8813")
else:
print("\n💡 Bazı testler başarısız oldu.")