Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/mutation/mutants.json
Original file line number Diff line number Diff line change
Expand Up @@ -5802,5 +5802,17 @@
],
"run": "^TestLocalIssuerKeysBoundIssuer$",
"why": "LocalIssuerKeys reports its own issuer as its binding"
},
{
"id": "sqlstore-ciba-unknown-handle-wraps-notfound",
"file": "sqlstore/backchannel.go",
"old": "return fmt.Errorf(\"sqlstore: %s: %w (%w)\", op, notFound(\"handle\"), storage.ErrBackchannelAuthenticationNotFound)",
"new": "return fmt.Errorf(\"sqlstore: %s: %w (%v)\", op, notFound(\"handle\"), storage.ErrBackchannelAuthenticationNotFound)",
"module": "sqlstore",
"packages": [
"."
],
"run": "^TestBackchannelDecisionsAndExpiry$",
"why": "sqlstore wraps ErrBackchannelAuthenticationNotFound for an unknown CIBA handle"
}
]
2 changes: 1 addition & 1 deletion examples/linked-accounts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/idfoundry/fapigo/examples/linked-accounts
go 1.26.11

require (
github.com/idfoundry/fapigo v0.84.0
github.com/idfoundry/fapigo v0.86.0
github.com/idfoundry/fapigo/examples/internal/demokit v0.0.0-00010101000000-000000000000
github.com/idfoundry/fapigo/sqlstore v0.0.0-00010101000000-000000000000
modernc.org/sqlite v1.62.0
Expand Down
12 changes: 10 additions & 2 deletions sqlstore/backchannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
handleHash[:]).Scan(&key, &clientID, &stored, &bound.deliveryMode, &bound.pollInterval, &bound.expires)
switch {
case errors.Is(err, sql.ErrNoRows):
return storage.LookedUpBackchannelAuthentication{}, fmt.Errorf("sqlstore: look up backchannel authentication: %w", notFound("handle"))
return storage.LookedUpBackchannelAuthentication{}, unknownBackchannelHandle("look up backchannel authentication")
case err != nil:
return storage.LookedUpBackchannelAuthentication{}, unavailable("look up backchannel authentication", err)
}
Expand Down Expand Up @@ -189,11 +189,19 @@
case errors.Is(err, sql.ErrNoRows):
return storage.DecidedBackchannelAuthentication{}, s.whyUndecided(ctx, decision.HandleHash)
case err != nil:
return storage.DecidedBackchannelAuthentication{}, unavailable("decide backchannel authentication", err)

Check failure on line 192 in sqlstore/backchannel.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "decide backchannel authentication" 3 times.

See more on https://sonarcloud.io/project/issues?id=IDFoundry_FAPIgo&issues=AaIWB-aOSfdp1gNdHC8A&open=AaIWB-aOSfdp1gNdHC8A&pullRequest=997
}
return out, nil
}

// unknownBackchannelHandle is op's error for a handle the store holds no
// request under: ErrNotFound, also wrapping
// storage.ErrBackchannelAuthenticationNotFound so the server can tell a
// request that is gone from any other refusal.
func unknownBackchannelHandle(op string) error {
return fmt.Errorf("sqlstore: %s: %w (%w)", op, notFound("handle"), storage.ErrBackchannelAuthenticationNotFound)
}

// whyUndecided is DecideBackchannelAuthentication's error for a handle
// its UPDATE didn't decide: unknown, or already decided.
func (s *BackchannelAuthenticationStore) whyUndecided(ctx context.Context, handleHash [32]byte) error {
Expand All @@ -202,7 +210,7 @@
return unavailable("decide backchannel authentication", err)
}
if n == 0 {
return fmt.Errorf("sqlstore: decide backchannel authentication: %w", notFound("handle"))
return unknownBackchannelHandle("decide backchannel authentication")
}
return errBackchannelDecided
}
Expand Down
12 changes: 8 additions & 4 deletions sqlstore/backchannel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ func TestBackchannelPollInterval(t *testing.T) {
})
}

// A decision for an unknown handle is ErrNotFound; for a decided one,
// A decision for an unknown handle is ErrNotFound, and
// storage.ErrBackchannelAuthenticationNotFound; for a decided one,
// storage.ErrBackchannelAuthenticationAlreadyDecided. Lookup keeps answering after the decision, and an approval
// polled once is spent even after the request expires.
func TestBackchannelDecisionsAndExpiry(t *testing.T) {
Expand All @@ -84,13 +85,16 @@ func TestBackchannelDecisionsAndExpiry(t *testing.T) {
b := freshDB(t, dialect).Backchannel()
r := cibaRequest("r", "poll")
must(t, b.CreateBackchannelAuthentication(ctx, r))
if _, err := b.DecideBackchannelAuthentication(ctx, storage.DecideBackchannelAuthentication{HandleHash: sha256.Sum256([]byte("unknown")), Status: storage.BackchannelAuthenticationDenied}); !errors.Is(err, sqlstore.ErrNotFound) {
t.Fatalf("DecideBackchannelAuthentication(unknown) = %v, want ErrNotFound", err)
if _, err := b.DecideBackchannelAuthentication(ctx, storage.DecideBackchannelAuthentication{HandleHash: sha256.Sum256([]byte("unknown")), Status: storage.BackchannelAuthenticationDenied}); !errors.Is(err, sqlstore.ErrNotFound) || !errors.Is(err, storage.ErrBackchannelAuthenticationNotFound) {
t.Fatalf("DecideBackchannelAuthentication(unknown) = %v, want ErrNotFound and ErrBackchannelAuthenticationNotFound", err)
}
if _, err := b.LookupBackchannelAuthentication(ctx, sha256.Sum256([]byte("unknown"))); !errors.Is(err, sqlstore.ErrNotFound) || !errors.Is(err, storage.ErrBackchannelAuthenticationNotFound) {
t.Fatalf("LookupBackchannelAuthentication(unknown) = %v, want ErrNotFound and ErrBackchannelAuthenticationNotFound", err)
}
approve := storage.DecideBackchannelAuthentication{HandleHash: r.HandleHash, Status: storage.BackchannelAuthenticationApproved, Grant: secretGrant}
_, err := b.DecideBackchannelAuthentication(ctx, approve)
must(t, err)
if _, err := b.DecideBackchannelAuthentication(ctx, approve); !errors.Is(err, storage.ErrBackchannelAuthenticationAlreadyDecided) || errors.Is(err, sqlstore.ErrNotFound) || errors.Is(err, storage.ErrStoreUnavailable) {
if _, err := b.DecideBackchannelAuthentication(ctx, approve); !errors.Is(err, storage.ErrBackchannelAuthenticationAlreadyDecided) || errors.Is(err, sqlstore.ErrNotFound) || errors.Is(err, storage.ErrBackchannelAuthenticationNotFound) || errors.Is(err, storage.ErrStoreUnavailable) {
t.Fatalf("second DecideBackchannelAuthentication = %v, want ErrBackchannelAuthenticationAlreadyDecided, not ErrNotFound", err)
}
if got, err := b.LookupBackchannelAuthentication(ctx, r.HandleHash); err != nil || got.ClientID != "c" || string(got.Request) != string(secretGrant) {
Expand Down
2 changes: 1 addition & 1 deletion sqlstore/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/idfoundry/fapigo/sqlstore
go 1.26.11

require (
github.com/idfoundry/fapigo v0.84.0
github.com/idfoundry/fapigo v0.86.0
github.com/jackc/pgx/v5 v5.13.0
modernc.org/sqlite v1.62.0
)
Expand Down
Loading