Skip to content

Commit

Permalink
Merge pull request #181 from plummer86/bugfix/sgml_server_v2xx
Browse files Browse the repository at this point in the history
Catch ofxget scan exceptions, allow V1 headers to support later versions
  • Loading branch information
csingley committed Jan 13, 2024
2 parents 61deb4f + 34a0abb commit cd280e7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions ofxtools/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class OFXHeaderV1(OFXHeaderBase):

ofxheader = Types.OneOf(100)
data = Types.OneOf("OFXSGML")
version = Types.OneOf(102, 103, 151, 160)
version = Types.Integer(length=3)
security = Types.OneOf("NONE", "TYPE1")
encoding = Types.OneOf("USASCII", "UNICODE", "UTF-8")
# DRY - mapping of CHARSET: codec used below in codec()
Expand Down Expand Up @@ -153,7 +153,7 @@ def __init__(
try:
self.ofxheader = int(ofxheader or 100)
self.data = data or "OFXSGML"
self.version = int(version)
self.version = int(version or 102)
self.security = security or "NONE"
self.encoding = encoding or "USASCII"
self.charset = charset or "NONE"
Expand Down
22 changes: 11 additions & 11 deletions ofxtools/scripts/ofxget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1277,8 +1277,14 @@ def _read_scan_response(
OSError,
socket.timeout,
) as exc:
logger.debug(f"Didn't receive HTTP response: {exc}")
future.cancel()
logger.error(f"Didn't receive response: {exc}")
return valid, signoninfo
except (
ParseError,
ET.ParseError,
OFXHeaderError,
) as exc:
logger.error("Response contains invalid OFX: {exc}")
return valid, signoninfo

if read_signoninfo:
Expand Down Expand Up @@ -1310,19 +1316,13 @@ def _read_scan_response(
logger.debug(
("Received HTTP response with valid OFX; " f"signoninfo={signoninfo}")
)
except (socket.timeout,):
# We didn't receive a response at all
logger.debug("Didn't receive HTTP response: socket timeout")
valid = False
except (ParseError, ET.ParseError, OFXHeaderError):
except (ParseError, ET.ParseError, OFXHeaderError) as exc:
# We didn't receive valid OFX in the response
logger.debug("Received HTTP response that didn't contain valid OFX")
logger.error(f"Response contains invalid OFX {exc}")
valid = False
except (ValueError,):
# We received OFX; can't find SIGNONIFO (probably no PROFRS)
logger.debug(
("Received HTTP response with valid OFX; can't parse SIGNONINFO")
)
logger.warning(("Response with valid OFX; can't parse SIGNONINFO"))
valid = True
else:
# IF we're not parsing the PROFRS, then we interpret receiving a good
Expand Down
5 changes: 3 additions & 2 deletions tests/test_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ class OFXHeaderV1TestCase(unittest.TestCase, OFXHeaderTestMixin):
headerClass = ofxtools.header.OFXHeaderV1
defaultVersion = 102
valid = {
"version": (102, 103, 151, 160),
"ofxheader": (100,),
"data": ("OFXSGML",),
# OFXHeader version 100 supports message sets from later versions
"version": (102, 103, 151, 160, 200, 203),
"security": ("NONE", "TYPE1"),
"encoding": ("USASCII", "UNICODE", "UTF-8"),
"charset": ("ISO-8859-1", "1252", "NONE"),
Expand All @@ -88,9 +89,9 @@ class OFXHeaderV1TestCase(unittest.TestCase, OFXHeaderTestMixin):
"newfileuid": (str(uuid.uuid4()),),
}
invalid = {
"version": (123,),
"ofxheader": (200,),
"data": ("XML",),
"version": (1111,),
"security": ("TYPE2",),
"encoding": ("UTF-16",),
"charset": ("ISO-8859-7",),
Expand Down
1 change: 0 additions & 1 deletion tests/test_ofxget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,6 @@ def testReadScanResponse(self):

# No valid OFX: return False, empty SIGNONINFO parameters
ofx_errors = [
socket.timeout,
ET.ParseError(),
Parser.ParseError(),
header.OFXHeaderError(),
Expand Down

0 comments on commit cd280e7

Please sign in to comment.