Skip to content
Snippets Groups Projects
Commit 9e4b9f9e authored by Fabian Seidl's avatar Fabian Seidl
Browse files

fixed issue with user creation, fixed user creation and modification test, added note in suer proto

parent 485b1a8f
Branches
Tags
1 merge request!652Resolve "Implement integration tests for RBAC"
...@@ -89,7 +89,7 @@ message CreateUsersResponse { ...@@ -89,7 +89,7 @@ message CreateUsersResponse {
// GetUser // GetUser
message GetUserRequest { message GetUserRequest {
int64 timestamp = 1; int64 timestamp = 1;
string name = 2 [(buf.validate.field).required = true]; string name = 2 [(buf.validate.field).required = true]; // TODO(faseid): reconsider if this is necessary as required, but id is not?
string id = 3; string id = 3;
} }
......
...@@ -92,7 +92,12 @@ func (u UserServer) CreateUsers(ctx context.Context, request *apb.CreateUsersReq ...@@ -92,7 +92,12 @@ func (u UserServer) CreateUsers(ctx context.Context, request *apb.CreateUsersReq
hashedPassword := base64.RawStdEncoding.EncodeToString(argon2.IDKey([]byte(user.Password), []byte(salt), 1, 64*1024, 4, 32)) hashedPassword := base64.RawStdEncoding.EncodeToString(argon2.IDKey([]byte(user.Password), []byte(salt), 1, 64*1024, 4, 32))
user := rbac.NewUser(uuid.New(), user.Name, roles, string(hashedPassword), user.Token, salt, conflict.Metadata{ResourceVersion: 0}) userID, err := uuid.Parse(user.Id)
if err != nil {
userID = uuid.New()
}
user := rbac.NewUser(userID, user.Name, roles, string(hashedPassword), user.Token, salt, conflict.Metadata{ResourceVersion: 0})
err = u.userService.Add(user) err = u.userService.Add(user)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
......
...@@ -46,7 +46,7 @@ func TestUserCreationAndModification(t *testing.T) { ...@@ -46,7 +46,7 @@ func TestUserCreationAndModification(t *testing.T) {
// setup required parameters // setup required parameters
const user2UUID = "0a28e837-473b-475d-b935-2457eb9462ae" const user2UUID = "0a28e837-473b-475d-b935-2457eb9462ae"
const expectedAmountOfUsers = 2 const expectedAmountOfUsers = 3
const expectedNameAfterChange = "testUser1Changed" const expectedNameAfterChange = "testUser1Changed"
createUserRequest := &apb.CreateUsersRequest{ createUserRequest := &apb.CreateUsersRequest{
...@@ -54,13 +54,22 @@ func TestUserCreationAndModification(t *testing.T) { ...@@ -54,13 +54,22 @@ func TestUserCreationAndModification(t *testing.T) {
User: []*apb.User{ User: []*apb.User{
{ {
Id: userUUID, Id: userUUID,
Name: "testUser1", Name: user1NameAndPW,
Roles: map[string]string{pndID: "admin", userUUID: "random"}, Roles: map[string]string{pndID: "admin", userUUID: "random"},
Password: user1NameAndPW, Password: user1NameAndPW,
Metadata: &conflict.Metadata{ Metadata: &conflict.Metadata{
ResourceVersion: 0, ResourceVersion: 0,
}, },
}, },
{
Id: user2UUID,
Name: "user2",
Roles: map[string]string{pndID: "random"},
Password: user1NameAndPW,
Metadata: &conflict.Metadata{
ResourceVersion: 0,
},
},
}, },
} }
...@@ -72,8 +81,10 @@ func TestUserCreationAndModification(t *testing.T) { ...@@ -72,8 +81,10 @@ func TestUserCreationAndModification(t *testing.T) {
Timestamp: time.Now().UnixNano(), Timestamp: time.Now().UnixNano(),
User: []*apb.UpdateUser{ User: []*apb.UpdateUser{
{ {
Id: userUUID, Id: userUUID,
Name: expectedNameAfterChange, Name: expectedNameAfterChange,
Roles: map[string]string{},
Metadata: &conflict.Metadata{},
}, },
}, },
} }
...@@ -81,6 +92,7 @@ func TestUserCreationAndModification(t *testing.T) { ...@@ -81,6 +92,7 @@ func TestUserCreationAndModification(t *testing.T) {
getUserRequest := &apb.GetUserRequest{ getUserRequest := &apb.GetUserRequest{
Timestamp: time.Now().UnixNano(), Timestamp: time.Now().UnixNano(),
Id: userUUID, Id: userUUID,
Name: expectedNameAfterChange,
} }
// setup gRPC services // setup gRPC services
...@@ -92,21 +104,6 @@ func TestUserCreationAndModification(t *testing.T) { ...@@ -92,21 +104,6 @@ func TestUserCreationAndModification(t *testing.T) {
t.Error(err) t.Error(err)
} }
// TODO(faseid): fix only one user can be created at a time
createUserRequest.User[0] = &apb.User{
Id: user2UUID,
Roles: map[string]string{pndID: "random"},
Password: user1NameAndPW,
Metadata: &conflict.Metadata{
ResourceVersion: 0,
},
}
_, err = userService.CreateUsers(ctx, createUserRequest)
if err != nil {
t.Error(err)
}
// get all users and compare // get all users and compare
getAllResponse, err := userService.GetUsers(ctx, getAllRequest) getAllResponse, err := userService.GetUsers(ctx, getAllRequest)
if err != nil { if err != nil {
...@@ -117,19 +114,17 @@ func TestUserCreationAndModification(t *testing.T) { ...@@ -117,19 +114,17 @@ func TestUserCreationAndModification(t *testing.T) {
t.Errorf("Error in Test: TestUserCreationAndModification, expected amount: %v, got: %v", expectedAmountOfUsers, len(getAllResponse.User)) t.Errorf("Error in Test: TestUserCreationAndModification, expected amount: %v, got: %v", expectedAmountOfUsers, len(getAllResponse.User))
} }
if getAllResponse.User[0].Name == getAllResponse.User[1].Name { if getAllResponse.User[1].Name == getAllResponse.User[2].Name {
t.Errorf("Error in Test: TestUserCreationAndModification, expected different names got: %v, %v", getAllResponse.User[0].Name, getAllResponse.User[1].Name) t.Errorf("Error in Test: TestUserCreationAndModification, expected different names got: %v, %v", getAllResponse.User[0].Name, getAllResponse.User[1].Name)
} }
// TODO(faseid): investigate why roles are same?! if getAllResponse.User[1].Roles[pndID] == getAllResponse.User[2].Roles[pndID] {
// if getAllResponse.User[0].Roles[pndID] == getAllResponse.User[1].Roles[pndID] { t.Errorf("Error in Test: TestUserCreationAndModification, expected different roles got: %v, %v", getAllResponse.User[0].Roles[pndID], getAllResponse.User[1].Roles[pndID])
// t.Errorf("Error in Test: TestUserCreationAndModification, expected different roles got: %v, %v", getAllResponse.User[0].Roles[pndID], getAllResponse.User[1].Roles[pndID]) }
// }
// change name of user1 // change name of user1
updateUserRequest.User[0].Roles = getAllResponse.User[0].Roles updateUserRequest.User[0].Roles = getAllResponse.User[1].Roles
// TODO(faseid): fix metadata is nil? updateUserRequest.User[0].Metadata.ResourceVersion = getAllResponse.User[1].Metadata.ResourceVersion
//updateUserRequest.User[0].Metadata.ResourceVersion = 1
_, err = userService.UpdateUsers(ctx, updateUserRequest) _, err = userService.UpdateUsers(ctx, updateUserRequest)
if err != nil { if err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment