Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions box/tarantool_test.go
Copy link
Collaborator

@oleg-jukovec oleg-jukovec Dec 23, 2025

Choose a reason for hiding this comment

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

The tests name is:

TestBox_Sugar_Schema_UserGrant_NoSu

and:

TestSchemaUser_Revoke_WithoutSu

But in the updated tests we actually do the su. It is very strange now. I suggest the following:

It will be better to create another user (testsu?) inside testdata/config.lua without grant access and use it for creating a connection in tests TestBox_Sugar_Schema_UserGrant_NoSu/TestBox_Sugar_Schema_UserGrant_Su. In that case you will not need to modify the tests structure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe we better change names

  • TestBox_Sugar_Schema_UserGrant_NoSu -> TestBox_Sugar_Schema_UserGrant_AccessDenied (or TestSchemaUser_Grant_AccessDenied)
  • TestSchemaUser_Revoke_WithoutSu -> TestSchemaUser_Revoke_AccessDenied
  • TestBox_Sugar_Schema_UserGrant_WithSu -> TestBox_Sugar_Schema_UserGrant (or TestSchemaUser_Grant)
  • TestSchemaUser_Revoke_WithSu -> TestSchemaUser_Revoke ?

It will keep config the same, I think it would be too complicated otherwise. Also, we can remove these Su lines, since they are unnecessary in new behavior

Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,18 @@ func TestBox_Sugar_Schema_UserGrant_NoSu(t *testing.T) {
err = b.Schema().User().Create(ctx, username, box.UserCreateOptions{Password: password})
require.NoError(t, err)

data, err := conn.Do(tarantool.NewCallRequest("box.session.user")).Get()
require.NoError(t, err)
this_user := data[0].(string)

err = b.Session().Su(ctx, username)
require.NoError(t, err)

defer func() {
err = b.Session().Su(ctx, this_user)
require.NoError(t, err)
}()

err = b.Schema().User().Grant(ctx, username, box.Privilege{
Permissions: []box.Permission{
box.PermissionRead,
Expand Down Expand Up @@ -529,14 +541,32 @@ func TestSchemaUser_Revoke_WithoutSu(t *testing.T) {
err = b.Schema().User().Create(ctx, username, box.UserCreateOptions{Password: password})
require.NoError(t, err)

startPrivileges, err := b.Schema().User().Info(ctx, username)
require.NoError(t, err)

require.NotEmpty(t, startPrivileges)
// Let's choose random first privilege.
examplePriv := startPrivileges[0]

data, err := conn.Do(tarantool.NewCallRequest("box.session.user")).Get()
require.NoError(t, err)
this_user := data[0].(string)

err = b.Session().Su(ctx, username)
require.NoError(t, err)

defer func() {
err = b.Session().Su(ctx, this_user)
require.NoError(t, err)
}()

// Can`t revoke without su permissions.
err = b.Schema().User().Grant(ctx, username, box.Privilege{
Permissions: []box.Permission{
box.PermissionRead,
},
Type: box.PrivilegeSpace,
Name: "space1",
}, box.UserGrantOptions{IfNotExists: false})
err = b.Schema().User().Revoke(ctx,
username,
examplePriv,
box.UserRevokeOptions{
IfExists: false,
})
require.Error(t, err)

// Require that error code is ER_ACCESS_DENIED.
Expand Down
Loading