   authn_statement = assertion[0].getElementsByTagNameNS(XMLNS.SAML, 'AuthnStatement')
   throw new Error("Expected 1 AuthnStatement; found #{authn_statement.length}") unless authn_statement.length is 1
 
-  for attr in authn_statement[0].attributes
-    if attr.name is 'SessionIndex'
+  for attr in authn_statement[0].attributes or []
+    if attr?.name is 'SessionIndex'
       return attr.value
 
   throw new Error("SessionIndex not an attribute of AuthnStatement.")

  status = dom.getElementsByTagNameNS(XMLNS.SAMLP, 'Status')
  return status_list unless status.length is 1

  for status_code in status[0].childNodes
    if status_code.attributes?
      for attr in status_code.attributes
        if attr.name is 'Value'
          top_status = attr.value
          status_list[top_status] ?= []
    for sub_status_code in status_code.childNodes
      if sub_status_code.attributes?
        for attr in sub_status_code.attributes
          if attr.name is 'Value'
            status_list[top_status].push attr.value
  status_list

to_error = (err) ->

check_status_success = (dom) ->
  status = dom.getElementsByTagNameNS(XMLNS.SAMLP, 'Status')
  return false unless status.length is 1
  for status_code in status[0].childNodes or []
    if status_code.attributes?
      for attr in status_code.attributes or []
        return true if attr?.name is 'Value' and attr?.value is 'urn:oasis:names:tc:SAML:2.0:status:Success'
  false

get_status = (dom) ->
