Auth: adapt tests for recent changes
This commit is contained in:
parent
8dfec4e5fe
commit
754a48c8d5
4 changed files with 55 additions and 8 deletions
|
@ -74,15 +74,15 @@ func TestChangeUserPasswords(t *testing.T) {
|
|||
} else {
|
||||
r := AuthenticatedRequestWithBody(app, "PUT", "/api/v1/users/uqxc08w3d0ej2283/password",
|
||||
string(pwStr), sessId)
|
||||
assert.Equal(t, http.StatusOK, r.Code)
|
||||
assert.Equal(t, http.StatusUnauthorized, r.Code)
|
||||
}
|
||||
})
|
||||
t.Run("bob: change password", func(t *testing.T) {
|
||||
t.Run("bob: change wrong password", func(t *testing.T) {
|
||||
app, router, conf := NewApiTest()
|
||||
conf.SetPublic(false)
|
||||
defer conf.SetPublic(true)
|
||||
ChangePassword(router)
|
||||
sessId := AuthenticateUser(app, router, "bob", "helloworld")
|
||||
sessId := AuthenticateUser(app, router, "bob", "Bobbob123!")
|
||||
|
||||
f := form.ChangePassword{
|
||||
OldPassword: "helloworld",
|
||||
|
@ -93,9 +93,27 @@ func TestChangeUserPasswords(t *testing.T) {
|
|||
} else {
|
||||
r := AuthenticatedRequestWithBody(app, "PUT", "/api/v1/users/uqxc08w3d0ej2283/password",
|
||||
string(pwStr), sessId)
|
||||
// TODO bob should be able to change his own password
|
||||
log.Error(r)
|
||||
//assert.Equal(t, http.StatusOK, r.Code)
|
||||
assert.Equal(t, http.StatusBadRequest, r.Code)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("friend: change password to same", func(t *testing.T) {
|
||||
app, router, conf := NewApiTest()
|
||||
conf.SetPublic(false)
|
||||
defer conf.SetPublic(true)
|
||||
ChangePassword(router)
|
||||
sessId := AuthenticateUser(app, router, "friend", "!Friend321")
|
||||
|
||||
f := form.ChangePassword{
|
||||
OldPassword: "!Friend321",
|
||||
NewPassword: "!Friend321",
|
||||
}
|
||||
if pwStr, err := json.Marshal(f); err != nil {
|
||||
log.Fatal(err)
|
||||
} else {
|
||||
r := AuthenticatedRequestWithBody(app, "PUT", "/api/v1/users/uqxqg7i1kperxvu7/password",
|
||||
string(pwStr), sessId)
|
||||
assert.Equal(t, http.StatusOK, r.Code)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -19,8 +19,9 @@ func (m PasswordMap) Pointer(name string) *Password {
|
|||
}
|
||||
|
||||
var PasswordFixtures = PasswordMap{
|
||||
"alice": NewPassword("uqxetse3cy5eo9z2", "Alice123!"),
|
||||
"bob": NewPassword("uqxc08w3d0ej2283", "Bobbob123!"),
|
||||
"alice": NewPassword("uqxetse3cy5eo9z2", "Alice123!"),
|
||||
"bob": NewPassword("uqxc08w3d0ej2283", "Bobbob123!"),
|
||||
"friend": NewPassword("uqxqg7i1kperxvu7", "!Friend321"),
|
||||
}
|
||||
|
||||
// CreatePasswordFixtures inserts known entities into the database for testing.
|
||||
|
|
|
@ -41,6 +41,18 @@ var UserFixtures = UserMap{
|
|||
UserDisabled: false,
|
||||
PrimaryEmail: "bob@example.com",
|
||||
},
|
||||
"friend": {
|
||||
ID: 8,
|
||||
AddressID: 1,
|
||||
UserUID: "uqxqg7i1kperxvu7",
|
||||
UserName: "friend",
|
||||
FullName: "Guy Friend",
|
||||
RoleAdmin: false,
|
||||
RoleGuest: false,
|
||||
RoleFriend: true,
|
||||
UserDisabled: true,
|
||||
PrimaryEmail: "friend@example.com",
|
||||
},
|
||||
}
|
||||
|
||||
// CreateUserFixtures inserts known entities into the database for testing.
|
||||
|
|
|
@ -221,6 +221,22 @@ func TestFindUserByUID(t *testing.T) {
|
|||
assert.NotEmpty(t, m.CreatedAt)
|
||||
assert.NotEmpty(t, m.UpdatedAt)
|
||||
})
|
||||
t.Run("friend", func(t *testing.T) {
|
||||
m := FindUserByUID("uqxqg7i1kperxvu7")
|
||||
|
||||
if m == nil {
|
||||
t.Fatal("result should not be nil")
|
||||
}
|
||||
|
||||
assert.Equal(t, 8, m.ID)
|
||||
assert.Equal(t, "uqxqg7i1kperxvu7", m.UserUID)
|
||||
assert.False(t, m.RoleAdmin)
|
||||
assert.False(t, m.RoleGuest)
|
||||
assert.True(t, m.RoleFriend)
|
||||
assert.True(t, m.UserDisabled)
|
||||
assert.NotEmpty(t, m.CreatedAt)
|
||||
assert.NotEmpty(t, m.UpdatedAt)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue