3
0

Fix user query lapsus

This commit is contained in:
Tomaž Jerman
2019-11-08 15:34:47 +01:00
parent 5a72a239e4
commit af5da175dc
2 changed files with 71 additions and 2 deletions
+1 -1
View File
@@ -172,7 +172,7 @@ func (r user) Find(filter types.UserFilter) (set types.UserSet, f types.UserFilt
}
if f.Email != "" {
query = query.Where(whereMasked(f.IsNameUnmaskable, squirrel.Eq{"u.name": f.Email}))
query = query.Where(whereMasked(f.IsNameUnmaskable, squirrel.Eq{"u.email": f.Email}))
}
if f.Username != "" {
+70 -1
View File
@@ -22,9 +22,13 @@ func (h helper) repoUser() repository.UserRepository {
}
func (h helper) repoMakeUser(email string) *types.User {
return h.repoSaveUser(&types.User{Email: email})
}
func (h helper) repoSaveUser(user *types.User) *types.User {
u, err := h.
repoUser().
Create(&types.User{Email: email})
Create(user)
h.a.NoError(err)
return u
@@ -106,6 +110,71 @@ func TestUserListQuery(t *testing.T) {
h.a.GreaterOrEqual(int(aux.Response.Filter.Count), 0)
}
func TestUserListQueryEmail(t *testing.T) {
h := newHelper(t)
h.secCtx()
h.allow(types.UserPermissionResource.AppendWildcard(), "read")
ee := h.randEmail()
h.repoMakeUser(ee)
h.apiInit().
Debug().
Get("/users/").
Query("email", ee).
Expect(t).
Status(http.StatusOK).
Assert(helpers.AssertNoErrors).
Assert(jsonpath.Present(`$.response.set != null`)).
End()
}
func TestUserListQueryUsername(t *testing.T) {
h := newHelper(t)
h.secCtx()
h.allow(types.UserPermissionResource.AppendWildcard(), "read")
ee := h.randEmail()
h.repoSaveUser(&types.User{
Email: "test@test.tld",
Username: ee,
})
h.apiInit().
Debug().
Get("/users/").
Query("username", ee).
Expect(t).
Status(http.StatusOK).
Assert(helpers.AssertNoErrors).
Assert(jsonpath.Present(`$.response.set != null`)).
End()
}
func TestUserListQueryHandle(t *testing.T) {
h := newHelper(t)
h.secCtx()
h.allow(types.UserPermissionResource.AppendWildcard(), "read")
h.repoSaveUser(&types.User{
Email: "test@test.tld",
Handle: "johnDoe",
})
h.apiInit().
Debug().
Get("/users/").
Query("handle", "johnDoe").
Expect(t).
Status(http.StatusOK).
Assert(helpers.AssertNoErrors).
Assert(jsonpath.Present(`$.response.set != null`)).
End()
}
func TestUserListWithOneAllowed(t *testing.T) {
h := newHelper(t)