Skip to content

test: Add unit test for rbac Authorize() function #853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
ab61328
WIP: This is a massive WIP
Emyrk Mar 26, 2022
03e4d0f
More info in the print
Emyrk Mar 26, 2022
9981291
Fix all()
Emyrk Mar 27, 2022
3ab32da
reduce the amount of memoery allocated
Emyrk Mar 27, 2022
e1d5893
Reuse a buffer
Emyrk Mar 28, 2022
84a90f3
fix: use return size over size
Emyrk Mar 29, 2022
1fac0d9
WIP: don't look at this
Emyrk Mar 29, 2022
1e3aac0
WIP: 🍐 auth-> testdata, refactoring and restructuring
johnstcn Mar 30, 2022
e977e84
testdata -> authztest
johnstcn Mar 30, 2022
00a7c3f
WIP: start work on SVO
johnstcn Mar 30, 2022
1f04c01
reduce allocations for union sets
Emyrk Mar 31, 2022
fbf4db1
fix: Fix nil permissions as Strings()
Emyrk Mar 31, 2022
4946897
chore: Make all permission variant levels
Emyrk Mar 31, 2022
7e6cc66
First full draft of the authz authorize test
Emyrk Mar 31, 2022
a0017e5
Tally up failed tests
Emyrk Mar 31, 2022
4b110b3
Change test pkg
Emyrk Mar 31, 2022
65ef4e3
Use an interface for the object
Emyrk Mar 31, 2022
d294786
fix: make authztest.Objects return correct type
johnstcn Apr 1, 2022
c1f8945
refactor: rename consts {Read,Write,Modify,Delete}Action to Action$1
johnstcn Apr 1, 2022
01f3d40
chore: Define object interface
Emyrk Apr 1, 2022
de7de6e
test: Unit test extra properties
Emyrk Apr 1, 2022
4c86e44
Merge remote-tracking branch 'origin/stevenmasley/rbac' into stevenma…
Emyrk Apr 1, 2022
30c6568
put back interface assertion
Emyrk Apr 1, 2022
a419a65
Fix some compile errors from merge
Emyrk Apr 1, 2022
bbd1c4c
test: Roles, sets, permissions, iterators
Emyrk Apr 1, 2022
def010f
Test string functions
Emyrk Apr 1, 2022
c4ee590
test: Unit test permission string
Emyrk Apr 4, 2022
84e3ab9
Add A+ and A-
Emyrk Apr 4, 2022
c2eec18
Parallelize tests
Emyrk Apr 4, 2022
5a2834a
fix code line in readme
Emyrk Apr 4, 2022
913d141
Merge remote-tracking branch 'origin/main' into stevenmasley/rbac
Emyrk Apr 4, 2022
2804b92
test: ParsePermissions from strings
Emyrk Apr 4, 2022
5698938
use fmt over str builder for easier to read
Emyrk Apr 4, 2022
75ed8ef
Linting
Emyrk Apr 4, 2022
b2db661
authz: README.md: update table formatting
johnstcn Apr 5, 2022
26ef1e6
Make action CRUD
Emyrk Apr 5, 2022
19aba30
LevelID -> OrganizationID
Emyrk Apr 5, 2022
ceee9cd
feat: authztest: categorize test failures by test name
johnstcn Apr 5, 2022
ee8bf04
fixup! feat: authztest: categorize test failures by test name
johnstcn Apr 5, 2022
44c02a1
chore: add documentation for authz and authztest
johnstcn Apr 6, 2022
dfb9ad1
fixup! chore: add documentation for authz and authztest
johnstcn Apr 6, 2022
e482d2c
chore: more authz/authztest docs
johnstcn Apr 6, 2022
a4e038f
Remove underscore from test names
Emyrk Apr 6, 2022
9918c16
zObject does not need exported fields
Emyrk Apr 6, 2022
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
Prev Previous commit
Next Next commit
Remove underscore from test names
unexport fields from zobject
  • Loading branch information
Emyrk committed Apr 6, 2022
commit a4e038f44bd20471a42b7d94f86560e6e538b659
2 changes: 1 addition & 1 deletion coderd/authz/authz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

