Skip to content

Commit

Permalink
Throw an error when we recieve an expired session key from B&T
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathangreen committed Feb 27, 2024
1 parent 822723a commit 9856d2e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
16 changes: 15 additions & 1 deletion api/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1703,7 +1703,8 @@ def _parse(self, parsed: dict[str, Any], **kwargs: Any) -> T:
class Axis360FulfillmentInfoResponseParser(
JSONResponseParser[
tuple[Union[FindawayManifest, "AxisNowManifest"], datetime.datetime]
]
],
LoggerMixin,
):
"""Parse JSON documents into Findaway audiobook manifests or AxisNow manifests."""

Expand Down Expand Up @@ -1771,6 +1772,19 @@ def parse_findaway(
sessionKey = k("FNDSessionKey", parsed)
checkoutId = k("FNDTransactionID", parsed)

if sessionKey == "Expired":
if license_pool.identifier is None:
identifier = f"LicensePool {license_pool.id}"
else:
identifier = f"{license_pool.identifier.type}/{license_pool.identifier.identifier}"

message = f"Expired findaway session key for {identifier}. Request data: {json.dumps(parsed)}"
self.log.error(message)
raise RemoteInitiatedServerError(
message,
self.SERVICE_NAME,
)

# Acquire the TOC information
metadata_response = self.api.get_audiobook_metadata(fulfillmentId)
parser = AudiobookMetadataParser()
Expand Down
7 changes: 7 additions & 0 deletions tests/api/test_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1639,6 +1639,13 @@ def get_data():
m(bad_date, license_pool=pool)
assert "Could not parse expiration date: not-a-date" in str(excinfo.value)

# Try with an expired session key.
expired_session_key = get_data()
expired_session_key["FNDSessionKey"] = "Expired"
with pytest.raises(RemoteInitiatedServerError) as excinfo:
m(expired_session_key, license_pool=pool)
assert "Expired findaway session key" in str(excinfo.value)

def test__parse_axisnow(self, axis360parsers: Axis360FixturePlusParsers) -> None:
# _parse will create a valid AxisNowManifest given a
# complete document.
Expand Down

0 comments on commit 9856d2e

Please sign in to comment.