Merge branch 'MSP-1068_metadata_hotfix' into 'master'

Resolve MSP-1068 "Metadata hotfix"

Closes MSP-1068

See merge request msp2.0/msp-admin-service!14
This commit is contained in:
Новиков Михаил Юрьевич committed 2022-10-07 12:28:39 +00:00
commit bb4c8cd8ad
6 files changed
+15 -14

No files matched your search

+1 -1
View File
@@ -1 +1 @@
4.0.1
4.0.2
+2
View File
@@ -1,3 +1,5 @@
### v4.0.2
* исправлена ошибка метадаты grpc
### v4.0.1
* изменен default_remote_config
### v4.0.0
+5 -4
View File
@@ -3,6 +3,7 @@ package controller
import (
"context"
"github.com/integration-system/isp-kit/grpc"
"github.com/pkg/errors"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
@@ -40,13 +41,13 @@ func NewUser(userService userService) User {
// @Failure 401 {object} domain.GrpcError "Токен не соответствует ни одному пользователю"
// @Failure 500 {object} domain.GrpcError
// @Router /user/get_profile [POST]
func (u User) GetProfile(ctx context.Context, metadata metadata.MD) (*domain.AdminUserShort, error) {
token := metadata.Get(domain.AdminAuthHeaderName)
if len(token) == 0 {
func (u User) GetProfile(ctx context.Context, authData grpc.AuthData) (*domain.AdminUserShort, error) {
token, err := grpc.StringFromMd(domain.AdminAuthHeaderName, metadata.MD(authData))
if err != nil {
return nil, status.Error(codes.InvalidArgument, "Невалидный токен")
}
profile, err := u.userService.GetProfileByToken(ctx, token[0])
profile, err := u.userService.GetProfileByToken(ctx, token)
switch {
case errors.Is(err, domain.ErrUnauthenticated):
+1 -1
View File
@@ -5,7 +5,7 @@ go 1.19
require (
github.com/Masterminds/squirrel v1.5.3
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/integration-system/isp-kit v1.12.0
github.com/integration-system/isp-kit v1.12.1
github.com/integration-system/isp-lib/v2 v2.8.7
github.com/integration-system/jsonschema v1.0.1
github.com/pkg/errors v0.9.1
+3 -2
View File
@@ -395,8 +395,8 @@ github.com/integration-system/isp-etp-go/v2 v2.1.3/go.mod h1:ZpB+FIH3hy7md+f8ylV
github.com/integration-system/isp-event-lib v1.6.0/go.mod h1:lCzAci6oS+vc51W8EfHVCh9p3p057r0DpMuY4T0lSj0=
github.com/integration-system/isp-event-lib v1.6.1/go.mod h1:5ZIXsMG3gC7sfQ+eICjkDpy2RSvSAxV3Cq1BVN8LFIk=
github.com/integration-system/isp-event-lib v1.6.5/go.mod h1:gQg0S8TMeISIkTLM9/DwgWwnpS3BUkNFjgByRg3+Ub0=
github.com/integration-system/isp-kit v1.12.0 h1:ULf3CBH4fulA5VbsFT4kUnc4Q64vsPCB5yS6sbiDRvc=
github.com/integration-system/isp-kit v1.12.0/go.mod h1:5wHdXzI8fWeZQbPfQdel5Jnf0zZ3R+KnYdat/NN0RRo=
github.com/integration-system/isp-kit v1.12.1 h1:/8YxDL2nedt9UbZjXaDplXLh5KfP/k8enCsWA5rG8Yc=
github.com/integration-system/isp-kit v1.12.1/go.mod h1:5wHdXzI8fWeZQbPfQdel5Jnf0zZ3R+KnYdat/NN0RRo=
github.com/integration-system/isp-lib-test v1.5.4/go.mod h1:rD+X0QMiOIeJDhqwB4avdYhnc1hoEkL4z+7C7lwTuOA=
github.com/integration-system/isp-lib-test v1.6.0/go.mod h1:If5QK5jsXE48DZuq6WzCw8yC22k7GogLrEnMngXiE2Y=
github.com/integration-system/isp-lib-test v1.6.4/go.mod h1:k8DiXG/Bx3k8cft0QI/+BTRsL/43effW5575udzWv1M=
@@ -479,6 +479,7 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
+3 -6
View File
@@ -71,11 +71,10 @@ func (s *UserTestSuite) TestGetProfileHappyPath() {
token, _, err := s.tokenService.GenerateToken(id)
s.Require().NoError(err)
md := map[string][]string{domain.AdminAuthHeaderName: {token}}
response := domain.AdminUserShort{}
err = s.grpcCli.Invoke("admin/user/get_profile").
JsonRequestBody(md).
ReadJsonResponse(&response).
AppendMetadata(domain.AdminAuthHeaderName, token).
Do(context.Background())
s.Require().NoError(err)
expected := domain.AdminUserShort{
@@ -98,9 +97,8 @@ func (s *UserTestSuite) TestGetProfileUnauthorized() {
token, _, err := s.tokenService.GenerateToken(id + 1)
s.Require().NoError(err)
md := map[string][]string{domain.AdminAuthHeaderName: {token}}
err = s.grpcCli.Invoke("admin/user/get_profile").
JsonRequestBody(md).
AppendMetadata(domain.AdminAuthHeaderName, token).
Do(context.Background())
s.Require().Error(err)
st, ok := status.FromError(err)
@@ -121,10 +119,9 @@ func (s *UserTestSuite) TestGetProfileSudir() {
token, _, err := s.tokenService.GenerateToken(id)
s.Require().NoError(err)
md := map[string][]string{domain.AdminAuthHeaderName: {token}}
response := domain.AdminUserShort{}
err = s.grpcCli.Invoke("admin/user/get_profile").
JsonRequestBody(md).
AppendMetadata(domain.AdminAuthHeaderName, token).
ReadJsonResponse(&response).
Do(context.Background())
s.Require().NoError(err)