Skip to content

Commit dbf7274

Browse files
test: resolve CI failures (#4067)
1 parent b0111d4 commit dbf7274

14 files changed

+46
-38
lines changed

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ require (
110110
github.com/cortesi/moddwatch v0.1.0 // indirect
111111
github.com/cortesi/termlog v0.0.0-20210222042314-a1eec763abec // indirect
112112
github.com/rjeczalik/notify v0.9.3 // indirect
113+
github.com/wI2L/jsondiff v0.6.0 // indirect
113114
golang.org/x/term v0.22.0 // indirect
114115
gopkg.in/alecthomas/kingpin.v2 v2.2.6 // indirect
115116
mvdan.cc/sh/v3 v3.6.0 // indirect

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,8 @@ github.com/toqueteos/webbrowser v1.2.0 h1:tVP/gpK69Fx+qMJKsLE7TD8LuGWPnEV71wBN9r
872872
github.com/toqueteos/webbrowser v1.2.0/go.mod h1:XWoZq4cyp9WeUeak7w7LXRUQf1F1ATJMir8RTqb4ayM=
873873
github.com/urfave/negroni v1.0.0 h1:kIimOitoypq34K7TG7DUaJ9kq/N4Ofuwi1sjz0KipXc=
874874
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
875+
github.com/wI2L/jsondiff v0.6.0 h1:zrsH3FbfVa3JO9llxrcDy/XLkYPLgoMX6Mz3T2PP2AI=
876+
github.com/wI2L/jsondiff v0.6.0/go.mod h1:D6aQ5gKgPF9g17j+E9N7aasmU1O+XvfmWm1y8UMmNpw=
875877
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
876878
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
877879
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=

identity/.snapshots/TestUpgradeCredentials-type=code-from=v0_with_correct_value.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"config": {
1010
"addresses": [
1111
{
12-
"address": "[email protected]",
13-
"channel": "email"
12+
"channel": "email",
13+
"address": "[email protected]"
1414
}
1515
]
1616
},

identity/.snapshots/TestUpgradeCredentials-type=code-from=v0_with_email_empty_space_value-with_one_identifier.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"config": {
1010
"addresses": [
1111
{
12-
"address": "[email protected]",
13-
"channel": "email"
12+
"channel": "email",
13+
"address": "[email protected]"
1414
}
1515
]
1616
},

identity/.snapshots/TestUpgradeCredentials-type=code-from=v0_with_email_empty_space_value-with_two_identifiers.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
"config": {
1111
"addresses": [
1212
{
13-
"address": "[email protected]",
14-
"channel": "email"
13+
"channel": "email",
14+
"address": "[email protected]"
1515
},
1616
{
17-
"address": "[email protected]",
18-
"channel": "email"
17+
"channel": "email",
18+
"address": "[email protected]"
1919
}
2020
]
2121
},

identity/.snapshots/TestUpgradeCredentials-type=code-from=v0_with_empty_value.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"config": {
1010
"addresses": [
1111
{
12-
"address": "[email protected]",
13-
"channel": "email"
12+
"channel": "email",
13+
"address": "[email protected]"
1414
}
1515
]
1616
},

identity/.snapshots/TestUpgradeCredentials-type=code-from=v0_with_unknown_value.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"config": {
1010
"addresses": [
1111
{
12-
"address": "[email protected]",
13-
"channel": "email"
12+
"channel": "email",
13+
"address": "[email protected]"
1414
}
1515
]
1616
},

identity/credentials.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/gofrs/uuid"
13+
"github.com/wI2L/jsondiff"
1314

1415
"github.com/ory/kratos/ui/node"
1516
"github.com/ory/x/sqlxx"
@@ -248,7 +249,13 @@ func CredentialsEqual(a, b map[CredentialsType]Credentials) bool {
248249
return false
249250
}
250251

251-
if string(expect.Config) != string(actual.Config) {
252+
// Try to normalize configs (remove spaces etc).
253+
patch, err := jsondiff.CompareJSON(actual.Config, expect.Config)
254+
if err != nil {
255+
return false
256+
}
257+
258+
if len(patch) > 0 {
252259
return false
253260
}
254261

identity/credentials_migrate.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,21 @@ func UpgradeCodeCredentials(c *Credentials) (err error) {
100100
continue
101101
}
102102

103-
c.Config, err = sjson.SetBytes(c.Config, "addresses.-1", map[string]any{
104-
"address": id,
105-
"channel": channel,
103+
c.Config, err = sjson.SetBytes(c.Config, "addresses.-1", &CredentialsCodeAddress{
104+
Address: id,
105+
Channel: channel,
106106
})
107107
if err != nil {
108108
return errors.WithStack(err)
109109
}
110110
}
111111

112+
// This is needed because sjson adds spaces which can trip string comparisons.
113+
c.Config, err = json.Marshal(json.RawMessage(c.Config))
114+
if err != nil {
115+
return errors.WithStack(err)
116+
}
117+
112118
c.Version = 1
113119
}
114120
return nil

identity/extension_credentials.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (r *SchemaExtensionCredentials) Run(ctx jsonschema.ValidationContext, s sch
9797

9898
conf.Addresses = append(conf.Addresses, CredentialsCodeAddress{
9999
Channel: via,
100-
Address: fmt.Sprintf("%s", value),
100+
Address: value,
101101
})
102102

103103
conf.Addresses = lo.UniqBy(conf.Addresses, func(item CredentialsCodeAddress) string {

identity/manager.go

+1
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ func (m *Manager) requiresPrivilegedAccess(ctx context.Context, original, update
350350
if !CredentialsEqual(updated.Credentials, original.Credentials) {
351351
// reset the identity
352352
*updated = *original
353+
353354
return errors.WithStack(ErrProtectedFieldModified)
354355
}
355356

internal/testhelpers/session.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func NewHTTPClientWithArbitrarySessionTokenAndTraits(t *testing.T, ctx context.C
161161

162162
func NewHTTPClientWithArbitrarySessionCookie(t *testing.T, ctx context.Context, reg *driver.RegistryDefault) *http.Client {
163163
req := NewTestHTTPRequest(t, "GET", "/sessions/whoami", nil)
164-
req.WithContext(confighelpers.WithConfigValue(ctx, "session.lifespan", time.Hour))
164+
req = req.WithContext(confighelpers.WithConfigValue(ctx, "session.lifespan", time.Hour))
165165
id := x.NewUUID()
166166
s, err := NewActiveSession(req, reg,
167167
&identity.Identity{ID: id, State: identity.StateActive, Traits: []byte("{}"), Credentials: map[identity.CredentialsType]identity.Credentials{
@@ -178,7 +178,7 @@ func NewHTTPClientWithArbitrarySessionCookie(t *testing.T, ctx context.Context,
178178

179179
func NewNoRedirectHTTPClientWithArbitrarySessionCookie(t *testing.T, ctx context.Context, reg *driver.RegistryDefault) *http.Client {
180180
req := NewTestHTTPRequest(t, "GET", "/sessions/whoami", nil)
181-
req.WithContext(confighelpers.WithConfigValue(ctx, "session.lifespan", time.Hour))
181+
req = req.WithContext(confighelpers.WithConfigValue(ctx, "session.lifespan", time.Hour))
182182
id := x.NewUUID()
183183
s, err := NewActiveSession(req, reg,
184184
&identity.Identity{ID: id, State: identity.StateActive,
@@ -196,7 +196,7 @@ func NewNoRedirectHTTPClientWithArbitrarySessionCookie(t *testing.T, ctx context
196196

197197
func NewHTTPClientWithIdentitySessionCookie(t *testing.T, ctx context.Context, reg *driver.RegistryDefault, id *identity.Identity) *http.Client {
198198
req := NewTestHTTPRequest(t, "GET", "/sessions/whoami", nil)
199-
req.WithContext(confighelpers.WithConfigValue(ctx, "session.lifespan", time.Hour))
199+
req = req.WithContext(confighelpers.WithConfigValue(ctx, "session.lifespan", time.Hour))
200200
s, err := NewActiveSession(req, reg,
201201
id,
202202
time.Now(),
@@ -223,7 +223,7 @@ func NewHTTPClientWithIdentitySessionCookieLocalhost(t *testing.T, ctx context.C
223223

224224
func NewHTTPClientWithIdentitySessionToken(t *testing.T, ctx context.Context, reg *driver.RegistryDefault, id *identity.Identity) *http.Client {
225225
req := NewTestHTTPRequest(t, "GET", "/sessions/whoami", nil)
226-
req.WithContext(confighelpers.WithConfigValue(ctx, "session.lifespan", time.Hour))
226+
req = req.WithContext(confighelpers.WithConfigValue(ctx, "session.lifespan", time.Hour))
227227
s, err := NewActiveSession(req, reg,
228228
id,
229229
time.Now(),

selfservice/strategy/code/strategy_login.go

+2-17
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,6 @@ func (s *Strategy) findIdentityByIdentifier(ctx context.Context, identifier stri
147147
return id, cred, false, nil
148148
}
149149

150-
func (s *Strategy) decode(r *http.Request) (*updateLoginFlowWithCodeMethod, error) {
151-
var p updateLoginFlowWithCodeMethod
152-
if err := s.dx.Decode(r, &p,
153-
decoderx.HTTPDecoderSetValidatePayloads(true),
154-
decoderx.HTTPKeepRequestBody(true),
155-
decoderx.MustHTTPRawJSONSchemaCompiler(loginMethodSchema),
156-
decoderx.HTTPDecoderAllowedMethods("POST"),
157-
decoderx.HTTPDecoderJSONFollowsFormFormat()); err != nil {
158-
return nil, err
159-
}
160-
return &p, nil
161-
}
162-
163150
type decodedMethod struct {
164151
Method string `json:"method" form:"method"`
165152
Address string `json:"address" form:"address"`
@@ -205,7 +192,7 @@ func (s *Strategy) Login(w http.ResponseWriter, r *http.Request, f *login.Flow,
205192
}
206193

207194
if p, err := s.methodEnabledAndAllowedFromRequest(r, f); errors.Is(err, flow.ErrStrategyNotResponsible) {
208-
if !(s.deps.Config().SelfServiceCodeStrategy(ctx).MFAEnabled && s.deps.Config().SelfServiceCodeStrategy(ctx).MFAEnabled && (p == nil || len(p.Address) > 0)) {
195+
if !(s.deps.Config().SelfServiceCodeStrategy(ctx).MFAEnabled && (p == nil || len(p.Address) > 0)) {
209196
return nil, err
210197
}
211198
// In this special case we only expect `address` to be set.
@@ -303,13 +290,11 @@ func (s *Strategy) findIdentityForIdentifier(ctx context.Context, identifier str
303290
return nil, nil, errors.WithStack(schema.NewNoCodeAuthnCredentials())
304291
}
305292

306-
address, err := s.findIdentifierInVerifiableAddress(session.Identity, identifier)
293+
_, err := s.findIdentifierInVerifiableAddress(session.Identity, identifier)
307294
if err != nil {
308295
return nil, nil, err
309296
}
310297

311-
addresses = []Address{*address}
312-
313298
// We only end up here if the identity's identity schema does not have the `code` identifier extension defined.
314299
// We know that this is the case for a couple of projects who use 2FA with the code credential.
315300
//

test/e2e/cypress/integration/profiles/code/login/error.spec.ts

+6
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ context("Login error messages with code method", () => {
160160
"contain",
161161
"Property identifier is missing",
162162
)
163+
} else if (app === "react") {
164+
// The backspace trick is not working in React.
165+
cy.get('[data-testid="ui/message/4010008"]').should(
166+
"contain",
167+
"code is invalid",
168+
)
163169
} else {
164170
cy.get('[data-testid="ui/message/4000002"]').should(
165171
"contain",

0 commit comments

Comments
 (0)