Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: keep HTML form type on registration error #698

Merged
merged 3 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion selfservice/form/html_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ func (c *HTMLForm) SetValue(name string, value interface{}) {

if f := c.getField(name); f != nil {
f.Value = value
f.Type = toFormType(name, value)
return
}
c.Fields = append(c.Fields, Field{
Expand Down
3 changes: 2 additions & 1 deletion selfservice/strategy/password/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func (s *Strategy) handleRegistrationError(w http.ResponseWriter, r *http.Reques

if p != nil {
for _, field := range form.NewHTMLFormFromJSON("", p.Traits, "traits").Fields {
method.Config.SetField(field)
// we only set the value and not the whole field because we want to keep types from the initial form generation
method.Config.SetValue(field.Name, field.Value)
}
}

Expand Down
4 changes: 4 additions & 0 deletions selfservice/strategy/password/registration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ func TestRegistration(t *testing.T) {
})

t.Run("case=should show the error ui because the request payload is malformed", func(t *testing.T) {
viper.Set(configuration.ViperKeyDefaultIdentitySchemaURL, "file://./stub/profile.schema.json")
defer viper.Set(configuration.ViperKeyDefaultIdentitySchemaURL, "file://./stub/registration.schema.json")

t.Run("type=api", func(t *testing.T) {
f := testhelpers.InitializeRegistrationFlowViaAPI(t, apiClient, publicTS)
c := testhelpers.GetRegistrationFlowMethodConfig(t, f.Payload, identity.CredentialsTypePassword.String())
Expand All @@ -121,6 +124,7 @@ func TestRegistration(t *testing.T) {
assert.Contains(t, res.Request.URL.String(), uiTS.URL+"/registration-ts")
assert.NotEmpty(t, gjson.Get(body, "id").String(), "%s", body)
assert.Contains(t, gjson.Get(body, "methods.password.config.messages.0.text").String(), "invalid URL escape", "%s", body)
assert.Equal(t, "email", gjson.Get(body, "methods.password.config.fields.#(name==\"traits.email\").type").String(), "%s", body)
})
})

Expand Down
17 changes: 9 additions & 8 deletions selfservice/strategy/password/stub/profile.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
"traits": {
"type": "object",
"properties": {
"email": {
"type": "string",
"ory.sh/kratos": {
"credentials": {
"password": {
"identifier": true
"email": {
"type": "string",
"format": "email",
"ory.sh/kratos": {
"credentials": {
"password": {
"identifier": true
}
}
}
}
}
}
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of this is only formatting

},
"additionalProperties": false
}