-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e61a21f
commit 2fc9640
Showing
3 changed files
with
99 additions
and
0 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,43 @@ | ||
package spacelift | ||
|
||
# Define team roles | ||
writers := {"team1", "team2", "team3"} | ||
|
||
admins := {"team4", "team5", "team6"} | ||
|
||
readers := {"team7", "team8", "team9"} | ||
|
||
# Extract login from session | ||
login := input.session.teams | ||
|
||
# Allow based on team role | ||
allow { # Allow writers | ||
writers[login] | ||
} | ||
|
||
allow { # Allow admins | ||
admins[login] | ||
} | ||
|
||
allow { # Allow readers | ||
readers[login] | ||
} | ||
|
||
# Space access rules | ||
# Check if user is an admin and assign admin access to the space | ||
space_admin[space.id] { | ||
space := input.spaces[_] | ||
admins[login] | ||
} | ||
|
||
# Check if user is a writer and assign write access to the space | ||
space_write[space.id] { | ||
space := input.spaces[_] | ||
writers[login] | ||
} | ||
|
||
# Check if user is a reader and assign read access to the space | ||
space_read[space.id] { | ||
space := input.spaces[_] | ||
readers[login] | ||
} |
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,55 @@ | ||
package spacelift | ||
|
||
# Test for writers | ||
test_allow_writers { | ||
allow with input as {"session": {"teams": "team1"}} with input.spaces as [{"id": "space1"}, {"id": "space2"}] | ||
} | ||
|
||
test_deny_non_writers { | ||
not allow with input as {"session": {"teams": "non_writer_team"}} with input.spaces as [{"id": "space1"}, {"id": "space2"}] | ||
} | ||
|
||
# Test for admins | ||
test_allow_admins { | ||
allow with input as {"session": {"teams": "team4"}} with input.spaces as [{"id": "space1"}, {"id": "space2"}] | ||
} | ||
|
||
test_deny_non_admins { | ||
not allow with input as {"session": {"teams": "non_admin_team"}} with input.spaces as [{"id": "space1"}, {"id": "space2"}] | ||
} | ||
|
||
# Test for readers | ||
test_allow_readers { | ||
allow with input as {"session": {"teams": "team7"}} with input.spaces as [{"id": "space1"}, {"id": "space2"}] | ||
} | ||
|
||
test_deny_non_readers { | ||
not allow with input as {"session": {"teams": "non_reader_team"}} with input.spaces as [{"id": "space1"}, {"id": "space2"}] | ||
} | ||
|
||
# Test space access for admins | ||
test_space_admin_access { | ||
space_admin.space1 with input as {"session": {"teams": "team4"}, "spaces": [{"id": "space1"}, {"id": "space2"}]} | ||
} | ||
|
||
test_space_admin_no_access { | ||
not space_admin.space1 with input as {"session": {"teams": "team1"}, "spaces": [{"id": "space1"}, {"id": "space2"}]} | ||
} | ||
|
||
# Test space access for writers | ||
test_space_write_access { | ||
space_write.space1 with input as {"session": {"teams": "team1"}, "spaces": [{"id": "space1"}, {"id": "space2"}]} | ||
} | ||
|
||
test_space_write_no_access { | ||
not space_write.space1 with input as {"session": {"teams": "team7"}, "spaces": [{"id": "space1"}, {"id": "space2"}]} | ||
} | ||
|
||
# Test space access for readers | ||
test_space_read_access { | ||
space_read.space1 with input as {"session": {"teams": "team7"}, "spaces": [{"id": "space1"}, {"id": "space2"}]} | ||
} | ||
|
||
test_space_read_no_access { | ||
not space_read.space1 with input as {"session": {"teams": "team1"}, "spaces": [{"id": "space1"}, {"id": "space2"}]} | ||
} |