Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9339766
D8906.id32098.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
D8906.id32098.diff
View Options
diff --git a/swh/graphql/tests/functional/test_search.py b/swh/graphql/tests/functional/test_search.py
--- a/swh/graphql/tests/functional/test_search.py
+++ b/swh/graphql/tests/functional/test_search.py
@@ -41,7 +41,7 @@
"targetType": "origin",
}
],
- "pageInfo": {"endCursor": "MQ==", "hasNextPage": True},
+ "pageInfo": {"endCursor": "VFJLSkplR1IxSkpFSEROT0hU", "hasNextPage": True},
}
}
diff --git a/swh/graphql/tests/unit/utils/test_utils.py b/swh/graphql/tests/unit/utils/test_utils.py
--- a/swh/graphql/tests/unit/utils/test_utils.py
+++ b/swh/graphql/tests/unit/utils/test_utils.py
@@ -22,12 +22,18 @@
assert utils.get_encoded_cursor(None) is None
assert utils.get_encoded_cursor("testing") == "dGVzdGluZw=="
+ def test_get_encoded_numeric_cursor(self):
+ assert utils.get_encoded_cursor("1003") == "VFJLSkplR1IxMDAzSkpFSEROT0hU"
+
def test_get_decoded_cursor_is_none(self):
assert utils.get_decoded_cursor(None) is None
def test_get_decoded_cursor(self):
assert utils.get_decoded_cursor("dGVzdGluZw==") == "testing"
+ def test_get_decoded_numeric_cursor(self):
+ assert utils.get_decoded_cursor("VFJLSkplR1IxMDAzSkpFSEROT0hU") == "1003"
+
def test_get_formatted_date(self):
date = datetime.datetime(
2015, 8, 4, 22, 26, 14, 804009, tzinfo=datetime.timezone.utc
diff --git a/swh/graphql/utils/utils.py b/swh/graphql/utils/utils.py
--- a/swh/graphql/utils/utils.py
+++ b/swh/graphql/utils/utils.py
@@ -10,6 +10,8 @@
from swh.storage.interface import PagedResult
ENCODING = "utf-8"
+CURSOR_PREFIX = "TRKJJeGR"
+CURSOR_SUFFIX = "JJEHDNOHT"
def get_b64_string(source) -> str:
@@ -21,13 +23,25 @@
def get_encoded_cursor(cursor: Optional[str]) -> Optional[str]:
if cursor is None:
return None
+ if type(cursor) == str and cursor.isnumeric():
+ # Add two random strings to make cursor a bit more opaque
+ # add this only when the cursor is numeric, this check is
+ # to avoid making cursor unnecessarily longer in other situations
+ # (eg: in snapshot-branches the branch name is used as the cursor)
+ cursor = CURSOR_PREFIX + cursor + CURSOR_SUFFIX
return get_b64_string(cursor)
def get_decoded_cursor(cursor: Optional[str]) -> Optional[str]:
if cursor is None:
return None
- return base64.b64decode(cursor, validate=True).decode()
+ # strip the added random strings from left and right
+ return (
+ base64.b64decode(cursor, validate=True)
+ .decode()
+ .lstrip(CURSOR_PREFIX)
+ .rstrip(CURSOR_SUFFIX)
+ )
def get_formatted_date(date: datetime) -> str:
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Jul 3 2025, 9:53 AM (5 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3222420
Attached To
D8906: [WIP] :Make numeric cursors a bit more opaque to avoid cursor hacks
Event Timeline
Log In to Comment