-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add admin additional role to mlp.project.post (#91)
* Update bootstrap.go * add bootstrap test * Update admin role to have default permission * update bootstrap test * edit bootstrap config and add test * update test name * fix long test name
- Loading branch information
1 parent
cae72b7
commit b3d74d1
Showing
2 changed files
with
99 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/caraml-dev/mlp/api/pkg/authz/enforcer" | ||
enforcerMock "github.com/caraml-dev/mlp/api/pkg/authz/enforcer/mocks" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestStartKetoBootsrap(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
projectReaders []string | ||
mlpAdmins []string | ||
expectedUpdateAuthorizationRequest enforcer.AuthorizationUpdateRequest | ||
}{ | ||
{ | ||
"admin role must have project post even there are no project readers", | ||
[]string{}, | ||
[]string{"admin1"}, | ||
enforcer.AuthorizationUpdateRequest{ | ||
RolePermissions: map[string][]string{ | ||
"mlp.administrator": {"mlp.projects.post"}, | ||
}, | ||
RoleMembers: map[string][]string{ | ||
"mlp.projects.reader": {}, | ||
"mlp.administrator": {"admin1"}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
"admin role should have project post, even there are no mlp admins or project readers", | ||
[]string{}, | ||
[]string{}, | ||
enforcer.AuthorizationUpdateRequest{ | ||
RolePermissions: map[string][]string{ | ||
"mlp.administrator": {"mlp.projects.post"}, | ||
}, | ||
RoleMembers: map[string][]string{ | ||
"mlp.projects.reader": {}, | ||
"mlp.administrator": {}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
"only admin role should have project post, even no mlp admins and project readers exist", | ||
[]string{"readers1", "readers2"}, | ||
[]string{}, | ||
enforcer.AuthorizationUpdateRequest{ | ||
RolePermissions: map[string][]string{ | ||
"mlp.administrator": {"mlp.projects.post"}, | ||
}, | ||
RoleMembers: map[string][]string{ | ||
"mlp.projects.reader": {"readers1", "readers2"}, | ||
"mlp.administrator": {}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
"only admin role should have project post, even project readers exist", | ||
[]string{"readers1", "readers2"}, | ||
[]string{"admin1"}, | ||
enforcer.AuthorizationUpdateRequest{ | ||
RolePermissions: map[string][]string{ | ||
"mlp.administrator": {"mlp.projects.post"}, | ||
}, | ||
RoleMembers: map[string][]string{ | ||
"mlp.projects.reader": {"readers1", "readers2"}, | ||
"mlp.administrator": {"admin1"}, | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
authEnforcer := &enforcerMock.Enforcer{} | ||
|
||
authEnforcer.On("UpdateAuthorization", mock.Anything, tt.expectedUpdateAuthorizationRequest).Return(nil) | ||
err := startKetoBootstrap(authEnforcer, tt.projectReaders, tt.mlpAdmins) | ||
authEnforcer.AssertExpectations(t) | ||
require.NoError(t, err) | ||
}) | ||
} | ||
} |