var nilSet = authztest.Set{nil}

func Test_ExhaustiveAuthorize(t *testing.T) {
func TestExhaustiveAuthorize(t *testing.T) {
t.Parallel()

all := authztest.GroupedPermissions(authztest.AllPermissions())
Expand Down
2 changes: 1 addition & 1 deletion coderd/authz/authztest/level_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/coder/coder/coderd/authz/authztest"
)

func Test_GroupedPermissions(t *testing.T) {
func TestGroupedPermissions(t *testing.T) {
t.Parallel()

set := make(authztest.Set, 0)
Expand Down
2 changes: 1 addition & 1 deletion coderd/authz/authztest/permissions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/coder/coder/coderd/authz/authztest"
)

func Test_AllPermissions(t *testing.T) {
func TestAllPermissions(t *testing.T) {
t.Parallel()

// If this changes, then we might have to fix some other tests. This constant
Expand Down
2 changes: 1 addition & 1 deletion coderd/authz/authztest/role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
crand "github.com/coder/coder/cryptorand"
)

func Test_NewRole(t *testing.T) {
func TestNewRole(t *testing.T) {
t.Parallel()

for i := 0; i < 50; i++ {
Expand Down
2 changes: 1 addition & 1 deletion coderd/authz/authztest/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
crand "github.com/coder/coder/cryptorand"
)

func Test_Set(t *testing.T) {
func TestSet(t *testing.T) {
t.Parallel()

t.Run("Simple", func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions coderd/authz/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"github.com/coder/coder/coderd/authz"
)

// Test_Example gives some examples on how to use the authz library.
// TestExample gives some examples on how to use the authz library.
// This serves to test syntax more than functionality.
func Test_Example(t *testing.T) {
func TestExample(t *testing.T) {
t.Parallel()

// user will become an authn object, and can even be a database.User if it
Expand Down
16 changes: 8 additions & 8 deletions coderd/authz/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ var _ OrgResource = (*zObject)(nil)
// that represents the set of workspaces you are trying to get access too.
// Do not export this type, as it can be created from a resource type constant.
type zObject struct {
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to be prefixed with z? The package already ends with z, so I'd assume not.

ObjectID string `json:"object_id"`
OwnedBy string `json:"owner_id"`
OwnedByOrg string `json:"org_owner_id"`
id string
owner string
OwnedByOrg string

// ObjectType is "workspace", "project", "devurl", etc
ObjectType ResourceType `json:"object_type"`
ObjectType ResourceType
// TODO: SharedUsers?
}

func (z zObject) ID() string {
return z.ObjectID
return z.id
}

func (z zObject) ResourceType() ResourceType {
return z.ObjectType
}

func (z zObject) OwnerID() string {
return z.OwnedBy
return z.owner
}

func (z zObject) OrgOwnerID() string {
Expand All @@ -60,12 +60,12 @@ func (z zObject) Org(orgID string) zObject {
// Owner adds an OwnerID to the resource
//nolint:revive
func (z zObject) Owner(id string) zObject {
z.OwnedBy = id
z.owner = id
return z
}

//nolint:revive
func (z zObject) AsID(id string) zObject {
z.ObjectID = id
z.id = id
return z
}
4 changes: 2 additions & 2 deletions coderd/authz/permission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/coder/coder/coderd/authz"
)

func Test_PermissionString(t *testing.T) {
func TestPermissionString(t *testing.T) {
t.Parallel()

testCases := []struct {
Expand Down Expand Up @@ -72,7 +72,7 @@ func Test_PermissionString(t *testing.T) {
}
}

func Test_ParsePermissions(t *testing.T) {
func TestParsePermissions(t *testing.T) {
t.Parallel()

testCases := []struct {
Expand Down
4 changes: 2 additions & 2 deletions coderd/authz/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ func (r ResourceType) Org(orgID string) zObject {
//nolint:revive
func (r ResourceType) Owner(id string) zObject {
return zObject{
OwnedBy: id,
owner: id,
ObjectType: r,
}
}

//nolint:revive
func (r ResourceType) AsID(id string) zObject {
return zObject{
ObjectID: id,
id: id,
ObjectType: r,
}
}