3
0

Add permission intg. tests

This commit is contained in:
Denis Arh
2019-09-10 02:55:09 +02:00
parent 778feb3967
commit 4e5288cce4
5 changed files with 86 additions and 5 deletions

View File

@@ -1,9 +1,36 @@
package messaging
import (
"fmt"
"net/http"
"testing"
"github.com/cortezaproject/corteza-server/internal/permissions"
"github.com/cortezaproject/corteza-server/tests/helpers"
)
func TestPermissionsDelete(t *testing.T) {
t.Skip("to be implemented")
h := newHelper(t)
h.a.Empty(p.FindRulesByRoleID(h.roleID))
h.allow("messaging", "access")
h.allow("messaging", "grant")
h.deny("messaging", "channel.group.create")
h.a.Len(p.FindRulesByRoleID(h.roleID), 3)
h.apiInit().
Delete(fmt.Sprintf("/permissions/%d/rules", h.roleID)).
Expect(t).
Status(http.StatusOK).
Assert(helpers.AssertNoErrors).
End()
// Make sure everything is deleted
rr, _ := p.FindRulesByRoleID(h.roleID).Filter(func(r *permissions.Rule) (b bool, e error) {
return r.Access != permissions.Inherit, nil
})
h.a.Empty(rr)
}

View File

@@ -1,9 +1,21 @@
package messaging
import (
"net/http"
"testing"
"github.com/cortezaproject/corteza-server/tests/helpers"
)
func TestPermissionsEffective(t *testing.T) {
t.Skip("to be implemented")
h := newHelper(t)
h.allow("messaging", "access")
h.deny("messaging", "channel.group.create")
h.apiInit().
Get("/permissions/effective").
Expect(t).
Status(http.StatusOK).
Assert(helpers.AssertNoErrors).
End()
}

View File

@@ -1,9 +1,22 @@
package messaging
import (
"net/http"
"testing"
jsonpath "github.com/steinfletcher/apitest-jsonpath"
"github.com/cortezaproject/corteza-server/tests/helpers"
)
func TestPermissionsList(t *testing.T) {
t.Skip("to be implemented")
h := newHelper(t)
h.apiInit().
Get("/permissions/").
Expect(t).
Status(http.StatusOK).
Assert(helpers.AssertNoErrors).
Assert(jsonpath.Present(`$.response[? @.resource=="messaging"]`)).
End()
}

View File

@@ -1,9 +1,23 @@
package messaging
import (
"fmt"
"net/http"
"testing"
"github.com/cortezaproject/corteza-server/tests/helpers"
)
func TestPermissionsRead(t *testing.T) {
t.Skip("to be implemented")
h := newHelper(t)
h.allow("messaging", "access")
h.allow("messaging", "grant")
h.deny("messaging", "channel.group.create")
h.apiInit().
Get(fmt.Sprintf("/permissions/%d/rules", h.roleID)).
Expect(t).
Status(http.StatusOK).
Assert(helpers.AssertNoErrors).
End()
}

View File

@@ -1,9 +1,24 @@
package messaging
import (
"fmt"
"net/http"
"testing"
"github.com/cortezaproject/corteza-server/tests/helpers"
)
func TestPermissionsUpdate(t *testing.T) {
t.Skip("to be implemented")
h := newHelper(t)
h.allow("messaging", "access")
h.allow("messaging", "grant")
h.deny("messaging", "channel.group.create")
h.apiInit().
Patch(fmt.Sprintf("/permissions/%d/rules", h.roleID)).
JSON(`{"rules":[{"resource":"messaging","operation":"channel.group.create","access":"allow"}]}`).
Expect(t).
Status(http.StatusOK).
Assert(helpers.AssertNoErrors).
End()
}