Skip to content

Commit

Permalink
fix: do not propagate parent validation error
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Oct 13, 2020
1 parent 2ef57c4 commit bf6093d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion selfservice/form/html_form.go
Expand Up @@ -179,7 +179,7 @@ func (c *HTMLForm) ParseError(err error) error {
default:
// The pointer can be ignored because if there is an error, we'll just use
// the empty field (global error).
for _, ee := range append([]*jsonschema.ValidationError{e}, e.Causes...) {
for _, ee := range e.Causes {
pointer, _ := jsonschemax.JSONPointerToDotNotation(ee.InstancePtr)
c.AddMessage(text.NewValidationErrorGeneric(ee.Message), pointer)
}
Expand Down
30 changes: 30 additions & 0 deletions selfservice/strategy/password/login_test.go
Expand Up @@ -216,6 +216,7 @@ func TestCompleteLogin(t *testing.T) {

ensureFieldsExist(t, []byte(body))
assert.Equal(t, "Property identifier is missing.", gjson.Get(body, "methods.password.config.fields.#(name==identifier).messages.0.text").String(), "%s", body)
assert.Len(t, gjson.Get(body, "methods.password.config.fields").Array(), 3)

// The password value should not be returned!
assert.Empty(t, gjson.Get(body, "methods.password.config.fields.#(name==password).value").String())
Expand Down Expand Up @@ -243,6 +244,7 @@ func TestCompleteLogin(t *testing.T) {
ensureFieldsExist(t, []byte(body))
assert.Equal(t, "Property password is missing.", gjson.Get(body, "methods.password.config.fields.#(name==password).messages.0.text").String(), "%s", body)
assert.Equal(t, "identifier", gjson.Get(body, "methods.password.config.fields.#(name==identifier).value").String(), "%s", body)
assert.Len(t, gjson.Get(body, "methods.password.config.fields").Array(), 3)

// This must not include the password!
assert.Empty(t, gjson.Get(body, "methods.password.config.fields.#(name==password).value").String())
Expand All @@ -262,6 +264,34 @@ func TestCompleteLogin(t *testing.T) {
})
})

t.Run("should return an error both identifier and password are missing", func(t *testing.T) {
var check = func(t *testing.T, body string) {
assert.NotEmpty(t, gjson.Get(body, "id").String(), "%s", body)
assert.Contains(t, gjson.Get(body, "methods.password.config.action").String(), publicTS.URL+password.RouteLogin, "%s", body)

ensureFieldsExist(t, []byte(body))
assert.Equal(t, "length must be >= 1, but got 0", gjson.Get(body, "methods.password.config.fields.#(name==password).messages.0.text").String(), "%s", body)
assert.Equal(t, "length must be >= 1, but got 0", gjson.Get(body, "methods.password.config.fields.#(name==identifier).messages.0.text").String(), "%s", body)
assert.Len(t, gjson.Get(body, "methods.password.config.fields").Array(), 3)

// This must not include the password!
assert.Empty(t, gjson.Get(body, "methods.password.config.fields.#(name==password).value").String())
}

var values = func(v url.Values) {
v.Set("password", "")
v.Set("identifier", "")
}

t.Run("type=browser", func(t *testing.T) {
check(t, expectValidationError(t, false, false, values))
})

t.Run("type=api", func(t *testing.T) {
check(t, expectValidationError(t, true, false, values))
})
})

t.Run("should return an error because the credentials are invalid (password not correct)", func(t *testing.T) {
var check = func(t *testing.T, body string) {
assert.NotEmpty(t, gjson.Get(body, "id").String(), "%s", body)
Expand Down

0 comments on commit bf6093d

Please sign in to comment.