Skip to content

Commit fffba47

Browse files
authored
fix: return empty array not null when there are no sessions (#2548)
1 parent 3b640ca commit fffba47

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

persistence/sql/persister_session.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (p *Persister) ListSessionsByIdentity(ctx context.Context, iID uuid.UUID, a
4747
ctx, span := p.r.Tracer(ctx).Tracer().Start(ctx, "persistence.sql.ListSessionsByIdentity")
4848
defer span.End()
4949

50-
var s []*session.Session
50+
s := make([]*session.Session, 0)
5151
nid := corp.ContextualizeNID(ctx, p.nid)
5252

5353
if err := p.Transaction(ctx, func(ctx context.Context, c *pop.Connection) error {

session/handler_test.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/ory/kratos/internal/testhelpers"
3333
. "github.com/ory/kratos/session"
3434
"github.com/ory/kratos/x"
35+
"github.com/ory/x/ioutilx"
3536
"github.com/ory/x/urlx"
3637
)
3738

@@ -441,10 +442,7 @@ func TestHandlerAdminSessionManagement(t *testing.T) {
441442
res, err := client.Do(req)
442443
require.NoError(t, err)
443444
assert.Equal(t, http.StatusOK, res.StatusCode)
444-
445-
var sessions []Session
446-
require.NoError(t, json.NewDecoder(res.Body).Decode(&sessions))
447-
assert.Len(t, sessions, 0)
445+
assert.JSONEq(t, "[]", string(ioutilx.MustReadAll(res.Body)))
448446
})
449447
})
450448

0 commit comments

Comments
 (0)