Secure authentication system with granular role-based permissions.
+
+
+
+
+
+
+
+
+
LLM Integration
+
Advanced AI capabilities with multiple LLM provider support.
+
+
+
+
+
+
+
+
+
Analytics & Monitoring
+
Comprehensive analytics and monitoring for development workflows.
+
+
+
+
+
+{% if current_user.is_authenticated %}
+
+
+
+
+ Welcome back, {{ current_user.username }}!
+ You are logged in with roles:
+ {% for role in current_user.get_roles() %}
+ {{ role }}
+ {% endfor %}
+
+
+
+{% endif %}
+{% endblock %}
\ No newline at end of file
diff --git a/test/unit/frontend/__init__.py b/test/unit/frontend/__init__.py
new file mode 100644
index 00000000..71dc1a74
--- /dev/null
+++ b/test/unit/frontend/__init__.py
@@ -0,0 +1 @@
+# Frontend tests
\ No newline at end of file
diff --git a/test/unit/frontend/test_auth.py b/test/unit/frontend/test_auth.py
new file mode 100644
index 00000000..bf9ea30b
--- /dev/null
+++ b/test/unit/frontend/test_auth.py
@@ -0,0 +1,272 @@
+"""
+Unit tests for frontend authentication system.
+"""
+import pytest
+import sys
+from pathlib import Path
+
+# Add src to path
+src_path = Path(__file__).parent.parent.parent.parent / 'src'
+sys.path.insert(0, str(src_path))
+
+from frontend.auth import create_app
+from frontend.models import db, User, Role, UserRole, init_default_roles
+
+
+@pytest.fixture
+def app():
+ """Create test application."""
+ app = create_app({
+ 'TESTING': True,
+ 'SQLALCHEMY_DATABASE_URI': 'sqlite:///:memory:',
+ 'WTF_CSRF_ENABLED': False,
+ 'SECRET_KEY': 'test-secret-key'
+ })
+
+ with app.app_context():
+ db.create_all()
+ init_default_roles()
+
+ # Create test users
+ admin_role = Role.query.filter_by(name='admin').first()
+ user_role = Role.query.filter_by(name='user').first()
+
+ admin_user = User(username='testadmin', email='admin@test.com')
+ admin_user.set_password('testpass123')
+ admin_user.add_role(admin_role)
+
+ regular_user = User(username='testuser', email='user@test.com')
+ regular_user.set_password('testpass123')
+ regular_user.add_role(user_role)
+
+ db.session.add(admin_user)
+ db.session.add(regular_user)
+ db.session.commit()
+
+ yield app
+
+
+@pytest.fixture
+def client(app):
+ """Create test client."""
+ return app.test_client()
+
+
+@pytest.fixture
+def runner(app):
+ """Create test CLI runner."""
+ return app.test_cli_runner()
+
+
+class TestUserModel:
+ """Test User model functionality."""
+
+ def test_user_creation(self, app):
+ """Test user creation."""
+ with app.app_context():
+ user = User(username='newuser', email='new@test.com')
+ user.set_password('password123')
+
+ assert user.username == 'newuser'
+ assert user.email == 'new@test.com'
+ assert user.check_password('password123')
+ assert not user.check_password('wrongpassword')
+
+ def test_user_roles(self, app):
+ """Test user role functionality."""
+ with app.app_context():
+ user = User.query.filter_by(username='testadmin').first()
+
+ assert user.has_role('admin')
+ assert not user.has_role('nonexistent')
+ assert 'admin' in user.get_roles()
+
+ def test_password_hashing(self, app):
+ """Test password hashing security."""
+ with app.app_context():
+ user = User(username='testpass', email='test@test.com')
+ user.set_password('plaintext')
+
+ # Password should be hashed
+ assert user.password_hash != 'plaintext'
+ assert user.check_password('plaintext')
+ assert not user.check_password('wrongtext')
+
+
+class TestRoleModel:
+ """Test Role model functionality."""
+
+ def test_role_creation(self, app):
+ """Test role creation."""
+ with app.app_context():
+ role = Role(name='testrole', description='Test role')
+ db.session.add(role)
+ db.session.commit()
+
+ assert role.name == 'testrole'
+ assert role.description == 'Test role'
+
+ def test_role_relationships(self, app):
+ """Test role-user relationships."""
+ with app.app_context():
+ admin_role = Role.query.filter_by(name='admin').first()
+ users_with_admin = admin_role.user_roles.count()
+
+ assert users_with_admin > 0
+
+
+class TestAuthentication:
+ """Test authentication routes and functionality."""
+
+ def test_login_page(self, client):
+ """Test login page renders."""
+ response = client.get('/auth/login')
+ assert response.status_code == 200
+ assert b'Sign In' in response.data
+
+ def test_register_page(self, client):
+ """Test register page renders."""
+ response = client.get('/auth/register')
+ assert response.status_code == 200
+ assert b'Register' in response.data
+
+ def test_valid_login(self, client):
+ """Test valid user login."""
+ response = client.post('/auth/login', data={
+ 'username': 'testuser',
+ 'password': 'testpass123'
+ }, follow_redirects=True)
+
+ assert response.status_code == 200
+ assert b'Dashboard' in response.data or b'Logged in successfully' in response.data
+
+ def test_invalid_login(self, client):
+ """Test invalid login credentials."""
+ response = client.post('/auth/login', data={
+ 'username': 'testuser',
+ 'password': 'wrongpassword'
+ })
+
+ assert response.status_code == 200
+ assert b'Invalid username or password' in response.data
+
+ def test_user_registration(self, client):
+ """Test user registration."""
+ response = client.post('/auth/register', data={
+ 'username': 'newuser',
+ 'email': 'newuser@test.com',
+ 'password': 'newpassword123',
+ 'confirm_password': 'newpassword123'
+ }, follow_redirects=True)
+
+ assert response.status_code == 200
+ assert b'Registration successful' in response.data or b'Sign In' in response.data
+
+ def test_duplicate_registration(self, client):
+ """Test registration with existing username."""
+ response = client.post('/auth/register', data={
+ 'username': 'testuser', # Already exists
+ 'email': 'different@test.com',
+ 'password': 'newpassword123',
+ 'confirm_password': 'newpassword123'
+ })
+
+ assert response.status_code == 200
+ assert b'Username already exists' in response.data or b'already registered' in response.data
+
+
+class TestAPIEndpoints:
+ """Test API authentication endpoints."""
+
+ def test_api_login_valid(self, client):
+ """Test API login with valid credentials."""
+ response = client.post('/auth/api/login',
+ json={
+ 'username': 'testuser',
+ 'password': 'testpass123'
+ },
+ content_type='application/json'
+ )
+
+ assert response.status_code == 200
+ data = response.get_json()
+ assert 'user' in data
+ assert data['user']['username'] == 'testuser'
+
+ def test_api_login_invalid(self, client):
+ """Test API login with invalid credentials."""
+ response = client.post('/auth/api/login',
+ json={
+ 'username': 'testuser',
+ 'password': 'wrongpassword'
+ },
+ content_type='application/json'
+ )
+
+ assert response.status_code == 401
+ data = response.get_json()
+ assert 'error' in data
+
+
+class TestRoleBasedAccess:
+ """Test role-based access control."""
+
+ def login_user(self, client, username, password):
+ """Helper method to login a user."""
+ return client.post('/auth/login', data={
+ 'username': username,
+ 'password': password
+ }, follow_redirects=True)
+
+ def test_admin_access(self, client):
+ """Test admin can access admin panel."""
+ self.login_user(client, 'testadmin', 'testpass123')
+ response = client.get('/admin')
+ assert response.status_code == 200
+ assert b'Admin Panel' in response.data or b'Users Management' in response.data
+
+ def test_user_no_admin_access(self, client):
+ """Test regular user cannot access admin panel."""
+ self.login_user(client, 'testuser', 'testpass123')
+ response = client.get('/admin')
+
+ # Should redirect to unauthorized or return 403
+ assert response.status_code in [302, 403]
+
+ def test_unauthenticated_access(self, client):
+ """Test unauthenticated user redirected to login."""
+ response = client.get('/dashboard')
+ assert response.status_code == 302 # Redirect to login
+
+
+class TestDecorators:
+ """Test authentication decorators."""
+
+ def test_login_required_decorator(self, app):
+ """Test login_required decorator functionality."""
+ from frontend.decorators import login_required
+
+ @login_required
+ def protected_view():
+ return "Protected content"
+
+ with app.test_request_context():
+ # Should redirect when not authenticated
+ from flask_login import current_user
+ assert not current_user.is_authenticated
+
+ def test_role_required_decorator(self, app):
+ """Test require_role decorator functionality."""
+ from frontend.decorators import require_role
+
+ @require_role('admin')
+ def admin_view():
+ return "Admin content"
+
+ with app.test_request_context():
+ # Function should be properly decorated
+ assert hasattr(admin_view, '__wrapped__')
+
+
+if __name__ == '__main__':
+ pytest.main([__file__])
\ No newline at end of file
From 13f0526ad63b4ed945e614a1ac4830a577ce724c Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Fri, 15 Aug 2025 22:32:22 +0000
Subject: [PATCH 3/3] Complete frontend infrastructure implementation with
documentation and integration guide
Co-authored-by: vinod0m <221896197+vinod0m@users.noreply.github.com>
---
FRONTEND_INTEGRATION.md | 181 ++++++++++++++++++++++++++++++++++++++
src/frontend/sdlc_core.db | Bin 32768 -> 32768 bytes
2 files changed, 181 insertions(+)
create mode 100644 FRONTEND_INTEGRATION.md
diff --git a/FRONTEND_INTEGRATION.md b/FRONTEND_INTEGRATION.md
new file mode 100644
index 00000000..fecab772
--- /dev/null
+++ b/FRONTEND_INTEGRATION.md
@@ -0,0 +1,181 @@
+# Frontend Infrastructure Integration Guide
+
+## Overview
+
+The frontend infrastructure has been successfully implemented and integrated into the SDLC Core system. This guide explains how to use and integrate the authentication system with the existing components.
+
+## Quick Start
+
+### 1. Starting the Frontend
+```bash
+cd src/frontend
+python app.py
+```
+
+### 2. Default Access
+- **URL**: http://localhost:5000
+- **Admin Username**: admin
+- **Admin Password**: admin123
+
+## Integration with Existing Components
+
+### Using Authentication in Your Code
+
+```python
+# Import the frontend components
+from src.frontend import create_app, User, Role, require_role, login_required
+
+# Example: Protecting an API endpoint
+from src.frontend.decorators import require_role
+
+@require_role('developer')
+def my_protected_api():
+ return {"message": "Developer access granted"}
+
+# Example: Checking user roles
+from flask_login import current_user
+
+if current_user.has_role('admin'):
+ # Admin functionality
+ pass
+```
+
+### Database Integration
+
+The frontend uses SQLAlchemy models that can be extended:
+
+```python
+from src.frontend.models import db, User
+
+# Add custom fields to user
+class ExtendedUser(User):
+ __tablename__ = 'users'
+
+ # Add custom fields
+ department = db.Column(db.String(100))
+ preferences = db.Column(db.JSON)
+```
+
+### API Integration
+
+The system provides REST API endpoints that can be used by other components:
+
+```python
+import requests
+
+# Login via API
+response = requests.post('http://localhost:5000/auth/api/login',
+ json={'username': 'admin', 'password': 'admin123'})
+
+# Get user profile
+response = requests.get('http://localhost:5000/auth/api/user/profile')
+```
+
+## Role-Based Access Control
+
+### Available Roles
+- **admin**: Full system access
+- **user**: Standard user access
+- **moderator**: Content moderation
+- **analyst**: Data analysis and reporting
+- **developer**: Development and API access
+
+### Using Roles in Components
+
+```python
+# In LLM components
+from src.frontend.decorators import require_role
+
+@require_role('analyst')
+def generate_analytics_report():
+ # Only analysts can generate reports
+ pass
+
+# In agents
+@require_role('developer')
+def deploy_agent():
+ # Only developers can deploy agents
+ pass
+```
+
+## Configuration
+
+### Environment Variables
+```bash
+export SECRET_KEY="your-production-secret-key"
+export DATABASE_URL="postgresql://user:pass@localhost/sdlc_core"
+export WTF_CSRF_ENABLED="true"
+```
+
+### Production Deployment
+1. Set secure SECRET_KEY
+2. Use PostgreSQL database
+3. Enable HTTPS
+4. Change default admin password
+5. Configure proper CORS settings
+
+## Security Considerations
+
+1. **Password Security**: Uses bcrypt hashing
+2. **Session Security**: Flask-Login session management
+3. **CSRF Protection**: Built-in CSRF token validation
+4. **Role Validation**: Server-side role checking
+5. **API Security**: JWT tokens can be added for API authentication
+
+## Extending the System
+
+### Adding New Roles
+```python
+# Add in models.py or via admin interface
+new_role = Role(name='researcher', description='Research access')
+db.session.add(new_role)
+db.session.commit()
+```
+
+### Custom Decorators
+```python
+from src.frontend.decorators import require_any_role
+
+@require_any_role('admin', 'developer', 'analyst')
+def advanced_feature():
+ pass
+```
+
+### Adding Custom Routes
+```python
+from src.frontend.auth import main_bp
+from src.frontend.decorators import login_required
+
+@main_bp.route('/custom-feature')
+@login_required
+def custom_feature():
+ return render_template('custom.html')
+```
+
+## Testing
+
+Run the authentication tests:
+```bash
+PYTHONPATH=src python -m pytest test/unit/frontend/ -v
+```
+
+## Troubleshooting
+
+### Common Issues
+1. **Import Errors**: Ensure PYTHONPATH includes src directory
+2. **Database Errors**: Check database permissions and connectivity
+3. **CSRF Errors**: Disable CSRF for API testing with WTF_CSRF_ENABLED=false
+4. **Role Errors**: Ensure users have appropriate roles assigned
+
+### Debug Mode
+```bash
+FLASK_ENV=development python app.py
+```
+
+## Next Steps
+
+1. Integrate with existing LLM components
+2. Add API authentication tokens
+3. Implement user preferences and profiles
+4. Add audit logging for security events
+5. Integrate with CI/CD pipelines for role-based deployments
\ No newline at end of file
diff --git a/src/frontend/sdlc_core.db b/src/frontend/sdlc_core.db
index 6d3fafb997e4415d9d511be689f64520cae4ecc9..ea6a121a8f6fd0c9da821d4985b9b4c687493d53 100644
GIT binary patch
delta 35
qcmZo@U}|V!njp={HBrWyk!xeZ6nP$F11ke_JxfCia|5GA3JCzJb_o>#
delta 35
qcmZo@U}|V!njp={IZ?)$k#l3h6nP#ab1Or0J!4}_a|8253JCzJn+Y5M