Report failed bank connections and stop resurrecting deleted accounts

Three defects made new connections silently vanish while removed
accounts returned:

- A single shared account the journal cannot represent (securities or
  card entries without IBAN, stable identification or currency) aborted
  the entire consent. Usable accounts are now linked and the rest
  counted and reported.
- A consent that linked nothing was stored, redirected as success and
  later reaped by session recovery. It now fails with the reason.
- Callback failures rendered a bare JSON error page and were never
  logged. They now log and redirect into the app with the reason shown.
- Deleting an account left its session binding, so the next connect or
  sync recovered the binding and re-added the account. Account deletion
  now releases bindings, consents and cursors before committing.
This commit is contained in:
Lars Nolden
2026-09-11 11:46:59 +02:00
parent 3df9bda989
commit e77969b8c5
9 changed files with 242 additions and 34 deletions
+9 -1
View File
@@ -37,6 +37,10 @@ type Session struct {
ID string `json:"session_id"`
ValidUntil string `json:"valid_until"`
Accounts []domain.Account `json:"accounts"`
// Unlinkable counts accounts the bank shared that cannot be represented
// as a journal account (no IBAN or stable identification, or an
// unsupported currency). They are excluded, never silently merged.
Unlinkable int `json:"unlinkable,omitempty"`
}
// SessionStatus contains only the current consent expiry and external account
@@ -585,10 +589,14 @@ func (p *EnableBanking) Exchange(ctx context.Context, code string) (Session, err
return Session{}, fmt.Errorf("Enable Banking returned invalid session expiry")
}
result := Session{ID: response.ID, ValidUntil: response.Access.ValidUntil, Accounts: []domain.Account{}}
// One account the journal cannot represent (securities or card entries
// commonly lack an IBAN, stable identification or a currency) must not
// discard the whole consent: link the usable accounts and count the rest.
for _, a := range response.Accounts {
account, err := a.account(response.ASPSP.Name)
if err != nil {
return Session{}, err
result.Unlinkable++
continue
}
result.Accounts = append(result.Accounts, account)
}
+21
View File
@@ -283,6 +283,27 @@ func TestEnableBankingInstitutionsListsOnlyConnectableBanksWithSafeLogos(t *test
t.Fatal("accepted an invalid country code")
}
}
func TestEnableBankingLinksUsableAccountsAndCountsTheRest(t *testing.T) {
p, _ := testProvider(t, func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `{"session_id":"session-1","access":{"valid_until":"2099-01-01T00:00:00Z"},"aspsp":{"name":"ING","country":"DE"},"accounts":[
{"uid":"giro","identification_hash":"hash-giro","account_id":{"iban":"DE02120300000000202051"},"details":"Girokonto","currency":"EUR"},
{"uid":"depot","identification_hash":"hash-depot","details":"Direkt-Depot"},
{"uid":"card","account_id":{},"details":"Credit card","currency":"EUR"},
{"uid":"extra","identification_hash":"hash-extra","details":"Extra-Konto","currency":"EUR"}
]}`)
})
session, err := p.Exchange(context.Background(), "code")
if err != nil {
t.Fatalf("one unusable shared account discarded the whole consent: %v", err)
}
var names []string
for _, account := range session.Accounts {
names = append(names, account.DisplayName)
}
if !reflect.DeepEqual(names, []string{"Girokonto", "Extra-Konto"}) || session.Unlinkable != 2 {
t.Fatalf("wrong linked accounts or unlinkable count: %v %d", names, session.Unlinkable)
}
}
func TestEnableBankingSurfacesOnlyDocumentedErrorCodes(t *testing.T) {
body := ""
p, _ := testProvider(t, func(w http.ResponseWriter, r *http.Request) {