authorize: fix nil reference (#704) (#741)

Signed-off-by: Bobby DeSimone <bobbydesimone@gmail.com>
This commit is contained in:
Bobby DeSimone 2020-05-20 09:34:41 -07:00 committed by GitHub
parent 394ae369a1
commit d31245fbba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View file

@ -27,6 +27,9 @@ func (a *Authorize) IsAuthorized(ctx context.Context, in *authorize.IsAuthorized
URL: getFullURL(in.GetRequestUrl(), in.GetRequestHost()), URL: getFullURL(in.GetRequestUrl(), in.GetRequestHost()),
} }
reply, err := a.pe.IsAuthorized(ctx, req) reply, err := a.pe.IsAuthorized(ctx, req)
if err != nil {
return nil, err
}
log.Info(). log.Info().
// request // request
Str("method", req.Method). Str("method", req.Method).
@ -38,7 +41,7 @@ func (a *Authorize) IsAuthorized(ctx context.Context, in *authorize.IsAuthorized
Str("email", reply.Email). Str("email", reply.Email).
Strs("groups", reply.Groups). Strs("groups", reply.Groups).
Msg("authorize.grpc.IsAuthorized") Msg("authorize.grpc.IsAuthorized")
return reply, err return reply, nil
} }
type protoHeader map[string]*authorize.IsAuthorizedRequest_Headers type protoHeader map[string]*authorize.IsAuthorizedRequest_Headers

View file

@ -23,7 +23,7 @@ func TestAuthorize_IsAuthorized(t *testing.T) {
wantErr bool wantErr bool
}{ }{
{"good", &authorize.IsAuthorizedReply{}, nil, context.TODO(), &authorize.IsAuthorizedRequest{UserToken: "good"}, &authorize.IsAuthorizedReply{}, false}, {"good", &authorize.IsAuthorizedReply{}, nil, context.TODO(), &authorize.IsAuthorizedRequest{UserToken: "good"}, &authorize.IsAuthorizedReply{}, false},
{"error", &authorize.IsAuthorizedReply{}, errors.New("error"), context.TODO(), &authorize.IsAuthorizedRequest{UserToken: "good"}, &authorize.IsAuthorizedReply{}, true}, {"error", &authorize.IsAuthorizedReply{}, errors.New("error"), context.TODO(), &authorize.IsAuthorizedRequest{UserToken: "good"}, nil, true},
{"headers", &authorize.IsAuthorizedReply{}, nil, context.TODO(), &authorize.IsAuthorizedRequest{UserToken: "good", RequestHeaders: nil}, &authorize.IsAuthorizedReply{}, false}, {"headers", &authorize.IsAuthorizedReply{}, nil, context.TODO(), &authorize.IsAuthorizedRequest{UserToken: "good", RequestHeaders: nil}, &authorize.IsAuthorizedReply{}, false},
} }
for _, tt := range tests { for _, tt := range tests {