Skip to content

Commit d27e95a

Browse files
authored
Merge pull request #60 from censys/logbook-bugfix
fix: fetch subsequent logbook pages correctly
2 parents 5bd7548 + 6fbe754 commit d27e95a

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

censys/asm/api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def _get_logbook_page(
103103
while not end_of_events:
104104
res = self._get(path, args=args)
105105
end_of_events = res["endOfEvents"]
106+
args = {"cursor": res["nextCursor"]}
106107

107108
for event in res["events"]:
108109
yield event

censys/asm/events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def get_cursor(
4040

4141
def get_events(self, cursor: Optional[str] = None) -> Generator[dict, None, None]:
4242
"""
43-
Requests a logbook cursor.
43+
Requests logbook events from inception or from the provided cursor.
4444
4545
Args:
4646
cursor (str, optional): Logbook cursor.

tests/asm/test_events.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
EVENTS_RESOURCE_TYPE = "events"
2020

2121
TEST_CURSOR = "eyJmaWx0ZXIiOnt9LCJzdGFydCI6MH0"
22+
TEST_NEXT_CURSOR = "eyJmaWx0ZXIiOnt9LCJzdGFydCI6MjA3MTJ9"
2223
TEST_START_DATE = "2020-10-29T19:26:34.371Z"
2324
TEST_START_ID = 20712
2425

@@ -108,9 +109,12 @@ def test_get_all_events(self, mock):
108109
res = [event for event in events]
109110

110111
self.assertEqual(RESOURCE_PAGING_RESULTS, res)
111-
mock.assert_called_with(
112+
mock.assert_any_call(
112113
EVENTS_URL, params={"cursor": None}, timeout=TEST_TIMEOUT
113114
)
115+
mock.assert_any_call(
116+
EVENTS_URL, params={"cursor": TEST_NEXT_CURSOR}, timeout=TEST_TIMEOUT
117+
)
114118

115119
@patch("censys.base.requests.Session.get")
116120
def test_get_events_with_cursor(self, mock):
@@ -119,9 +123,12 @@ def test_get_events_with_cursor(self, mock):
119123
res = [event for event in events]
120124

121125
self.assertEqual(RESOURCE_PAGING_RESULTS, res)
122-
mock.assert_called_with(
126+
mock.assert_any_call(
123127
EVENTS_URL, params={"cursor": TEST_CURSOR}, timeout=TEST_TIMEOUT
124128
)
129+
mock.assert_any_call(
130+
EVENTS_URL, params={"cursor": TEST_NEXT_CURSOR}, timeout=TEST_TIMEOUT
131+
)
125132

126133

127134
if __name__ == "__main__":

tests/asm/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ def __init__(self, status_code, resource_type, page_number=1):
4040
resource_type: self.get_resource(), # Return dummy resource generator
4141
"pageNumber": 1,
4242
"totalPages": 3, # Default to 3 pages of resources
43-
"cursor": "eyJmaWx0ZXIiOnt9LCJzdGFydCI6MjA3MTJ9",
43+
"nextCursor": "eyJmaWx0ZXIiOnt9LCJzdGFydCI6MjA3MTJ9",
44+
"cursor": "eyJmaWx0ZXIiOnt9LCJzdGFydCI6MH0",
4445
"endOfEvents": False,
4546
}
4647

0 commit comments

Comments
 (0)