1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-05-02 22:17:10 +08:00
Aleksandar Novaković a6a8648e4f MF-783 - Allow access checking by a thing ID (#784)
* Add can access by things ID endpoint to things service

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>

* Add new auth endpoint to the swagger docs

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>

* Add test for the new endpoint of the things service

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>
2019-07-15 18:28:15 +02:00

52 lines
1.2 KiB
Go

//
// Copyright (c) 2018
// Mainflux
//
// SPDX-License-Identifier: Apache-2.0
//
package mocks
import (
"context"
"github.com/golang/protobuf/ptypes/empty"
"github.com/mainflux/mainflux"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
var errUnauthorized = status.Error(codes.PermissionDenied, "missing or invalid credentials provided")
var _ mainflux.ThingsServiceClient = (*thingsServiceMock)(nil)
type thingsServiceMock struct{}
// NewThingsService returns mock implementation of things service
func NewThingsService() mainflux.ThingsServiceClient {
return thingsServiceMock{}
}
func (svc thingsServiceMock) CanAccess(ctx context.Context, in *mainflux.AccessReq, opts ...grpc.CallOption) (*mainflux.ThingID, error) {
token := in.GetToken()
if token == "invalid" {
return nil, errUnauthorized
}
if token == "" {
return nil, errUnauthorized
}
return &mainflux.ThingID{Value: token}, nil
}
func (svc thingsServiceMock) CanAccessByID(context.Context, *mainflux.AccessByIDReq, ...grpc.CallOption) (*empty.Empty, error) {
panic("not implemented")
}
func (svc thingsServiceMock) Identify(context.Context, *mainflux.Token, ...grpc.CallOption) (*mainflux.ThingID, error) {
panic("not implemented")
}