Skip to content

A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.

feat(types): refactor to use nodeLabel

dextmorgn21376168ef12
diff --git a/flowsint-types/src/flowsint_types/__init__.py b/flowsint-types/src/flowsint_types/__init__.py
index 5be0ca92..7f913037 100644
--- a/flowsint-types/src/flowsint_types/__init__.py
+++ b/flowsint-types/src/flowsint_types/__init__.py
@@ -4,12 +4,7 @@ Flowsint Types - Pydantic models for flowsint
# Import registry first to ensure it's ready for auto-registration
# Import base class
-from .flowsint_base import FlowsintType
-from .registry import TYPE_REGISTRY, flowsint_type, get_type, load_all_types
-
# Auto-discover and register all types
-load_all_types()
-
# For backward compatibility, explicitly import commonly used types
from typing import Any, Dict, Optional, Type
@@ -30,6 +25,7 @@ from .document import Document
from .domain import Domain
from .email import Email
from .file import File
+from .flowsint_base import FlowsintType
from .gravatar import Gravatar
from .individual import Individual
from .ip import Ip
@@ -40,6 +36,7 @@ from .organization import Organization
from .phone import Phone
from .phrase import Phrase
from .port import Port
+from .registry import TYPE_REGISTRY, flowsint_type, get_type, load_all_types
from .reputation_score import ReputationScore
from .risk_profile import RiskProfile
from .script import Script
@@ -53,6 +50,8 @@ from .web_tracker import WebTracker
from .website import Website
from .whois import Whois
+load_all_types()
+
__version__ = "0.1.0"
__author__ = "dextmorgn <[email protected]>"
@@ -99,8 +98,6 @@ __all__ = [
# Type registry utilities (legacy)
"TYPE_TO_MODEL",
"get_model_for_type",
- "clean_neo4j_node_data",
- "parse_node_to_pydantic",
"serialize_pydantic_for_transport",
"deserialize_pydantic_from_transport",
# New type registry
@@ -169,75 +166,21 @@ def get_model_for_type(type_name: str) -> Optional[Type[BaseModel]]:
return TYPE_TO_MODEL.get(type_name.lower())
-def clean_neo4j_node_data(node_data: Dict[str, Any]) -> Dict[str, Any]:
- """
- Clean Neo4j node data by removing Neo4j-specific fields and empty values.
-
- This is a preprocessing step that should be applied before Pydantic validation.
-
- Args:
- node_data: Dictionary containing node properties from Neo4j
-
- Returns:
- Cleaned dictionary with Neo4j fields and empty values removed
-
- Example:
- >>> node_data = {
- ... 'type': 'ip',
- ... 'address': '192.168.1.1',
- ... 'latitude': '',
- ... 'sketch_id': 'abc-123',
- ... 'x': 100,
- ... }
- >>> clean_neo4j_node_data(node_data)
- {'address': '192.168.1.1', 'label': 'sample'}
- """
- cleaned = {}
- for k, v in node_data.items():
- # Skip Neo4j-specific fields (including 'type' which is the node type in Neo4j)
- if k in ["sketch_id", "created_at", "type", "x", "y", "caption", "color"]:
- continue
- # Skip empty values (empty strings, None, empty lists, etc.)
- if v in ("", None, [], {}):
- continue
- cleaned[k] = v
- return cleaned
-
-
-def parse_node_to_pydantic(node_data: Dict[str, Any]) -> Optional[BaseModel]:
- """
- Parse a Neo4j node's properties into a Pydantic model instance.
- Args:
- node_data: Dictionary containing node properties from Neo4j.
- Must include a 'type' field indicating the node type.
- Returns:
- An instance of the appropriate Pydantic model, or None if parsing fails
- Example:
- >>> node_data = {
- ... 'type': 'domain',
- ... 'domain': 'example.com',
- ... 'label': 'example.com'
- ... }
- >>> result = parse_node_to_pydantic(node_data)
- >>> isinstance(result, Domain)
- True
- """
- if not node_data or "type" not in node_data:
- return None
- node_type = node_data.get("type")
- model_class = get_model_for_type(node_type)
- if not model_class:
- return None
- try:
- # Clean the node data first
- cleaned_data = clean_neo4j_node_data(node_data)
-
- # Try to instantiate the Pydantic model
- return model_class(**cleaned_data)
- except Exception as e:
- # If validation fails, log the error for debugging
- print(f"[ERROR] Failed to parse {node_type} node: {e}")
- return None
+reserved_properties = [
+ "id",
+ "x",
+ "y",
+ "nodeLabel",
+ "label",
+ "nodeType",
+ "type",
+ "nodeImage",
+ "nodeIcon",
+ "nodeColor",
+ "nodeSize",
+ "created_at",
+ "sketch_id",
+]
def serialize_pydantic_for_transport(obj: BaseModel) -> Dict[str, Any]:
diff --git a/flowsint-types/src/flowsint_types/address.py b/flowsint-types/src/flowsint_types/address.py
index 822c0d79..a04ce1cd 100644
--- a/flowsint-types/src/flowsint_types/address.py
+++ b/flowsint-types/src/flowsint_types/address.py
@@ -21,7 +21,7 @@ class Location(FlowsintType):
@model_validator(mode="after")
def compute_label(self) -> Self:
- self.label = f"{self.address}, {self.city}, {self.country}"
+ self.nodeLabel = f"{self.address}, {self.city}, {self.country}"
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/affiliation.py b/flowsint-types/src/flowsint_types/affiliation.py
index 9bcd8c4e..ea2cd80d 100644
--- a/flowsint-types/src/flowsint_types/affiliation.py
+++ b/flowsint-types/src/flowsint_types/affiliation.py
@@ -61,9 +61,9 @@ class Affiliation(FlowsintType):
@model_validator(mode='after')
def compute_label(self) -> Self:
if self.role:
- self.label = f"{self.role} at {self.organization}"
+ self.nodeLabel = f"{self.role} at {self.organization}"
else:
- self.label = self.organization
+ self.nodeLabel = self.organization
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/alias.py b/flowsint-types/src/flowsint_types/alias.py
index 5489400a..a3ddf674 100644
--- a/flowsint-types/src/flowsint_types/alias.py
+++ b/flowsint-types/src/flowsint_types/alias.py
@@ -50,7 +50,7 @@ class Alias(FlowsintType):
@model_validator(mode='after')
def compute_label(self) -> Self:
- self.label = self.alias
+ self.nodeLabel = self.alias
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/asn.py b/flowsint-types/src/flowsint_types/asn.py
index 8be0a856..d7d7a1c2 100644
--- a/flowsint-types/src/flowsint_types/asn.py
+++ b/flowsint-types/src/flowsint_types/asn.py
@@ -77,9 +77,9 @@ class ASN(FlowsintType):
def compute_label(self) -> Self:
# Use name and ASN string if available
if self.name:
- self.label = f"{self.asn_str} - {self.name}"
+ self.nodeLabel = f"{self.asn_str} - {self.name}"
else:
- self.label = self.asn_str
+ self.nodeLabel = self.asn_str
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/bank_account.py b/flowsint-types/src/flowsint_types/bank_account.py
index 0aee2f43..82560217 100644
--- a/flowsint-types/src/flowsint_types/bank_account.py
+++ b/flowsint-types/src/flowsint_types/bank_account.py
@@ -72,7 +72,7 @@ class BankAccount(FlowsintType):
if self.bank_name:
parts.append(self.bank_name)
parts.append(f"****{self.account_number[-4:]}" if len(self.account_number) > 4 else self.account_number)
- self.label = " - ".join(parts)
+ self.nodeLabel = " - ".join(parts)
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/breach.py b/flowsint-types/src/flowsint_types/breach.py
index be2e4a94..1e41335c 100644
--- a/flowsint-types/src/flowsint_types/breach.py
+++ b/flowsint-types/src/flowsint_types/breach.py
@@ -74,9 +74,9 @@ class Breach(FlowsintType):
def compute_label(self) -> Self:
# Use title if available, otherwise name
if self.title:
- self.label = self.title
+ self.nodeLabel = self.title
else:
- self.label = self.name
+ self.nodeLabel = self.name
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/cidr.py b/flowsint-types/src/flowsint_types/cidr.py
index bf991e78..1a9a2ebe 100644
--- a/flowsint-types/src/flowsint_types/cidr.py
+++ b/flowsint-types/src/flowsint_types/cidr.py
@@ -15,7 +15,7 @@ class CIDR(FlowsintType):
@model_validator(mode='after')
def compute_label(self) -> Self:
- self.label = str(self.network)
+ self.nodeLabel = str(self.network)
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/credential.py b/flowsint-types/src/flowsint_types/credential.py
index 019a8d2f..865b0ced 100644
--- a/flowsint-types/src/flowsint_types/credential.py
+++ b/flowsint-types/src/flowsint_types/credential.py
@@ -70,9 +70,9 @@ class Credential(FlowsintType):
@model_validator(mode='after')
def compute_label(self) -> Self:
if self.service:
- self.label = f"{self.username}@{self.service}"
+ self.nodeLabel = f"{self.username}@{self.service}"
else:
- self.label = self.username
+ self.nodeLabel = self.username
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/credit_card.py b/flowsint-types/src/flowsint_types/credit_card.py
index 72f5541e..33d1eafd 100644
--- a/flowsint-types/src/flowsint_types/credit_card.py
+++ b/flowsint-types/src/flowsint_types/credit_card.py
@@ -67,7 +67,7 @@ class CreditCard(FlowsintType):
if self.card_type:
parts.append(self.card_type)
parts.append(f"****{self.card_number[-4:]}" if len(self.card_number) > 4 else self.card_number)
- self.label = " ".join(parts)
+ self.nodeLabel = " ".join(parts)
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/device.py b/flowsint-types/src/flowsint_types/device.py
index b2b3edab..87ca72f2 100644
--- a/flowsint-types/src/flowsint_types/device.py
+++ b/flowsint-types/src/flowsint_types/device.py
@@ -77,7 +77,7 @@ class Device(FlowsintType):
parts.append(self.model)
if not parts:
parts.append(self.device_id)
- self.label = " ".join(parts)
+ self.nodeLabel = " ".join(parts)
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/dns_record.py b/flowsint-types/src/flowsint_types/dns_record.py
index a8970cac..5c0b5bc1 100644
--- a/flowsint-types/src/flowsint_types/dns_record.py
+++ b/flowsint-types/src/flowsint_types/dns_record.py
@@ -59,7 +59,7 @@ class DNSRecord(FlowsintType):
@model_validator(mode="after")
def compute_label(self) -> Self:
- self.label = self.value
+ self.nodeLabel = self.value
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/document.py b/flowsint-types/src/flowsint_types/document.py
index d48a10a5..fb4c2b34 100644
--- a/flowsint-types/src/flowsint_types/document.py
+++ b/flowsint-types/src/flowsint_types/document.py
@@ -63,7 +63,7 @@ class Document(FlowsintType):
@model_validator(mode='after')
def compute_label(self) -> Self:
- self.label = self.title
+ self.nodeLabel = self.title
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/domain.py b/flowsint-types/src/flowsint_types/domain.py
index 3dbcfe75..d04643ef 100644
--- a/flowsint-types/src/flowsint_types/domain.py
+++ b/flowsint-types/src/flowsint_types/domain.py
@@ -41,7 +41,7 @@ class Domain(FlowsintType):
@model_validator(mode="after")
def compute_label(self) -> Self:
- self.label = self.domain
+ self.nodeLabel = self.domain
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/email.py b/flowsint-types/src/flowsint_types/email.py
index 713f8e14..77ac22ac 100644
--- a/flowsint-types/src/flowsint_types/email.py
+++ b/flowsint-types/src/flowsint_types/email.py
@@ -13,7 +13,7 @@ class Email(FlowsintType):
@model_validator(mode='after')
def compute_label(self) -> Self:
- self.label = self.email
+ self.nodeLabel = self.email
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/file.py b/flowsint-types/src/flowsint_types/file.py
index fb0d9f17..bcaeaf17 100644
--- a/flowsint-types/src/flowsint_types/file.py
+++ b/flowsint-types/src/flowsint_types/file.py
@@ -68,7 +68,7 @@ class File(FlowsintType):
@model_validator(mode='after')
def compute_label(self) -> Self:
- self.label = self.filename
+ self.nodeLabel = self.filename
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/flowsint_base.py b/flowsint-types/src/flowsint_types/flowsint_base.py
index e56ee73c..51b3b14a 100644
--- a/flowsint-types/src/flowsint_types/flowsint_base.py
+++ b/flowsint-types/src/flowsint_types/flowsint_base.py
@@ -1,10 +1,11 @@
-from pydantic import BaseModel, Field
from typing import Optional
+from pydantic import BaseModel, Field
+
class FlowsintType(BaseModel):
- """Base class for all Flowsint entity types with label support.
- Label is optional but computed at definition time.
+ """Base class for all Flowsint entity types with nodeLabel support.
+ nodeLabel is optional but computed at definition time.
All classes that inherit from FlowsintType must be decorated with @flowsint_type
to be registered in the global TYPE_REGISTRY and accessed by their class name.
@@ -16,6 +17,13 @@ class FlowsintType(BaseModel):
class Domain(FlowsintType):
domain: str
"""
- label: Optional[str] = Field(
- None, description="UI-readable label for this entity, the one used on the graph.", title="Label"
+
+ nodeLabel: Optional[str] = Field(
+ None,
+ description="UI-readable label for this entity, the one used on the graph.",
+ title="Label",
)
+
+ # Allow extra keys to support for additional properties from user
+ class ConfigDict:
+ extra = "allow"
diff --git a/flowsint-types/src/flowsint_types/gravatar.py b/flowsint-types/src/flowsint_types/gravatar.py
index 2373fd96..85860e8a 100644
--- a/flowsint-types/src/flowsint_types/gravatar.py
+++ b/flowsint-types/src/flowsint_types/gravatar.py
@@ -50,9 +50,9 @@ class Gravatar(FlowsintType):
def compute_label(self) -> Self:
# Use display name if available, otherwise hash
if self.display_name:
- self.label = f"{self.display_name}"
+ self.nodeLabel = f"{self.display_name}"
else:
- self.label = f"{self.hash}"
+ self.nodeLabel = f"{self.hash}"
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/individual.py b/flowsint-types/src/flowsint_types/individual.py
index d62cc1a8..89f9fddb 100644
--- a/flowsint-types/src/flowsint_types/individual.py
+++ b/flowsint-types/src/flowsint_types/individual.py
@@ -404,14 +404,14 @@ class Individual(FlowsintType):
def compute_label(self) -> Self:
# Use full_name if available, otherwise concatenate first and last name
if self.full_name:
- self.label = self.full_name
+ self.nodeLabel = self.full_name
elif self.first_name and self.last_name:
- self.label = f"{self.first_name} {self.last_name}"
+ self.nodeLabel = f"{self.first_name} {self.last_name}"
elif self.first_name:
- self.label = self.first_name
+ self.nodeLabel = self.first_name
elif self.last_name:
- self.label = self.last_name
- self.full_name = self.label
+ self.nodeLabel = self.last_name
+ self.full_name = self.nodeLabel
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/ip.py b/flowsint-types/src/flowsint_types/ip.py
index 7630acc4..ef59928f 100644
--- a/flowsint-types/src/flowsint_types/ip.py
+++ b/flowsint-types/src/flowsint_types/ip.py
@@ -43,7 +43,7 @@ class Ip(FlowsintType):
@model_validator(mode="after")
def compute_label(self) -> Self:
- self.label = self.address
+ self.nodeLabel = self.address
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/leak.py b/flowsint-types/src/flowsint_types/leak.py
index bd2c4921..64583aca 100644
--- a/flowsint-types/src/flowsint_types/leak.py
+++ b/flowsint-types/src/flowsint_types/leak.py
@@ -18,7 +18,7 @@ class Leak(FlowsintType):
@model_validator(mode='after')
def compute_label(self) -> Self:
- self.label = self.name
+ self.nodeLabel = self.name
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/malware.py b/flowsint-types/src/flowsint_types/malware.py
index f24854da..2c6cf79e 100644
--- a/flowsint-types/src/flowsint_types/malware.py
+++ b/flowsint-types/src/flowsint_types/malware.py
@@ -66,9 +66,9 @@ class Malware(FlowsintType):
@model_validator(mode='after')
def compute_label(self) -> Self:
if self.family:
- self.label = f"{self.name} ({self.family})"
+ self.nodeLabel = f"{self.name} ({self.family})"
else:
- self.label = self.name
+ self.nodeLabel = self.name
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/message.py b/flowsint-types/src/flowsint_types/message.py
index 50648e87..084e0c7e 100644
--- a/flowsint-types/src/flowsint_types/message.py
+++ b/flowsint-types/src/flowsint_types/message.py
@@ -68,11 +68,11 @@ class Message(FlowsintType):
@model_validator(mode='after')
def compute_label(self) -> Self:
if self.subject:
- self.label = self.subject
+ self.nodeLabel = self.subject
else:
# Truncate content to first 50 characters
content_preview = self.content[:50] + "..." if len(self.content) > 50 else self.content
- self.label = content_preview
+ self.nodeLabel = content_preview
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/organization.py b/flowsint-types/src/flowsint_types/organization.py
index a008df9d..1005c105 100644
--- a/flowsint-types/src/flowsint_types/organization.py
+++ b/flowsint-types/src/flowsint_types/organization.py
@@ -377,11 +377,11 @@ class Organization(FlowsintType):
def compute_label(self) -> Self:
# Use the full name if available, otherwise use name
if self.nom_complet:
- self.label = str(self.nom_complet)
+ self.nodeLabel = str(self.nom_complet)
elif self.nom_raison_sociale:
- self.label = str(self.nom_raison_sociale)
+ self.nodeLabel = str(self.nom_raison_sociale)
elif self.name:
- self.label = str(self.name)
+ self.nodeLabel = str(self.name)
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/phone.py b/flowsint-types/src/flowsint_types/phone.py
index 4d0ac4ad..c9f04b57 100644
--- a/flowsint-types/src/flowsint_types/phone.py
+++ b/flowsint-types/src/flowsint_types/phone.py
@@ -61,7 +61,7 @@ class Phone(FlowsintType):
@model_validator(mode='after')
def compute_label(self) -> Self:
- self.label = self.number
+ self.nodeLabel = self.number
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/phrase.py b/flowsint-types/src/flowsint_types/phrase.py
index 0839d400..4934f551 100644
--- a/flowsint-types/src/flowsint_types/phrase.py
+++ b/flowsint-types/src/flowsint_types/phrase.py
@@ -17,7 +17,7 @@ class Phrase(FlowsintType):
def compute_label(self) -> Self:
text_str = str(self.text)
# Truncate to 100 characters for display
- self.label = text_str[:100] + "..." if len(text_str) > 100 else text_str
+ self.nodeLabel = text_str[:100] + "..." if len(text_str) > 100 else text_str
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/port.py b/flowsint-types/src/flowsint_types/port.py
index 88a836ae..c79b2dcd 100644
--- a/flowsint-types/src/flowsint_types/port.py
+++ b/flowsint-types/src/flowsint_types/port.py
@@ -38,7 +38,7 @@ class Port(FlowsintType):
parts.append(self.service)
if self.protocol:
parts.append(f"({self.protocol})")
- self.label = " ".join(parts)
+ self.nodeLabel = " ".join(parts)
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/registry.py b/flowsint-types/src/flowsint_types/registry.py
index 30d47284..cefe5a9e 100644
--- a/flowsint-types/src/flowsint_types/registry.py
+++ b/flowsint-types/src/flowsint_types/registry.py
@@ -7,14 +7,14 @@ Auto-discovery is performed by calling load_all_types() which imports all module
in the flowsint_types package, triggering the @flowsint_type decorators.
"""
-from typing import Dict, Type, TypeVar, Optional
-from pydantic import BaseModel
import importlib
import pkgutil
import sys
+from typing import Dict, Optional, Type, TypeVar
+from .flowsint_base import FlowsintType
-T = TypeVar("T", bound=BaseModel)
+T = TypeVar("T", bound=FlowsintType)
class TypeRegistry:
@@ -27,8 +27,8 @@ class TypeRegistry:
"""
def __init__(self):
- self._types: Dict[str, Type[BaseModel]] = {}
- self._lowercase_types: Dict[str, Type[BaseModel]] = {}
+ self._types: Dict[str, Type[FlowsintType]] = {}
+ self._lowercase_types: Dict[str, Type[FlowsintType]] = {}
def register(self, cls: Type[T]) -> Type[T]:
"""
@@ -51,7 +51,7 @@ class TypeRegistry:
return cls
- def get(self, type_name: str) -> Optional[Type[BaseModel]]:
+ def get(self, type_name: str) -> Optional[Type[FlowsintType]]:
"""
Get a type by its name (case-sensitive).
@@ -63,7 +63,7 @@ class TypeRegistry:
"""
return self._types.get(type_name)
- def get_lowercase(self, type_name: str) -> Optional[Type[BaseModel]]:
+ def get_lowercase(self, type_name: str) -> Optional[Type[FlowsintType]]:
"""
Get a type by its lowercase name (for Neo4j compatibility).
@@ -75,7 +75,7 @@ class TypeRegistry:
"""
return self._lowercase_types.get(type_name.lower())
- def all_types(self) -> Dict[str, Type[BaseModel]]:
+ def all_types(self) -> Dict[str, Type[FlowsintType]]:
"""
Get all registered types.
@@ -84,7 +84,7 @@ class TypeRegistry:
"""
return self._types.copy()
- def all_types_lowercase(self) -> Dict[str, Type[BaseModel]]:
+ def all_types_lowercase(self) -> Dict[str, Type[FlowsintType]]:
"""
Get all registered types with lowercase keys.
@@ -126,7 +126,9 @@ def flowsint_type(cls: Type[T]) -> Type[T]:
return TYPE_REGISTRY.register(cls)
-def get_type(type_name: str, case_sensitive: bool = False) -> Optional[Type[BaseModel]]:
+def get_type(
+ type_name: str, case_sensitive: bool = False
+) -> Optional[Type[FlowsintType]]:
"""
Convenience function to get a type from the global registry.
@@ -171,14 +173,17 @@ def load_all_types() -> None:
# Get the flowsint_types package
import flowsint_types
+
package = flowsint_types
package_path = package.__path__
package_name = package.__name__
# Iterate over all modules in the package
- for importer, modname, ispkg in pkgutil.iter_modules(package_path, prefix=f"{package_name}."):
+ for importer, modname, ispkg in pkgutil.iter_modules(
+ package_path, prefix=f"{package_name}."
+ ):
# Skip private modules
- if modname.split('.')[-1].startswith('_'):
+ if modname.split(".")[-1].startswith("_"):
continue
# Skip if already imported
diff --git a/flowsint-types/src/flowsint_types/reputation_score.py b/flowsint-types/src/flowsint_types/reputation_score.py
index dfa13ec1..e1aa4e51 100644
--- a/flowsint-types/src/flowsint_types/reputation_score.py
+++ b/flowsint-types/src/flowsint_types/reputation_score.py
@@ -64,7 +64,7 @@ class ReputationScore(FlowsintType):
parts = [self.entity_id]
if self.score is not None:
parts.append(f"Score: {self.score}")
- self.label = " - ".join(parts)
+ self.nodeLabel = " - ".join(parts)
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/risk_profile.py b/flowsint-types/src/flowsint_types/risk_profile.py
index f8de1820..0ebc0408 100644
--- a/flowsint-types/src/flowsint_types/risk_profile.py
+++ b/flowsint-types/src/flowsint_types/risk_profile.py
@@ -81,7 +81,7 @@ class RiskProfile(FlowsintType):
parts = [self.entity_id]
if self.risk_level:
parts.append(f"Risk: {self.risk_level}")
- self.label = " - ".join(parts)
+ self.nodeLabel = " - ".join(parts)
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/script.py b/flowsint-types/src/flowsint_types/script.py
index aa905c2a..db131e05 100644
--- a/flowsint-types/src/flowsint_types/script.py
+++ b/flowsint-types/src/flowsint_types/script.py
@@ -71,9 +71,9 @@ class Script(FlowsintType):
@model_validator(mode='after')
def compute_label(self) -> Self:
if self.name:
- self.label = self.name
+ self.nodeLabel = self.name
else:
- self.label = self.script_id
+ self.nodeLabel = self.script_id
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/session.py b/flowsint-types/src/flowsint_types/session.py
index 15afa6bc..c8577a15 100644
--- a/flowsint-types/src/flowsint_types/session.py
+++ b/flowsint-types/src/flowsint_types/session.py
@@ -63,7 +63,7 @@ class Session(FlowsintType):
parts.append(self.service)
if not parts:
parts.append(self.session_id)
- self.label = " - ".join(parts)
+ self.nodeLabel = " - ".join(parts)
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/social_account.py b/flowsint-types/src/flowsint_types/social_account.py
index 1635af4f..cabbae44 100644
--- a/flowsint-types/src/flowsint_types/social_account.py
+++ b/flowsint-types/src/flowsint_types/social_account.py
@@ -90,13 +90,13 @@ class SocialAccount(FlowsintType):
self.id = f"{self.username.value}@{self.platform}"
elif self.username:
self.id = self.username.value
- self.label = self.id
+ self.nodeLabel = self.id
# Use display name if available, otherwise username
if self.display_name:
- self.label = f"{self.display_name} (@{self.username.value})"
+ self.nodeLabel = f"{self.display_name} (@{self.username.value})"
else:
- self.label = self.id
+ self.nodeLabel = self.id
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/ssl_certificate.py b/flowsint-types/src/flowsint_types/ssl_certificate.py
index fb06cc45..1aca7f80 100644
--- a/flowsint-types/src/flowsint_types/ssl_certificate.py
+++ b/flowsint-types/src/flowsint_types/ssl_certificate.py
@@ -76,7 +76,7 @@ class SSLCertificate(FlowsintType):
@model_validator(mode='after')
def compute_label(self) -> Self:
- self.label = self.subject
+ self.nodeLabel = self.subject
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/username.py b/flowsint-types/src/flowsint_types/username.py
index e8241fce..b03b0190 100644
--- a/flowsint-types/src/flowsint_types/username.py
+++ b/flowsint-types/src/flowsint_types/username.py
@@ -45,7 +45,7 @@ class Username(FlowsintType):
@model_validator(mode="after")
def compute_label(self) -> Self:
- self.label = f"{self.value}"
+ self.nodeLabel = f"{self.value}"
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/wallet.py b/flowsint-types/src/flowsint_types/wallet.py
index ac2d65f4..9c2fa27f 100644
--- a/flowsint-types/src/flowsint_types/wallet.py
+++ b/flowsint-types/src/flowsint_types/wallet.py
@@ -51,7 +51,7 @@ class CryptoWallet(FlowsintType):
@model_validator(mode="after")
def compute_label(self) -> Self:
- self.label = self.address
+ self.nodeLabel = self.address
return self
@classmethod
@@ -189,11 +189,11 @@ class CryptoWalletTransaction(FlowsintType):
def compute_label(self) -> Self:
# Use hash if available, otherwise create a descriptive label
if self.hash:
- self.label = self.hash
+ self.nodeLabel = self.hash
elif self.source and self.target:
- self.label = f"Transaction from {self.source.address[:8]}... to {self.target.address[:8]}..."
+ self.nodeLabel = f"Transaction from {self.source.address[:8]}... to {self.target.address[:8]}..."
elif self.source:
- self.label = f"Transaction from {self.source.address[:8]}..."
+ self.nodeLabel = f"Transaction from {self.source.address[:8]}..."
return self
@@ -281,11 +281,11 @@ class CryptoNFT(FlowsintType):
def compute_label(self) -> Self:
# Prefer name, then collection_name with token_id, fallback to uid
if self.name:
- self.label = self.name
+ self.nodeLabel = self.name
elif self.collection_name:
- self.label = f"{self.collection_name} #{self.token_id}"
+ self.nodeLabel = f"{self.collection_name} #{self.token_id}"
else:
- self.label = self.uid
+ self.nodeLabel = self.uid
return self
diff --git a/flowsint-types/src/flowsint_types/weapon.py b/flowsint-types/src/flowsint_types/weapon.py
index 5367745d..8dda830c 100644
--- a/flowsint-types/src/flowsint_types/weapon.py
+++ b/flowsint-types/src/flowsint_types/weapon.py
@@ -122,7 +122,7 @@ class Weapon(FlowsintType):
parts = [self.name]
if self.type:
parts.append(f"({self.type})")
- self.label = " ".join(parts)
+ self.nodeLabel = " ".join(parts)
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/web_tracker.py b/flowsint-types/src/flowsint_types/web_tracker.py
index 43a2e00e..f55f65bf 100644
--- a/flowsint-types/src/flowsint_types/web_tracker.py
+++ b/flowsint-types/src/flowsint_types/web_tracker.py
@@ -65,9 +65,9 @@ class WebTracker(FlowsintType):
@model_validator(mode='after')
def compute_label(self) -> Self:
if self.name:
- self.label = self.name
+ self.nodeLabel = self.name
else:
- self.label = self.tracker_id
+ self.nodeLabel = self.tracker_id
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/website.py b/flowsint-types/src/flowsint_types/website.py
index 31bfc435..3b1a82c6 100644
--- a/flowsint-types/src/flowsint_types/website.py
+++ b/flowsint-types/src/flowsint_types/website.py
@@ -46,7 +46,7 @@ class Website(FlowsintType):
@model_validator(mode="after")
def compute_label(self) -> Self:
- self.label = str(self.url)
+ self.nodeLabel = str(self.url)
return self
@classmethod
diff --git a/flowsint-types/src/flowsint_types/whois.py b/flowsint-types/src/flowsint_types/whois.py
index 988e37ef..6b50d47d 100644
--- a/flowsint-types/src/flowsint_types/whois.py
+++ b/flowsint-types/src/flowsint_types/whois.py
@@ -69,9 +69,9 @@ class Whois(FlowsintType):
def compute_label(self) -> Self:
# Use domain and organization if available
if self.organization:
- self.label = f"{self.domain.domain} - {self.organization.name}"
+ self.nodeLabel = f"{self.domain.domain} - {self.organization.name}"
else:
- self.label = self.domain.domain
+ self.nodeLabel = self.domain.domain
return self
@classmethod
diff --git a/flowsint-types/tests/test_domain.py b/flowsint-types/tests/test_domain.py
index 5ffbd35c..ecbaf8de 100644
--- a/flowsint-types/tests/test_domain.py
+++ b/flowsint-types/tests/test_domain.py
@@ -1,33 +1,34 @@
-from flowsint_types.domain import Domain
import pytest
+from flowsint_types.domain import Domain
+
def test_valid_domain_from_object():
domain = Domain(**{"domain": "mydomain.com"})
assert domain.domain == "mydomain.com"
- assert domain.label == "mydomain.com"
- assert domain.root == True
+ assert domain.nodeLabel == "mydomain.com"
+ assert domain.root
def test_valid_subbomain_from_object():
domain = Domain(**{"domain": "blog.mydomain.com"})
assert domain.domain == "blog.mydomain.com"
- assert domain.label == "blog.mydomain.com"
- assert domain.root == False
+ assert domain.nodeLabel == "blog.mydomain.com"
+ assert not domain.root
def test_valid_domain_from_instance():
domain = Domain(domain="mydomain.com")
assert domain.domain == "mydomain.com"
- assert domain.label == "mydomain.com"
- assert domain.root == True
+ assert domain.nodeLabel == "mydomain.com"
+ assert domain.root
def test_valid_subdomain_from_instance():
domain = Domain(domain="blog.mydomain.com")
assert domain.domain == "blog.mydomain.com"
- assert domain.label == "blog.mydomain.com"
- assert domain.root == False
+ assert domain.nodeLabel == "blog.mydomain.com"
+ assert not domain.root
def test_invalid_domain_from_object():
diff --git a/flowsint-types/tests/test_ip.py b/flowsint-types/tests/test_ip.py
index 5c34151e..50dbc13f 100644
--- a/flowsint-types/tests/test_ip.py
+++ b/flowsint-types/tests/test_ip.py
@@ -1,11 +1,11 @@
-from flowsint_types.ip import Ip
import pytest
+from flowsint_types.ip import Ip
def test_valid_ip():
ip = Ip(address="12.23.34.56")
assert ip.address == "12.23.34.56"
- assert ip.label == "12.23.34.56"
+ assert ip.nodeLabel == "12.23.34.56"
def test_invalid_ip():
diff --git a/flowsint-types/tests/test_labels.py b/flowsint-types/tests/test_labels.py
index e3930f6d..63feaf22 100644
--- a/flowsint-types/tests/test_labels.py
+++ b/flowsint-types/tests/test_labels.py
@@ -21,73 +21,73 @@ from flowsint_types import (
def test_ip_label():
ip = Ip(address="12.23.34.56")
- assert ip.label == "12.23.34.56"
+ assert ip.nodeLabel == "12.23.34.56"
def test_domain_label():
domain = Domain(domain="blog.mydomain.com")
- assert domain.label == "blog.mydomain.com"
+ assert domain.nodeLabel == "blog.mydomain.com"
def test_individual_label():
individual = Individual(first_name="John", last_name="Doe")
- assert individual.label == "John Doe"
+ assert individual.nodeLabel == "John Doe"
assert individual.full_name == "John Doe"
def test_email_label():
email = Email(email="[email protected]")
- assert email.label == "[email protected]"
+ assert email.nodeLabel == "[email protected]"
def test_phone_label():
phone = Phone(number="+33123456789")
- assert phone.label == "+33123456789"
+ assert phone.nodeLabel == "+33123456789"
def test_organization_label():
# Test with name only
org = Organization(name="Acme Corp")
- assert org.label == "Acme Corp"
+ assert org.nodeLabel == "Acme Corp"
def test_organization_label_with_nom_complet():
# Test with nom_complet (has priority)
org = Organization(name="Acme", nom_complet="Acme Corporation Full Name")
- assert org.label == "Acme Corporation Full Name"
+ assert org.nodeLabel == "Acme Corporation Full Name"
def test_organization_label_with_nom_raison_sociale():
# Test with nom_raison_sociale (priority over name)
org = Organization(name="Acme", nom_raison_sociale="Acme Corporation")
- assert org.label == "Acme Corporation"
+ assert org.nodeLabel == "Acme Corporation"
def test_username_label():
username = Username(value="johndoe")
- assert username.label == "johndoe"
+ assert username.nodeLabel == "johndoe"
def test_username_label_2():
username = Username(value="@johndoe")
- assert username.label == "johndoe"
+ assert username.nodeLabel == "johndoe"
def test_credential_label():
# Test with service
credential = Credential(username="john", service="github")
- assert credential.label == "john@github"
+ assert credential.nodeLabel == "john@github"
def test_credential_label_without_service():
# Test without service
credential = Credential(username="john")
- assert credential.label == "john"
+ assert credential.nodeLabel == "john"
def test_crypto_wallet_label():
wallet = CryptoWallet(address="0x742d35Cc6634C0532925a3b844Bc454e4438f44e")
- assert wallet.label == "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"
+ assert wallet.nodeLabel == "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"
def test_crypto_nft_label_with_name():
@@ -98,7 +98,7 @@ def test_crypto_nft_label_with_name():
token_id="1234",
name="Cool NFT",
)
- assert nft.label == "Cool NFT"
+ assert nft.nodeLabel == "Cool NFT"
def test_crypto_nft_label_with_collection():
@@ -109,7 +109,7 @@ def test_crypto_nft_label_with_collection():
token_id="1234",
collection_name="Bored Apes",
)
- assert nft.label == "Bored Apes #1234"
+ assert nft.nodeLabel == "Bored Apes #1234"
def test_crypto_nft_label_fallback_uid():
@@ -119,26 +119,26 @@ def test_crypto_nft_label_fallback_uid():
contract_address="0x123d35Cc6634C0532925a3b844Bc454e4438f123",
token_id="1234",
)
- assert nft.label == "0x123d35Cc6634C0532925a3b844Bc454e4438f123:1234"
+ assert nft.nodeLabel == "0x123d35Cc6634C0532925a3b844Bc454e4438f123:1234"
def test_crypto_wallet_transaction_label_with_hash():
source_wallet = CryptoWallet(address="0x742d35Cc6634C0532925a3b844Bc454e4438f44e")
transaction = CryptoWalletTransaction(source=source_wallet, hash="0xabc123def456")
- assert transaction.label == "0xabc123def456"
+ assert transaction.nodeLabel == "0xabc123def456"
def test_crypto_wallet_transaction_label_with_source_and_target():
source_wallet = CryptoWallet(address="0x742d35Cc6634C0532925a3b844Bc454e4438f44e")
target_wallet = CryptoWallet(address="0x123d35Cc6634C0532925a3b844Bc454e4438f123")
transaction = CryptoWalletTransaction(source=source_wallet, target=target_wallet)
- assert transaction.label == "Transaction from 0x742d35... to 0x123d35..."
+ assert transaction.nodeLabel == "Transaction from 0x742d35... to 0x123d35..."
def test_crypto_wallet_transaction_label_source_only():
source_wallet = CryptoWallet(address="0x742d35Cc6634C0532925a3b844Bc454e4438f44e")
transaction = CryptoWalletTransaction(source=source_wallet)
- assert transaction.label == "Transaction from 0x742d35..."
+ assert transaction.nodeLabel == "Transaction from 0x742d35..."
def test_social_account_label_with_display_name():
@@ -146,55 +146,55 @@ def test_social_account_label_with_display_name():
account = SocialAccount(
username=username, display_name="John Doe", platform="twitter"
)
- assert account.label == "John Doe (@johndoe)"
+ assert account.nodeLabel == "John Doe (@johndoe)"
def test_social_account_label_without_display_name():
username = Username(value="johndoe")
account = SocialAccount(username=username, platform="twitter")
- assert account.label == "johndoe@twitter"
+ assert account.nodeLabel == "johndoe@twitter"
def test_website_label():
website = Website(url="https://www.example.com")
- assert website.label == "https://www.example.com/"
+ assert website.nodeLabel == "https://www.example.com/"
def test_port_label():
# Test with service and protocol
port = Port(number=80, service="http", protocol="TCP")
- assert port.label == "80 http (TCP)"
+ assert port.nodeLabel == "80 http (TCP)"
def test_port_label_with_service_only():
# Test with service only
port = Port(number=443, service="https")
- assert port.label == "443 https"
+ assert port.nodeLabel == "443 https"
def test_port_label_number_only():
# Test with number only
port = Port(number=8080)
- assert port.label == "8080"
+ assert port.nodeLabel == "8080"
def test_cidr_label():
cidr = CIDR(network="8.8.8.0/24")
- assert cidr.label == "8.8.8.0/24"
+ assert cidr.nodeLabel == "8.8.8.0/24"
def test_asn_label_with_name():
asn = ASN(asn_str="AS15169", name="Google LLC")
- assert asn.label == "AS15169 - Google LLC"
+ assert asn.nodeLabel == "AS15169 - Google LLC"
def test_asn_label_without_name():
asn = ASN(asn_str="AS15169")
- assert asn.label == "AS15169"
+ assert asn.nodeLabel == "AS15169"
def test_location_label():
location = Location(
address="123 Main St", city="Paris", country="France", zip="75001"
)
- assert location.label == "123 Main St, Paris, France"
+ assert location.nodeLabel == "123 Main St, Paris, France"
diff --git a/flowsint-types/tests/test_parser.py b/flowsint-types/tests/test_parser.py
deleted file mode 100644
index e98df467..00000000
--- a/flowsint-types/tests/test_parser.py
+++ /dev/null
@@ -1,616 +0,0 @@
-"""
-Tests for Neo4j node to Pydantic model parsing.
-
-These tests ensure that parse_node_to_pydantic correctly handles:
-- Valid nodes with all fields
-- Nodes with empty strings for optional fields
-- Nodes with missing optional fields
-- Nodes with Neo4j-specific fields that should be filtered
-- Invalid nodes that should fail validation
-"""
-
-import pytest
-from flowsint_types import (
- parse_node_to_pydantic,
- clean_neo4j_node_data,
- TYPE_TO_MODEL,
- get_model_for_type,
- Domain,
- Ip,
- Email,
- Phone,
- Organization,
-)
-
-
-class TestCleanNeo4jNodeData:
- """Test suite for clean_neo4j_node_data function."""
-
- def test_clean_removes_neo4j_fields(self):
- """Test that Neo4j-specific fields are removed."""
- node_data = {
- "type": "domain",
- "domain": "example.com",
- "label": "example.com",
- "sketch_id": "should-be-removed",
- "created_at": "should-be-removed",
- "x": 100,
- "y": 200,
- "caption": "should-be-removed",
- "color": "should-be-removed",
- }
-
- result = clean_neo4j_node_data(node_data)
-
- assert "type" not in result # Neo4j 'type' field should be removed
- assert "domain" in result
- assert "label" in result
- assert "sketch_id" not in result
- assert "created_at" not in result
- assert "x" not in result
- assert "y" not in result
- assert "caption" not in result
- assert "color" not in result
-
- def test_clean_removes_empty_strings(self):
- """Test that empty strings are removed."""
- node_data = {
- "type": "ip",
- "address": "192.168.1.1",
- "latitude": "",
- "longitude": "",
- "country": "",
- }
-
- result = clean_neo4j_node_data(node_data)
-
- assert result == {"address": "192.168.1.1"}
-
- def test_clean_removes_none_values(self):
- """Test that None values are removed."""
- node_data = {
- "type": "domain",
- "domain": "example.com",
- "some_field": None,
- }
-
- result = clean_neo4j_node_data(node_data)
-
- assert result == {"domain": "example.com"}
-
- def test_clean_removes_empty_lists(self):
- """Test that empty lists are removed."""
- node_data = {
- "type": "domain",
- "domain": "example.com",
- "tags": [],
- }
-
- result = clean_neo4j_node_data(node_data)
-
- assert result == {"domain": "example.com"}
-
- def test_clean_removes_empty_dicts(self):
- """Test that empty dicts are removed."""
- node_data = {
- "type": "domain",
- "domain": "example.com",
- "metadata": {},
- }
-
- result = clean_neo4j_node_data(node_data)
-
- assert result == {"domain": "example.com"}
-
- def test_clean_preserves_valid_data(self):
- """Test that valid data is preserved (except Neo4j 'type' field)."""
- node_data = {
- "type": "ip",
- "address": "8.8.8.8",
- "label": "8.8.8.8",
- "latitude": 37.386,
- "longitude": -122.0838,
- "country": "US",
- }
-
- result = clean_neo4j_node_data(node_data)
-
- # 'type' is filtered, rest is preserved
- expected = {
- "address": "8.8.8.8",
- "label": "8.8.8.8",
- "latitude": 37.386,
- "longitude": -122.0838,
- "country": "US",
- }
- assert result == expected
-
- def test_clean_preserves_zero_values(self):
- """Test that zero values are preserved (not treated as empty)."""
- node_data = {
- "type": "ip",
- "address": "127.0.0.1",
- "latitude": 0,
- "longitude": 0,
- }
-
- result = clean_neo4j_node_data(node_data)
-
- assert result["latitude"] == 0
- assert result["longitude"] == 0
-
- def test_clean_empty_dict(self):
- """Test cleaning an empty dict."""
- result = clean_neo4j_node_data({})
- assert result == {}
-
-
-class TestParseNodeToPydantic:
- """Test suite for parse_node_to_pydantic function."""
-
- def test_parse_domain_valid(self):
- """Test parsing a valid domain node from Neo4j."""
- node_data = {
- "type": "domain",
- "domain": "example.com",
- "label": "example.com",
- "root": True,
- "sketch_id": "abc-123",
- "created_at": "2024-01-01T00:00:00Z",
- "x": 100,
- "y": 200,
- }
-
- result = parse_node_to_pydantic(node_data)
-
- assert result is not None
- assert isinstance(result, Domain)
- assert result.domain == "example.com"
- assert result.label == "example.com"
- assert result.root == True
-
- def test_parse_ip_with_empty_optional_fields(self):
- """Test parsing IP node with empty strings for optional fields."""
- node_data = {
- "type": "ip",
- "address": "192.168.1.1",
- "label": "192.168.1.1",
- "latitude": "", # Empty string should be filtered
- "longitude": "", # Empty string should be filtered
- "country": "",
- "city": "",
- "isp": "",
- "sketch_id": "abc-123",
- "created_at": "2024-01-01T00:00:00Z",
- }
-
- result = parse_node_to_pydantic(node_data)
-
- assert result is not None
- assert isinstance(result, Ip)
- assert result.address == "192.168.1.1"
- assert result.latitude is None
- assert result.longitude is None
- assert result.country is None
- assert result.city is None
- assert result.isp is None
-
- def test_parse_ip_with_valid_optional_fields(self):
- """Test parsing IP node with valid optional fields."""
- node_data = {
- "type": "ip",
- "address": "8.8.8.8",
- "label": "8.8.8.8",
- "latitude": 37.386,
- "longitude": -122.0838,
- "country": "US",
- "city": "Mountain View",
- "isp": "Google LLC",
- }
-
- result = parse_node_to_pydantic(node_data)
-
- assert result is not None
- assert isinstance(result, Ip)
- assert result.address == "8.8.8.8"
- assert result.latitude == 37.386
- assert result.longitude == -122.0838
- assert result.country == "US"
- assert result.city == "Mountain View"
- assert result.isp == "Google LLC"
-
- def test_parse_email_valid(self):
- """Test parsing a valid email node."""
- node_data = {
- "type": "email",
- "email": "[email protected]",
- "label": "[email protected]",
- }
-
- result = parse_node_to_pydantic(node_data)
-
- assert result is not None
- assert isinstance(result, Email)
- assert result.email == "[email protected]"
-
- def test_parse_phone_valid(self):
- """Test parsing a valid phone node."""
- node_data = {
- "type": "phone",
- "number": "+33612345678",
- "label": "+33612345678",
- "country": "FR",
- }
-
- result = parse_node_to_pydantic(node_data)
-
- assert result is not None
- assert isinstance(result, Phone)
- assert result.number == "+33612345678"
- assert result.country == "FR"
-
- def test_parse_organization_valid(self):
- """Test parsing a valid organization node."""
- node_data = {
- "type": "organization",
- "name": "ACME Corp",
- "label": "ACME Corp",
- }
-
- result = parse_node_to_pydantic(node_data)
-
- assert result is not None
- assert isinstance(result, Organization)
- assert result.name == "ACME Corp"
-
- def test_parse_node_filters_neo4j_fields(self):
- """Test that Neo4j-specific fields are filtered out."""
- node_data = {
- "type": "domain",
- "domain": "test.com",
- "label": "test.com",
- "sketch_id": "should-be-filtered",
- "created_at": "should-be-filtered",
- "x": 100,
- "y": 200,
- "caption": "should-be-filtered",
- "color": "should-be-filtered",
- }
-
- result = parse_node_to_pydantic(node_data)
-
- assert result is not None
- assert isinstance(result, Domain)
- # These fields should not cause errors even though they're not in the Pydantic model
- assert result.domain == "test.com"
-
- def test_parse_node_missing_type(self):
- """Test that nodes without 'type' field return None."""
- node_data = {
- "domain": "example.com",
- "label": "example.com",
- }
-
- result = parse_node_to_pydantic(node_data)
-
- assert result is None
-
- def test_parse_node_unknown_type(self):
- """Test that nodes with unknown type return None."""
- node_data = {
- "type": "unknown_type_xyz",
- "some_field": "some_value",
- }
-
- result = parse_node_to_pydantic(node_data)
-
- assert result is None
-
- def test_parse_node_invalid_email(self):
- """Test that invalid data fails validation and returns None."""
- node_data = {
- "type": "email",
- "email": "not-an-email", # Invalid email
- "label": "not-an-email",
- }
-
- result = parse_node_to_pydantic(node_data)
-
- assert result is None
-
- def test_parse_node_invalid_ip(self):
- """Test that invalid IP address fails validation and returns None."""
- node_data = {
- "type": "ip",
- "address": "999.999.999.999", # Invalid IP
- "label": "999.999.999.999",
- }
-
- result = parse_node_to_pydantic(node_data)
-
- assert result is None
-
- def test_parse_node_missing_required_field(self):
- """Test that missing required fields cause validation to fail."""
- node_data = {
- "type": "email",
- # Missing 'email' field which is required
- "label": "test",
- }
-
- result = parse_node_to_pydantic(node_data)
-
- assert result is None
-
- def test_parse_node_empty_string_for_required_field(self):
- """Test that empty string for required field is filtered and causes validation to fail."""
- node_data = {
- "type": "domain",
- "domain": "", # Empty string should be filtered, causing validation to fail
- "label": "test",
- }
-
- result = parse_node_to_pydantic(node_data)
-
- assert result is None
-
- def test_parse_node_filters_none_values(self):
- """Test that None values are filtered out."""
- node_data = {
- "type": "ip",
- "address": "1.2.3.4",
- "label": "1.2.3.4",
- "latitude": None,
- "longitude": None,
- }
-
- result = parse_node_to_pydantic(node_data)
-
- assert result is not None
- assert isinstance(result, Ip)
- assert result.latitude is None
- assert result.longitude is None
-
- def test_parse_node_filters_empty_lists(self):
- """Test that empty lists are filtered out."""
- node_data = {
- "type": "domain",
- "domain": "example.com",
- "label": "example.com",
- "some_list_field": [], # Should be filtered
- }
-
- result = parse_node_to_pydantic(node_data)
-
- assert result is not None
- assert isinstance(result, Domain)
-
- def test_parse_node_filters_empty_dicts(self):
- """Test that empty dicts are filtered out."""
- node_data = {
- "type": "domain",
- "domain": "example.com",
- "label": "example.com",
- "some_dict_field": {}, # Should be filtered
- }
-
- result = parse_node_to_pydantic(node_data)
-
- assert result is not None
- assert isinstance(result, Domain)
-
- def test_parse_node_empty_data(self):
- """Test that empty node_data returns None."""
- result = parse_node_to_pydantic({})
- assert result is None
-
- def test_parse_node_none_data(self):
- """Test that None node_data returns None."""
- result = parse_node_to_pydantic(None)
- assert result is None
-
-
-class TestEdgeCases:
- """Test edge cases and special scenarios."""
-
- def test_ip_with_string_zero_coordinates(self):
- """Test IP with '0' string for coordinates (edge case from real data)."""
- node_data = {
- "type": "ip",
- "address": "127.0.0.1",
- "label": "127.0.0.1",
- "latitude": "0",
- "longitude": "0",
- }
-
- result = parse_node_to_pydantic(node_data)
-
- assert result is not None
- assert isinstance(result, Ip)
- # String '0' should be converted to float 0.0
- assert result.latitude == 0.0
- assert result.longitude == 0.0
-
- def test_domain_with_subdomain(self):
- """Test domain parsing with subdomain."""
- node_data = {
- "type": "domain",
- "domain": "sub.example.com",
- "label": "sub.example.com",
- }
-
- result = parse_node_to_pydantic(node_data)
-
- assert result is not None
- assert isinstance(result, Domain)
- assert result.domain == "sub.example.com"
- assert result.root == False # Should be computed as not root
-
- def test_multiple_neo4j_specific_fields(self):
- """Test that all Neo4j-specific fields are properly filtered."""
- neo4j_fields = {
- "sketch_id": "test",
- "created_at": "2024-01-01",
- "type": "domain",
- "caption": "test caption",
- "x": 100.5,
- "y": 200.5,
- "color": "#FF0000",
- }
-
- node_data = {
- **neo4j_fields,
- "domain": "example.com",
- "label": "example.com",
- }
-
- result = parse_node_to_pydantic(node_data)
-
- assert result is not None
- assert isinstance(result, Domain)
- # Verify only valid fields were used
- assert result.domain == "example.com"
- assert result.label == "example.com"
-
-
-class TestAllTypes:
- """Test parsing for ALL types in the registry."""
-
- # Mapping of type names to valid minimal data for testing
- # This ensures every type in TYPE_TO_MODEL can be parsed
- VALID_TEST_DATA = {
- "domain": {"domain": "example.com"},
- "email": {"email": "[email protected]"},
- "ip": {"address": "192.168.1.1"},
- "phone": {"number": "+33612345678"},
- "username": {"value": "john_doe"},
- "organization": {"name": "ACME Corp"},
- "individual": {"first_name": "John", "last_name": "Doe"},
- "socialaccount": {"username": {"value": "johndoe"}},
- "asn": {"asn_str": "AS15169"},
- "cidr": {"network": "192.168.1.0/24"},
- "cryptowallet": {"address": "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"},
- "cryptowallettransaction": {
- "source": {"address": "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"}
- },
- "cryptonft": {
- "wallet": {"address": "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"},
- "contract_address": "0x" + "a" * 40,
- "token_id": "123",
- },
- "website": {"url": "https://example.com"},
- "port": {"number": 443},
- "phrase": {"text": "test phrase"},
- "breach": {"name": "Test Breach"},
- "credential": {"username": "user"},
- "device": {"device_id": "device-123"},
- "document": {"title": "Test Document"},
- "file": {"filename": "test.txt"},
- "malware": {"name": "TestMalware"},
- "sslcertificate": {"subject": "CN=example.com"},
- "location": {
- "address": "123 Main St",
- "city": "Paris",
- "country": "France",
- "zip": "75001",
- },
- "affiliation": {"organization": "test org"},
- "alias": {"alias": "test_alias"},
- "bankaccount": {"account_number": "123456789"},
- "creditcard": {"card_number": "4111111111111111"},
- "dnsrecord": {
- "name": "example.com",
- "record_type": "A",
- "value": "192.168.1.1",
- },
- "gravatar": {"src": "https://gravatar.com/avatar/abc", "hash": "abc123"},
- "leak": {"name": "test leak"},
- "message": {"message_id": "msg-123", "content": "test message"},
- "reputationscore": {"entity_id": "entity-123"},
- "riskprofile": {"entity_id": "entity-123"},
- "script": {"script_id": "script-123"},
- "session": {"session_id": "session-123"},
- "webtracker": {"tracker_id": "tracker-123"},
- "weapon": {"name": "Test Weapon"},
- "whois": {"domain": {"domain": "example.com"}},
- }
-
- @pytest.mark.parametrize("type_name", list(TYPE_TO_MODEL.keys()))
- def test_type_in_registry_has_test_data(self, type_name):
- """Verify that every type in registry has test data defined."""
- assert type_name in self.VALID_TEST_DATA, (
- f"Type '{type_name}' is in TYPE_TO_MODEL but has no test data in VALID_TEST_DATA. "
- f"Please add minimal valid data for this type."
- )
-
- @pytest.mark.parametrize("type_name,model_class", TYPE_TO_MODEL.items())
- def test_parse_all_types_with_valid_data(self, type_name, model_class):
- """Test parsing each type with valid minimal data."""
- if type_name not in self.VALID_TEST_DATA:
- pytest.skip(f"No test data for {type_name}")
-
- node_data = {
- "type": type_name,
- **self.VALID_TEST_DATA[type_name],
- "label": f"test-{type_name}",
- # Add Neo4j fields that should be filtered
- "sketch_id": "test-sketch",
- "created_at": "2024-01-01T00:00:00Z",
- "x": 100,
- "y": 200,
- }
-
- result = parse_node_to_pydantic(node_data)
-
- assert result is not None, f"Failed to parse valid {type_name} data"
- assert isinstance(
- result, model_class
- ), f"Expected {model_class.__name__} but got {type(result).__name__}"
-
- @pytest.mark.parametrize("type_name,model_class", TYPE_TO_MODEL.items())
- def test_parse_all_types_with_empty_optional_fields(self, type_name, model_class):
- """Test that empty strings in optional fields don't break parsing."""
- if type_name not in self.VALID_TEST_DATA:
- pytest.skip(f"No test data for {type_name}")
-
- # Get the required fields from test data
- required_data = self.VALID_TEST_DATA[type_name].copy()
-
- # Add empty strings for some potential optional fields
- node_data = {
- "type": type_name,
- **required_data,
- "label": f"test-{type_name}",
- "description": "", # Common optional field
- "metadata": "",
- "tags": "",
- "notes": "",
- "custom_field": "",
- }
-
- result = parse_node_to_pydantic(node_data)
-
- assert (
- result is not None
- ), f"Failed to parse {type_name} with empty optional fields"
- assert isinstance(result, model_class)
-
- def test_type_registry_completeness(self):
- """Verify TYPE_TO_MODEL contains all expected types."""
- # This is a sanity check to ensure the registry isn't empty
- assert (
- len(TYPE_TO_MODEL) > 30
- ), f"TYPE_TO_MODEL should have 30+ types, found {len(TYPE_TO_MODEL)}"
-
- # Verify some key types are present
- required_types = ["domain", "email", "ip", "phone", "username", "organization"]
- for type_name in required_types:
- assert (
- type_name in TYPE_TO_MODEL
- ), f"Required type '{type_name}' missing from TYPE_TO_MODEL"
-
- def test_get_model_for_type_case_insensitive(self):
- """Test that get_model_for_type is case-insensitive."""
- assert get_model_for_type("domain") == get_model_for_type("Domain")
- assert get_model_for_type("EMAIL") == get_model_for_type("email")
- assert get_model_for_type("Ip") == get_model_for_type("ip")
diff --git a/flowsint-types/tests/test_socialaccount.py b/flowsint-types/tests/test_socialaccount.py
index d837652f..f91f39c0 100644
--- a/flowsint-types/tests/test_socialaccount.py
+++ b/flowsint-types/tests/test_socialaccount.py
@@ -1,4 +1,4 @@
-from flowsint_types import Username, SocialAccount
+from flowsint_types import SocialAccount, Username
def test_social_account_from_type():
@@ -6,14 +6,16 @@ def test_social_account_from_type():
account = SocialAccount(
username=username, display_name="John Doe", platform="twitter"
)
- assert account.label == "John Doe (@johndoe)"
+ assert account.nodeLabel == "John Doe (@johndoe)"
assert account.username.value == "johndoe"
def test_social_account_from_string():
account = SocialAccount(
# insert username as string instead of obj
- username="johndoe", display_name="John Doe", platform="twitter"
+ username="johndoe",
+ display_name="John Doe",
+ platform="twitter",
)
- assert account.label == "John Doe (@johndoe)"
+ assert account.nodeLabel == "John Doe (@johndoe)"
assert account.username.value == "johndoe"