Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
NOISSUE - Improve tests in Auth service (#262)
Browse files Browse the repository at this point in the history
Signed-off-by: felix.gateru <[email protected]>
  • Loading branch information
felixgateru authored Jan 25, 2024
1 parent 4a909a1 commit 7a93e6a
Show file tree
Hide file tree
Showing 52 changed files with 7,162 additions and 845 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/check-generated-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
- "auth/domains.go"
- "auth/keys.go"
- "auth/policies.go"
- "auth/service.go"
- "pkg/events/events.go"
- "provision/service.go"
- "pkg/groups/groups.go"
Expand Down Expand Up @@ -109,6 +110,7 @@ jobs:
mv ./auth/mocks/authz.go ./auth/mocks/authz.go.tmp
mv ./auth/mocks/domains.go ./auth/mocks/domains.go.tmp
mv ./auth/mocks/keys.go ./auth/mocks/keys.go.tmp
mv ./auth/mocks/service.go ./auth/mocks/service.go.tmp
mv ./pkg/events/mocks/publisher.go ./pkg/events/mocks/publisher.go.tmp
mv ./pkg/events/mocks/subscriber.go ./pkg/events/mocks/subscriber.go.tmp
mv ./provision/mocks/service.go ./provision/mocks/service.go.tmp
Expand Down Expand Up @@ -140,6 +142,7 @@ jobs:
check_mock_changes ./auth/mocks/authz.go "Auth Authz ./auth/mocks/authz.go"
check_mock_changes ./auth/mocks/domains.go "Auth Domains ./auth/mocks/domains.go"
check_mock_changes ./auth/mocks/keys.go "Auth Keys ./auth/mocks/keys.go"
check_mock_changes ./auth/mocks/service.go "Auth Service ./auth/mocks/service.go"
check_mock_changes ./pkg/events/mocks/publisher.go "ES Publisher ./pkg/events/mocks/publisher.go"
check_mock_changes ./pkg/events/mocks/subscriber.go "EE Subscriber ./pkg/events/mocks/subscriber.go"
check_mock_changes ./provision/mocks/service.go "Provision Service ./provision/mocks/service.go"
Expand Down
427 changes: 213 additions & 214 deletions auth.pb.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions auth.proto
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ message AddPoliciesReq{
repeated AddPolicyReq addPoliciesReq= 1;
}

message AddPolicyRes { bool authorized = 1; }
message AddPolicyRes { bool added = 1; }

message AddPoliciesRes { bool authorized = 1; }
message AddPoliciesRes { bool added = 1; }

message DeletePolicyReq {
string domain = 1;
Expand Down
21 changes: 11 additions & 10 deletions auth/api/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,12 @@ func (client grpcClient) AddPolicy(ctx context.Context, in *magistrala.AddPolicy
}

apr := res.(addPolicyRes)
return &magistrala.AddPolicyRes{Authorized: apr.authorized}, nil
return &magistrala.AddPolicyRes{Added: apr.added}, nil
}

func decodeAddPolicyResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
res := grpcRes.(*magistrala.AddPolicyRes)
return addPolicyRes{authorized: res.Authorized}, nil
return addPolicyRes{added: res.Added}, nil
}

func encodeAddPolicyRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
Expand Down Expand Up @@ -341,12 +341,12 @@ func (client grpcClient) AddPolicies(ctx context.Context, in *magistrala.AddPoli
}

apr := res.(addPoliciesRes)
return &magistrala.AddPoliciesRes{Authorized: apr.authorized}, nil
return &magistrala.AddPoliciesRes{Added: apr.added}, nil
}

func decodeAddPoliciesResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
res := grpcRes.(*magistrala.AddPoliciesRes)
return addPoliciesRes{authorized: res.Authorized}, nil
return addPoliciesRes{added: res.Added}, nil
}

func encodeAddPoliciesRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
Expand Down Expand Up @@ -532,7 +532,7 @@ func (client grpcClient) CountObjects(ctx context.Context, in *magistrala.CountO
ctx, cancel := context.WithTimeout(ctx, client.timeout)
defer cancel()

res, err := client.countObjects(ctx, listObjectsReq{
res, err := client.countObjects(ctx, countObjectsReq{
Domain: in.GetDomain(),
SubjectType: in.GetSubjectType(),
Subject: in.GetSubject(),
Expand Down Expand Up @@ -712,11 +712,12 @@ func decodeListPermissionsResponse(_ context.Context, grpcRes interface{}) (inte
func encodeListPermissionsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
req := grpcReq.(listPermissionsReq)
return &magistrala.ListPermissionsReq{
Domain: req.Domain,
SubjectType: req.SubjectType,
Subject: req.Subject,
ObjectType: req.ObjectType,
Object: req.Object,
Domain: req.Domain,
SubjectType: req.SubjectType,
Subject: req.Subject,
ObjectType: req.ObjectType,
Object: req.Object,
FilterPermissions: req.FilterPermissions,
}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions auth/api/grpc/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func addPolicyEndpoint(svc auth.Service) endpoint.Endpoint {
if err != nil {
return addPolicyRes{}, err
}
return addPolicyRes{authorized: true}, err
return addPolicyRes{added: true}, err
}
}

Expand Down Expand Up @@ -147,7 +147,7 @@ func addPoliciesEndpoint(svc auth.Service) endpoint.Endpoint {
if err := svc.AddPolicies(ctx, prs); err != nil {
return addPoliciesRes{}, err
}
return addPoliciesRes{authorized: true}, nil
return addPoliciesRes{added: true}, nil
}
}

Expand Down
Loading

0 comments on commit 7a93e6a

Please sign in to comment.