Skip to content

Commit

Permalink
Merge pull request #1196 from SEKOIA-IO/adsearch_manage_dates
Browse files Browse the repository at this point in the history
datetime management from ad results
  • Loading branch information
penhouetp authored Nov 29, 2024
2 parents 02dae15 + cb86f42 commit 2c4c827
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions MicrosoftActiveDirectory/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
## 2024-11-28 - 1.3.7

### Fixed

- Manage datetime from ldap search response

## 2024-11-27 - 1.3.6

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion MicrosoftActiveDirectory/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"name": "Microsoft Active Directory",
"uuid": "b2d96259-af89-4f7a-ae6e-a0af2d2400f3",
"slug": "microsoft-ad",
"version": "1.3.6",
"version": "1.3.7",
"categories": [
"IAM"
]
Expand Down
4 changes: 4 additions & 0 deletions MicrosoftActiveDirectory/microsoft_ad/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from pydantic import BaseModel
from typing import List
from ldap3 import ALL_ATTRIBUTES
from ldap3.core.timezone import OffsetTzInfo
from datetime import datetime


class SearchArguments(BaseModel):
Expand All @@ -26,6 +28,8 @@ def make_serializable(self, data):
return data.entry_to_json()
elif isinstance(data, dict):
return {key: self.make_serializable(value) for key, value in data.items()}
if isinstance(data, datetime):
return data.isoformat()
else:
return data

Expand Down
8 changes: 6 additions & 2 deletions MicrosoftActiveDirectory/tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from microsoft_ad.search import SearchAction
from unittest.mock import patch
import pytest
import json
import orjson
import datetime
from ldap3.core.timezone import OffsetTzInfo


def configured_action(action: MicrosoftADAction):
Expand Down Expand Up @@ -89,6 +91,7 @@ def test_ldap_action_serialization():
"attributes": {
"cn": [b"John Doe"],
"mail": [b"[email protected]"],
"date": datetime.datetime(9999, 12, 31, 23, 59, 59, 999999, tzinfo=OffsetTzInfo(offset=0, name="UTC")),
"objectGUID": b"\x12\x34\x56\x78\x90",
"memberOf": [b"CN=Group1,DC=example,DC=com", b"CN=Group2,DC=example,DC=com"],
},
Expand All @@ -98,13 +101,14 @@ def test_ldap_action_serialization():
"attributes": {
"cn": [b"Jane Smith"],
"mail": [b"[email protected]"],
"date": datetime.datetime(2024, 11, 21, 15, 16, 38, tzinfo=datetime.timezone.utc),
"objectGUID": b"\x98\x76\x54\x32\x10",
"memberOf": [b"CN=Group1,DC=example,DC=com", b"CN=Admins,DC=example,DC=com"],
},
},
]
results = action.transform_ldap_results(entries)
try:
json.dumps(results)
orjson.dumps(results)
except (TypeError, ValueError) as e:
assert False, f"Serialization failed: {str(e)}"

0 comments on commit 2c4c827

Please sign in to comment.