cp
This commit is contained in:
parent
348bcf93a7
commit
cc2810bbf9
@ -1 +0,0 @@
|
|||||||
{"ID":"9b771a70-f4b7-dbb4-f919-38d27ca55e23","Operation":"OperationTypeApply","Info":"","Who":"DESKTOP\\habal@Desktop","Version":"1.10.1","Created":"2025-05-24T22:38:22.6064375Z","Path":"terraform.tfstate"}
|
|
||||||
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"version": 4,
|
"version": 4,
|
||||||
"terraform_version": "1.10.1",
|
"terraform_version": "1.10.1",
|
||||||
"serial": 415,
|
"serial": 417,
|
||||||
"lineage": "a183cd95-f987-8698-c6dd-84e933c394a5",
|
"lineage": "a183cd95-f987-8698-c6dd-84e933c394a5",
|
||||||
"outputs": {
|
"outputs": {
|
||||||
"cloud_function_name": {
|
"cloud_function_name": {
|
||||||
@ -469,7 +469,7 @@
|
|||||||
"automatic_update_policy": [
|
"automatic_update_policy": [
|
||||||
{}
|
{}
|
||||||
],
|
],
|
||||||
"build": "projects/761163285547/locations/us-central1/builds/b2b7e513-e00e-462a-8ac8-94abdfb4a0b9",
|
"build": "projects/761163285547/locations/us-central1/builds/7b34015c-eb2f-4a80-ac64-b7d3355173ac",
|
||||||
"docker_repository": "projects/gen-lang-client-0424120530/locations/us-central1/repositories/gcf-artifacts",
|
"docker_repository": "projects/gen-lang-client-0424120530/locations/us-central1/repositories/gcf-artifacts",
|
||||||
"entry_point": "process_image_embedding",
|
"entry_point": "process_image_embedding",
|
||||||
"environment_variables": {},
|
"environment_variables": {},
|
||||||
@ -483,7 +483,7 @@
|
|||||||
{
|
{
|
||||||
"bucket": "gen-lang-client-0424120530-cloud-function-source",
|
"bucket": "gen-lang-client-0424120530-cloud-function-source",
|
||||||
"generation": 1748123369545880,
|
"generation": 1748123369545880,
|
||||||
"object": "function-source-a5d3a7fe131c972bf8d0edf309545042.zip"
|
"object": "function-source-46efa1aee5386e2f244b597289c7c4ba.zip"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -523,6 +523,7 @@
|
|||||||
"FIRESTORE_DATABASE_NAME": "sereact-imagedb",
|
"FIRESTORE_DATABASE_NAME": "sereact-imagedb",
|
||||||
"FIRESTORE_PROJECT_ID": "gen-lang-client-0424120530",
|
"FIRESTORE_PROJECT_ID": "gen-lang-client-0424120530",
|
||||||
"GCS_BUCKET_NAME": "sereact-images",
|
"GCS_BUCKET_NAME": "sereact-images",
|
||||||
|
"GOOGLE_CLOUD_PROJECT": "gen-lang-client-0424120530",
|
||||||
"LOG_EXECUTION_ID": "true",
|
"LOG_EXECUTION_ID": "true",
|
||||||
"LOG_LEVEL": "INFO",
|
"LOG_LEVEL": "INFO",
|
||||||
"QDRANT_API_KEY": "",
|
"QDRANT_API_KEY": "",
|
||||||
@ -530,7 +531,7 @@
|
|||||||
"QDRANT_HOST": "34.71.6.1",
|
"QDRANT_HOST": "34.71.6.1",
|
||||||
"QDRANT_HTTPS": "false",
|
"QDRANT_HTTPS": "false",
|
||||||
"QDRANT_PORT": "6333",
|
"QDRANT_PORT": "6333",
|
||||||
"VISION_API_ENABLED": "true"
|
"VERTEX_AI_LOCATION": "us-central1"
|
||||||
},
|
},
|
||||||
"gcf_uri": "",
|
"gcf_uri": "",
|
||||||
"ingress_settings": "ALLOW_ALL",
|
"ingress_settings": "ALLOW_ALL",
|
||||||
@ -552,7 +553,7 @@
|
|||||||
"goog-terraform-provisioned": "true"
|
"goog-terraform-provisioned": "true"
|
||||||
},
|
},
|
||||||
"timeouts": null,
|
"timeouts": null,
|
||||||
"update_time": "2025-05-24T22:31:52.525335119Z",
|
"update_time": "2025-05-24T22:39:42.051374046Z",
|
||||||
"url": "https://us-central1-gen-lang-client-0424120530.cloudfunctions.net/process-image-embedding"
|
"url": "https://us-central1-gen-lang-client-0424120530.cloudfunctions.net/process-image-embedding"
|
||||||
},
|
},
|
||||||
"sensitive_attributes": [
|
"sensitive_attributes": [
|
||||||
@ -596,13 +597,6 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"mode": "managed",
|
|
||||||
"type": "google_compute_address",
|
|
||||||
"name": "vector_db_static_ip",
|
|
||||||
"provider": "provider[\"registry.terraform.io/hashicorp/google\"]",
|
|
||||||
"instances": []
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"mode": "managed",
|
"mode": "managed",
|
||||||
"type": "google_compute_firewall",
|
"type": "google_compute_firewall",
|
||||||
|
|||||||
@ -1,201 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
"""
|
|
||||||
Test script to verify admin image access functionality.
|
|
||||||
This script tests that:
|
|
||||||
1. Regular users can only see images from their own team
|
|
||||||
2. Admin users can see all images across all teams
|
|
||||||
"""
|
|
||||||
|
|
||||||
import asyncio
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
from datetime import datetime
|
|
||||||
from bson import ObjectId
|
|
||||||
|
|
||||||
# Add the src directory to the path
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
|
|
||||||
|
|
||||||
from src.models.image import ImageModel
|
|
||||||
from src.models.user import UserModel
|
|
||||||
from src.db.repositories.image_repository import image_repository
|
|
||||||
from src.db.repositories.user_repository import user_repository
|
|
||||||
from src.db.providers.firestore_provider import firestore_db
|
|
||||||
|
|
||||||
|
|
||||||
async def setup_test_data():
|
|
||||||
"""Set up test data for the admin functionality test"""
|
|
||||||
print("Setting up test data...")
|
|
||||||
|
|
||||||
# Create two teams
|
|
||||||
team1_id = ObjectId()
|
|
||||||
team2_id = ObjectId()
|
|
||||||
|
|
||||||
# Create users
|
|
||||||
regular_user = UserModel(
|
|
||||||
email="regular@test.com",
|
|
||||||
name="Regular User",
|
|
||||||
team_id=team1_id,
|
|
||||||
is_admin=False
|
|
||||||
)
|
|
||||||
|
|
||||||
admin_user = UserModel(
|
|
||||||
email="admin@test.com",
|
|
||||||
name="Admin User",
|
|
||||||
team_id=team1_id,
|
|
||||||
is_admin=True
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create test images for team 1
|
|
||||||
image1_team1 = ImageModel(
|
|
||||||
filename="team1-image1.jpg",
|
|
||||||
original_filename="team1_image1.jpg",
|
|
||||||
file_size=1024,
|
|
||||||
content_type="image/jpeg",
|
|
||||||
storage_path="images/team1-image1.jpg",
|
|
||||||
team_id=team1_id,
|
|
||||||
uploader_id=regular_user.id,
|
|
||||||
description="Team 1 Image 1",
|
|
||||||
tags=["team1", "test"]
|
|
||||||
)
|
|
||||||
|
|
||||||
image2_team1 = ImageModel(
|
|
||||||
filename="team1-image2.jpg",
|
|
||||||
original_filename="team1_image2.jpg",
|
|
||||||
file_size=2048,
|
|
||||||
content_type="image/jpeg",
|
|
||||||
storage_path="images/team1-image2.jpg",
|
|
||||||
team_id=team1_id,
|
|
||||||
uploader_id=admin_user.id,
|
|
||||||
description="Team 1 Image 2",
|
|
||||||
tags=["team1", "admin"]
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create test images for team 2
|
|
||||||
image1_team2 = ImageModel(
|
|
||||||
filename="team2-image1.jpg",
|
|
||||||
original_filename="team2_image1.jpg",
|
|
||||||
file_size=1536,
|
|
||||||
content_type="image/jpeg",
|
|
||||||
storage_path="images/team2-image1.jpg",
|
|
||||||
team_id=team2_id,
|
|
||||||
uploader_id=ObjectId(), # Different user from team 2
|
|
||||||
description="Team 2 Image 1",
|
|
||||||
tags=["team2", "test"]
|
|
||||||
)
|
|
||||||
|
|
||||||
return {
|
|
||||||
'regular_user': regular_user,
|
|
||||||
'admin_user': admin_user,
|
|
||||||
'team1_id': team1_id,
|
|
||||||
'team2_id': team2_id,
|
|
||||||
'images': [image1_team1, image2_team1, image1_team2]
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async def test_regular_user_access(regular_user, team1_id):
|
|
||||||
"""Test that regular users only see their team's images"""
|
|
||||||
print("\n=== Testing Regular User Access ===")
|
|
||||||
|
|
||||||
# Simulate getting images for regular user (team-filtered)
|
|
||||||
team1_images = await image_repository.get_by_team(team1_id, skip=0, limit=50)
|
|
||||||
team1_count = await image_repository.count_by_team(team1_id)
|
|
||||||
|
|
||||||
print(f"Regular user sees {len(team1_images)} images from their team")
|
|
||||||
print(f"Total count for team: {team1_count}")
|
|
||||||
|
|
||||||
for image in team1_images:
|
|
||||||
print(f" - {image.filename} (Team: {image.team_id})")
|
|
||||||
|
|
||||||
# Verify all images belong to the user's team
|
|
||||||
for image in team1_images:
|
|
||||||
assert image.team_id == team1_id, f"Regular user should not see image from different team: {image.filename}"
|
|
||||||
|
|
||||||
print("✅ Regular user access test passed - only sees team images")
|
|
||||||
return len(team1_images)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_admin_user_access(admin_user):
|
|
||||||
"""Test that admin users see all images across all teams"""
|
|
||||||
print("\n=== Testing Admin User Access ===")
|
|
||||||
|
|
||||||
# Simulate getting all images for admin user
|
|
||||||
all_images = await image_repository.get_all_with_pagination(skip=0, limit=50)
|
|
||||||
all_count = await image_repository.count_all()
|
|
||||||
|
|
||||||
print(f"Admin user sees {len(all_images)} images across all teams")
|
|
||||||
print(f"Total count across all teams: {all_count}")
|
|
||||||
|
|
||||||
teams_seen = set()
|
|
||||||
for image in all_images:
|
|
||||||
teams_seen.add(str(image.team_id))
|
|
||||||
print(f" - {image.filename} (Team: {image.team_id})")
|
|
||||||
|
|
||||||
print(f"Admin sees images from {len(teams_seen)} different teams")
|
|
||||||
|
|
||||||
# Verify admin sees more images than regular user would
|
|
||||||
assert len(all_images) >= 2, "Admin should see images from multiple teams"
|
|
||||||
assert len(teams_seen) >= 2, "Admin should see images from at least 2 teams"
|
|
||||||
|
|
||||||
print("✅ Admin user access test passed - sees all images across teams")
|
|
||||||
return len(all_images)
|
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
|
||||||
"""Main test function"""
|
|
||||||
print("🧪 Testing Admin Image Access Functionality")
|
|
||||||
print("=" * 50)
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Connect to database
|
|
||||||
firestore_db.connect()
|
|
||||||
print("✅ Connected to Firestore")
|
|
||||||
|
|
||||||
# Set up test data
|
|
||||||
test_data = await setup_test_data()
|
|
||||||
|
|
||||||
# Create test images in database
|
|
||||||
created_images = []
|
|
||||||
for image in test_data['images']:
|
|
||||||
created_image = await image_repository.create(image)
|
|
||||||
created_images.append(created_image)
|
|
||||||
print(f"Created test image: {created_image.filename}")
|
|
||||||
|
|
||||||
# Test regular user access
|
|
||||||
regular_count = await test_regular_user_access(
|
|
||||||
test_data['regular_user'],
|
|
||||||
test_data['team1_id']
|
|
||||||
)
|
|
||||||
|
|
||||||
# Test admin user access
|
|
||||||
admin_count = await test_admin_user_access(test_data['admin_user'])
|
|
||||||
|
|
||||||
# Verify admin sees more images than regular user
|
|
||||||
print(f"\n=== Summary ===")
|
|
||||||
print(f"Regular user images: {regular_count}")
|
|
||||||
print(f"Admin user images: {admin_count}")
|
|
||||||
|
|
||||||
if admin_count > regular_count:
|
|
||||||
print("✅ SUCCESS: Admin sees more images than regular user")
|
|
||||||
else:
|
|
||||||
print("❌ FAILURE: Admin should see more images than regular user")
|
|
||||||
|
|
||||||
# Clean up test data
|
|
||||||
print(f"\n=== Cleanup ===")
|
|
||||||
for image in created_images:
|
|
||||||
await image_repository.delete(image.id)
|
|
||||||
print(f"Deleted test image: {image.filename}")
|
|
||||||
|
|
||||||
print("✅ Test completed successfully!")
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"❌ Test failed with error: {e}")
|
|
||||||
import traceback
|
|
||||||
traceback.print_exc()
|
|
||||||
finally:
|
|
||||||
# Disconnect from database
|
|
||||||
firestore_db.disconnect()
|
|
||||||
print("✅ Disconnected from Firestore")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
asyncio.run(main())
|
|
||||||
Loading…
x
Reference in New Issue
Block a user