-
Notifications
You must be signed in to change notification settings - Fork 62
/
mocks.go
82 lines (76 loc) · 2.87 KB
/
mocks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package service
import (
"context"
"strings"
types "github.com/paralus/paralus/proto/types/authz"
)
type ApUpdate struct {
id string
traits map[string]interface{}
}
type mockAuthProvider struct {
c []map[string]interface{}
u []ApUpdate
r []string
d []string
}
func (m *mockAuthProvider) Create(ctx context.Context, traits map[string]interface{}) (string, error) {
m.c = append(m.c, traits)
return strings.Split(traits["email"].(string), "user-")[1], nil
}
func (m *mockAuthProvider) Update(ctx context.Context, id string, traits map[string]interface{}) error {
m.u = append(m.u, ApUpdate{id: id, traits: traits})
return nil
}
func (m *mockAuthProvider) GetRecoveryLink(ctx context.Context, id string) (string, error) {
m.r = append(m.r, id)
return "https://recoverme.testing/" + id, nil
}
func (m *mockAuthProvider) Delete(ctx context.Context, id string) error {
m.d = append(m.d, id)
return nil
}
type mockAuthzClient struct {
cp []*types.Policies
dp []*types.Policy
cug []*types.UserGroups
dug []*types.UserGroup
crpm []*types.RolePermissionMappingList
drpm []*types.FilteredRolePermissionMapping
}
func (c *mockAuthzClient) Enforce(ctx context.Context, in *types.EnforceRequest) (*types.BoolReply, error) {
return &types.BoolReply{Res: true}, nil
}
func (c *mockAuthzClient) ListPolicies(ctx context.Context, in *types.Policy) (*types.Policies, error) {
return &types.Policies{}, nil
}
func (c *mockAuthzClient) CreatePolicies(ctx context.Context, in *types.Policies) (*types.BoolReply, error) {
c.cp = append(c.cp, in)
return &types.BoolReply{Res: true}, nil
}
func (c *mockAuthzClient) DeletePolicies(ctx context.Context, in *types.Policy) (*types.BoolReply, error) {
c.dp = append(c.dp, in)
return &types.BoolReply{Res: true}, nil
}
func (c *mockAuthzClient) ListUserGroups(ctx context.Context, in *types.UserGroup) (*types.UserGroups, error) {
return &types.UserGroups{}, nil
}
func (c *mockAuthzClient) CreateUserGroups(ctx context.Context, in *types.UserGroups) (*types.BoolReply, error) {
c.cug = append(c.cug, in)
return &types.BoolReply{Res: true}, nil
}
func (c *mockAuthzClient) DeleteUserGroups(ctx context.Context, in *types.UserGroup) (*types.BoolReply, error) {
c.dug = append(c.dug, in)
return &types.BoolReply{Res: true}, nil
}
func (c *mockAuthzClient) ListRolePermissionMappings(ctx context.Context, in *types.FilteredRolePermissionMapping) (*types.RolePermissionMappingList, error) {
return &types.RolePermissionMappingList{}, nil
}
func (c *mockAuthzClient) CreateRolePermissionMappings(ctx context.Context, in *types.RolePermissionMappingList) (*types.BoolReply, error) {
c.crpm = append(c.crpm, in)
return &types.BoolReply{Res: true}, nil
}
func (c *mockAuthzClient) DeleteRolePermissionMappings(ctx context.Context, in *types.FilteredRolePermissionMapping) (*types.BoolReply, error) {
c.drpm = append(c.drpm, in)
return &types.BoolReply{Res: true}, nil
}