#!/usr/bin/env python # -*- coding: utf-8 -*- """Test LDAP authentication with provided credentials""" import os import sys from dotenv import load_dotenv from app import create_app from utils.ldap_utils import authenticate_user # Load environment variables load_dotenv() def test_ldap_auth(): """Test LDAP authentication""" print("=" * 60) print("Testing LDAP Authentication") print("=" * 60) print(f"LDAP Server: {os.getenv('LDAP_SERVER')}") print(f"Search Base: {os.getenv('LDAP_SEARCH_BASE')}") print(f"Login Attr: {os.getenv('LDAP_USER_LOGIN_ATTR')}") print("-" * 60) username = 'ymirliu@panjit.com.tw' password = '3EDC4rfv5tgb' print(f"Testing authentication for: {username}") # Create Flask app and context app = create_app() with app.app_context(): try: result = authenticate_user(username, password) if result: print("[SUCCESS] Authentication successful!") print(f"User info: {result}") else: print("[FAILED] Authentication failed") return result is not None except Exception as e: print(f"[ERROR] Exception during authentication: {str(e)}") import traceback traceback.print_exc() return False if __name__ == "__main__": test_ldap_auth()