Skip to content

Commit

Permalink
test: check if internal context is validated in store
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Oct 19, 2021
1 parent 152bfc7 commit a23d851
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
24 changes: 24 additions & 0 deletions selfservice/flow/settings/test/persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package test
import (
"context"
"encoding/json"
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -65,6 +66,29 @@ func TestRequestPersister(ctx context.Context, conf *config.Config, p interface
})
})

t.Run("case=should create and update and properly deal with internal context", func(t *testing.T) {
for k, tc := range []struct {
in []byte
expect string
}{
{in: []byte("[]"), expect: "{}"},
{expect: "{}"},
{in: []byte("null"), expect: "{}"},
{in: []byte(`"{"foo":"bar"}"`), expect: `"{"foo":"bar"}"`},
} {
t.Run(fmt.Sprintf("run=%d", k), func(t *testing.T) {
r := newFlow(t)
r.InternalContext = tc.in
require.NoError(t, p.CreateSettingsFlow(ctx, r))
assert.Equal(t, tc.expect, string(r.InternalContext))

r.InternalContext = tc.in
require.NoError(t, p.UpdateSettingsFlow(ctx, r))
assert.Equal(t, tc.expect, string(r.InternalContext))
})
}
})

t.Run("case=should ensure that internal context is an object", func(t *testing.T) {
r := newFlow(t)
r.InternalContext = []byte("null")
Expand Down
3 changes: 2 additions & 1 deletion session/test/persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package test

import (
"context"
"github.com/ory/kratos/identity"
"testing"
"time"

"github.com/ory/kratos/identity"

"github.com/bxcodec/faker/v3"
"github.com/gofrs/uuid"
"github.com/stretchr/testify/assert"
Expand Down

0 comments on commit a23d851

Please sign in to comment.