From 84101003df451ea7074a7067d8ff70717f2682dd Mon Sep 17 00:00:00 2001 From: Brian Conway Date: Fri, 20 Oct 2023 19:31:45 -0500 Subject: [PATCH] Add protogetter linter - Linter updates and style fixes. - Sync `vendor/` for updated dependencies. - All test variations pass. --- Makefile | 4 +- build/deploy/hermes/docker-compose.yml | 4 +- go.mod | 12 +- go.sum | 24 +- internal/hermes-api/interceptor/auth.go | 4 +- internal/hermes-api/interceptor/auth_test.go | 14 +- internal/hermes-api/service/app.go | 34 +- internal/hermes-api/service/app_test.go | 44 +- internal/hermes-api/service/event.go | 12 +- internal/hermes-api/service/event_test.go | 12 +- internal/hermes-api/service/identity.go | 134 ++--- internal/hermes-api/service/identity_test.go | 534 +++++++++--------- internal/hermes-api/service/org.go | 40 +- internal/hermes-api/service/org_test.go | 44 +- internal/hermes-api/service/session.go | 40 +- internal/hermes-api/service/session_test.go | 50 +- internal/hermes-api/service/user.go | 52 +- internal/hermes-api/service/user_test.go | 48 +- internal/hermes-api/session/page_token.go | 6 +- internal/hermes-api/session/session_test.go | 4 +- internal/hermes-api/session/web_token.go | 14 +- internal/hermes-api/session/web_token_test.go | 14 +- internal/hermes-api/test/app_test.go | 84 +-- internal/hermes-api/test/event_test.go | 61 +- internal/hermes-api/test/helper_test.go | 12 +- internal/hermes-api/test/identity_test.go | 500 ++++++++-------- internal/hermes-api/test/org_test.go | 96 ++-- internal/hermes-api/test/session_test.go | 80 +-- internal/hermes-api/test/user_test.go | 110 ++-- internal/hermes-notifier/notifier/notify.go | 60 +- .../hermes-notifier/notifier/notify_test.go | 64 +-- .../hermes-notifier/test/notifier_test.go | 82 +-- pkg/dao/app/crudl.go | 12 +- pkg/dao/app/crudl_test.go | 94 +-- pkg/dao/event/crudl.go | 6 +- pkg/dao/event/crudl_test.go | 48 +- pkg/dao/identity/crudl.go | 6 +- pkg/dao/identity/crudl_test.go | 242 ++++---- pkg/dao/identity/method.go | 44 +- pkg/dao/identity/method_test.go | 2 +- pkg/dao/key/crudl.go | 4 +- pkg/dao/key/crudl_test.go | 58 +- pkg/dao/org/crudl.go | 14 +- pkg/dao/org/crudl_test.go | 84 +-- pkg/dao/user/crudl.go | 10 +- pkg/dao/user/crudl_test.go | 124 ++-- pkg/test/random/api_test.go | 60 +- tool/hermes-create/main.go | 6 +- vendor/google.golang.org/grpc/README.md | 2 +- .../grpc/attributes/attributes.go | 4 +- .../grpc/balancer/balancer.go | 15 + vendor/google.golang.org/grpc/clientconn.go | 18 +- vendor/google.golang.org/grpc/dialoptions.go | 5 +- .../grpc/encoding/encoding.go | 13 +- .../health/grpc_health_v1/health_grpc.pb.go | 22 +- .../grpc/internal/backoff/backoff.go | 36 ++ .../grpc/internal/internal.go | 6 + .../grpc/internal/status/status.go | 28 + .../grpc/internal/transport/handler_server.go | 13 +- .../grpc/internal/transport/http2_client.go | 13 +- .../grpc/internal/transport/http2_server.go | 14 +- .../grpc/internal/transport/http_util.go | 18 +- .../grpc/internal/transport/transport.go | 2 +- vendor/google.golang.org/grpc/server.go | 136 ++--- vendor/google.golang.org/grpc/tap/tap.go | 6 + vendor/google.golang.org/grpc/version.go | 2 +- vendor/google.golang.org/grpc/vet.sh | 3 + vendor/modules.txt | 12 +- web/hermes.swagger.json | 2 +- 69 files changed, 1776 insertions(+), 1701 deletions(-) diff --git a/Makefile b/Makefile index 7281a877..1b34d740 100644 --- a/Makefile +++ b/Makefile @@ -36,8 +36,8 @@ lint: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest golangci-lint version golangci-lint run -E bidichk,durationcheck,errname,exportloopref \ - -E forcetypeassert,goconst,godot,goerr113,gofumpt,gosec,nlreturn,prealloc \ - -E unconvert,unparam,usestdlibvars --exclude-use-default=false + -E forcetypeassert,godot,goerr113,gofumpt,gosec,nlreturn,prealloc \ + -E protogetter,unconvert,unparam,usestdlibvars --exclude-use-default=false go install golang.org/x/vuln/cmd/govulncheck@latest govulncheck -test ./... diff --git a/build/deploy/hermes/docker-compose.yml b/build/deploy/hermes/docker-compose.yml index 75d803dc..c38a2c4d 100644 --- a/build/deploy/hermes/docker-compose.yml +++ b/build/deploy/hermes/docker-compose.yml @@ -1,7 +1,7 @@ version: "3" services: hermes-api: - image: ghcr.io/ownmfa/hermes:7bdca87c + image: ghcr.io/ownmfa/hermes:db584d7a command: hermes-api restart: on-failure depends_on: @@ -35,7 +35,7 @@ services: - "traefik.http.services.hermes-grpc.loadbalancer.server.scheme=h2c" hermes-notifier: - image: ghcr.io/ownmfa/hermes:7bdca87c + image: ghcr.io/ownmfa/hermes:db584d7a command: hermes-notifier restart: on-failure environment: diff --git a/go.mod b/go.mod index 5f663428..c45ea9f6 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/ownmfa/hermes -go 1.21.0 +go 1.21.3 require ( github.com/NYTimes/gziphandler v1.1.1 @@ -11,14 +11,14 @@ require ( github.com/jellydator/ttlcache/v3 v3.1.0 github.com/mennanov/fmutils v0.2.1 github.com/nsqio/go-nsq v1.1.0 - github.com/ownmfa/api/go v1.0.27 + github.com/ownmfa/api/go v1.0.28 github.com/redis/go-redis/v9 v9.2.1 github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e github.com/smira/go-statsd v1.3.3 github.com/stretchr/testify v1.8.4 go.uber.org/mock v0.3.0 golang.org/x/crypto v0.14.0 - google.golang.org/grpc v1.58.3 + google.golang.org/grpc v1.59.0 google.golang.org/protobuf v1.31.0 ) @@ -37,8 +37,8 @@ require ( golang.org/x/sync v0.4.0 // indirect golang.org/x/sys v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect - google.golang.org/genproto v0.0.0-20231009173412-8bfb1ae86b6c // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20231009173412-8bfb1ae86b6c // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20231009173412-8bfb1ae86b6c // indirect + google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 06dfbc34..d59db458 100644 --- a/go.sum +++ b/go.sum @@ -428,8 +428,8 @@ github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9 github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/glog v1.1.0 h1:/d3pCKDPWNnvIWe0vVUpNP32qc8U3PDVxySP/y360qE= -github.com/golang/glog v1.1.0/go.mod h1:pfYeQZ3JWZoXTV5sFc986z3HTpwQs9At6P4ImfuP3NQ= +github.com/golang/glog v1.1.2 h1:DVjP2PbBOzHyzA+dn3WhHIq4NdVu3Q+pvivFICf/7fo= +github.com/golang/glog v1.1.2/go.mod h1:zR+okUeTbrL6EL3xHUDxZuEtGv04p5shwip1+mL/rLQ= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -551,8 +551,8 @@ github.com/mennanov/fmutils v0.2.1 h1:AUxeJv4o92vKbZaM4RBLZ/i8WzPF/UISTNeXB3gEIl github.com/mennanov/fmutils v0.2.1/go.mod h1:ph1jsu8gV1gUgMURCmfIVbXKG3O2/O5o/UbPbbqu8zs= github.com/nsqio/go-nsq v1.1.0 h1:PQg+xxiUjA7V+TLdXw7nVrJ5Jbl3sN86EhGCQj4+FYE= github.com/nsqio/go-nsq v1.1.0/go.mod h1:vKq36oyeVXgsS5Q8YEO7WghqidAVXQlcFxzQbQTuDEY= -github.com/ownmfa/api/go v1.0.27 h1:fOruRrzqnAJezhSSxpZjB8wd0djA+ii98x+eI6fI6GE= -github.com/ownmfa/api/go v1.0.27/go.mod h1:99PmUKxcZdiNGTHyJRlDkennbI7OWYiuRny6u9zbpkI= +github.com/ownmfa/api/go v1.0.28 h1:ynvj335X3pCt1UkWkYuGTZdfqcdyon6gkmYMLAy+soQ= +github.com/ownmfa/api/go v1.0.28/go.mod h1:oahF0+3YvReV98Pg+hyXVwwZzKqZ6Gb6naSTXC6rBOk= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= @@ -1044,12 +1044,12 @@ google.golang.org/genproto v0.0.0-20221117204609-8f9c96812029/go.mod h1:rZS5c/ZV google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6/go.mod h1:rZS5c/ZVYMaOGBfO68GWtjOw/eLaZM1X6iVtgjZ+EWg= google.golang.org/genproto v0.0.0-20221201164419-0e50fba7f41c/go.mod h1:rZS5c/ZVYMaOGBfO68GWtjOw/eLaZM1X6iVtgjZ+EWg= google.golang.org/genproto v0.0.0-20230202175211-008b39050e57/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= -google.golang.org/genproto v0.0.0-20231009173412-8bfb1ae86b6c h1:ml3TAUoIIzQUtX88s/icpXCFW9lV5VwsuIuS1htNjKY= -google.golang.org/genproto v0.0.0-20231009173412-8bfb1ae86b6c/go.mod h1:MugzuwC+GYOxyF0XUGQvsT97bOgWCV7MM1XMc5FZv8E= -google.golang.org/genproto/googleapis/api v0.0.0-20231009173412-8bfb1ae86b6c h1:0RtEmmHjemvUXloH7+RuBSIw7n+GEHMOMY1CkGYnWq4= -google.golang.org/genproto/googleapis/api v0.0.0-20231009173412-8bfb1ae86b6c/go.mod h1:Wth13BrWMRN/G+guBLupKa6fslcWZv14R0ZKDRkNfY8= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231009173412-8bfb1ae86b6c h1:jHkCUWkseRf+W+edG5hMzr/Uh1xkDREY4caybAq4dpY= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231009173412-8bfb1ae86b6c/go.mod h1:4cYg8o5yUbm77w8ZX00LhMVNl/YVBFJRYWDc0uYWMs0= +google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b h1:+YaDE2r2OG8t/z5qmsh7Y+XXwCbvadxxZ0YY6mTdrVA= +google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:CgAqfJo+Xmu0GwA0411Ht3OU3OntXwsGmrmjI8ioGXI= +google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b h1:CIC2YMXmIhYw6evmhPxBKJ4fmLbOFtXQN/GV3XOZR8k= +google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:IBQ646DjkDkvUIsVq/cc03FUFQ9wbZu7yE396YcL870= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b h1:ZlWIi1wSK56/8hn4QcBp/j9M7Gt3U/3hZw3mC7vDICo= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:swOH3j0KzcDDgGUWr+SNpyTen5YrXjS3eyPzFYKc6lc= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -1086,8 +1086,8 @@ google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCD google.golang.org/grpc v1.50.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= google.golang.org/grpc v1.50.1/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= google.golang.org/grpc v1.51.0/go.mod h1:wgNDFcnuBGmxLKI/qn4T+m5BtEBYXJPvibbUPsAIPww= -google.golang.org/grpc v1.58.3 h1:BjnpXut1btbtgN/6sp+brB2Kbm2LjNXnidYujAVbSoQ= -google.golang.org/grpc v1.58.3/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= +google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk= +google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= diff --git a/internal/hermes-api/interceptor/auth.go b/internal/hermes-api/interceptor/auth.go index 028c2052..5d4cfc93 100644 --- a/internal/hermes-api/interceptor/auth.go +++ b/internal/hermes-api/interceptor/auth.go @@ -62,10 +62,10 @@ func Auth( // Check for disabled organization. This read is cached. org, err := orgDAO.Read(ctx, sess.OrgID) - if err != nil || org.Status == api.Status_DISABLED { + if err != nil || org.GetStatus() == api.Status_DISABLED { return nil, status.Error(codes.Unauthenticated, "unauthorized") } - sess.OrgPlan = org.Plan + sess.OrgPlan = org.GetPlan() // Add logging fields. logger := hlog.FromContext(ctx) diff --git a/internal/hermes-api/interceptor/auth_test.go b/internal/hermes-api/interceptor/auth_test.go index 13ffe32e..9325c842 100644 --- a/internal/hermes-api/interceptor/auth_test.go +++ b/internal/hermes-api/interceptor/auth_test.go @@ -37,8 +37,8 @@ func TestAuth(t *testing.T) { t.Logf("webToken, err: %v, %v", webToken, err) require.NoError(t, err) - keyToken, err := session.GenerateKeyToken(key, uuid.NewString(), user.OrgId, - user.Role) + keyToken, err := session.GenerateKeyToken(key, uuid.NewString(), user.GetOrgId(), + user.GetRole()) t.Logf("keyToken, err: %v, %v", keyToken, err) require.NoError(t, err) @@ -61,13 +61,13 @@ func TestAuth(t *testing.T) { []string{"authorization", "Bearer " + webToken}, nil, nil, &grpc.UnaryServerInfo{FullMethod: random.String(10)}, false, nil, 0, - &api.Org{Id: user.OrgId, Status: api.Status_ACTIVE}, nil, 1, nil, + &api.Org{Id: user.GetOrgId(), Status: api.Status_ACTIVE}, nil, 1, nil, }, { []string{"authorization", "Bearer " + keyToken}, nil, nil, &grpc.UnaryServerInfo{FullMethod: random.String(10)}, false, nil, 1, - &api.Org{Id: user.OrgId, Status: api.Status_ACTIVE}, nil, 1, nil, + &api.Org{Id: user.GetOrgId(), Status: api.Status_ACTIVE}, nil, 1, nil, }, { nil, errTestFunc, @@ -112,14 +112,14 @@ func TestAuth(t *testing.T) { []string{"authorization", "Bearer " + webToken}, errTestFunc, nil, &grpc.UnaryServerInfo{FullMethod: random.String(10)}, false, nil, 0, - &api.Org{Id: user.OrgId, Status: api.Status_ACTIVE}, errTestFunc, 1, + &api.Org{Id: user.GetOrgId(), Status: api.Status_ACTIVE}, errTestFunc, 1, status.Error(codes.Unauthenticated, "unauthorized"), }, { []string{"authorization", "Bearer " + webToken}, errTestFunc, nil, &grpc.UnaryServerInfo{FullMethod: random.String(10)}, false, nil, 0, - &api.Org{Id: user.OrgId, Status: api.Status_DISABLED}, nil, 1, + &api.Org{Id: user.GetOrgId(), Status: api.Status_DISABLED}, nil, 1, status.Error(codes.Unauthenticated, "unauthorized"), }, } @@ -136,7 +136,7 @@ func TestAuth(t *testing.T) { Return(lTest.inpCache, "", lTest.inpCacheErr). Times(lTest.inpCacheTimes) orger := service.NewMockOrger(ctrl) - orger.EXPECT().Read(gomock.Any(), lTest.inpOrg.Id). + orger.EXPECT().Read(gomock.Any(), lTest.inpOrg.GetId()). Return(lTest.inpOrg, lTest.inpOrgErr).Times(lTest.inpOrgTimes) ctx, cancel := context.WithTimeout(context.Background(), diff --git a/internal/hermes-api/service/app.go b/internal/hermes-api/service/app.go index ab1be974..3ee1405c 100644 --- a/internal/hermes-api/service/app.go +++ b/internal/hermes-api/service/app.go @@ -78,7 +78,7 @@ func (ai *AppIdentity) CreateApp( req.App.OrgId = sess.OrgID - app, err := ai.appDAO.Create(ctx, req.App) + app, err := ai.appDAO.Create(ctx, req.GetApp()) if err != nil { return nil, errToStatus(err) } @@ -101,7 +101,7 @@ func (ai *AppIdentity) GetApp(ctx context.Context, req *api.GetAppRequest) ( return nil, errPerm(api.Role_VIEWER) } - app, err := ai.appDAO.Read(ctx, req.Id, sess.OrgID) + app, err := ai.appDAO.Read(ctx, req.GetId(), sess.OrgID) if err != nil { return nil, errToStatus(err) } @@ -119,28 +119,28 @@ func (ai *AppIdentity) UpdateApp( return nil, errPerm(api.Role_ADMIN) } - if req.App == nil { + if req.GetApp() == nil { return nil, status.Error(codes.InvalidArgument, req.Validate().Error()) } req.App.OrgId = sess.OrgID // Perform partial update if directed. - if req.UpdateMask != nil && len(req.UpdateMask.Paths) > 0 { + if len(req.GetUpdateMask().GetPaths()) > 0 { // Normalize and validate field mask. - req.UpdateMask.Normalize() - if !req.UpdateMask.IsValid(req.App) { + req.GetUpdateMask().Normalize() + if !req.GetUpdateMask().IsValid(req.GetApp()) { return nil, status.Error(codes.InvalidArgument, "invalid field mask") } - app, err := ai.appDAO.Read(ctx, req.App.Id, sess.OrgID) + app, err := ai.appDAO.Read(ctx, req.GetApp().GetId(), sess.OrgID) if err != nil { return nil, errToStatus(err) } - fmutils.Filter(req.App, req.UpdateMask.Paths) - proto.Merge(app, req.App) + fmutils.Filter(req.GetApp(), req.GetUpdateMask().GetPaths()) + proto.Merge(app, req.GetApp()) req.App = app } @@ -149,7 +149,7 @@ func (ai *AppIdentity) UpdateApp( return nil, status.Error(codes.InvalidArgument, err.Error()) } - app, err := ai.appDAO.Update(ctx, req.App) + app, err := ai.appDAO.Update(ctx, req.GetApp()) if err != nil { return nil, errToStatus(err) } @@ -166,7 +166,7 @@ func (ai *AppIdentity) DeleteApp( return nil, errPerm(api.Role_ADMIN) } - if err := ai.appDAO.Delete(ctx, req.Id, sess.OrgID); err != nil { + if err := ai.appDAO.Delete(ctx, req.GetId(), sess.OrgID); err != nil { return nil, errToStatus(err) } @@ -188,18 +188,18 @@ func (ai *AppIdentity) ListApps(ctx context.Context, req *api.ListAppsRequest) ( return nil, errPerm(api.Role_VIEWER) } - if req.PageSize == 0 { + if req.GetPageSize() == 0 { req.PageSize = defaultPageSize } - lBoundTS, prevID, err := session.ParsePageToken(req.PageToken) + lBoundTS, prevID, err := session.ParsePageToken(req.GetPageToken()) if err != nil { return nil, status.Error(codes.InvalidArgument, "invalid page token") } // Retrieve PageSize+1 entries to find last page. apps, count, err := ai.appDAO.List(ctx, sess.OrgID, lBoundTS, prevID, - req.PageSize+1) + req.GetPageSize()+1) if err != nil { return nil, errToStatus(err) } @@ -207,12 +207,12 @@ func (ai *AppIdentity) ListApps(ctx context.Context, req *api.ListAppsRequest) ( resp := &api.ListAppsResponse{Apps: apps, TotalSize: count} // Populate next page token. - if len(apps) == int(req.PageSize+1) { + if len(apps) == int(req.GetPageSize()+1) { resp.Apps = apps[:len(apps)-1] if resp.NextPageToken, err = session.GeneratePageToken( - apps[len(apps)-2].CreatedAt.AsTime(), - apps[len(apps)-2].Id); err != nil { + apps[len(apps)-2].GetCreatedAt().AsTime(), + apps[len(apps)-2].GetId()); err != nil { // GeneratePageToken should not error based on a DB-derived UUID. // Log the error and include the usable empty token. logger := hlog.FromContext(ctx) diff --git a/internal/hermes-api/service/app_test.go b/internal/hermes-api/service/app_test.go index c39ffd47..d1d6baa5 100644 --- a/internal/hermes-api/service/app_test.go +++ b/internal/hermes-api/service/app_test.go @@ -35,7 +35,7 @@ func TestCreateApp(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: app.OrgId, Role: api.Role_ADMIN, + OrgID: app.GetOrgId(), Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -92,7 +92,7 @@ func TestCreateApp(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: app.OrgId, Role: api.Role_ADMIN, + OrgID: app.GetOrgId(), Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -115,17 +115,17 @@ func TestGetApp(t *testing.T) { retApp, _ := proto.Clone(app).(*api.App) apper := NewMockApper(gomock.NewController(t)) - apper.EXPECT().Read(gomock.Any(), app.Id, app.OrgId).Return(retApp, + apper.EXPECT().Read(gomock.Any(), app.GetId(), app.GetOrgId()).Return(retApp, nil).Times(1) ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: app.OrgId, Role: api.Role_ADMIN, + OrgID: app.GetOrgId(), Role: api.Role_ADMIN, }), testTimeout) defer cancel() aiSvc := NewAppIdentity(apper, nil, nil, nil, nil, nil, "") - getApp, err := aiSvc.GetApp(ctx, &api.GetAppRequest{Id: app.Id}) + getApp, err := aiSvc.GetApp(ctx, &api.GetAppRequest{Id: app.GetId()}) t.Logf("app, getApp, err: %+v, %+v, %v", app, getApp, err) require.NoError(t, err) @@ -201,7 +201,7 @@ func TestUpdateApp(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: app.OrgId, Role: api.Role_ADMIN, + OrgID: app.GetOrgId(), Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -225,27 +225,27 @@ func TestUpdateApp(t *testing.T) { app := random.App("api-app", uuid.NewString()) retApp, _ := proto.Clone(app).(*api.App) part := &api.App{ - Id: app.Id, Name: random.String(10), DisplayName: random.String(10), + Id: app.GetId(), Name: random.String(10), DisplayName: random.String(10), PushoverKey: random.String(30), } merged := &api.App{ - Id: app.Id, OrgId: app.OrgId, Name: part.Name, - DisplayName: part.DisplayName, Email: app.Email, - PushoverKey: part.PushoverKey, SubjectTemplate: app.SubjectTemplate, - TextBodyTemplate: app.TextBodyTemplate, - HtmlBodyTemplate: app.HtmlBodyTemplate, + Id: app.GetId(), OrgId: app.GetOrgId(), Name: part.GetName(), + DisplayName: part.GetDisplayName(), Email: app.GetEmail(), + PushoverKey: part.GetPushoverKey(), SubjectTemplate: app.GetSubjectTemplate(), + TextBodyTemplate: app.GetTextBodyTemplate(), + HtmlBodyTemplate: app.GetHtmlBodyTemplate(), } retMerged, _ := proto.Clone(merged).(*api.App) apper := NewMockApper(gomock.NewController(t)) - apper.EXPECT().Read(gomock.Any(), app.Id, app.OrgId).Return(retApp, + apper.EXPECT().Read(gomock.Any(), app.GetId(), app.GetOrgId()).Return(retApp, nil).Times(1) apper.EXPECT().Update(gomock.Any(), matcher.NewProtoMatcher(merged)). Return(retMerged, nil).Times(1) ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: app.OrgId, Role: api.Role_ADMIN, + OrgID: app.GetOrgId(), Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -341,7 +341,7 @@ func TestUpdateApp(t *testing.T) { part := &api.App{Id: uuid.NewString(), Name: random.String(10)} apper := NewMockApper(gomock.NewController(t)) - apper.EXPECT().Read(gomock.Any(), part.Id, orgID). + apper.EXPECT().Read(gomock.Any(), part.GetId(), orgID). Return(nil, dao.ErrNotFound).Times(1) ctx, cancel := context.WithTimeout(session.NewContext( @@ -369,7 +369,7 @@ func TestUpdateApp(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: app.OrgId, Role: api.Role_ADMIN, + OrgID: app.GetOrgId(), Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -396,7 +396,7 @@ func TestUpdateApp(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: app.OrgId, Role: api.Role_ADMIN, + OrgID: app.GetOrgId(), Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -510,7 +510,7 @@ func TestListApps(t *testing.T) { listApps, err := aiSvc.ListApps(ctx, &api.ListAppsRequest{}) t.Logf("listApps, err: %+v, %v", listApps, err) require.NoError(t, err) - require.Equal(t, int32(3), listApps.TotalSize) + require.Equal(t, int32(3), listApps.GetTotalSize()) // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -532,8 +532,8 @@ func TestListApps(t *testing.T) { random.App("api-app", uuid.NewString()), } - next, err := session.GeneratePageToken(apps[1].CreatedAt.AsTime(), - apps[1].Id) + next, err := session.GeneratePageToken(apps[1].GetCreatedAt().AsTime(), + apps[1].GetId()) require.NoError(t, err) apper := NewMockApper(gomock.NewController(t)) @@ -550,7 +550,7 @@ func TestListApps(t *testing.T) { listApps, err := aiSvc.ListApps(ctx, &api.ListAppsRequest{PageSize: 2}) t.Logf("listApps, err: %+v, %v", listApps, err) require.NoError(t, err) - require.Equal(t, int32(3), listApps.TotalSize) + require.Equal(t, int32(3), listApps.GetTotalSize()) // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -657,7 +657,7 @@ func TestListApps(t *testing.T) { listApps, err := aiSvc.ListApps(ctx, &api.ListAppsRequest{PageSize: 2}) t.Logf("listApps, err: %+v, %v", listApps, err) require.NoError(t, err) - require.Equal(t, int32(3), listApps.TotalSize) + require.Equal(t, int32(3), listApps.GetTotalSize()) // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 diff --git a/internal/hermes-api/service/event.go b/internal/hermes-api/service/event.go index 39a63f59..4700fd27 100644 --- a/internal/hermes-api/service/event.go +++ b/internal/hermes-api/service/event.go @@ -46,13 +46,13 @@ func (e *Event) ListEvents(ctx context.Context, req *api.ListEventsRequest) ( } end := time.Now().UTC() - if req.EndTime != nil { - end = req.EndTime.AsTime() + if req.GetEndTime() != nil { + end = req.GetEndTime().AsTime() } start := end.Add(-24 * time.Hour) - if req.StartTime != nil && req.StartTime.AsTime().Before(end) { - start = req.StartTime.AsTime() + if req.GetStartTime() != nil && req.GetStartTime().AsTime().Before(end) { + start = req.GetStartTime().AsTime() } if end.Sub(start) > 90*24*time.Hour { @@ -60,7 +60,7 @@ func (e *Event) ListEvents(ctx context.Context, req *api.ListEventsRequest) ( "maximum time range exceeded") } - events, err := e.evDAO.List(ctx, sess.OrgID, req.IdentityId, end, start) + events, err := e.evDAO.List(ctx, sess.OrgID, req.GetIdentityId(), end, start) if err != nil { return nil, errToStatus(err) } @@ -78,7 +78,7 @@ func (e *Event) LatestEvents( return nil, errPerm(api.Role_VIEWER) } - events, err := e.evDAO.Latest(ctx, sess.OrgID, req.AppId, req.IdentityId) + events, err := e.evDAO.Latest(ctx, sess.OrgID, req.GetAppId(), req.GetIdentityId()) if err != nil { return nil, errToStatus(err) } diff --git a/internal/hermes-api/service/event_test.go b/internal/hermes-api/service/event_test.go index bca2927b..53466677 100644 --- a/internal/hermes-api/service/event_test.go +++ b/internal/hermes-api/service/event_test.go @@ -32,18 +32,18 @@ func TestListEvents(t *testing.T) { start := time.Now().UTC().Add(-15 * time.Minute) eventer := NewMockEventer(gomock.NewController(t)) - eventer.EXPECT().List(gomock.Any(), event.OrgId, event.IdentityId, + eventer.EXPECT().List(gomock.Any(), event.GetOrgId(), event.GetIdentityId(), end, start).Return([]*api.Event{retEvent}, nil).Times(1) ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: event.OrgId, Role: api.Role_ADMIN, + OrgID: event.GetOrgId(), Role: api.Role_ADMIN, }), testTimeout) defer cancel() evSvc := NewEvent(eventer) listEvents, err := evSvc.ListEvents(ctx, &api.ListEventsRequest{ - IdentityId: event.IdentityId, EndTime: timestamppb.New(end), + IdentityId: event.GetIdentityId(), EndTime: timestamppb.New(end), StartTime: timestamppb.New(start), }) t.Logf("event, listEvents, err: %+v, %+v, %v", event, listEvents, err) @@ -141,8 +141,8 @@ func TestLatestEvents(t *testing.T) { orgID := uuid.NewString() eventer := NewMockEventer(gomock.NewController(t)) - eventer.EXPECT().Latest(gomock.Any(), orgID, event.AppId, - event.IdentityId).Return([]*api.Event{retEvent}, nil).Times(1) + eventer.EXPECT().Latest(gomock.Any(), orgID, event.GetAppId(), + event.GetIdentityId()).Return([]*api.Event{retEvent}, nil).Times(1) ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ @@ -152,7 +152,7 @@ func TestLatestEvents(t *testing.T) { evSvc := NewEvent(eventer) latEvents, err := evSvc.LatestEvents(ctx, &api.LatestEventsRequest{ - AppId: event.AppId, IdentityId: event.IdentityId, + AppId: event.GetAppId(), IdentityId: event.GetIdentityId(), }) t.Logf("event, latEvents, err: %+v, %+v, %v", event, latEvents, err) require.NoError(t, err) diff --git a/internal/hermes-api/service/identity.go b/internal/hermes-api/service/identity.go index 5fd8e2cc..06e4fae7 100644 --- a/internal/hermes-api/service/identity.go +++ b/internal/hermes-api/service/identity.go @@ -56,18 +56,18 @@ type Identityer interface { func (ai *AppIdentity) validatePlan( ctx context.Context, orgPlan api.Plan, i *api.Identity, ) error { - switch m := i.MethodOneof.(type) { + switch m := i.GetMethodOneof().(type) { case *api.Identity_SmsMethod: if orgPlan < api.Plan_PRO { return errPlan(api.Plan_PRO) } - if !rePhone.MatchString(m.SmsMethod.Phone) { + if !rePhone.MatchString(m.SmsMethod.GetPhone()) { return status.Error(codes.InvalidArgument, "invalid E.164 phone number") } - if err := ai.notify.ValidateSMS(ctx, m.SmsMethod.Phone); err != nil { + if err := ai.notify.ValidateSMS(ctx, m.SmsMethod.GetPhone()); err != nil { return errToStatus(err) } case *api.Identity_PushoverMethod: @@ -76,7 +76,7 @@ func (ai *AppIdentity) validatePlan( } if err := ai.notify.ValidatePushover( - m.PushoverMethod.PushoverKey); err != nil { + m.PushoverMethod.GetPushoverKey()); err != nil { return errToStatus(err) } case *api.Identity_EmailMethod: @@ -107,13 +107,13 @@ func (ai *AppIdentity) CreateIdentity( } // Validate notification methods and apply plan limits. - if err := ai.validatePlan(ctx, sess.OrgPlan, req.Identity); err != nil { + if err := ai.validatePlan(ctx, sess.OrgPlan, req.GetIdentity()); err != nil { return nil, err } req.Identity.OrgId = sess.OrgID - identity, otp, retSecret, err := ai.identDAO.Create(ctx, req.Identity) + identity, otp, retSecret, err := ai.identDAO.Create(ctx, req.GetIdentity()) if err != nil { return nil, errToStatus(err) } @@ -122,35 +122,35 @@ func (ai *AppIdentity) CreateIdentity( if retSecret { resp.Secret = otp.Secret() - app, err := ai.appDAO.Read(ctx, identity.AppId, sess.OrgID) + app, err := ai.appDAO.Read(ctx, identity.GetAppId(), sess.OrgID) if err != nil { return nil, errToStatus(err) } - resp.Qr, err = otp.QR(app.DisplayName) + resp.Qr, err = otp.QR(app.GetDisplayName()) if err != nil { return nil, errToStatus(err) } } // Populate pregenerated backup codes. - if m, ok := identity.MethodOneof.(*api.Identity_BackupCodesMethod); ok { - for i := 0; i < int(m.BackupCodesMethod.Passcodes); i++ { + if m, ok := identity.GetMethodOneof().(*api.Identity_BackupCodesMethod); ok { + for i := 0; i < int(m.BackupCodesMethod.GetPasscodes()); i++ { passcode, err := otp.HOTP(int64(i + 10)) if err != nil { return nil, errToStatus(err) } - resp.Passcodes = append(resp.Passcodes, passcode) + resp.Passcodes = append(resp.GetPasscodes(), passcode) } } // Failure to write an event is non-fatal, but should be logged for // investigation. event := &api.Event{ - OrgId: identity.OrgId, - AppId: identity.AppId, - IdentityId: identity.Id, + OrgId: identity.GetOrgId(), + AppId: identity.GetAppId(), + IdentityId: identity.GetId(), Status: api.EventStatus_IDENTITY_CREATED, TraceId: sess.TraceID.String(), } @@ -177,18 +177,18 @@ func (ai *AppIdentity) verify( return err } - if identity.Status != expStatus { + if identity.GetStatus() != expStatus { return fmt.Errorf("%w %s", errExpStatus, strings.ToLower(expStatus.String())) } // Check passcode expiration for methods that utilize it. Continue to // verification, even if found, to keep HOTP counters in sync. - switch identity.MethodOneof.(type) { + switch identity.GetMethodOneof().(type) { case *api.Identity_SmsMethod, *api.Identity_PushoverMethod, *api.Identity_EmailMethod: - ok, _, err := ai.cache.GetI(ctx, key.Expire(identity.OrgId, - identity.AppId, identity.Id, passcode)) + ok, _, err := ai.cache.GetI(ctx, key.Expire(identity.GetOrgId(), + identity.GetAppId(), identity.GetId(), passcode)) if err != nil { return err } @@ -199,9 +199,9 @@ func (ai *AppIdentity) verify( // Disallow passcode reuse, even when counter tracking would prevent it. Do // not expire to support backup codes. - if _, ok := identity.MethodOneof.(*api.Identity_SecurityQuestionsMethod); !ok { - ok, err := ai.cache.SetIfNotExist(ctx, ikey.Reuse(identity.OrgId, - identity.AppId, identity.Id, passcode), 1) + if _, ok := identity.GetMethodOneof().(*api.Identity_SecurityQuestionsMethod); !ok { + ok, err := ai.cache.SetIfNotExist(ctx, ikey.Reuse(identity.GetOrgId(), + identity.GetAppId(), identity.GetId(), passcode), 1) if err != nil { return err } @@ -212,21 +212,21 @@ func (ai *AppIdentity) verify( // Add logging fields. logger := hlog.FromContext(ctx) - logger.Logger = logger.WithField("appID", identity.AppId) - logger.Logger = logger.WithField("identityID", identity.Id) + logger.Logger = logger.WithField("appID", identity.GetAppId()) + logger.Logger = logger.WithField("identityID", identity.GetId()) // Verify passcode and calculate HOTP counter or TOTP window offset. var counter int64 var offset int - switch identity.MethodOneof.(type) { + switch identity.GetMethodOneof().(type) { case *api.Identity_SoftwareHotpMethod, *api.Identity_GoogleAuthHotpMethod, *api.Identity_HardwareHotpMethod, *api.Identity_SmsMethod, *api.Identity_PushoverMethod, *api.Identity_EmailMethod: // Retrieve current HOTP counter. If not found, use the zero value. var curr int64 - _, curr, err = ai.cache.GetI(ctx, key.HOTPCounter(identity.OrgId, - identity.AppId, identity.Id)) + _, curr, err = ai.cache.GetI(ctx, key.HOTPCounter(identity.GetOrgId(), + identity.GetAppId(), identity.GetId())) if err != nil { return err } @@ -236,8 +236,8 @@ func (ai *AppIdentity) verify( *api.Identity_AppleIosTotpMethod: // Retrieve TOTP window offset. If not found, use the zero value. var off int64 - _, off, err = ai.cache.GetI(ctx, ikey.TOTPOffset(identity.OrgId, - identity.AppId, identity.Id)) + _, off, err = ai.cache.GetI(ctx, ikey.TOTPOffset(identity.GetOrgId(), + identity.GetAppId(), identity.GetId())) if err != nil { return err } @@ -246,8 +246,8 @@ func (ai *AppIdentity) verify( case *api.Identity_HardwareTotpMethod: // Retrieve TOTP window offset. If not found, use the zero value. var off int64 - _, off, err = ai.cache.GetI(ctx, ikey.TOTPOffset(identity.OrgId, - identity.AppId, identity.Id)) + _, off, err = ai.cache.GetI(ctx, ikey.TOTPOffset(identity.GetOrgId(), + identity.GetAppId(), identity.GetId())) if err != nil { return err } @@ -275,13 +275,13 @@ func (ai *AppIdentity) verify( // Store HOTP counter or TOTP window offset for future verifications. switch { case counter != 0: - if err = ai.cache.Set(ctx, key.HOTPCounter(identity.OrgId, - identity.AppId, identity.Id), counter); err != nil { + if err = ai.cache.Set(ctx, key.HOTPCounter(identity.GetOrgId(), + identity.GetAppId(), identity.GetId()), counter); err != nil { return err } case offset != 0: - if err = ai.cache.Set(ctx, ikey.TOTPOffset(identity.OrgId, - identity.AppId, identity.Id), offset); err != nil { + if err = ai.cache.Set(ctx, ikey.TOTPOffset(identity.GetOrgId(), + identity.GetAppId(), identity.GetId()), offset); err != nil { return err } } @@ -305,8 +305,8 @@ func (ai *AppIdentity) ActivateIdentity( writeEvent := func(status api.EventStatus, err string) { event := &api.Event{ OrgId: sess.OrgID, - AppId: req.AppId, - IdentityId: req.Id, + AppId: req.GetAppId(), + IdentityId: req.GetId(), Status: status, Error: err, TraceId: sess.TraceID.String(), @@ -317,8 +317,8 @@ func (ai *AppIdentity) ActivateIdentity( } } - if err := ai.verify(ctx, req.Id, sess.OrgID, req.AppId, - api.IdentityStatus_UNVERIFIED, req.Passcode, 1000, 6, 20); err != nil { + if err := ai.verify(ctx, req.GetId(), sess.OrgID, req.GetAppId(), + api.IdentityStatus_UNVERIFIED, req.GetPasscode(), 1000, 6, 20); err != nil { if errors.Is(err, errExpStatus) || errors.Is(err, oath.ErrInvalidPasscode) { writeEvent(api.EventStatus_ACTIVATE_FAIL, err.Error()) @@ -327,8 +327,8 @@ func (ai *AppIdentity) ActivateIdentity( return nil, errToStatus(err) } - identity, err := ai.identDAO.UpdateStatus(ctx, req.Id, sess.OrgID, - req.AppId, api.IdentityStatus_ACTIVATED) + identity, err := ai.identDAO.UpdateStatus(ctx, req.GetId(), sess.OrgID, + req.GetAppId(), api.IdentityStatus_ACTIVATED) if err != nil { return nil, errToStatus(err) } @@ -348,8 +348,8 @@ func (ai *AppIdentity) ChallengeIdentity( return nil, errPerm(api.Role_AUTHENTICATOR) } - identity, _, err := ai.identDAO.Read(ctx, req.Id, sess.OrgID, - req.AppId) + identity, _, err := ai.identDAO.Read(ctx, req.GetId(), sess.OrgID, + req.GetAppId()) if err != nil { return nil, errToStatus(err) } @@ -358,9 +358,9 @@ func (ai *AppIdentity) ChallengeIdentity( // is non-fatal, but should be logged for investigation. writeEvent := func(status api.EventStatus, err string) { event := &api.Event{ - OrgId: identity.OrgId, - AppId: identity.AppId, - IdentityId: identity.Id, + OrgId: identity.GetOrgId(), + AppId: identity.GetAppId(), + IdentityId: identity.GetId(), Status: status, Error: err, TraceId: sess.TraceID.String(), @@ -372,7 +372,7 @@ func (ai *AppIdentity) ChallengeIdentity( } // Build and publish NotifierIn message for methods that utilize it. - switch identity.MethodOneof.(type) { + switch identity.GetMethodOneof().(type) { case *api.Identity_SmsMethod, *api.Identity_PushoverMethod, *api.Identity_EmailMethod: // Apply plan limits, in the event that the organization's plan was @@ -382,7 +382,7 @@ func (ai *AppIdentity) ChallengeIdentity( } // Rate limit. - notifyKey := ikey.Challenge(identity.OrgId, identity.AppId, identity.Id) + notifyKey := ikey.Challenge(identity.GetOrgId(), identity.GetAppId(), identity.GetId()) ok, err := ai.cache.SetIfNotExistTTL(ctx, notifyKey, 1, notifyRate) if err != nil { return nil, errToStatus(err) @@ -399,13 +399,13 @@ func (ai *AppIdentity) ChallengeIdentity( } // Add logging fields. - logger.Logger = logger.WithField("appID", identity.AppId) - logger.Logger = logger.WithField("identityID", identity.Id) + logger.Logger = logger.WithField("appID", identity.GetAppId()) + logger.Logger = logger.WithField("identityID", identity.GetId()) nIn := &message.NotifierIn{ - OrgId: identity.OrgId, - AppId: identity.AppId, - IdentityId: identity.Id, + OrgId: identity.GetOrgId(), + AppId: identity.GetAppId(), + IdentityId: identity.GetId(), TraceId: sess.TraceID[:], } @@ -459,8 +459,8 @@ func (ai *AppIdentity) VerifyIdentity( writeEvent := func(status api.EventStatus, err string) { event := &api.Event{ OrgId: sess.OrgID, - AppId: req.AppId, - IdentityId: req.Id, + AppId: req.GetAppId(), + IdentityId: req.GetId(), Status: status, Error: err, TraceId: sess.TraceID.String(), @@ -471,8 +471,8 @@ func (ai *AppIdentity) VerifyIdentity( } } - if err := ai.verify(ctx, req.Id, sess.OrgID, req.AppId, - api.IdentityStatus_ACTIVATED, req.Passcode, oath.DefaultHOTPLookAhead, + if err := ai.verify(ctx, req.GetId(), sess.OrgID, req.GetAppId(), + api.IdentityStatus_ACTIVATED, req.GetPasscode(), oath.DefaultHOTPLookAhead, oath.DefaultTOTPLookAhead, oath.DefaultTOTPLookAhead); err != nil { if errors.Is(err, errExpStatus) || errors.Is(err, oath.ErrInvalidPasscode) { @@ -496,7 +496,7 @@ func (ai *AppIdentity) GetIdentity( return nil, errPerm(api.Role_VIEWER) } - identity, _, err := ai.identDAO.Read(ctx, req.Id, sess.OrgID, req.AppId) + identity, _, err := ai.identDAO.Read(ctx, req.GetId(), sess.OrgID, req.GetAppId()) if err != nil { return nil, errToStatus(err) } @@ -514,8 +514,8 @@ func (ai *AppIdentity) DeleteIdentity( return nil, errPerm(api.Role_AUTHENTICATOR) } - if err := ai.identDAO.Delete(ctx, req.Id, sess.OrgID, - req.AppId); err != nil { + if err := ai.identDAO.Delete(ctx, req.GetId(), sess.OrgID, + req.GetAppId()); err != nil { return nil, errToStatus(err) } @@ -523,8 +523,8 @@ func (ai *AppIdentity) DeleteIdentity( // investigation. event := &api.Event{ OrgId: sess.OrgID, - AppId: req.AppId, - IdentityId: req.Id, + AppId: req.GetAppId(), + IdentityId: req.GetId(), Status: api.EventStatus_IDENTITY_DELETED, TraceId: sess.TraceID.String(), } @@ -549,18 +549,18 @@ func (ai *AppIdentity) ListIdentities( return nil, errPerm(api.Role_VIEWER) } - if req.PageSize == 0 { + if req.GetPageSize() == 0 { req.PageSize = defaultPageSize } - lBoundTS, prevID, err := session.ParsePageToken(req.PageToken) + lBoundTS, prevID, err := session.ParsePageToken(req.GetPageToken()) if err != nil { return nil, status.Error(codes.InvalidArgument, "invalid page token") } // Retrieve PageSize+1 entries to find last page. identities, count, err := ai.identDAO.List(ctx, sess.OrgID, lBoundTS, - prevID, req.PageSize+1, req.AppId) + prevID, req.GetPageSize()+1, req.GetAppId()) if err != nil { return nil, errToStatus(err) } @@ -570,12 +570,12 @@ func (ai *AppIdentity) ListIdentities( } // Populate next page token. - if len(identities) == int(req.PageSize+1) { + if len(identities) == int(req.GetPageSize()+1) { resp.Identities = identities[:len(identities)-1] if resp.NextPageToken, err = session.GeneratePageToken( - identities[len(identities)-2].CreatedAt.AsTime(), - identities[len(identities)-2].Id); err != nil { + identities[len(identities)-2].GetCreatedAt().AsTime(), + identities[len(identities)-2].GetId()); err != nil { // GeneratePageToken should not error based on a DB-derived UUID. // Log the error and include the usable empty token. logger := hlog.FromContext(ctx) diff --git a/internal/hermes-api/service/identity_test.go b/internal/hermes-api/service/identity_test.go index 5d72af95..34f1f068 100644 --- a/internal/hermes-api/service/identity_test.go +++ b/internal/hermes-api/service/identity_test.go @@ -41,8 +41,8 @@ func TestCreateIdentity(t *testing.T) { retIdentity, _ := proto.Clone(identity).(*api.Identity) traceID := uuid.New() event := &api.Event{ - OrgId: identity.OrgId, AppId: identity.AppId, - IdentityId: identity.Id, Status: api.EventStatus_IDENTITY_CREATED, + OrgId: identity.GetOrgId(), AppId: identity.GetAppId(), + IdentityId: identity.GetId(), Status: api.EventStatus_IDENTITY_CREATED, TraceId: traceID.String(), } @@ -56,7 +56,7 @@ func TestCreateIdentity(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, Role: api.Role_ADMIN, + OrgID: identity.GetOrgId(), Role: api.Role_ADMIN, TraceID: traceID, }), testTimeout) defer cancel() @@ -86,8 +86,8 @@ func TestCreateIdentity(t *testing.T) { retIdentity, _ := proto.Clone(identity).(*api.Identity) traceID := uuid.New() event := &api.Event{ - OrgId: identity.OrgId, AppId: identity.AppId, - IdentityId: identity.Id, Status: api.EventStatus_IDENTITY_CREATED, + OrgId: identity.GetOrgId(), AppId: identity.GetAppId(), + IdentityId: identity.GetId(), Status: api.EventStatus_IDENTITY_CREATED, TraceId: traceID.String(), } @@ -97,14 +97,14 @@ func TestCreateIdentity(t *testing.T) { nil, false, nil).Times(1) notifier := notify.NewMockNotifier(ctrl) notifier.EXPECT().ValidateSMS(gomock.Any(), - identity.GetSmsMethod().Phone).Return(nil).Times(1) + identity.GetSmsMethod().GetPhone()).Return(nil).Times(1) eventer := NewMockEventer(ctrl) eventer.EXPECT().Create(gomock.Any(), event).Return(dao.ErrNotFound). Times(1) ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, OrgPlan: api.Plan_PRO, + OrgID: identity.GetOrgId(), OrgPlan: api.Plan_PRO, Role: api.Role_ADMIN, TraceID: traceID, }), testTimeout) defer cancel() @@ -135,8 +135,8 @@ func TestCreateIdentity(t *testing.T) { retIdentity, _ := proto.Clone(identity).(*api.Identity) traceID := uuid.New() event := &api.Event{ - OrgId: identity.OrgId, AppId: identity.AppId, - IdentityId: identity.Id, Status: api.EventStatus_IDENTITY_CREATED, + OrgId: identity.GetOrgId(), AppId: identity.GetAppId(), + IdentityId: identity.GetId(), Status: api.EventStatus_IDENTITY_CREATED, TraceId: traceID.String(), } @@ -145,15 +145,14 @@ func TestCreateIdentity(t *testing.T) { identityer.EXPECT().Create(gomock.Any(), identity).Return(retIdentity, nil, false, nil).Times(1) notifier := notify.NewMockNotifier(ctrl) - notifier.EXPECT().ValidatePushover(identity.GetPushoverMethod(). - PushoverKey).Return(nil).Times(1) + notifier.EXPECT().ValidatePushover(identity.GetPushoverMethod().GetPushoverKey()).Return(nil).Times(1) eventer := NewMockEventer(ctrl) eventer.EXPECT().Create(gomock.Any(), event).Return(dao.ErrNotFound). Times(1) ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, OrgPlan: api.Plan_PRO, + OrgID: identity.GetOrgId(), OrgPlan: api.Plan_PRO, Role: api.Role_ADMIN, TraceID: traceID, }), testTimeout) defer cancel() @@ -184,8 +183,8 @@ func TestCreateIdentity(t *testing.T) { retIdentity, _ := proto.Clone(identity).(*api.Identity) traceID := uuid.New() event := &api.Event{ - OrgId: identity.OrgId, AppId: identity.AppId, - IdentityId: identity.Id, Status: api.EventStatus_IDENTITY_CREATED, + OrgId: identity.GetOrgId(), AppId: identity.GetAppId(), + IdentityId: identity.GetId(), Status: api.EventStatus_IDENTITY_CREATED, TraceId: traceID.String(), } @@ -199,7 +198,7 @@ func TestCreateIdentity(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, OrgPlan: api.Plan_PRO, + OrgID: identity.GetOrgId(), OrgPlan: api.Plan_PRO, Role: api.Role_ADMIN, TraceID: traceID, }), testTimeout) defer cancel() @@ -234,12 +233,12 @@ func TestCreateIdentity(t *testing.T) { } app := random.App("api-app", uuid.NewString()) - identity := random.HOTPIdentity("api-identity", app.OrgId, app.Id) + identity := random.HOTPIdentity("api-identity", app.GetOrgId(), app.GetId()) retIdentity, _ := proto.Clone(identity).(*api.Identity) traceID := uuid.New() event := &api.Event{ - OrgId: identity.OrgId, AppId: identity.AppId, - IdentityId: identity.Id, Status: api.EventStatus_IDENTITY_CREATED, + OrgId: identity.GetOrgId(), AppId: identity.GetAppId(), + IdentityId: identity.GetId(), Status: api.EventStatus_IDENTITY_CREATED, TraceId: traceID.String(), } @@ -248,7 +247,7 @@ func TestCreateIdentity(t *testing.T) { identityer.EXPECT().Create(gomock.Any(), identity).Return(retIdentity, otp, true, nil).Times(1) apper := NewMockApper(ctrl) - apper.EXPECT().Read(gomock.Any(), app.Id, app.OrgId).Return(app, nil). + apper.EXPECT().Read(gomock.Any(), app.GetId(), app.GetOrgId()).Return(app, nil). Times(1) eventer := NewMockEventer(ctrl) eventer.EXPECT().Create(gomock.Any(), event).Return(dao.ErrNotFound). @@ -256,7 +255,7 @@ func TestCreateIdentity(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, Role: api.Role_ADMIN, + OrgID: identity.GetOrgId(), Role: api.Role_ADMIN, TraceID: traceID, }), testTimeout) defer cancel() @@ -271,8 +270,8 @@ func TestCreateIdentity(t *testing.T) { resp := &api.CreateIdentityResponse{Identity: identity, Secret: b32Key} // Normalize QR code. - require.Greater(t, len(createIdentity.Qr), 800) - resp.Qr = createIdentity.Qr + require.Greater(t, len(createIdentity.GetQr()), 800) + resp.Qr = createIdentity.GetQr() // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -298,8 +297,8 @@ func TestCreateIdentity(t *testing.T) { retIdentity, _ := proto.Clone(identity).(*api.Identity) traceID := uuid.New() event := &api.Event{ - OrgId: identity.OrgId, AppId: identity.AppId, - IdentityId: identity.Id, Status: api.EventStatus_IDENTITY_CREATED, + OrgId: identity.GetOrgId(), AppId: identity.GetAppId(), + IdentityId: identity.GetId(), Status: api.EventStatus_IDENTITY_CREATED, TraceId: traceID.String(), } @@ -313,7 +312,7 @@ func TestCreateIdentity(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, OrgPlan: api.Plan_PRO, + OrgID: identity.GetOrgId(), OrgPlan: api.Plan_PRO, Role: api.Role_ADMIN, TraceID: traceID, }), testTimeout) defer cancel() @@ -326,16 +325,16 @@ func TestCreateIdentity(t *testing.T) { require.NoError(t, err) // Normalize backup codes. - require.Len(t, createIdentity.Passcodes, - int(identity.GetBackupCodesMethod().Passcodes)) + require.Len(t, createIdentity.GetPasscodes(), + int(identity.GetBackupCodesMethod().GetPasscodes())) // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 if !proto.Equal(&api.CreateIdentityResponse{ - Identity: identity, Passcodes: createIdentity.Passcodes, + Identity: identity, Passcodes: createIdentity.GetPasscodes(), }, createIdentity) { t.Fatalf("\nExpect: %+v\nActual: %+v", &api.CreateIdentityResponse{ - Identity: identity, Passcodes: createIdentity.Passcodes, + Identity: identity, Passcodes: createIdentity.GetPasscodes(), }, createIdentity) } }) @@ -354,8 +353,8 @@ func TestCreateIdentity(t *testing.T) { retIdentity, _ := proto.Clone(identity).(*api.Identity) traceID := uuid.New() event := &api.Event{ - OrgId: identity.OrgId, AppId: identity.AppId, - IdentityId: identity.Id, Status: api.EventStatus_IDENTITY_CREATED, + OrgId: identity.GetOrgId(), AppId: identity.GetAppId(), + IdentityId: identity.GetId(), Status: api.EventStatus_IDENTITY_CREATED, TraceId: traceID.String(), } @@ -369,7 +368,7 @@ func TestCreateIdentity(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, OrgPlan: api.Plan_PRO, + OrgID: identity.GetOrgId(), OrgPlan: api.Plan_PRO, Role: api.Role_ADMIN, TraceID: traceID, }), testTimeout) defer cancel() @@ -446,7 +445,7 @@ func TestCreateIdentity(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: lTest.OrgId, OrgPlan: api.Plan_STARTER, + OrgID: lTest.GetOrgId(), OrgPlan: api.Plan_STARTER, Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -473,7 +472,7 @@ func TestCreateIdentity(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, OrgPlan: api.Plan_PRO, + OrgID: identity.GetOrgId(), OrgPlan: api.Plan_PRO, Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -496,11 +495,11 @@ func TestCreateIdentity(t *testing.T) { notifier := notify.NewMockNotifier(gomock.NewController(t)) notifier.EXPECT().ValidateSMS(gomock.Any(), - identity.GetSmsMethod().Phone).Return(notify.ErrInvalidSMS).Times(1) + identity.GetSmsMethod().GetPhone()).Return(notify.ErrInvalidSMS).Times(1) ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, OrgPlan: api.Plan_PRO, + OrgID: identity.GetOrgId(), OrgPlan: api.Plan_PRO, Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -522,12 +521,11 @@ func TestCreateIdentity(t *testing.T) { uuid.NewString()) notifier := notify.NewMockNotifier(gomock.NewController(t)) - notifier.EXPECT().ValidatePushover(identity.GetPushoverMethod(). - PushoverKey).Return(notify.ErrInvalidPushover).Times(1) + notifier.EXPECT().ValidatePushover(identity.GetPushoverMethod().GetPushoverKey()).Return(notify.ErrInvalidPushover).Times(1) ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, OrgPlan: api.Plan_PRO, + OrgID: identity.GetOrgId(), OrgPlan: api.Plan_PRO, Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -555,7 +553,7 @@ func TestCreateIdentity(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, Role: api.Role_ADMIN, + OrgID: identity.GetOrgId(), Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -573,7 +571,7 @@ func TestCreateIdentity(t *testing.T) { t.Parallel() app := random.App("api-app", uuid.NewString()) - identity := random.HOTPIdentity("api-identity", app.OrgId, app.Id) + identity := random.HOTPIdentity("api-identity", app.GetOrgId(), app.GetId()) retIdentity, _ := proto.Clone(identity).(*api.Identity) ctrl := gomock.NewController(t) @@ -581,12 +579,12 @@ func TestCreateIdentity(t *testing.T) { identityer.EXPECT().Create(gomock.Any(), identity).Return(retIdentity, &oath.OTP{}, true, nil).Times(1) apper := NewMockApper(ctrl) - apper.EXPECT().Read(gomock.Any(), app.Id, app.OrgId).Return(nil, + apper.EXPECT().Read(gomock.Any(), app.GetId(), app.GetOrgId()).Return(nil, dao.ErrInvalidFormat).Times(1) ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, Role: api.Role_ADMIN, + OrgID: identity.GetOrgId(), Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -614,7 +612,7 @@ func TestCreateIdentity(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, OrgPlan: api.Plan_PRO, + OrgID: identity.GetOrgId(), OrgPlan: api.Plan_PRO, Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -651,22 +649,22 @@ func TestVerify(t *testing.T) { ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(retIdentity, otp, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(retIdentity, otp, nil).Times(1) cacher := cache.NewMockCacher(ctrl) - cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.OrgId, - identity.AppId, identity.Id, "861821"), 1).Return(true, nil). + cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.GetOrgId(), + identity.GetAppId(), identity.GetId(), "861821"), 1).Return(true, nil). Times(1) - cacher.EXPECT().GetI(gomock.Any(), key.HOTPCounter(identity.OrgId, - identity.AppId, identity.Id)).Return(false, int64(0), nil).Times(1) - cacher.EXPECT().Set(gomock.Any(), key.HOTPCounter(identity.OrgId, - identity.AppId, identity.Id), int64(6)).Return(nil).Times(1) + cacher.EXPECT().GetI(gomock.Any(), key.HOTPCounter(identity.GetOrgId(), + identity.GetAppId(), identity.GetId())).Return(false, int64(0), nil).Times(1) + cacher.EXPECT().Set(gomock.Any(), key.HOTPCounter(identity.GetOrgId(), + identity.GetAppId(), identity.GetId()), int64(6)).Return(nil).Times(1) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, nil, cacher, nil, nil, "") - err := aiSvc.verify(ctx, identity.Id, identity.OrgId, identity.AppId, + err := aiSvc.verify(ctx, identity.GetId(), identity.GetOrgId(), identity.GetAppId(), api.IdentityStatus_UNVERIFIED, "861821", oath.DefaultHOTPLookAhead, oath.DefaultTOTPLookAhead, oath.DefaultTOTPLookAhead) t.Logf("err: %v", err) @@ -690,22 +688,22 @@ func TestVerify(t *testing.T) { ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(retIdentity, otp, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(retIdentity, otp, nil).Times(1) cacher := cache.NewMockCacher(ctrl) - cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.OrgId, - identity.AppId, identity.Id, passcode), 1).Return(true, nil). + cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.GetOrgId(), + identity.GetAppId(), identity.GetId(), passcode), 1).Return(true, nil). Times(1) - cacher.EXPECT().GetI(gomock.Any(), ikey.TOTPOffset(identity.OrgId, - identity.AppId, identity.Id)).Return(false, int64(0), nil).Times(1) - cacher.EXPECT().Set(gomock.Any(), ikey.TOTPOffset(identity.OrgId, - identity.AppId, identity.Id), -1).Return(nil).Times(1) + cacher.EXPECT().GetI(gomock.Any(), ikey.TOTPOffset(identity.GetOrgId(), + identity.GetAppId(), identity.GetId())).Return(false, int64(0), nil).Times(1) + cacher.EXPECT().Set(gomock.Any(), ikey.TOTPOffset(identity.GetOrgId(), + identity.GetAppId(), identity.GetId()), -1).Return(nil).Times(1) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, nil, cacher, nil, nil, "") - err = aiSvc.verify(ctx, identity.Id, identity.OrgId, identity.AppId, + err = aiSvc.verify(ctx, identity.GetId(), identity.GetOrgId(), identity.GetAppId(), api.IdentityStatus_UNVERIFIED, passcode, oath.DefaultHOTPLookAhead, oath.DefaultTOTPLookAhead, oath.DefaultTOTPLookAhead) t.Logf("err: %v", err) @@ -729,22 +727,22 @@ func TestVerify(t *testing.T) { ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(retIdentity, otp, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(retIdentity, otp, nil).Times(1) cacher := cache.NewMockCacher(ctrl) - cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.OrgId, - identity.AppId, identity.Id, passcode), 1).Return(true, nil). + cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.GetOrgId(), + identity.GetAppId(), identity.GetId(), passcode), 1).Return(true, nil). Times(1) - cacher.EXPECT().GetI(gomock.Any(), ikey.TOTPOffset(identity.OrgId, - identity.AppId, identity.Id)).Return(false, int64(0), nil).Times(1) - cacher.EXPECT().Set(gomock.Any(), ikey.TOTPOffset(identity.OrgId, - identity.AppId, identity.Id), -3).Return(nil).Times(1) + cacher.EXPECT().GetI(gomock.Any(), ikey.TOTPOffset(identity.GetOrgId(), + identity.GetAppId(), identity.GetId())).Return(false, int64(0), nil).Times(1) + cacher.EXPECT().Set(gomock.Any(), ikey.TOTPOffset(identity.GetOrgId(), + identity.GetAppId(), identity.GetId()), -3).Return(nil).Times(1) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, nil, cacher, nil, nil, "") - err = aiSvc.verify(ctx, identity.Id, identity.OrgId, identity.AppId, + err = aiSvc.verify(ctx, identity.GetId(), identity.GetOrgId(), identity.GetAppId(), api.IdentityStatus_UNVERIFIED, passcode, oath.DefaultHOTPLookAhead, oath.DefaultTOTPLookAhead, 20) t.Logf("err: %v", err) @@ -765,25 +763,25 @@ func TestVerify(t *testing.T) { ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(retIdentity, otp, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(retIdentity, otp, nil).Times(1) cacher := cache.NewMockCacher(ctrl) - cacher.EXPECT().GetI(gomock.Any(), key.Expire(identity.OrgId, - identity.AppId, identity.Id, "861821")).Return(true, int64(0), nil). + cacher.EXPECT().GetI(gomock.Any(), key.Expire(identity.GetOrgId(), + identity.GetAppId(), identity.GetId(), "861821")).Return(true, int64(0), nil). Times(1) - cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.OrgId, - identity.AppId, identity.Id, "861821"), 1).Return(true, nil). + cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.GetOrgId(), + identity.GetAppId(), identity.GetId(), "861821"), 1).Return(true, nil). Times(1) - cacher.EXPECT().GetI(gomock.Any(), key.HOTPCounter(identity.OrgId, - identity.AppId, identity.Id)).Return(false, int64(0), nil).Times(1) - cacher.EXPECT().Set(gomock.Any(), key.HOTPCounter(identity.OrgId, - identity.AppId, identity.Id), int64(6)).Return(nil).Times(1) + cacher.EXPECT().GetI(gomock.Any(), key.HOTPCounter(identity.GetOrgId(), + identity.GetAppId(), identity.GetId())).Return(false, int64(0), nil).Times(1) + cacher.EXPECT().Set(gomock.Any(), key.HOTPCounter(identity.GetOrgId(), + identity.GetAppId(), identity.GetId()), int64(6)).Return(nil).Times(1) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, nil, cacher, nil, nil, "") - err := aiSvc.verify(ctx, identity.Id, identity.OrgId, identity.AppId, + err := aiSvc.verify(ctx, identity.GetId(), identity.GetOrgId(), identity.GetAppId(), api.IdentityStatus_UNVERIFIED, "861821", oath.DefaultHOTPLookAhead, oath.DefaultTOTPLookAhead, oath.DefaultTOTPLookAhead) t.Logf("err: %v", err) @@ -804,18 +802,18 @@ func TestVerify(t *testing.T) { ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(retIdentity, otp, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(retIdentity, otp, nil).Times(1) cacher := cache.NewMockCacher(ctrl) - cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.OrgId, - identity.AppId, identity.Id, "861821"), 1).Return(true, nil). + cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.GetOrgId(), + identity.GetAppId(), identity.GetId(), "861821"), 1).Return(true, nil). Times(1) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, nil, cacher, nil, nil, "") - err := aiSvc.verify(ctx, identity.Id, identity.OrgId, identity.AppId, + err := aiSvc.verify(ctx, identity.GetId(), identity.GetOrgId(), identity.GetAppId(), api.IdentityStatus_ACTIVATED, "861821", oath.DefaultHOTPLookAhead, oath.DefaultTOTPLookAhead, oath.DefaultTOTPLookAhead) t.Logf("err: %v", err) @@ -836,14 +834,14 @@ func TestVerify(t *testing.T) { retIdentity, _ := proto.Clone(identity).(*api.Identity) identityer := NewMockIdentityer(gomock.NewController(t)) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(retIdentity, otp, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(retIdentity, otp, nil).Times(1) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, nil, nil, nil, nil, "") - err := aiSvc.verify(ctx, identity.Id, identity.OrgId, identity.AppId, + err := aiSvc.verify(ctx, identity.GetId(), identity.GetOrgId(), identity.GetAppId(), api.IdentityStatus_ACTIVATED, strings.ToUpper(otp.Answer), oath.DefaultHOTPLookAhead, oath.DefaultTOTPLookAhead, oath.DefaultTOTPLookAhead) @@ -879,14 +877,14 @@ func TestVerify(t *testing.T) { retIdentity, _ := proto.Clone(identity).(*api.Identity) identityer := NewMockIdentityer(gomock.NewController(t)) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(retIdentity, nil, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(retIdentity, nil, nil).Times(1) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, nil, nil, nil, nil, "") - err := aiSvc.verify(ctx, identity.Id, identity.OrgId, identity.AppId, + err := aiSvc.verify(ctx, identity.GetId(), identity.GetOrgId(), identity.GetAppId(), api.IdentityStatus_UNVERIFIED, "", oath.DefaultHOTPLookAhead, oath.DefaultTOTPLookAhead, oath.DefaultTOTPLookAhead) t.Logf("err: %v", err) @@ -903,18 +901,18 @@ func TestVerify(t *testing.T) { ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(retIdentity, nil, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(retIdentity, nil, nil).Times(1) cacher := cache.NewMockCacher(ctrl) - cacher.EXPECT().GetI(gomock.Any(), key.Expire(identity.OrgId, - identity.AppId, identity.Id, "")).Return(false, int64(0), + cacher.EXPECT().GetI(gomock.Any(), key.Expire(identity.GetOrgId(), + identity.GetAppId(), identity.GetId(), "")).Return(false, int64(0), dao.ErrNotFound).Times(1) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, nil, cacher, nil, nil, "") - err := aiSvc.verify(ctx, identity.Id, identity.OrgId, identity.AppId, + err := aiSvc.verify(ctx, identity.GetId(), identity.GetOrgId(), identity.GetAppId(), api.IdentityStatus_UNVERIFIED, "", oath.DefaultHOTPLookAhead, oath.DefaultTOTPLookAhead, oath.DefaultTOTPLookAhead) t.Logf("err: %v", err) @@ -931,18 +929,18 @@ func TestVerify(t *testing.T) { ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(retIdentity, nil, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(retIdentity, nil, nil).Times(1) cacher := cache.NewMockCacher(ctrl) - cacher.EXPECT().GetI(gomock.Any(), key.Expire(identity.OrgId, - identity.AppId, identity.Id, "")).Return(false, int64(0), nil). + cacher.EXPECT().GetI(gomock.Any(), key.Expire(identity.GetOrgId(), + identity.GetAppId(), identity.GetId(), "")).Return(false, int64(0), nil). Times(1) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, nil, cacher, nil, nil, "") - err := aiSvc.verify(ctx, identity.Id, identity.OrgId, identity.AppId, + err := aiSvc.verify(ctx, identity.GetId(), identity.GetOrgId(), identity.GetAppId(), api.IdentityStatus_UNVERIFIED, "", oath.DefaultHOTPLookAhead, oath.DefaultTOTPLookAhead, oath.DefaultTOTPLookAhead) t.Logf("err: %v", err) @@ -959,18 +957,18 @@ func TestVerify(t *testing.T) { ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(retIdentity, nil, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(retIdentity, nil, nil).Times(1) cacher := cache.NewMockCacher(ctrl) - cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.OrgId, - identity.AppId, identity.Id, "861821"), 1).Return(false, + cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.GetOrgId(), + identity.GetAppId(), identity.GetId(), "861821"), 1).Return(false, dao.ErrNotFound).Times(1) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, nil, cacher, nil, nil, "") - err := aiSvc.verify(ctx, identity.Id, identity.OrgId, identity.AppId, + err := aiSvc.verify(ctx, identity.GetId(), identity.GetOrgId(), identity.GetAppId(), api.IdentityStatus_UNVERIFIED, "861821", oath.DefaultHOTPLookAhead, oath.DefaultTOTPLookAhead, oath.DefaultTOTPLookAhead) t.Logf("err: %v", err) @@ -991,18 +989,18 @@ func TestVerify(t *testing.T) { ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(retIdentity, otp, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(retIdentity, otp, nil).Times(1) cacher := cache.NewMockCacher(ctrl) - cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.OrgId, - identity.AppId, identity.Id, "861821"), 1).Return(false, nil). + cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.GetOrgId(), + identity.GetAppId(), identity.GetId(), "861821"), 1).Return(false, nil). Times(1) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, nil, cacher, nil, nil, "") - err := aiSvc.verify(ctx, identity.Id, identity.OrgId, identity.AppId, + err := aiSvc.verify(ctx, identity.GetId(), identity.GetOrgId(), identity.GetAppId(), api.IdentityStatus_UNVERIFIED, "861821", oath.DefaultHOTPLookAhead, oath.DefaultTOTPLookAhead, oath.DefaultTOTPLookAhead) t.Logf("err: %v", err) @@ -1023,21 +1021,21 @@ func TestVerify(t *testing.T) { ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(retIdentity, otp, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(retIdentity, otp, nil).Times(1) cacher := cache.NewMockCacher(ctrl) - cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.OrgId, - identity.AppId, identity.Id, "0000000"), 1).Return(true, nil). + cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.GetOrgId(), + identity.GetAppId(), identity.GetId(), "0000000"), 1).Return(true, nil). Times(1) - cacher.EXPECT().GetI(gomock.Any(), key.HOTPCounter(identity.OrgId, - identity.AppId, identity.Id)).Return(false, int64(0), + cacher.EXPECT().GetI(gomock.Any(), key.HOTPCounter(identity.GetOrgId(), + identity.GetAppId(), identity.GetId())).Return(false, int64(0), dao.ErrNotFound).Times(1) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, nil, cacher, nil, nil, "") - err := aiSvc.verify(ctx, identity.Id, identity.OrgId, identity.AppId, + err := aiSvc.verify(ctx, identity.GetId(), identity.GetOrgId(), identity.GetAppId(), api.IdentityStatus_UNVERIFIED, "0000000", oath.DefaultHOTPLookAhead, oath.DefaultTOTPLookAhead, oath.DefaultTOTPLookAhead) t.Logf("err: %v", err) @@ -1059,21 +1057,21 @@ func TestVerify(t *testing.T) { ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(retIdentity, otp, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(retIdentity, otp, nil).Times(1) cacher := cache.NewMockCacher(ctrl) - cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.OrgId, - identity.AppId, identity.Id, "0000000"), 1).Return(true, nil). + cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.GetOrgId(), + identity.GetAppId(), identity.GetId(), "0000000"), 1).Return(true, nil). Times(1) - cacher.EXPECT().GetI(gomock.Any(), ikey.TOTPOffset(identity.OrgId, - identity.AppId, identity.Id)).Return(false, int64(0), + cacher.EXPECT().GetI(gomock.Any(), ikey.TOTPOffset(identity.GetOrgId(), + identity.GetAppId(), identity.GetId())).Return(false, int64(0), dao.ErrNotFound).Times(1) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, nil, cacher, nil, nil, "") - err := aiSvc.verify(ctx, identity.Id, identity.OrgId, identity.AppId, + err := aiSvc.verify(ctx, identity.GetId(), identity.GetOrgId(), identity.GetAppId(), api.IdentityStatus_UNVERIFIED, "0000000", oath.DefaultHOTPLookAhead, oath.DefaultTOTPLookAhead, oath.DefaultTOTPLookAhead) t.Logf("err: %v", err) @@ -1095,21 +1093,21 @@ func TestVerify(t *testing.T) { ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(retIdentity, otp, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(retIdentity, otp, nil).Times(1) cacher := cache.NewMockCacher(ctrl) - cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.OrgId, - identity.AppId, identity.Id, "0000000"), 1).Return(true, nil). + cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.GetOrgId(), + identity.GetAppId(), identity.GetId(), "0000000"), 1).Return(true, nil). Times(1) - cacher.EXPECT().GetI(gomock.Any(), ikey.TOTPOffset(identity.OrgId, - identity.AppId, identity.Id)).Return(false, int64(0), + cacher.EXPECT().GetI(gomock.Any(), ikey.TOTPOffset(identity.GetOrgId(), + identity.GetAppId(), identity.GetId())).Return(false, int64(0), dao.ErrNotFound).Times(1) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, nil, cacher, nil, nil, "") - err := aiSvc.verify(ctx, identity.Id, identity.OrgId, identity.AppId, + err := aiSvc.verify(ctx, identity.GetId(), identity.GetOrgId(), identity.GetAppId(), api.IdentityStatus_UNVERIFIED, "0000000", oath.DefaultHOTPLookAhead, oath.DefaultTOTPLookAhead, oath.DefaultTOTPLookAhead) t.Logf("err: %v", err) @@ -1127,18 +1125,18 @@ func TestVerify(t *testing.T) { ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(retIdentity, nil, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(retIdentity, nil, nil).Times(1) cacher := cache.NewMockCacher(ctrl) - cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.OrgId, - identity.AppId, identity.Id, "0000000"), 1).Return(true, nil). + cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.GetOrgId(), + identity.GetAppId(), identity.GetId(), "0000000"), 1).Return(true, nil). Times(1) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, nil, cacher, nil, nil, "") - err := aiSvc.verify(ctx, identity.Id, identity.OrgId, identity.AppId, + err := aiSvc.verify(ctx, identity.GetId(), identity.GetOrgId(), identity.GetAppId(), api.IdentityStatus_UNVERIFIED, "0000000", oath.DefaultHOTPLookAhead, oath.DefaultTOTPLookAhead, oath.DefaultTOTPLookAhead) t.Logf("err: %v", err) @@ -1159,20 +1157,20 @@ func TestVerify(t *testing.T) { ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(retIdentity, otp, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(retIdentity, otp, nil).Times(1) cacher := cache.NewMockCacher(ctrl) - cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.OrgId, - identity.AppId, identity.Id, "0000000"), 1).Return(true, nil). + cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.GetOrgId(), + identity.GetAppId(), identity.GetId(), "0000000"), 1).Return(true, nil). Times(1) - cacher.EXPECT().GetI(gomock.Any(), key.HOTPCounter(identity.OrgId, - identity.AppId, identity.Id)).Return(false, int64(0), nil).Times(1) + cacher.EXPECT().GetI(gomock.Any(), key.HOTPCounter(identity.GetOrgId(), + identity.GetAppId(), identity.GetId())).Return(false, int64(0), nil).Times(1) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, nil, cacher, nil, nil, "") - err := aiSvc.verify(ctx, identity.Id, identity.OrgId, identity.AppId, + err := aiSvc.verify(ctx, identity.GetId(), identity.GetOrgId(), identity.GetAppId(), api.IdentityStatus_UNVERIFIED, "0000000", oath.DefaultHOTPLookAhead, oath.DefaultTOTPLookAhead, oath.DefaultTOTPLookAhead) t.Logf("err: %v", err) @@ -1193,14 +1191,14 @@ func TestVerify(t *testing.T) { retIdentity, _ := proto.Clone(identity).(*api.Identity) identityer := NewMockIdentityer(gomock.NewController(t)) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(retIdentity, otp, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(retIdentity, otp, nil).Times(1) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, nil, nil, nil, nil, "") - err := aiSvc.verify(ctx, identity.Id, identity.OrgId, identity.AppId, + err := aiSvc.verify(ctx, identity.GetId(), identity.GetOrgId(), identity.GetAppId(), api.IdentityStatus_UNVERIFIED, "answer", oath.DefaultHOTPLookAhead, oath.DefaultTOTPLookAhead, oath.DefaultTOTPLookAhead) t.Logf("err: %v", err) @@ -1221,23 +1219,23 @@ func TestVerify(t *testing.T) { ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(retIdentity, otp, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(retIdentity, otp, nil).Times(1) cacher := cache.NewMockCacher(ctrl) - cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.OrgId, - identity.AppId, identity.Id, "861821"), 1).Return(true, nil). + cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.GetOrgId(), + identity.GetAppId(), identity.GetId(), "861821"), 1).Return(true, nil). Times(1) - cacher.EXPECT().GetI(gomock.Any(), key.HOTPCounter(identity.OrgId, - identity.AppId, identity.Id)).Return(false, int64(0), nil).Times(1) - cacher.EXPECT().Set(gomock.Any(), key.HOTPCounter(identity.OrgId, - identity.AppId, identity.Id), int64(6)).Return(dao.ErrNotFound). + cacher.EXPECT().GetI(gomock.Any(), key.HOTPCounter(identity.GetOrgId(), + identity.GetAppId(), identity.GetId())).Return(false, int64(0), nil).Times(1) + cacher.EXPECT().Set(gomock.Any(), key.HOTPCounter(identity.GetOrgId(), + identity.GetAppId(), identity.GetId()), int64(6)).Return(dao.ErrNotFound). Times(1) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, nil, cacher, nil, nil, "") - err := aiSvc.verify(ctx, identity.Id, identity.OrgId, identity.AppId, + err := aiSvc.verify(ctx, identity.GetId(), identity.GetOrgId(), identity.GetAppId(), api.IdentityStatus_UNVERIFIED, "861821", oath.DefaultHOTPLookAhead, oath.DefaultTOTPLookAhead, oath.DefaultTOTPLookAhead) t.Logf("err: %v", err) @@ -1261,23 +1259,23 @@ func TestVerify(t *testing.T) { ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(retIdentity, otp, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(retIdentity, otp, nil).Times(1) cacher := cache.NewMockCacher(ctrl) - cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.OrgId, - identity.AppId, identity.Id, passcode), 1).Return(true, nil). + cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.GetOrgId(), + identity.GetAppId(), identity.GetId(), passcode), 1).Return(true, nil). Times(1) - cacher.EXPECT().GetI(gomock.Any(), ikey.TOTPOffset(identity.OrgId, - identity.AppId, identity.Id)).Return(false, int64(0), nil).Times(1) - cacher.EXPECT().Set(gomock.Any(), ikey.TOTPOffset(identity.OrgId, - identity.AppId, identity.Id), -1).Return(dao.ErrNotFound). + cacher.EXPECT().GetI(gomock.Any(), ikey.TOTPOffset(identity.GetOrgId(), + identity.GetAppId(), identity.GetId())).Return(false, int64(0), nil).Times(1) + cacher.EXPECT().Set(gomock.Any(), ikey.TOTPOffset(identity.GetOrgId(), + identity.GetAppId(), identity.GetId()), -1).Return(dao.ErrNotFound). Times(1) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, nil, cacher, nil, nil, "") - err = aiSvc.verify(ctx, identity.Id, identity.OrgId, identity.AppId, + err = aiSvc.verify(ctx, identity.GetId(), identity.GetOrgId(), identity.GetAppId(), api.IdentityStatus_UNVERIFIED, passcode, oath.DefaultHOTPLookAhead, oath.DefaultTOTPLookAhead, oath.DefaultTOTPLookAhead) t.Logf("err: %v", err) @@ -1305,33 +1303,33 @@ func TestActivateIdentity(t *testing.T) { retIdentity, _ := proto.Clone(identity).(*api.Identity) traceID := uuid.New() event := &api.Event{ - OrgId: identity.OrgId, AppId: identity.AppId, - IdentityId: identity.Id, Status: api.EventStatus_ACTIVATE_SUCCESS, + OrgId: identity.GetOrgId(), AppId: identity.GetAppId(), + IdentityId: identity.GetId(), Status: api.EventStatus_ACTIVATE_SUCCESS, TraceId: traceID.String(), } ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(retIdentity, otp, nil).Times(1) - identityer.EXPECT().UpdateStatus(gomock.Any(), identity.Id, - identity.OrgId, identity.AppId, api.IdentityStatus_ACTIVATED). + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(retIdentity, otp, nil).Times(1) + identityer.EXPECT().UpdateStatus(gomock.Any(), identity.GetId(), + identity.GetOrgId(), identity.GetAppId(), api.IdentityStatus_ACTIVATED). Return(retIdentity, nil).Times(1) cacher := cache.NewMockCacher(ctrl) - cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.OrgId, - identity.AppId, identity.Id, "861821"), 1).Return(true, nil). + cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.GetOrgId(), + identity.GetAppId(), identity.GetId(), "861821"), 1).Return(true, nil). Times(1) - cacher.EXPECT().GetI(gomock.Any(), key.HOTPCounter(identity.OrgId, - identity.AppId, identity.Id)).Return(false, int64(0), nil).Times(1) - cacher.EXPECT().Set(gomock.Any(), key.HOTPCounter(identity.OrgId, - identity.AppId, identity.Id), int64(6)).Return(nil).Times(1) + cacher.EXPECT().GetI(gomock.Any(), key.HOTPCounter(identity.GetOrgId(), + identity.GetAppId(), identity.GetId())).Return(false, int64(0), nil).Times(1) + cacher.EXPECT().Set(gomock.Any(), key.HOTPCounter(identity.GetOrgId(), + identity.GetAppId(), identity.GetId()), int64(6)).Return(nil).Times(1) eventer := NewMockEventer(ctrl) eventer.EXPECT().Create(gomock.Any(), event).Return(dao.ErrNotFound). Times(1) ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, Role: api.Role_ADMIN, + OrgID: identity.GetOrgId(), Role: api.Role_ADMIN, TraceID: traceID, }), testTimeout) defer cancel() @@ -1339,7 +1337,7 @@ func TestActivateIdentity(t *testing.T) { aiSvc := NewAppIdentity(nil, identityer, eventer, cacher, nil, nil, "") activateIdentity, err := aiSvc.ActivateIdentity(ctx, &api.ActivateIdentityRequest{ - Id: identity.Id, AppId: identity.AppId, Passcode: "861821", + Id: identity.GetId(), AppId: identity.GetAppId(), Passcode: "861821", }) t.Logf("identity, activateIdentity, err: %+v, %+v, %v", identity, activateIdentity, err) @@ -1392,22 +1390,22 @@ func TestActivateIdentity(t *testing.T) { retIdentity, _ := proto.Clone(identity).(*api.Identity) traceID := uuid.New() event := &api.Event{ - OrgId: identity.OrgId, AppId: identity.AppId, - IdentityId: identity.Id, Status: api.EventStatus_ACTIVATE_FAIL, + OrgId: identity.GetOrgId(), AppId: identity.GetAppId(), + IdentityId: identity.GetId(), Status: api.EventStatus_ACTIVATE_FAIL, Error: "identity is not unverified", TraceId: traceID.String(), } ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(retIdentity, nil, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(retIdentity, nil, nil).Times(1) eventer := NewMockEventer(ctrl) eventer.EXPECT().Create(gomock.Any(), event).Return(dao.ErrNotFound). Times(1) ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, Role: api.Role_ADMIN, + OrgID: identity.GetOrgId(), Role: api.Role_ADMIN, TraceID: traceID, }), testTimeout) defer cancel() @@ -1415,7 +1413,7 @@ func TestActivateIdentity(t *testing.T) { aiSvc := NewAppIdentity(nil, identityer, eventer, nil, nil, nil, "") activateIdentity, err := aiSvc.ActivateIdentity(ctx, &api.ActivateIdentityRequest{ - Id: identity.Id, AppId: identity.AppId, + Id: identity.GetId(), AppId: identity.GetAppId(), }) t.Logf("activateIdentity, err: %+v, %v", activateIdentity, err) require.Nil(t, activateIdentity) @@ -1437,30 +1435,30 @@ func TestActivateIdentity(t *testing.T) { ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(retIdentity, otp, nil).Times(1) - identityer.EXPECT().UpdateStatus(gomock.Any(), identity.Id, - identity.OrgId, identity.AppId, api.IdentityStatus_ACTIVATED). + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(retIdentity, otp, nil).Times(1) + identityer.EXPECT().UpdateStatus(gomock.Any(), identity.GetId(), + identity.GetOrgId(), identity.GetAppId(), api.IdentityStatus_ACTIVATED). Return(nil, dao.ErrNotFound).Times(1) cacher := cache.NewMockCacher(ctrl) - cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.OrgId, - identity.AppId, identity.Id, "861821"), 1).Return(true, nil). + cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.GetOrgId(), + identity.GetAppId(), identity.GetId(), "861821"), 1).Return(true, nil). Times(1) - cacher.EXPECT().GetI(gomock.Any(), key.HOTPCounter(identity.OrgId, - identity.AppId, identity.Id)).Return(false, int64(0), nil).Times(1) - cacher.EXPECT().Set(gomock.Any(), key.HOTPCounter(identity.OrgId, - identity.AppId, identity.Id), int64(6)).Return(nil).Times(1) + cacher.EXPECT().GetI(gomock.Any(), key.HOTPCounter(identity.GetOrgId(), + identity.GetAppId(), identity.GetId())).Return(false, int64(0), nil).Times(1) + cacher.EXPECT().Set(gomock.Any(), key.HOTPCounter(identity.GetOrgId(), + identity.GetAppId(), identity.GetId()), int64(6)).Return(nil).Times(1) ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, Role: api.Role_ADMIN, + OrgID: identity.GetOrgId(), Role: api.Role_ADMIN, }), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, nil, cacher, nil, nil, "") activateIdentity, err := aiSvc.ActivateIdentity(ctx, &api.ActivateIdentityRequest{ - Id: identity.Id, AppId: identity.AppId, Passcode: "861821", + Id: identity.GetId(), AppId: identity.GetAppId(), Passcode: "861821", }) t.Logf("activateIdentity, err: %+v, %v", activateIdentity, err) require.Nil(t, activateIdentity) @@ -1478,29 +1476,29 @@ func TestChallengeIdentity(t *testing.T) { uuid.NewString()) traceID := uuid.New() event := &api.Event{ - OrgId: identity.OrgId, AppId: identity.AppId, - IdentityId: identity.Id, Status: api.EventStatus_CHALLENGE_NOOP, + OrgId: identity.GetOrgId(), AppId: identity.GetAppId(), + IdentityId: identity.GetId(), Status: api.EventStatus_CHALLENGE_NOOP, TraceId: traceID.String(), } ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(identity, nil, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(identity, nil, nil).Times(1) eventer := NewMockEventer(ctrl) eventer.EXPECT().Create(gomock.Any(), event).Return(dao.ErrNotFound). Times(1) ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, OrgPlan: api.Plan_PRO, + OrgID: identity.GetOrgId(), OrgPlan: api.Plan_PRO, Role: api.Role_ADMIN, TraceID: traceID, }), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, eventer, nil, nil, nil, "") _, err := aiSvc.ChallengeIdentity(ctx, &api.ChallengeIdentityRequest{ - Id: identity.Id, AppId: identity.AppId, + Id: identity.GetId(), AppId: identity.GetAppId(), }) t.Logf("err: %v", err) require.NoError(t, err) @@ -1514,11 +1512,11 @@ func TestChallengeIdentity(t *testing.T) { ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(identity, nil, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(identity, nil, nil).Times(1) cacher := cache.NewMockCacher(ctrl) cacher.EXPECT().SetIfNotExistTTL(gomock.Any(), ikey.Challenge( - identity.OrgId, identity.AppId, identity.Id), 1, notifyRate). + identity.GetOrgId(), identity.GetAppId(), identity.GetId()), 1, notifyRate). Return(true, nil).Times(1) aiQueue := queue.NewFake() @@ -1528,7 +1526,7 @@ func TestChallengeIdentity(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, OrgPlan: api.Plan_PRO, + OrgID: identity.GetOrgId(), OrgPlan: api.Plan_PRO, Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -1536,7 +1534,7 @@ func TestChallengeIdentity(t *testing.T) { aiSvc := NewAppIdentity(nil, identityer, nil, cacher, nil, aiQueue, nInPubTopic) _, err = aiSvc.ChallengeIdentity(ctx, &api.ChallengeIdentityRequest{ - Id: identity.Id, AppId: identity.AppId, + Id: identity.GetId(), AppId: identity.GetAppId(), }) t.Logf("err: %v", err) require.NoError(t, err) @@ -1553,10 +1551,10 @@ func TestChallengeIdentity(t *testing.T) { // Normalize generated trace ID. nIn := &message.NotifierIn{ - OrgId: identity.OrgId, - AppId: identity.AppId, - IdentityId: identity.Id, - TraceId: res.TraceId, + OrgId: identity.GetOrgId(), + AppId: identity.GetAppId(), + IdentityId: identity.GetId(), + TraceId: res.GetTraceId(), } // Testify does not currently support protobuf equality: @@ -1624,19 +1622,19 @@ func TestChallengeIdentity(t *testing.T) { uuid.NewString()) identityer := NewMockIdentityer(gomock.NewController(t)) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(identity, nil, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(identity, nil, nil).Times(1) ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, OrgPlan: api.Plan_STARTER, + OrgID: identity.GetOrgId(), OrgPlan: api.Plan_STARTER, Role: api.Role_ADMIN, }), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, nil, nil, nil, nil, "") _, err := aiSvc.ChallengeIdentity(ctx, &api.ChallengeIdentityRequest{ - Id: identity.Id, AppId: identity.AppId, + Id: identity.GetId(), AppId: identity.GetAppId(), }) t.Logf("err: %v", err) require.Equal(t, errPlan(api.Plan_PRO), err) @@ -1650,23 +1648,23 @@ func TestChallengeIdentity(t *testing.T) { ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(identity, nil, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(identity, nil, nil).Times(1) cacher := cache.NewMockCacher(ctrl) cacher.EXPECT().SetIfNotExistTTL(gomock.Any(), ikey.Challenge( - identity.OrgId, identity.AppId, identity.Id), 1, notifyRate). + identity.GetOrgId(), identity.GetAppId(), identity.GetId()), 1, notifyRate). Return(false, dao.ErrNotFound).Times(1) ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, OrgPlan: api.Plan_PRO, + OrgID: identity.GetOrgId(), OrgPlan: api.Plan_PRO, Role: api.Role_ADMIN, }), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, nil, cacher, nil, nil, "") _, err := aiSvc.ChallengeIdentity(ctx, &api.ChallengeIdentityRequest{ - Id: identity.Id, AppId: identity.AppId, + Id: identity.GetId(), AppId: identity.GetAppId(), }) t.Logf("err: %v", err) require.Equal(t, status.Error(codes.NotFound, "object not found"), err) @@ -1679,18 +1677,18 @@ func TestChallengeIdentity(t *testing.T) { uuid.NewString()) traceID := uuid.New() event := &api.Event{ - OrgId: identity.OrgId, AppId: identity.AppId, - IdentityId: identity.Id, Status: api.EventStatus_CHALLENGE_FAIL, + OrgId: identity.GetOrgId(), AppId: identity.GetAppId(), + IdentityId: identity.GetId(), Status: api.EventStatus_CHALLENGE_FAIL, Error: "rate limit exceeded", TraceId: traceID.String(), } ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(identity, nil, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(identity, nil, nil).Times(1) cacher := cache.NewMockCacher(ctrl) cacher.EXPECT().SetIfNotExistTTL(gomock.Any(), ikey.Challenge( - identity.OrgId, identity.AppId, identity.Id), 1, notifyRate). + identity.GetOrgId(), identity.GetAppId(), identity.GetId()), 1, notifyRate). Return(false, nil).Times(1) eventer := NewMockEventer(ctrl) eventer.EXPECT().Create(gomock.Any(), event).Return(dao.ErrNotFound). @@ -1698,14 +1696,14 @@ func TestChallengeIdentity(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, OrgPlan: api.Plan_PRO, + OrgID: identity.GetOrgId(), OrgPlan: api.Plan_PRO, Role: api.Role_ADMIN, TraceID: traceID, }), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, eventer, cacher, nil, nil, "") _, err := aiSvc.ChallengeIdentity(ctx, &api.ChallengeIdentityRequest{ - Id: identity.Id, AppId: identity.AppId, + Id: identity.GetId(), AppId: identity.GetAppId(), }) t.Logf("err: %v", err) require.Equal(t, status.Error(codes.Unavailable, "rate limit exceeded"), @@ -1721,11 +1719,11 @@ func TestChallengeIdentity(t *testing.T) { ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(identity, nil, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(identity, nil, nil).Times(1) cacher := cache.NewMockCacher(ctrl) cacher.EXPECT().SetIfNotExistTTL(gomock.Any(), ikey.Challenge( - identity.OrgId, identity.AppId, identity.Id), 1, notifyRate). + identity.GetOrgId(), identity.GetAppId(), identity.GetId()), 1, notifyRate). Return(true, nil).Times(1) queuer := queue.NewMockQueuer(ctrl) queuer.EXPECT().Publish(nInPubTopic, gomock.Any()). @@ -1733,7 +1731,7 @@ func TestChallengeIdentity(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, OrgPlan: api.Plan_PRO, + OrgID: identity.GetOrgId(), OrgPlan: api.Plan_PRO, Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -1741,7 +1739,7 @@ func TestChallengeIdentity(t *testing.T) { aiSvc := NewAppIdentity(nil, identityer, nil, cacher, nil, queuer, nInPubTopic) _, err := aiSvc.ChallengeIdentity(ctx, &api.ChallengeIdentityRequest{ - Id: identity.Id, AppId: identity.AppId, + Id: identity.GetId(), AppId: identity.GetAppId(), }) t.Logf("err: %v", err) require.Equal(t, status.Error(codes.Internal, "publish failure"), err) @@ -1768,37 +1766,37 @@ func TestVerifyIdentity(t *testing.T) { retIdentity, _ := proto.Clone(identity).(*api.Identity) traceID := uuid.New() event := &api.Event{ - OrgId: identity.OrgId, AppId: identity.AppId, - IdentityId: identity.Id, Status: api.EventStatus_VERIFY_SUCCESS, + OrgId: identity.GetOrgId(), AppId: identity.GetAppId(), + IdentityId: identity.GetId(), Status: api.EventStatus_VERIFY_SUCCESS, TraceId: traceID.String(), } ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(retIdentity, otp, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(retIdentity, otp, nil).Times(1) cacher := cache.NewMockCacher(ctrl) - cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.OrgId, - identity.AppId, identity.Id, "861821"), 1).Return(true, nil). + cacher.EXPECT().SetIfNotExist(gomock.Any(), ikey.Reuse(identity.GetOrgId(), + identity.GetAppId(), identity.GetId(), "861821"), 1).Return(true, nil). Times(1) - cacher.EXPECT().GetI(gomock.Any(), key.HOTPCounter(identity.OrgId, - identity.AppId, identity.Id)).Return(false, int64(0), nil).Times(1) - cacher.EXPECT().Set(gomock.Any(), key.HOTPCounter(identity.OrgId, - identity.AppId, identity.Id), int64(6)).Return(nil).Times(1) + cacher.EXPECT().GetI(gomock.Any(), key.HOTPCounter(identity.GetOrgId(), + identity.GetAppId(), identity.GetId())).Return(false, int64(0), nil).Times(1) + cacher.EXPECT().Set(gomock.Any(), key.HOTPCounter(identity.GetOrgId(), + identity.GetAppId(), identity.GetId()), int64(6)).Return(nil).Times(1) eventer := NewMockEventer(ctrl) eventer.EXPECT().Create(gomock.Any(), event).Return(dao.ErrNotFound). Times(1) ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, Role: api.Role_ADMIN, + OrgID: identity.GetOrgId(), Role: api.Role_ADMIN, TraceID: traceID, }), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, eventer, cacher, nil, nil, "") _, err := aiSvc.VerifyIdentity(ctx, &api.VerifyIdentityRequest{ - Id: identity.Id, AppId: identity.AppId, Passcode: "861821", + Id: identity.GetId(), AppId: identity.GetAppId(), Passcode: "861821", }) t.Logf("err: %v", err) require.NoError(t, err) @@ -1840,29 +1838,29 @@ func TestVerifyIdentity(t *testing.T) { retIdentity, _ := proto.Clone(identity).(*api.Identity) traceID := uuid.New() event := &api.Event{ - OrgId: identity.OrgId, AppId: identity.AppId, - IdentityId: identity.Id, Status: api.EventStatus_VERIFY_FAIL, + OrgId: identity.GetOrgId(), AppId: identity.GetAppId(), + IdentityId: identity.GetId(), Status: api.EventStatus_VERIFY_FAIL, Error: "identity is not activated", TraceId: traceID.String(), } ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(retIdentity, nil, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(retIdentity, nil, nil).Times(1) eventer := NewMockEventer(ctrl) eventer.EXPECT().Create(gomock.Any(), event).Return(dao.ErrNotFound). Times(1) ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, Role: api.Role_ADMIN, + OrgID: identity.GetOrgId(), Role: api.Role_ADMIN, TraceID: traceID, }), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, eventer, nil, nil, nil, "") _, err := aiSvc.VerifyIdentity(ctx, &api.VerifyIdentityRequest{ - Id: identity.Id, AppId: identity.AppId, + Id: identity.GetId(), AppId: identity.GetAppId(), }) t.Logf("err:%v", err) require.Equal(t, status.Error(codes.FailedPrecondition, @@ -1881,18 +1879,18 @@ func TestGetIdentity(t *testing.T) { retIdentity, _ := proto.Clone(identity).(*api.Identity) identityer := NewMockIdentityer(gomock.NewController(t)) - identityer.EXPECT().Read(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(retIdentity, nil, nil).Times(1) + identityer.EXPECT().Read(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(retIdentity, nil, nil).Times(1) ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, Role: api.Role_ADMIN, + OrgID: identity.GetOrgId(), Role: api.Role_ADMIN, }), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, nil, nil, nil, nil, "") getIdentity, err := aiSvc.GetIdentity(ctx, - &api.GetIdentityRequest{Id: identity.Id, AppId: identity.AppId}) + &api.GetIdentityRequest{Id: identity.GetId(), AppId: identity.GetAppId()}) t.Logf("identity, getIdentity, err: %+v, %+v, %v", identity, getIdentity, err) require.NoError(t, err) @@ -1969,29 +1967,29 @@ func TestDeleteIdentity(t *testing.T) { uuid.NewString()) traceID := uuid.New() event := &api.Event{ - OrgId: identity.OrgId, AppId: identity.AppId, - IdentityId: identity.Id, Status: api.EventStatus_IDENTITY_DELETED, + OrgId: identity.GetOrgId(), AppId: identity.GetAppId(), + IdentityId: identity.GetId(), Status: api.EventStatus_IDENTITY_DELETED, TraceId: traceID.String(), } ctrl := gomock.NewController(t) identityer := NewMockIdentityer(ctrl) - identityer.EXPECT().Delete(gomock.Any(), identity.Id, identity.OrgId, - identity.AppId).Return(nil).Times(1) + identityer.EXPECT().Delete(gomock.Any(), identity.GetId(), identity.GetOrgId(), + identity.GetAppId()).Return(nil).Times(1) eventer := NewMockEventer(ctrl) eventer.EXPECT().Create(gomock.Any(), event).Return(dao.ErrNotFound). Times(1) ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: identity.OrgId, Role: api.Role_ADMIN, + OrgID: identity.GetOrgId(), Role: api.Role_ADMIN, TraceID: traceID, }), testTimeout) defer cancel() aiSvc := NewAppIdentity(nil, identityer, eventer, nil, nil, nil, "") _, err := aiSvc.DeleteIdentity(ctx, &api.DeleteIdentityRequest{ - Id: identity.Id, AppId: identity.AppId, + Id: identity.GetId(), AppId: identity.GetAppId(), }) t.Logf("err: %v", err) require.NoError(t, err) @@ -2078,7 +2076,7 @@ func TestListIdentities(t *testing.T) { &api.ListIdentitiesRequest{}) t.Logf("listIdentities, err: %+v, %v", listIdentities, err) require.NoError(t, err) - require.Equal(t, int32(3), listIdentities.TotalSize) + require.Equal(t, int32(3), listIdentities.GetTotalSize()) // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -2105,8 +2103,8 @@ func TestListIdentities(t *testing.T) { uuid.NewString()), } - next, err := session.GeneratePageToken(identities[1].CreatedAt.AsTime(), - identities[1].Id) + next, err := session.GeneratePageToken(identities[1].GetCreatedAt().AsTime(), + identities[1].GetId()) require.NoError(t, err) identityer := NewMockIdentityer(gomock.NewController(t)) @@ -2124,7 +2122,7 @@ func TestListIdentities(t *testing.T) { &api.ListIdentitiesRequest{PageSize: 2}) t.Logf("listIdentities, err: %+v, %v", listIdentities, err) require.NoError(t, err) - require.Equal(t, int32(3), listIdentities.TotalSize) + require.Equal(t, int32(3), listIdentities.GetTotalSize()) // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -2239,7 +2237,7 @@ func TestListIdentities(t *testing.T) { &api.ListIdentitiesRequest{PageSize: 2}) t.Logf("listIdentities, err: %+v, %v", listIdentities, err) require.NoError(t, err) - require.Equal(t, int32(3), listIdentities.TotalSize) + require.Equal(t, int32(3), listIdentities.GetTotalSize()) // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 diff --git a/internal/hermes-api/service/org.go b/internal/hermes-api/service/org.go index e1803c4b..636f5d34 100644 --- a/internal/hermes-api/service/org.go +++ b/internal/hermes-api/service/org.go @@ -53,7 +53,7 @@ func (o *Org) CreateOrg(ctx context.Context, req *api.CreateOrgRequest) ( return nil, errPerm(api.Role_SYS_ADMIN) } - org, err := o.orgDAO.Create(ctx, req.Org) + org, err := o.orgDAO.Create(ctx, req.GetOrg()) if err != nil { return nil, errToStatus(err) } @@ -72,11 +72,11 @@ func (o *Org) GetOrg(ctx context.Context, req *api.GetOrgRequest) ( *api.Org, error, ) { sess, ok := session.FromContext(ctx) - if !ok || (sess.Role < api.Role_SYS_ADMIN && req.Id != sess.OrgID) { + if !ok || (sess.Role < api.Role_SYS_ADMIN && req.GetId() != sess.OrgID) { return nil, errPerm(api.Role_SYS_ADMIN) } - org, err := o.orgDAO.Read(ctx, req.Id) + org, err := o.orgDAO.Read(ctx, req.GetId()) if err != nil { return nil, errToStatus(err) } @@ -94,33 +94,33 @@ func (o *Org) UpdateOrg(ctx context.Context, req *api.UpdateOrgRequest) ( return nil, errPerm(api.Role_SYS_ADMIN) } - if req.Org == nil { + if req.GetOrg() == nil { return nil, status.Error(codes.InvalidArgument, req.Validate().Error()) } // Admins can only update their own org, system admins can update any org. - if (sess.Role < api.Role_SYS_ADMIN && req.Org.Id != sess.OrgID) || - (sess.Role < api.Role_ADMIN && req.Org.Id == sess.OrgID) { + if (sess.Role < api.Role_SYS_ADMIN && req.GetOrg().GetId() != sess.OrgID) || + (sess.Role < api.Role_ADMIN && req.GetOrg().GetId() == sess.OrgID) { return nil, errPerm(api.Role_SYS_ADMIN) } // Perform partial update if directed. - if req.UpdateMask != nil && len(req.UpdateMask.Paths) > 0 { + if len(req.GetUpdateMask().GetPaths()) > 0 { // Normalize and validate field mask. - req.UpdateMask.Normalize() - if !req.UpdateMask.IsValid(req.Org) { + req.GetUpdateMask().Normalize() + if !req.GetUpdateMask().IsValid(req.GetOrg()) { return nil, status.Error(codes.InvalidArgument, "invalid field mask") } - org, err := o.orgDAO.Read(ctx, req.Org.Id) + org, err := o.orgDAO.Read(ctx, req.GetOrg().GetId()) if err != nil { return nil, errToStatus(err) } - fmutils.Filter(req.Org, req.UpdateMask.Paths) - proto.Merge(org, req.Org) + fmutils.Filter(req.GetOrg(), req.GetUpdateMask().GetPaths()) + proto.Merge(org, req.GetOrg()) req.Org = org } @@ -129,7 +129,7 @@ func (o *Org) UpdateOrg(ctx context.Context, req *api.UpdateOrgRequest) ( return nil, status.Error(codes.InvalidArgument, err.Error()) } - org, err := o.orgDAO.Update(ctx, req.Org) + org, err := o.orgDAO.Update(ctx, req.GetOrg()) if err != nil { return nil, errToStatus(err) } @@ -146,7 +146,7 @@ func (o *Org) DeleteOrg(ctx context.Context, req *api.DeleteOrgRequest) ( return nil, errPerm(api.Role_SYS_ADMIN) } - if err := o.orgDAO.Delete(ctx, req.Id); err != nil { + if err := o.orgDAO.Delete(ctx, req.GetId()); err != nil { return nil, errToStatus(err) } @@ -181,17 +181,17 @@ func (o *Org) ListOrgs(ctx context.Context, req *api.ListOrgsRequest) ( }, nil } - if req.PageSize == 0 { + if req.GetPageSize() == 0 { req.PageSize = defaultPageSize } - lBoundTS, prevID, err := session.ParsePageToken(req.PageToken) + lBoundTS, prevID, err := session.ParsePageToken(req.GetPageToken()) if err != nil { return nil, status.Error(codes.InvalidArgument, "invalid page token") } // Retrieve PageSize+1 entries to find last page. - orgs, count, err := o.orgDAO.List(ctx, lBoundTS, prevID, req.PageSize+1) + orgs, count, err := o.orgDAO.List(ctx, lBoundTS, prevID, req.GetPageSize()+1) if err != nil { return nil, errToStatus(err) } @@ -199,12 +199,12 @@ func (o *Org) ListOrgs(ctx context.Context, req *api.ListOrgsRequest) ( resp := &api.ListOrgsResponse{Orgs: orgs, TotalSize: count} // Populate next page token. - if len(orgs) == int(req.PageSize+1) { + if len(orgs) == int(req.GetPageSize()+1) { resp.Orgs = orgs[:len(orgs)-1] if resp.NextPageToken, err = session.GeneratePageToken( - orgs[len(orgs)-2].CreatedAt.AsTime(), - orgs[len(orgs)-2].Id); err != nil { + orgs[len(orgs)-2].GetCreatedAt().AsTime(), + orgs[len(orgs)-2].GetId()); err != nil { // GeneratePageToken should not error based on a DB-derived UUID. // Log the error and include the usable empty token. logger := hlog.FromContext(ctx) diff --git a/internal/hermes-api/service/org_test.go b/internal/hermes-api/service/org_test.go index b757e8df..70881eec 100644 --- a/internal/hermes-api/service/org_test.go +++ b/internal/hermes-api/service/org_test.go @@ -35,7 +35,7 @@ func TestCreateOrg(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: org.Id, Role: api.Role_SYS_ADMIN, + OrgID: org.GetId(), Role: api.Role_SYS_ADMIN, }), testTimeout) defer cancel() @@ -91,7 +91,7 @@ func TestCreateOrg(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: org.Id, Role: api.Role_SYS_ADMIN, + OrgID: org.GetId(), Role: api.Role_SYS_ADMIN, }), testTimeout) defer cancel() @@ -114,16 +114,16 @@ func TestGetOrg(t *testing.T) { retOrg, _ := proto.Clone(org).(*api.Org) orger := NewMockOrger(gomock.NewController(t)) - orger.EXPECT().Read(gomock.Any(), org.Id).Return(retOrg, nil).Times(1) + orger.EXPECT().Read(gomock.Any(), org.GetId()).Return(retOrg, nil).Times(1) ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: org.Id, Role: api.Role_SYS_ADMIN, + OrgID: org.GetId(), Role: api.Role_SYS_ADMIN, }), testTimeout) defer cancel() orgSvc := NewOrg(orger) - getOrg, err := orgSvc.GetOrg(ctx, &api.GetOrgRequest{Id: org.Id}) + getOrg, err := orgSvc.GetOrg(ctx, &api.GetOrgRequest{Id: org.GetId()}) t.Logf("org, getOrg, err: %+v, %+v, %v", org, getOrg, err) require.NoError(t, err) @@ -199,7 +199,7 @@ func TestUpdateOrg(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: org.Id, Role: api.Role_SYS_ADMIN, + OrgID: org.GetId(), Role: api.Role_SYS_ADMIN, }), testTimeout) defer cancel() @@ -221,21 +221,21 @@ func TestUpdateOrg(t *testing.T) { org := random.Org("api-org") retOrg, _ := proto.Clone(org).(*api.Org) part := &api.Org{ - Id: org.Id, Name: random.String(10), Status: api.Status_DISABLED, + Id: org.GetId(), Name: random.String(10), Status: api.Status_DISABLED, } merged := &api.Org{ - Id: org.Id, Name: part.Name, Status: part.Status, Plan: org.Plan, + Id: org.GetId(), Name: part.GetName(), Status: part.GetStatus(), Plan: org.GetPlan(), } retMerged, _ := proto.Clone(merged).(*api.Org) orger := NewMockOrger(gomock.NewController(t)) - orger.EXPECT().Read(gomock.Any(), org.Id).Return(retOrg, nil).Times(1) + orger.EXPECT().Read(gomock.Any(), org.GetId()).Return(retOrg, nil).Times(1) orger.EXPECT().Update(gomock.Any(), matcher.NewProtoMatcher(merged)). Return(retMerged, nil).Times(1) ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: org.Id, Role: api.Role_SYS_ADMIN, + OrgID: org.GetId(), Role: api.Role_SYS_ADMIN, }), testTimeout) defer cancel() @@ -292,7 +292,7 @@ func TestUpdateOrg(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: org.Id, Role: api.Role_AUTHENTICATOR, + OrgID: org.GetId(), Role: api.Role_AUTHENTICATOR, }), testTimeout) defer cancel() @@ -349,7 +349,7 @@ func TestUpdateOrg(t *testing.T) { part := &api.Org{Id: uuid.NewString(), Name: random.String(10)} orger := NewMockOrger(gomock.NewController(t)) - orger.EXPECT().Read(gomock.Any(), part.Id).Return(nil, dao.ErrNotFound). + orger.EXPECT().Read(gomock.Any(), part.GetId()).Return(nil, dao.ErrNotFound). Times(1) ctx, cancel := context.WithTimeout(session.NewContext( @@ -376,7 +376,7 @@ func TestUpdateOrg(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: org.Id, Role: api.Role_SYS_ADMIN, + OrgID: org.GetId(), Role: api.Role_SYS_ADMIN, }), testTimeout) defer cancel() @@ -401,7 +401,7 @@ func TestUpdateOrg(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: org.Id, Role: api.Role_SYS_ADMIN, + OrgID: org.GetId(), Role: api.Role_SYS_ADMIN, }), testTimeout) defer cancel() @@ -512,7 +512,7 @@ func TestListOrgs(t *testing.T) { listOrgs, err := orgSvc.ListOrgs(ctx, &api.ListOrgsRequest{}) t.Logf("listOrgs, err: %+v, %v", listOrgs, err) require.NoError(t, err) - require.Equal(t, int32(3), listOrgs.TotalSize) + require.Equal(t, int32(3), listOrgs.GetTotalSize()) // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -534,8 +534,8 @@ func TestListOrgs(t *testing.T) { random.Org("api-org"), } - next, err := session.GeneratePageToken(orgs[1].CreatedAt.AsTime(), - orgs[1].Id) + next, err := session.GeneratePageToken(orgs[1].GetCreatedAt().AsTime(), + orgs[1].GetId()) require.NoError(t, err) orger := NewMockOrger(gomock.NewController(t)) @@ -552,7 +552,7 @@ func TestListOrgs(t *testing.T) { listOrgs, err := orgSvc.ListOrgs(ctx, &api.ListOrgsRequest{PageSize: 2}) t.Logf("listOrgs, err: %+v, %v", listOrgs, err) require.NoError(t, err) - require.Equal(t, int32(3), listOrgs.TotalSize) + require.Equal(t, int32(3), listOrgs.GetTotalSize()) // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -584,11 +584,11 @@ func TestListOrgs(t *testing.T) { org := random.Org("api-org") orger := NewMockOrger(gomock.NewController(t)) - orger.EXPECT().Read(gomock.Any(), org.Id).Return(org, nil).Times(1) + orger.EXPECT().Read(gomock.Any(), org.GetId()).Return(org, nil).Times(1) ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: org.Id, Role: api.Role_ADMIN, + OrgID: org.GetId(), Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -619,7 +619,7 @@ func TestListOrgs(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: org.Id, Role: api.Role_ADMIN, + OrgID: org.GetId(), Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -695,7 +695,7 @@ func TestListOrgs(t *testing.T) { listOrgs, err := orgSvc.ListOrgs(ctx, &api.ListOrgsRequest{PageSize: 2}) t.Logf("listOrgs, err: %+v, %v", listOrgs, err) require.NoError(t, err) - require.Equal(t, int32(3), listOrgs.TotalSize) + require.Equal(t, int32(3), listOrgs.GetTotalSize()) // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 diff --git a/internal/hermes-api/service/session.go b/internal/hermes-api/service/session.go index 6b6ce208..d83272fe 100644 --- a/internal/hermes-api/service/session.go +++ b/internal/hermes-api/service/session.go @@ -60,24 +60,24 @@ func (s *Session) Login(ctx context.Context, req *api.LoginRequest) ( logger := hlog.FromContext(ctx) // Read an active user by email and active organization. - user, hash, err := s.userDAO.ReadByEmail(ctx, req.Email, req.OrgName) + user, hash, err := s.userDAO.ReadByEmail(ctx, req.GetEmail(), req.GetOrgName()) // Hash the provided password if an error is returned to prevent account // enumeration attacks. if err != nil { - _, hashErr := crypto.HashPass(req.Password) + _, hashErr := crypto.HashPass(req.GetPassword()) logger.Debugf("Login s.userDAO.ReadByEmail Email, OrgName, err, "+ - "hashErr: %v, %v, %v, %v", req.Email, req.OrgName, err, hashErr) + "hashErr: %v, %v, %v, %v", req.GetEmail(), req.GetOrgName(), err, hashErr) return nil, status.Error(codes.Unauthenticated, "unauthorized") } - logger.Logger = logger.WithField("userID", user.Id).WithField("orgID", - user.OrgId) + logger.Logger = logger.WithField("userID", user.GetId()).WithField("orgID", + user.GetOrgId()) - if err := crypto.CompareHashPass(hash, req.Password); err != nil || - user.Role < api.Role_VIEWER { + if err := crypto.CompareHashPass(hash, req.GetPassword()); err != nil || + user.GetRole() < api.Role_VIEWER { logger.Debugf("Login crypto.CompareHashPass err, user.Role: %v, %s", - err, user.Role) + err, user.GetRole()) return nil, status.Error(codes.Unauthenticated, "unauthorized") } @@ -104,20 +104,20 @@ func (s *Session) CreateKey(ctx context.Context, req *api.CreateKeyRequest) ( // Only system admins can create keys with system admin role. if sess.Role < api.Role_SYS_ADMIN && - req.Key.Role == api.Role_SYS_ADMIN { + req.GetKey().GetRole() == api.Role_SYS_ADMIN { return nil, status.Error(codes.PermissionDenied, "permission denied, role modification not allowed") } req.Key.OrgId = sess.OrgID - key, err := s.keyDAO.Create(ctx, req.Key) + key, err := s.keyDAO.Create(ctx, req.GetKey()) if err != nil { return nil, errToStatus(err) } - token, err := session.GenerateKeyToken(s.pwtKey, key.Id, key.OrgId, - key.Role) + token, err := session.GenerateKeyToken(s.pwtKey, key.GetId(), key.GetOrgId(), + key.GetRole()) if err != nil { logger.Errorf("CreateKey session.GenerateKeyToken: %v", err) @@ -143,13 +143,13 @@ func (s *Session) DeleteKey(ctx context.Context, req *api.DeleteKeyRequest) ( // Disable API key before removing record. If a faulty key ID is given, // it will be confined to this org. - if err := s.cache.Set(ctx, key.Disabled(sess.OrgID, req.Id), + if err := s.cache.Set(ctx, key.Disabled(sess.OrgID, req.GetId()), ""); err != nil { return nil, errToStatus(err) } // Delete key record. - if err := s.keyDAO.Delete(ctx, req.Id, sess.OrgID); err != nil { + if err := s.keyDAO.Delete(ctx, req.GetId(), sess.OrgID); err != nil { return nil, errToStatus(err) } @@ -171,18 +171,18 @@ func (s *Session) ListKeys(ctx context.Context, req *api.ListKeysRequest) ( return nil, errPerm(api.Role_ADMIN) } - if req.PageSize == 0 { + if req.GetPageSize() == 0 { req.PageSize = defaultPageSize } - lBoundTS, prevID, err := session.ParsePageToken(req.PageToken) + lBoundTS, prevID, err := session.ParsePageToken(req.GetPageToken()) if err != nil { return nil, status.Error(codes.InvalidArgument, "invalid page token") } // Retrieve PageSize+1 entries to find last page. keys, count, err := s.keyDAO.List(ctx, sess.OrgID, lBoundTS, prevID, - req.PageSize+1) + req.GetPageSize()+1) if err != nil { return nil, errToStatus(err) } @@ -190,12 +190,12 @@ func (s *Session) ListKeys(ctx context.Context, req *api.ListKeysRequest) ( resp := &api.ListKeysResponse{Keys: keys, TotalSize: count} // Populate next page token. - if len(keys) == int(req.PageSize+1) { + if len(keys) == int(req.GetPageSize()+1) { resp.Keys = keys[:len(keys)-1] if resp.NextPageToken, err = session.GeneratePageToken( - keys[len(keys)-2].CreatedAt.AsTime(), - keys[len(keys)-2].Id); err != nil { + keys[len(keys)-2].GetCreatedAt().AsTime(), + keys[len(keys)-2].GetId()); err != nil { // GeneratePageToken should not error based on a DB-derived UUID. // Log the error and include the usable empty token. logger := hlog.FromContext(ctx) diff --git a/internal/hermes-api/service/session_test.go b/internal/hermes-api/service/session_test.go index e6999b85..7b1331ee 100644 --- a/internal/hermes-api/service/session_test.go +++ b/internal/hermes-api/service/session_test.go @@ -28,11 +28,11 @@ func TestLogin(t *testing.T) { t.Parallel() org := random.Org("api-session") - user := random.User("api-session", org.Id) + user := random.User("api-session", org.GetId()) user.Role = api.Role_ADMIN userer := NewMockUserer(gomock.NewController(t)) - userer.EXPECT().ReadByEmail(gomock.Any(), user.Email, org.Name). + userer.EXPECT().ReadByEmail(gomock.Any(), user.GetEmail(), org.GetName()). Return(user, globalHash, nil).Times(1) pwtKey := make([]byte, 32) @@ -44,13 +44,13 @@ func TestLogin(t *testing.T) { sessSvc := NewSession(userer, nil, nil, pwtKey) loginResp, err := sessSvc.Login(ctx, &api.LoginRequest{ - Email: user.Email, OrgName: org.Name, Password: globalPass, + Email: user.GetEmail(), OrgName: org.GetName(), Password: globalPass, }) t.Logf("loginResp, err: %+v, %v", loginResp, err) require.NoError(t, err) - require.Greater(t, len(loginResp.Token), 90) + require.Greater(t, len(loginResp.GetToken()), 90) require.WithinDuration(t, time.Now().Add( - session.WebTokenExp*time.Second), loginResp.ExpiresAt.AsTime(), + session.WebTokenExp*time.Second), loginResp.GetExpiresAt().AsTime(), 2*time.Second) }) @@ -58,10 +58,10 @@ func TestLogin(t *testing.T) { t.Parallel() org := random.Org("api-session") - user := random.User("api-session", org.Id) + user := random.User("api-session", org.GetId()) userer := NewMockUserer(gomock.NewController(t)) - userer.EXPECT().ReadByEmail(gomock.Any(), user.Email, org.Name). + userer.EXPECT().ReadByEmail(gomock.Any(), user.GetEmail(), org.GetName()). Return(nil, nil, dao.ErrNotFound).Times(1) pwtKey := make([]byte, 32) @@ -73,7 +73,7 @@ func TestLogin(t *testing.T) { sessSvc := NewSession(userer, nil, nil, pwtKey) loginResp, err := sessSvc.Login(ctx, &api.LoginRequest{ - Email: user.Email, OrgName: org.Name, Password: globalPass, + Email: user.GetEmail(), OrgName: org.GetName(), Password: globalPass, }) t.Logf("loginResp, err: %+v, %v", loginResp, err) require.Nil(t, loginResp) @@ -85,10 +85,10 @@ func TestLogin(t *testing.T) { t.Parallel() org := random.Org("api-session") - user := random.User("api-session", org.Id) + user := random.User("api-session", org.GetId()) userer := NewMockUserer(gomock.NewController(t)) - userer.EXPECT().ReadByEmail(gomock.Any(), user.Email, org.Name). + userer.EXPECT().ReadByEmail(gomock.Any(), user.GetEmail(), org.GetName()). Return(user, globalHash, nil).Times(1) pwtKey := make([]byte, 32) @@ -100,7 +100,7 @@ func TestLogin(t *testing.T) { sessSvc := NewSession(userer, nil, nil, pwtKey) loginResp, err := sessSvc.Login(ctx, &api.LoginRequest{ - Email: user.Email, OrgName: org.Name, Password: random.String(10), + Email: user.GetEmail(), OrgName: org.GetName(), Password: random.String(10), }) t.Logf("loginResp, err: %+v, %v", loginResp, err) require.Nil(t, loginResp) @@ -112,11 +112,11 @@ func TestLogin(t *testing.T) { t.Parallel() org := random.Org("api-session") - user := random.User("api-session", org.Id) + user := random.User("api-session", org.GetId()) user.Role = api.Role_ROLE_UNSPECIFIED userer := NewMockUserer(gomock.NewController(t)) - userer.EXPECT().ReadByEmail(gomock.Any(), user.Email, org.Name). + userer.EXPECT().ReadByEmail(gomock.Any(), user.GetEmail(), org.GetName()). Return(user, globalHash, nil).Times(1) pwtKey := make([]byte, 32) @@ -128,7 +128,7 @@ func TestLogin(t *testing.T) { sessSvc := NewSession(userer, nil, nil, pwtKey) loginResp, err := sessSvc.Login(ctx, &api.LoginRequest{ - Email: user.Email, OrgName: org.Name, Password: globalPass, + Email: user.GetEmail(), OrgName: org.GetName(), Password: globalPass, }) t.Logf("loginResp, err: %+v, %v", loginResp, err) require.Nil(t, loginResp) @@ -140,11 +140,11 @@ func TestLogin(t *testing.T) { t.Parallel() org := random.Org("api-session") - user := random.User("api-session", org.Id) + user := random.User("api-session", org.GetId()) user.Role = api.Role_ADMIN userer := NewMockUserer(gomock.NewController(t)) - userer.EXPECT().ReadByEmail(gomock.Any(), user.Email, org.Name). + userer.EXPECT().ReadByEmail(gomock.Any(), user.GetEmail(), org.GetName()). Return(user, globalHash, nil).Times(1) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -152,7 +152,7 @@ func TestLogin(t *testing.T) { sessSvc := NewSession(userer, nil, nil, nil) loginResp, err := sessSvc.Login(ctx, &api.LoginRequest{ - Email: user.Email, OrgName: org.Name, Password: globalPass, + Email: user.GetEmail(), OrgName: org.GetName(), Password: globalPass, }) t.Logf("loginResp, err: %+v, %v", loginResp, err) require.Nil(t, loginResp) @@ -180,7 +180,7 @@ func TestCreateKey(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: key.OrgId, Role: api.Role_ADMIN, + OrgID: key.GetOrgId(), Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -190,7 +190,7 @@ func TestCreateKey(t *testing.T) { require.NoError(t, err) // Normalize token. - resp := &api.CreateKeyResponse{Key: key, Token: createKey.Token} + resp := &api.CreateKeyResponse{Key: key, Token: createKey.GetToken()} // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -260,7 +260,7 @@ func TestCreateKey(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: key.OrgId, Role: api.Role_ADMIN, + OrgID: key.GetOrgId(), Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -423,7 +423,7 @@ func TestListKeys(t *testing.T) { listKeys, err := keySvc.ListKeys(ctx, &api.ListKeysRequest{}) t.Logf("listKeys, err: %+v, %v", listKeys, err) require.NoError(t, err) - require.Equal(t, int32(3), listKeys.TotalSize) + require.Equal(t, int32(3), listKeys.GetTotalSize()) // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -445,8 +445,8 @@ func TestListKeys(t *testing.T) { random.Key("api-key", uuid.NewString()), } - next, err := session.GeneratePageToken(keys[1].CreatedAt.AsTime(), - keys[1].Id) + next, err := session.GeneratePageToken(keys[1].GetCreatedAt().AsTime(), + keys[1].GetId()) require.NoError(t, err) keyer := NewMockKeyer(gomock.NewController(t)) @@ -463,7 +463,7 @@ func TestListKeys(t *testing.T) { listKeys, err := keySvc.ListKeys(ctx, &api.ListKeysRequest{PageSize: 2}) t.Logf("listKeys, err: %+v, %v", listKeys, err) require.NoError(t, err) - require.Equal(t, int32(3), listKeys.TotalSize) + require.Equal(t, int32(3), listKeys.GetTotalSize()) // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -555,7 +555,7 @@ func TestListKeys(t *testing.T) { listKeys, err := keySvc.ListKeys(ctx, &api.ListKeysRequest{PageSize: 2}) t.Logf("listKeys, err: %+v, %v", listKeys, err) require.NoError(t, err) - require.Equal(t, int32(3), listKeys.TotalSize) + require.Equal(t, int32(3), listKeys.GetTotalSize()) // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 diff --git a/internal/hermes-api/service/user.go b/internal/hermes-api/service/user.go index 5e50caf0..3721c2f8 100644 --- a/internal/hermes-api/service/user.go +++ b/internal/hermes-api/service/user.go @@ -60,14 +60,14 @@ func (u *User) CreateUser(ctx context.Context, req *api.CreateUserRequest) ( // Only system admins can elevate to system admin. if sess.Role < api.Role_SYS_ADMIN && - req.User.Role == api.Role_SYS_ADMIN { + req.GetUser().GetRole() == api.Role_SYS_ADMIN { return nil, status.Error(codes.PermissionDenied, "permission denied, role modification not allowed") } req.User.OrgId = sess.OrgID - user, err := u.userDAO.Create(ctx, req.User) + user, err := u.userDAO.Create(ctx, req.GetUser()) if err != nil { return nil, errToStatus(err) } @@ -86,11 +86,11 @@ func (u *User) GetUser(ctx context.Context, req *api.GetUserRequest) ( *api.User, error, ) { sess, ok := session.FromContext(ctx) - if !ok || (sess.Role < api.Role_ADMIN && req.Id != sess.UserID) { + if !ok || (sess.Role < api.Role_ADMIN && req.GetId() != sess.UserID) { return nil, errPerm(api.Role_ADMIN) } - user, err := u.userDAO.Read(ctx, req.Id, sess.OrgID) + user, err := u.userDAO.Read(ctx, req.GetId(), sess.OrgID) if err != nil { return nil, errToStatus(err) } @@ -108,42 +108,42 @@ func (u *User) UpdateUser(ctx context.Context, req *api.UpdateUserRequest) ( return nil, errPerm(api.Role_ADMIN) } - if req.User == nil { + if req.GetUser() == nil { return nil, status.Error(codes.InvalidArgument, req.Validate().Error()) } req.User.OrgId = sess.OrgID // Non-admins can only update their own user. - if sess.Role < api.Role_ADMIN && req.User.Id != sess.UserID { + if sess.Role < api.Role_ADMIN && req.GetUser().GetId() != sess.UserID { return nil, errPerm(api.Role_ADMIN) } // Only admins can update roles, and only system admins can elevate to // system admin. - if (sess.Role < api.Role_ADMIN && req.User.Role != sess.Role) || + if (sess.Role < api.Role_ADMIN && req.GetUser().GetRole() != sess.Role) || (sess.Role < api.Role_SYS_ADMIN && - req.User.Role == api.Role_SYS_ADMIN) { + req.GetUser().GetRole() == api.Role_SYS_ADMIN) { return nil, status.Error(codes.PermissionDenied, "permission denied, role modification not allowed") } // Perform partial update if directed. - if req.UpdateMask != nil && len(req.UpdateMask.Paths) > 0 { + if len(req.GetUpdateMask().GetPaths()) > 0 { // Normalize and validate field mask. - req.UpdateMask.Normalize() - if !req.UpdateMask.IsValid(req.User) { + req.GetUpdateMask().Normalize() + if !req.GetUpdateMask().IsValid(req.GetUser()) { return nil, status.Error(codes.InvalidArgument, "invalid field mask") } - user, err := u.userDAO.Read(ctx, req.User.Id, sess.OrgID) + user, err := u.userDAO.Read(ctx, req.GetUser().GetId(), sess.OrgID) if err != nil { return nil, errToStatus(err) } - fmutils.Filter(req.User, req.UpdateMask.Paths) - proto.Merge(user, req.User) + fmutils.Filter(req.GetUser(), req.GetUpdateMask().GetPaths()) + proto.Merge(user, req.GetUser()) req.User = user } @@ -152,7 +152,7 @@ func (u *User) UpdateUser(ctx context.Context, req *api.UpdateUserRequest) ( return nil, status.Error(codes.InvalidArgument, err.Error()) } - user, err := u.userDAO.Update(ctx, req.User) + user, err := u.userDAO.Update(ctx, req.GetUser()) if err != nil { return nil, errToStatus(err) } @@ -165,15 +165,15 @@ func (u *User) UpdateUserPassword( ctx context.Context, req *api.UpdateUserPasswordRequest, ) (*emptypb.Empty, error) { sess, ok := session.FromContext(ctx) - if !ok || (sess.Role < api.Role_ADMIN && req.Id != sess.UserID) { + if !ok || (sess.Role < api.Role_ADMIN && req.GetId() != sess.UserID) { return nil, errPerm(api.Role_ADMIN) } - if err := crypto.CheckPass(req.Password); err != nil { + if err := crypto.CheckPass(req.GetPassword()); err != nil { return nil, errToStatus(err) } - hash, err := crypto.HashPass(req.Password) + hash, err := crypto.HashPass(req.GetPassword()) if err != nil { logger := hlog.FromContext(ctx) logger.Errorf("UpdateUserPassword crypto.HashPass: %v", err) @@ -181,7 +181,7 @@ func (u *User) UpdateUserPassword( return nil, errToStatus(crypto.ErrWeakPass) } - if err := u.userDAO.UpdatePassword(ctx, req.Id, sess.OrgID, + if err := u.userDAO.UpdatePassword(ctx, req.GetId(), sess.OrgID, hash); err != nil { return nil, errToStatus(err) } @@ -198,7 +198,7 @@ func (u *User) DeleteUser(ctx context.Context, req *api.DeleteUserRequest) ( return nil, errPerm(api.Role_ADMIN) } - if err := u.userDAO.Delete(ctx, req.Id, sess.OrgID); err != nil { + if err := u.userDAO.Delete(ctx, req.GetId(), sess.OrgID); err != nil { return nil, errToStatus(err) } @@ -238,18 +238,18 @@ func (u *User) ListUsers(ctx context.Context, req *api.ListUsersRequest) ( }, nil } - if req.PageSize == 0 { + if req.GetPageSize() == 0 { req.PageSize = defaultPageSize } - lBoundTS, prevID, err := session.ParsePageToken(req.PageToken) + lBoundTS, prevID, err := session.ParsePageToken(req.GetPageToken()) if err != nil { return nil, status.Error(codes.InvalidArgument, "invalid page token") } // Retrieve PageSize+1 entries to find last page. users, count, err := u.userDAO.List(ctx, sess.OrgID, lBoundTS, prevID, - req.PageSize+1) + req.GetPageSize()+1) if err != nil { return nil, errToStatus(err) } @@ -257,12 +257,12 @@ func (u *User) ListUsers(ctx context.Context, req *api.ListUsersRequest) ( resp := &api.ListUsersResponse{Users: users, TotalSize: count} // Populate next page token. - if len(users) == int(req.PageSize+1) { + if len(users) == int(req.GetPageSize()+1) { resp.Users = users[:len(users)-1] if resp.NextPageToken, err = session.GeneratePageToken( - users[len(users)-2].CreatedAt.AsTime(), - users[len(users)-2].Id); err != nil { + users[len(users)-2].GetCreatedAt().AsTime(), + users[len(users)-2].GetId()); err != nil { // GeneratePageToken should not error based on a DB-derived UUID. // Log the error and include the usable empty token. logger := hlog.FromContext(ctx) diff --git a/internal/hermes-api/service/user_test.go b/internal/hermes-api/service/user_test.go index 3e471c3f..e5893848 100644 --- a/internal/hermes-api/service/user_test.go +++ b/internal/hermes-api/service/user_test.go @@ -37,7 +37,7 @@ func TestCreateUser(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: user.OrgId, Role: api.Role_ADMIN, + OrgID: user.GetOrgId(), Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -116,7 +116,7 @@ func TestCreateUser(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: user.OrgId, Role: api.Role_ADMIN, + OrgID: user.GetOrgId(), Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -140,17 +140,17 @@ func TestGetUser(t *testing.T) { retUser, _ := proto.Clone(user).(*api.User) userer := NewMockUserer(gomock.NewController(t)) - userer.EXPECT().Read(gomock.Any(), user.Id, user.OrgId).Return(retUser, + userer.EXPECT().Read(gomock.Any(), user.GetId(), user.GetOrgId()).Return(retUser, nil).Times(1) ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: user.OrgId, Role: api.Role_ADMIN, + OrgID: user.GetOrgId(), Role: api.Role_ADMIN, }), testTimeout) defer cancel() userSvc := NewUser(userer) - getUser, err := userSvc.GetUser(ctx, &api.GetUserRequest{Id: user.Id}) + getUser, err := userSvc.GetUser(ctx, &api.GetUserRequest{Id: user.GetId()}) t.Logf("user, getUser, err: %+v, %+v, %v", user, getUser, err) require.NoError(t, err) @@ -228,7 +228,7 @@ func TestUpdateUser(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: user.OrgId, Role: api.Role_ADMIN, + OrgID: user.GetOrgId(), Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -251,22 +251,22 @@ func TestUpdateUser(t *testing.T) { user := random.User("api-user", uuid.NewString()) user.Role = api.Role_ADMIN retUser, _ := proto.Clone(user).(*api.User) - part := &api.User{Id: user.Id, Status: api.Status_ACTIVE} + part := &api.User{Id: user.GetId(), Status: api.Status_ACTIVE} merged := &api.User{ - Id: user.Id, OrgId: user.OrgId, Name: user.Name, Email: user.Email, - Role: user.Role, Status: part.Status, + Id: user.GetId(), OrgId: user.GetOrgId(), Name: user.GetName(), Email: user.GetEmail(), + Role: user.GetRole(), Status: part.GetStatus(), } retMerged, _ := proto.Clone(merged).(*api.User) userer := NewMockUserer(gomock.NewController(t)) - userer.EXPECT().Read(gomock.Any(), user.Id, user.OrgId).Return(retUser, + userer.EXPECT().Read(gomock.Any(), user.GetId(), user.GetOrgId()).Return(retUser, nil).Times(1) userer.EXPECT().Update(gomock.Any(), matcher.NewProtoMatcher(merged)). Return(retMerged, nil).Times(1) ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: user.OrgId, Role: api.Role_ADMIN, + OrgID: user.GetOrgId(), Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -344,7 +344,7 @@ func TestUpdateUser(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - UserID: user.Id, OrgID: user.OrgId, Role: api.Role_AUTHENTICATOR, + UserID: user.GetId(), OrgID: user.GetOrgId(), Role: api.Role_AUTHENTICATOR, }), testTimeout) defer cancel() @@ -365,7 +365,7 @@ func TestUpdateUser(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - UserID: user.Id, OrgID: user.OrgId, Role: api.Role_ADMIN, + UserID: user.GetId(), OrgID: user.GetOrgId(), Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -409,7 +409,7 @@ func TestUpdateUser(t *testing.T) { part := &api.User{Id: uuid.NewString(), Status: api.Status_ACTIVE} userer := NewMockUserer(gomock.NewController(t)) - userer.EXPECT().Read(gomock.Any(), part.Id, orgID). + userer.EXPECT().Read(gomock.Any(), part.GetId(), orgID). Return(nil, dao.ErrNotFound).Times(1) ctx, cancel := context.WithTimeout(session.NewContext( @@ -438,7 +438,7 @@ func TestUpdateUser(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: user.OrgId, Role: api.Role_ADMIN, + OrgID: user.GetOrgId(), Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -466,7 +466,7 @@ func TestUpdateUser(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - OrgID: user.OrgId, Role: api.Role_ADMIN, + OrgID: user.GetOrgId(), Role: api.Role_ADMIN, }), testTimeout) defer cancel() @@ -676,7 +676,7 @@ func TestListUsers(t *testing.T) { listUsers, err := userSvc.ListUsers(ctx, &api.ListUsersRequest{}) t.Logf("listUsers, err: %+v, %v", listUsers, err) require.NoError(t, err) - require.Equal(t, int32(3), listUsers.TotalSize) + require.Equal(t, int32(3), listUsers.GetTotalSize()) // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -698,8 +698,8 @@ func TestListUsers(t *testing.T) { random.User("api-user", uuid.NewString()), } - next, err := session.GeneratePageToken(users[1].CreatedAt.AsTime(), - users[1].Id) + next, err := session.GeneratePageToken(users[1].GetCreatedAt().AsTime(), + users[1].GetId()) require.NoError(t, err) userer := NewMockUserer(gomock.NewController(t)) @@ -717,7 +717,7 @@ func TestListUsers(t *testing.T) { &api.ListUsersRequest{PageSize: 2}) t.Logf("listUsers, err: %+v, %v", listUsers, err) require.NoError(t, err) - require.Equal(t, int32(3), listUsers.TotalSize) + require.Equal(t, int32(3), listUsers.GetTotalSize()) // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -770,12 +770,12 @@ func TestListUsers(t *testing.T) { user := random.User("api-user", uuid.NewString()) userer := NewMockUserer(gomock.NewController(t)) - userer.EXPECT().Read(gomock.Any(), user.Id, user.OrgId).Return(user, + userer.EXPECT().Read(gomock.Any(), user.GetId(), user.GetOrgId()).Return(user, nil).Times(1) ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - UserID: user.Id, OrgID: user.OrgId, Role: api.Role_VIEWER, + UserID: user.GetId(), OrgID: user.GetOrgId(), Role: api.Role_VIEWER, }), testTimeout) defer cancel() @@ -806,7 +806,7 @@ func TestListUsers(t *testing.T) { ctx, cancel := context.WithTimeout(session.NewContext( context.Background(), &session.Session{ - UserID: user.Id, OrgID: user.OrgId, Role: api.Role_VIEWER, + UserID: user.GetId(), OrgID: user.GetOrgId(), Role: api.Role_VIEWER, }), testTimeout) defer cancel() @@ -883,7 +883,7 @@ func TestListUsers(t *testing.T) { &api.ListUsersRequest{PageSize: 2}) t.Logf("listUsers, err: %+v, %v", listUsers, err) require.NoError(t, err) - require.Equal(t, int32(3), listUsers.TotalSize) + require.Equal(t, int32(3), listUsers.GetTotalSize()) // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 diff --git a/internal/hermes-api/session/page_token.go b/internal/hermes-api/session/page_token.go index da003205..926ce21f 100644 --- a/internal/hermes-api/session/page_token.go +++ b/internal/hermes-api/session/page_token.go @@ -51,14 +51,14 @@ func ParsePageToken(pToken string) (time.Time, string, error) { // Unmarshal page token. A nil error with missing timestamp is treated as an // empty token. pt := &token.Page{} - if err := proto.Unmarshal(bPT, pt); err != nil || pt.BoundTs == nil { + if err := proto.Unmarshal(bPT, pt); err != nil || pt.GetBoundTs() == nil { return time.Time{}, "", err } - lastUUID, err := uuid.FromBytes(pt.PrevId) + lastUUID, err := uuid.FromBytes(pt.GetPrevId()) if err != nil { return time.Time{}, "", err } - return pt.BoundTs.AsTime(), lastUUID.String(), nil + return pt.GetBoundTs().AsTime(), lastUUID.String(), nil } diff --git a/internal/hermes-api/session/session_test.go b/internal/hermes-api/session/session_test.go index 8a0e9c7c..49947b54 100644 --- a/internal/hermes-api/session/session_test.go +++ b/internal/hermes-api/session/session_test.go @@ -17,7 +17,7 @@ func TestNewUserFromContext(t *testing.T) { user := random.User("session", uuid.NewString()) sess := &Session{ - UserID: user.Id, OrgID: user.OrgId, Role: user.Role, + UserID: user.GetId(), OrgID: user.GetOrgId(), Role: user.GetRole(), TraceID: uuid.New(), } t.Logf("sess: %+v", sess) @@ -37,7 +37,7 @@ func TestNewKeyFromContext(t *testing.T) { user := random.User("session", uuid.NewString()) sess := &Session{ - KeyID: uuid.NewString(), OrgID: user.OrgId, Role: user.Role, + KeyID: uuid.NewString(), OrgID: user.GetOrgId(), Role: user.GetRole(), TraceID: uuid.New(), } t.Logf("sess: %+v", sess) diff --git a/internal/hermes-api/session/web_token.go b/internal/hermes-api/session/web_token.go index 39a8da62..02708705 100644 --- a/internal/hermes-api/session/web_token.go +++ b/internal/hermes-api/session/web_token.go @@ -28,12 +28,12 @@ func GenerateWebToken(pwtKey []byte, user *api.User) ( string, *timestamppb.Timestamp, error, ) { // Convert user.Id and user.OrgId to bytes. - userUUID, err := uuid.Parse(user.Id) + userUUID, err := uuid.Parse(user.GetId()) if err != nil { return "", nil, err } - orgUUID, err := uuid.Parse(user.OrgId) + orgUUID, err := uuid.Parse(user.GetOrgId()) if err != nil { return "", nil, err } @@ -47,7 +47,7 @@ func GenerateWebToken(pwtKey []byte, user *api.User) ( pwt := &token.Web{ IdOneof: &token.Web_UserId{UserId: userUUID[:]}, OrgId: orgUUID[:], - Role: user.Role, + Role: user.GetRole(), ExpiresAt: exp, } @@ -122,19 +122,19 @@ func ValidateWebToken(pwtKey []byte, ciphertoken string) (*Session, error) { } // Validate expiration, if present. - if pwt.ExpiresAt != nil && pwt.ExpiresAt.AsTime().Before(time.Now()) { + if pwt.GetExpiresAt() != nil && pwt.GetExpiresAt().AsTime().Before(time.Now()) { return nil, errWebTokenExp } // Build Session with new TraceID. UUIDs have been authenticated and are // safe to copy. sess := &Session{ - Role: pwt.Role, + Role: pwt.GetRole(), TraceID: uuid.New(), } var idUUID uuid.UUID - switch id := pwt.IdOneof.(type) { + switch id := pwt.GetIdOneof().(type) { case *token.Web_UserId: _ = copy(idUUID[:], id.UserId) sess.UserID = idUUID.String() @@ -144,7 +144,7 @@ func ValidateWebToken(pwtKey []byte, ciphertoken string) (*Session, error) { } var orgUUID uuid.UUID - _ = copy(orgUUID[:], pwt.OrgId) + _ = copy(orgUUID[:], pwt.GetOrgId()) sess.OrgID = orgUUID.String() return sess, nil diff --git a/internal/hermes-api/session/web_token_test.go b/internal/hermes-api/session/web_token_test.go index 65ae04d8..3e177498 100644 --- a/internal/hermes-api/session/web_token_test.go +++ b/internal/hermes-api/session/web_token_test.go @@ -188,10 +188,10 @@ func TestValidateWebToken(t *testing.T) { } t.Logf("resVal, err: %+v, %v", resVal, err) if resVal != nil { - require.Equal(t, user.Id, resVal.UserID) + require.Equal(t, user.GetId(), resVal.UserID) require.Empty(t, resVal.KeyID) - require.Equal(t, user.OrgId, resVal.OrgID) - require.Equal(t, user.Role, resVal.Role) + require.Equal(t, user.GetOrgId(), resVal.OrgID) + require.Equal(t, user.GetRole(), resVal.Role) require.NotEmpty(t, resVal.TraceID) } if lTest.err == "" { @@ -242,8 +242,8 @@ func TestValidateKeyToken(t *testing.T) { keyID := uuid.NewString() user := random.User("keytoken", uuid.NewString()) - resGen, err := GenerateKeyToken(lTest.inpKey, keyID, user.OrgId, - user.Role) + resGen, err := GenerateKeyToken(lTest.inpKey, keyID, user.GetOrgId(), + user.GetRole()) t.Logf("resGen, err: %v, %v", resGen, err) require.NoError(t, err) @@ -258,8 +258,8 @@ func TestValidateKeyToken(t *testing.T) { if resVal != nil { require.Empty(t, resVal.UserID) require.Equal(t, keyID, resVal.KeyID) - require.Equal(t, user.OrgId, resVal.OrgID) - require.Equal(t, user.Role, resVal.Role) + require.Equal(t, user.GetOrgId(), resVal.OrgID) + require.Equal(t, user.GetRole(), resVal.Role) require.NotEmpty(t, resVal.TraceID) } if lTest.err == "" { diff --git a/internal/hermes-api/test/app_test.go b/internal/hermes-api/test/app_test.go index a7fe21a8..08d2e9d0 100644 --- a/internal/hermes-api/test/app_test.go +++ b/internal/hermes-api/test/app_test.go @@ -31,10 +31,10 @@ func TestCreateApp(t *testing.T) { &api.CreateAppRequest{App: app}) t.Logf("createApp, err: %+v, %v", createApp, err) require.NoError(t, err) - require.NotEqual(t, app.Id, createApp.Id) - require.WithinDuration(t, time.Now(), createApp.CreatedAt.AsTime(), + require.NotEqual(t, app.GetId(), createApp.GetId()) + require.WithinDuration(t, time.Now(), createApp.GetCreatedAt().AsTime(), 2*time.Second) - require.WithinDuration(t, time.Now(), createApp.UpdatedAt.AsTime(), + require.WithinDuration(t, time.Now(), createApp.GetUpdatedAt().AsTime(), 2*time.Second) }) @@ -96,7 +96,7 @@ func TestGetApp(t *testing.T) { aiCli := api.NewAppIdentityServiceClient(globalAdminGRPCConn) getApp, err := aiCli.GetApp(ctx, - &api.GetAppRequest{Id: createApp.Id}) + &api.GetAppRequest{Id: createApp.GetId()}) t.Logf("getApp, err: %+v, %v", getApp, err) require.NoError(t, err) @@ -130,7 +130,7 @@ func TestGetApp(t *testing.T) { secCli := api.NewAppIdentityServiceClient(secondaryAdminGRPCConn) getApp, err := secCli.GetApp(ctx, - &api.GetAppRequest{Id: createApp.Id}) + &api.GetAppRequest{Id: createApp.GetId()}) t.Logf("getApp, err: %+v, %v", getApp, err) require.Nil(t, getApp) require.EqualError(t, err, "rpc error: code = NotFound desc = object "+ @@ -165,17 +165,17 @@ func TestUpdateApp(t *testing.T) { &api.UpdateAppRequest{App: createApp}) t.Logf("updateApp, err: %+v, %v", updateApp, err) require.NoError(t, err) - require.Equal(t, createApp.Name, updateApp.Name) - require.Equal(t, createApp.DisplayName, updateApp.DisplayName) - require.Equal(t, createApp.Email, updateApp.Email) - require.Equal(t, createApp.PushoverKey, updateApp.PushoverKey) - require.True(t, updateApp.UpdatedAt.AsTime().After( - updateApp.CreatedAt.AsTime())) - require.WithinDuration(t, createApp.CreatedAt.AsTime(), - updateApp.UpdatedAt.AsTime(), 2*time.Second) + require.Equal(t, createApp.GetName(), updateApp.GetName()) + require.Equal(t, createApp.GetDisplayName(), updateApp.GetDisplayName()) + require.Equal(t, createApp.GetEmail(), updateApp.GetEmail()) + require.Equal(t, createApp.GetPushoverKey(), updateApp.GetPushoverKey()) + require.True(t, updateApp.GetUpdatedAt().AsTime().After( + updateApp.GetCreatedAt().AsTime())) + require.WithinDuration(t, createApp.GetCreatedAt().AsTime(), + updateApp.GetUpdatedAt().AsTime(), 2*time.Second) getApp, err := aiCli.GetApp(ctx, - &api.GetAppRequest{Id: createApp.Id}) + &api.GetAppRequest{Id: createApp.GetId()}) t.Logf("getApp, err: %+v, %v", getApp, err) require.NoError(t, err) @@ -202,7 +202,7 @@ func TestUpdateApp(t *testing.T) { // Update app fields. part := &api.App{ - Id: createApp.Id, Name: "api-app-" + random.String(10), + Id: createApp.GetId(), Name: "api-app-" + random.String(10), DisplayName: "api-app-" + random.String(10), Email: "api-app-" + random.Email(), PushoverKey: "api-app-" + random.String(30), } @@ -214,17 +214,17 @@ func TestUpdateApp(t *testing.T) { }) t.Logf("updateApp, err: %+v, %v", updateApp, err) require.NoError(t, err) - require.Equal(t, part.Name, updateApp.Name) - require.Equal(t, part.DisplayName, updateApp.DisplayName) - require.Equal(t, part.Email, updateApp.Email) - require.Equal(t, part.PushoverKey, updateApp.PushoverKey) - require.True(t, updateApp.UpdatedAt.AsTime().After( - updateApp.CreatedAt.AsTime())) - require.WithinDuration(t, createApp.CreatedAt.AsTime(), - updateApp.UpdatedAt.AsTime(), 2*time.Second) + require.Equal(t, part.GetName(), updateApp.GetName()) + require.Equal(t, part.GetDisplayName(), updateApp.GetDisplayName()) + require.Equal(t, part.GetEmail(), updateApp.GetEmail()) + require.Equal(t, part.GetPushoverKey(), updateApp.GetPushoverKey()) + require.True(t, updateApp.GetUpdatedAt().AsTime().After( + updateApp.GetCreatedAt().AsTime())) + require.WithinDuration(t, createApp.GetCreatedAt().AsTime(), + updateApp.GetUpdatedAt().AsTime(), 2*time.Second) getApp, err := aiCli.GetApp(ctx, - &api.GetAppRequest{Id: createApp.Id}) + &api.GetAppRequest{Id: createApp.GetId()}) t.Logf("getApp, err: %+v, %v", getApp, err) require.NoError(t, err) @@ -411,7 +411,7 @@ func TestDeleteApp(t *testing.T) { require.NoError(t, err) _, err = aiCli.DeleteApp(ctx, - &api.DeleteAppRequest{Id: createApp.Id}) + &api.DeleteAppRequest{Id: createApp.GetId()}) t.Logf("err: %v", err) require.NoError(t, err) @@ -424,7 +424,7 @@ func TestDeleteApp(t *testing.T) { aiCli := api.NewAppIdentityServiceClient(globalAdminKeyGRPCConn) getApp, err := aiCli.GetApp(ctx, - &api.GetAppRequest{Id: createApp.Id}) + &api.GetAppRequest{Id: createApp.GetId()}) t.Logf("getApp, err: %+v, %v", getApp, err) require.Nil(t, getApp) require.EqualError(t, err, "rpc error: code = NotFound desc = "+ @@ -475,7 +475,7 @@ func TestDeleteApp(t *testing.T) { secCli := api.NewAppIdentityServiceClient(secondaryAdminGRPCConn) _, err = secCli.DeleteApp(ctx, - &api.DeleteAppRequest{Id: createApp.Id}) + &api.DeleteAppRequest{Id: createApp.GetId()}) t.Logf("err: %v", err) require.EqualError(t, err, "rpc error: code = NotFound desc = object "+ "not found") @@ -499,8 +499,8 @@ func TestListApps(t *testing.T) { t.Logf("createApp, err: %+v, %v", createApp, err) require.NoError(t, err) - appIDs = append(appIDs, createApp.Id) - appNames = append(appNames, createApp.Name) + appIDs = append(appIDs, createApp.GetId()) + appNames = append(appNames, createApp.GetName()) } t.Run("List apps by valid org ID", func(t *testing.T) { @@ -513,13 +513,13 @@ func TestListApps(t *testing.T) { listApps, err := aiCli.ListApps(ctx, &api.ListAppsRequest{}) t.Logf("listApps, err: %+v, %v", listApps, err) require.NoError(t, err) - require.GreaterOrEqual(t, len(listApps.Apps), 3) - require.GreaterOrEqual(t, listApps.TotalSize, int32(3)) + require.GreaterOrEqual(t, len(listApps.GetApps()), 3) + require.GreaterOrEqual(t, listApps.GetTotalSize(), int32(3)) var found bool - for _, app := range listApps.Apps { - if app.Id == appIDs[len(appIDs)-1] && - app.Name == appNames[len(appNames)-1] { + for _, app := range listApps.GetApps() { + if app.GetId() == appIDs[len(appIDs)-1] && + app.GetName() == appNames[len(appNames)-1] { found = true } } @@ -537,17 +537,17 @@ func TestListApps(t *testing.T) { &api.ListAppsRequest{PageSize: 2}) t.Logf("listApps, err: %+v, %v", listApps, err) require.NoError(t, err) - require.Len(t, listApps.Apps, 2) - require.NotEmpty(t, listApps.NextPageToken) - require.GreaterOrEqual(t, listApps.TotalSize, int32(3)) + require.Len(t, listApps.GetApps(), 2) + require.NotEmpty(t, listApps.GetNextPageToken()) + require.GreaterOrEqual(t, listApps.GetTotalSize(), int32(3)) nextApps, err := aiCli.ListApps(ctx, &api.ListAppsRequest{ - PageSize: 2, PageToken: listApps.NextPageToken, + PageSize: 2, PageToken: listApps.GetNextPageToken(), }) t.Logf("nextApps, err: %+v, %v", nextApps, err) require.NoError(t, err) - require.GreaterOrEqual(t, len(nextApps.Apps), 1) - require.GreaterOrEqual(t, nextApps.TotalSize, int32(3)) + require.GreaterOrEqual(t, len(nextApps.GetApps()), 1) + require.GreaterOrEqual(t, nextApps.GetTotalSize(), int32(3)) }) t.Run("Lists are isolated by org ID", func(t *testing.T) { @@ -560,8 +560,8 @@ func TestListApps(t *testing.T) { listApps, err := secCli.ListApps(ctx, &api.ListAppsRequest{}) t.Logf("listApps, err: %+v, %v", listApps, err) require.NoError(t, err) - require.Len(t, listApps.Apps, 0) - require.Equal(t, int32(0), listApps.TotalSize) + require.Len(t, listApps.GetApps(), 0) + require.Equal(t, int32(0), listApps.GetTotalSize()) }) t.Run("List apps by invalid page token", func(t *testing.T) { diff --git a/internal/hermes-api/test/event_test.go b/internal/hermes-api/test/event_test.go index 7b2b6d00..85b9b4a4 100644 --- a/internal/hermes-api/test/event_test.go +++ b/internal/hermes-api/test/event_test.go @@ -35,7 +35,7 @@ func TestListEvents(t *testing.T) { createIdentity, err := aiCli.CreateIdentity(ctx, &api.CreateIdentityRequest{ Identity: random.HOTPIdentity("api-event", uuid.NewString(), - createApp.Id), + createApp.GetId()), }) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) @@ -44,8 +44,8 @@ func TestListEvents(t *testing.T) { for i := 0; i < 5; i++ { event := random.Event("api-event", globalAdminOrgID) - event.AppId = createApp.Id - event.IdentityId = createIdentity.Identity.Id + event.AppId = createApp.GetId() + event.IdentityId = createIdentity.GetIdentity().GetId() events = append(events, event) ctx, cancel := context.WithTimeout(context.Background(), @@ -58,8 +58,8 @@ func TestListEvents(t *testing.T) { } sort.Slice(events, func(i, j int) bool { - return events[i].CreatedAt.AsTime().After( - events[j].CreatedAt.AsTime()) + return events[i].GetCreatedAt().AsTime().After( + events[j].GetCreatedAt().AsTime()) }) ctx, cancel = context.WithTimeout(context.Background(), testTimeout) @@ -68,14 +68,13 @@ func TestListEvents(t *testing.T) { // Verify results by identity ID. evCli := api.NewEventServiceClient(globalAdminGRPCConn) listEvents, err := evCli.ListEvents(ctx, &api.ListEventsRequest{ - IdentityId: createIdentity.Identity.Id, - EndTime: events[0].CreatedAt, - StartTime: timestamppb.New(events[len(events)-1].CreatedAt. - AsTime().Add(-time.Microsecond)), + IdentityId: createIdentity.GetIdentity().GetId(), + EndTime: events[0].GetCreatedAt(), + StartTime: timestamppb.New(events[len(events)-1].GetCreatedAt().AsTime().Add(-time.Microsecond)), }) t.Logf("listEvents, err: %+v, %v", listEvents, err) require.NoError(t, err) - require.Len(t, listEvents.Events, len(events)) + require.Len(t, listEvents.GetEvents(), len(events)) // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -86,12 +85,12 @@ func TestListEvents(t *testing.T) { // Verify results by identity ID without oldest event. listEventsTS, err := evCli.ListEvents(ctx, &api.ListEventsRequest{ - IdentityId: createIdentity.Identity.Id, - StartTime: events[len(events)-1].CreatedAt, + IdentityId: createIdentity.GetIdentity().GetId(), + StartTime: events[len(events)-1].GetCreatedAt(), }) t.Logf("listEventsTS, err: %+v, %v", listEventsTS, err) require.NoError(t, err) - require.Len(t, listEventsTS.Events, len(events)-1) + require.Len(t, listEventsTS.GetEvents(), len(events)-1) // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -113,7 +112,7 @@ func TestListEvents(t *testing.T) { t.Logf("createOrg, err: %+v, %v", createOrg, err) require.NoError(t, err) - event := random.Event("api-event", createOrg.Id) + event := random.Event("api-event", createOrg.GetId()) err = globalEvDAO.Create(ctx, event) t.Logf("err: %#v", err) @@ -121,11 +120,11 @@ func TestListEvents(t *testing.T) { evCli := api.NewEventServiceClient(globalAdminGRPCConn) listEvents, err := evCli.ListEvents(ctx, &api.ListEventsRequest{ - IdentityId: event.IdentityId, + IdentityId: event.GetIdentityId(), }) t.Logf("listEvents, err: %+v, %v", listEvents, err) require.NoError(t, err) - require.Len(t, listEvents.Events, 0) + require.Len(t, listEvents.GetEvents(), 0) }) t.Run("List events by invalid time range", func(t *testing.T) { @@ -185,8 +184,8 @@ func TestLatestEvents(t *testing.T) { } sort.Slice(events, func(i, j int) bool { - return events[i].CreatedAt.AsTime().After( - events[j].CreatedAt.AsTime()) + return events[i].GetCreatedAt().AsTime().After( + events[j].GetCreatedAt().AsTime()) }) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -197,12 +196,12 @@ func TestLatestEvents(t *testing.T) { latEvents, err := evCli.LatestEvents(ctx, &api.LatestEventsRequest{}) t.Logf("latEvents, err: %+v, %v", latEvents, err) require.NoError(t, err) - require.GreaterOrEqual(t, len(latEvents.Events), 5) + require.GreaterOrEqual(t, len(latEvents.GetEvents()), 5) var found bool - for _, event := range latEvents.Events { - if event.AppId == events[len(events)-1].AppId && - event.IdentityId == events[len(events)-1].IdentityId { + for _, event := range latEvents.GetEvents() { + if event.GetAppId() == events[len(events)-1].GetAppId() && + event.GetIdentityId() == events[len(events)-1].GetIdentityId() { found = true } } @@ -211,13 +210,13 @@ func TestLatestEvents(t *testing.T) { // Verify results by app ID and identity ID. latEventsAppIDIdentityID, err := evCli.LatestEvents(ctx, &api.LatestEventsRequest{ - AppId: events[len(events)-1].AppId, - IdentityId: events[len(events)-1].IdentityId, + AppId: events[len(events)-1].GetAppId(), + IdentityId: events[len(events)-1].GetIdentityId(), }) t.Logf("latEventsAppIDIdentityID, err: %+v, %v", latEventsAppIDIdentityID, err) require.NoError(t, err) - require.Len(t, latEventsAppIDIdentityID.Events, 1) + require.Len(t, latEventsAppIDIdentityID.GetEvents(), 1) // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -231,10 +230,10 @@ func TestLatestEvents(t *testing.T) { // Verify results by app ID. latEventsAppID, err := evCli.LatestEvents(ctx, - &api.LatestEventsRequest{AppId: events[0].AppId}) + &api.LatestEventsRequest{AppId: events[0].GetAppId()}) t.Logf("latEventsAppID, err: %+v, %v", latEventsAppID, err) require.NoError(t, err) - require.Len(t, latEventsAppID.Events, 1) + require.Len(t, latEventsAppID.GetEvents(), 1) // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -248,10 +247,10 @@ func TestLatestEvents(t *testing.T) { // Verify results by identity ID. latEventsIdentityID, err := evCli.LatestEvents(ctx, - &api.LatestEventsRequest{IdentityId: events[1].IdentityId}) + &api.LatestEventsRequest{IdentityId: events[1].GetIdentityId()}) t.Logf("latEventsIdentityID, err: %+v, %v", latEventsIdentityID, err) require.NoError(t, err) - require.Len(t, latEventsIdentityID.Events, 1) + require.Len(t, latEventsIdentityID.GetEvents(), 1) // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -274,7 +273,7 @@ func TestLatestEvents(t *testing.T) { t.Logf("createOrg, err: %+v, %v", createOrg, err) require.NoError(t, err) - event := random.Event("api-event", createOrg.Id) + event := random.Event("api-event", createOrg.GetId()) err = globalEvDAO.Create(ctx, event) t.Logf("err: %#v", err) @@ -284,7 +283,7 @@ func TestLatestEvents(t *testing.T) { latEvents, err := evCli.LatestEvents(ctx, &api.LatestEventsRequest{}) t.Logf("latEvents, err: %+v, %v", latEvents, err) require.NoError(t, err) - require.Len(t, latEvents.Events, 0) + require.Len(t, latEvents.GetEvents(), 0) }) t.Run("Latest events by invalid identity ID", func(t *testing.T) { diff --git a/internal/hermes-api/test/helper_test.go b/internal/hermes-api/test/helper_test.go index 36af0c56..ba373e7c 100644 --- a/internal/hermes-api/test/helper_test.go +++ b/internal/hermes-api/test/helper_test.go @@ -50,7 +50,7 @@ func authGRPCConn(role api.Role, plan api.Plan) ( return "", nil, err } - user := random.User("api-helper", createOrg.Id) + user := random.User("api-helper", createOrg.GetId()) user.Role = role user.Status = api.Status_ACTIVE createUser, err := globalUserDAO.Create(ctx, user) @@ -58,14 +58,14 @@ func authGRPCConn(role api.Role, plan api.Plan) ( return "", nil, err } - if err = globalUserDAO.UpdatePassword(ctx, createUser.Id, createOrg.Id, + if err = globalUserDAO.UpdatePassword(ctx, createUser.GetId(), createOrg.GetId(), globalHash); err != nil { return "", nil, err } sessCli := api.NewSessionServiceClient(globalNoAuthGRPCConn) login, err := sessCli.Login(ctx, &api.LoginRequest{ - Email: createUser.Email, OrgName: createOrg.Name, Password: globalPass, + Email: createUser.GetEmail(), OrgName: createOrg.GetName(), Password: globalPass, }) if err != nil { return "", nil, err @@ -75,14 +75,14 @@ func authGRPCConn(role api.Role, plan api.Plan) ( grpc.WithBlock(), grpc.FailOnNonTempDialError(true), grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithPerRPCCredentials(&credential{token: login.Token}), + grpc.WithPerRPCCredentials(&credential{token: login.GetToken()}), } authConn, err := grpc.Dial(iapi.GRPCHost+iapi.GRPCPort, opts...) if err != nil { return "", nil, err } - return createOrg.Id, authConn, nil + return createOrg.GetId(), authConn, nil } func keyGRPCConn(conn *grpc.ClientConn, role api.Role) ( @@ -104,7 +104,7 @@ func keyGRPCConn(conn *grpc.ClientConn, role api.Role) ( grpc.WithBlock(), grpc.FailOnNonTempDialError(true), grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithPerRPCCredentials(&credential{token: createKey.Token}), + grpc.WithPerRPCCredentials(&credential{token: createKey.GetToken()}), } keyConn, err := grpc.Dial(iapi.GRPCHost+iapi.GRPCPort, opts...) if err != nil { diff --git a/internal/hermes-api/test/identity_test.go b/internal/hermes-api/test/identity_test.go index e9278fe9..b8c0d513 100644 --- a/internal/hermes-api/test/identity_test.go +++ b/internal/hermes-api/test/identity_test.go @@ -40,7 +40,7 @@ func TestCreateIdentity(t *testing.T) { t.Parallel() identity := random.HOTPIdentity("api-identity", uuid.NewString(), - createApp.Id) + createApp.GetId()) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() @@ -49,38 +49,38 @@ func TestCreateIdentity(t *testing.T) { &api.CreateIdentityRequest{Identity: identity}) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) - require.NotEqual(t, identity.Id, createIdentity.Identity.Id) + require.NotEqual(t, identity.GetId(), createIdentity.GetIdentity().GetId()) require.Equal(t, api.IdentityStatus_UNVERIFIED, - createIdentity.Identity.Status) + createIdentity.GetIdentity().GetStatus()) require.WithinDuration(t, time.Now(), - createIdentity.Identity.CreatedAt.AsTime(), 2*time.Second) + createIdentity.GetIdentity().GetCreatedAt().AsTime(), 2*time.Second) require.WithinDuration(t, time.Now(), - createIdentity.Identity.UpdatedAt.AsTime(), 2*time.Second) - require.Greater(t, len(createIdentity.Secret), 50) - require.Greater(t, len(createIdentity.Qr), 800) - require.Empty(t, createIdentity.Passcodes) + createIdentity.GetIdentity().GetUpdatedAt().AsTime(), 2*time.Second) + require.Greater(t, len(createIdentity.GetSecret()), 50) + require.Greater(t, len(createIdentity.GetQr()), 800) + require.Empty(t, createIdentity.GetPasscodes()) // Verify event. event := &api.Event{ OrgId: globalAdminOrgID, - AppId: createIdentity.Identity.AppId, - IdentityId: createIdentity.Identity.Id, + AppId: createIdentity.GetIdentity().GetAppId(), + IdentityId: createIdentity.GetIdentity().GetId(), Status: api.EventStatus_IDENTITY_CREATED, } listEvents, err := globalEvDAO.List(ctx, globalAdminOrgID, - createIdentity.Identity.Id, time.Now(), + createIdentity.GetIdentity().GetId(), time.Now(), time.Now().Add(-testTimeout)) t.Logf("listEvents, err: %+v, %v", listEvents, err) require.NoError(t, err) require.Len(t, listEvents, 1) // Normalize generated trace ID. - event.TraceId = listEvents[0].TraceId + event.TraceId = listEvents[0].GetTraceId() // Normalize timestamp. require.WithinDuration(t, time.Now(), - listEvents[0].CreatedAt.AsTime(), testTimeout) - event.CreatedAt = listEvents[0].CreatedAt + listEvents[0].GetCreatedAt().AsTime(), testTimeout) + event.CreatedAt = listEvents[0].GetCreatedAt() // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -93,7 +93,7 @@ func TestCreateIdentity(t *testing.T) { t.Parallel() identity := random.SMSIdentity("api-identity", uuid.NewString(), - createApp.Id) + createApp.GetId()) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() @@ -102,23 +102,23 @@ func TestCreateIdentity(t *testing.T) { &api.CreateIdentityRequest{Identity: identity}) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) - require.NotEqual(t, identity.Id, createIdentity.Identity.Id) + require.NotEqual(t, identity.GetId(), createIdentity.GetIdentity().GetId()) require.Equal(t, api.IdentityStatus_UNVERIFIED, - createIdentity.Identity.Status) + createIdentity.GetIdentity().GetStatus()) require.WithinDuration(t, time.Now(), - createIdentity.Identity.CreatedAt.AsTime(), 2*time.Second) + createIdentity.GetIdentity().GetCreatedAt().AsTime(), 2*time.Second) require.WithinDuration(t, time.Now(), - createIdentity.Identity.UpdatedAt.AsTime(), 2*time.Second) - require.Empty(t, createIdentity.Secret) - require.Empty(t, createIdentity.Qr) - require.Empty(t, createIdentity.Passcodes) + createIdentity.GetIdentity().GetUpdatedAt().AsTime(), 2*time.Second) + require.Empty(t, createIdentity.GetSecret()) + require.Empty(t, createIdentity.GetQr()) + require.Empty(t, createIdentity.GetPasscodes()) }) t.Run("Create valid Pushover identity", func(t *testing.T) { t.Parallel() identity := random.PushoverIdentity("api-identity", uuid.NewString(), - createApp.Id) + createApp.GetId()) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() @@ -127,23 +127,23 @@ func TestCreateIdentity(t *testing.T) { &api.CreateIdentityRequest{Identity: identity}) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) - require.NotEqual(t, identity.Id, createIdentity.Identity.Id) + require.NotEqual(t, identity.GetId(), createIdentity.GetIdentity().GetId()) require.Equal(t, api.IdentityStatus_UNVERIFIED, - createIdentity.Identity.Status) + createIdentity.GetIdentity().GetStatus()) require.WithinDuration(t, time.Now(), - createIdentity.Identity.CreatedAt.AsTime(), 2*time.Second) + createIdentity.GetIdentity().GetCreatedAt().AsTime(), 2*time.Second) require.WithinDuration(t, time.Now(), - createIdentity.Identity.UpdatedAt.AsTime(), 2*time.Second) - require.Empty(t, createIdentity.Secret) - require.Empty(t, createIdentity.Qr) - require.Empty(t, createIdentity.Passcodes) + createIdentity.GetIdentity().GetUpdatedAt().AsTime(), 2*time.Second) + require.Empty(t, createIdentity.GetSecret()) + require.Empty(t, createIdentity.GetQr()) + require.Empty(t, createIdentity.GetPasscodes()) }) t.Run("Create valid email identity", func(t *testing.T) { t.Parallel() identity := random.EmailIdentity("api-identity", uuid.NewString(), - createApp.Id) + createApp.GetId()) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() @@ -152,23 +152,23 @@ func TestCreateIdentity(t *testing.T) { &api.CreateIdentityRequest{Identity: identity}) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) - require.NotEqual(t, identity.Id, createIdentity.Identity.Id) + require.NotEqual(t, identity.GetId(), createIdentity.GetIdentity().GetId()) require.Equal(t, api.IdentityStatus_UNVERIFIED, - createIdentity.Identity.Status) + createIdentity.GetIdentity().GetStatus()) require.WithinDuration(t, time.Now(), - createIdentity.Identity.CreatedAt.AsTime(), 2*time.Second) + createIdentity.GetIdentity().GetCreatedAt().AsTime(), 2*time.Second) require.WithinDuration(t, time.Now(), - createIdentity.Identity.UpdatedAt.AsTime(), 2*time.Second) - require.Empty(t, createIdentity.Secret) - require.Empty(t, createIdentity.Qr) - require.Empty(t, createIdentity.Passcodes) + createIdentity.GetIdentity().GetUpdatedAt().AsTime(), 2*time.Second) + require.Empty(t, createIdentity.GetSecret()) + require.Empty(t, createIdentity.GetQr()) + require.Empty(t, createIdentity.GetPasscodes()) }) t.Run("Create valid backup codes identity", func(t *testing.T) { t.Parallel() identity := random.BackupCodesIdentity("api-identity", uuid.NewString(), - createApp.Id) + createApp.GetId()) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() @@ -177,24 +177,24 @@ func TestCreateIdentity(t *testing.T) { &api.CreateIdentityRequest{Identity: identity}) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) - require.NotEqual(t, identity.Id, createIdentity.Identity.Id) + require.NotEqual(t, identity.GetId(), createIdentity.GetIdentity().GetId()) require.Equal(t, api.IdentityStatus_ACTIVATED, - createIdentity.Identity.Status) + createIdentity.GetIdentity().GetStatus()) require.WithinDuration(t, time.Now(), - createIdentity.Identity.CreatedAt.AsTime(), 2*time.Second) + createIdentity.GetIdentity().GetCreatedAt().AsTime(), 2*time.Second) require.WithinDuration(t, time.Now(), - createIdentity.Identity.UpdatedAt.AsTime(), 2*time.Second) - require.Empty(t, createIdentity.Secret) - require.Empty(t, createIdentity.Qr) - require.Len(t, createIdentity.Passcodes, - int(identity.GetBackupCodesMethod().Passcodes)) + createIdentity.GetIdentity().GetUpdatedAt().AsTime(), 2*time.Second) + require.Empty(t, createIdentity.GetSecret()) + require.Empty(t, createIdentity.GetQr()) + require.Len(t, createIdentity.GetPasscodes(), + int(identity.GetBackupCodesMethod().GetPasscodes())) }) t.Run("Create valid security questions identity", func(t *testing.T) { t.Parallel() identity := random.SecurityQuestionsIdentity("api-identity", - uuid.NewString(), createApp.Id) + uuid.NewString(), createApp.GetId()) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() @@ -203,18 +203,18 @@ func TestCreateIdentity(t *testing.T) { &api.CreateIdentityRequest{Identity: identity}) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) - require.NotEqual(t, identity.Id, createIdentity.Identity.Id) + require.NotEqual(t, identity.GetId(), createIdentity.GetIdentity().GetId()) require.Equal(t, api.IdentityStatus_ACTIVATED, - createIdentity.Identity.Status) + createIdentity.GetIdentity().GetStatus()) require.Equal(t, "********", - createIdentity.Identity.GetSecurityQuestionsMethod().Answer) + createIdentity.GetIdentity().GetSecurityQuestionsMethod().GetAnswer()) require.WithinDuration(t, time.Now(), - createIdentity.Identity.CreatedAt.AsTime(), 2*time.Second) + createIdentity.GetIdentity().GetCreatedAt().AsTime(), 2*time.Second) require.WithinDuration(t, time.Now(), - createIdentity.Identity.UpdatedAt.AsTime(), 2*time.Second) - require.Empty(t, createIdentity.Secret) - require.Empty(t, createIdentity.Qr) - require.Empty(t, createIdentity.Passcodes) + createIdentity.GetIdentity().GetUpdatedAt().AsTime(), 2*time.Second) + require.Empty(t, createIdentity.GetSecret()) + require.Empty(t, createIdentity.GetQr()) + require.Empty(t, createIdentity.GetPasscodes()) }) t.Run("Create valid identity with insufficient role", func(t *testing.T) { @@ -341,13 +341,13 @@ func TestActivateIdentity(t *testing.T) { createIdentity, err := aiCli.CreateIdentity(ctx, &api.CreateIdentityRequest{ Identity: random.HOTPIdentity("api-identity", uuid.NewString(), - createApp.Id), + createApp.GetId()), }) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) base32NoPad := base32.StdEncoding.WithPadding(base32.NoPadding) - secret, err := base32NoPad.DecodeString(createIdentity.Secret) + secret, err := base32NoPad.DecodeString(createIdentity.GetSecret()) require.NoError(t, err) otp := &oath.OTP{ @@ -358,18 +358,18 @@ func TestActivateIdentity(t *testing.T) { activateIdentity, err := aiCli.ActivateIdentity(ctx, &api.ActivateIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), Passcode: passcode, }) t.Logf("activateIdentity, err: %+v, %v", activateIdentity, err) require.NoError(t, err) - require.Equal(t, api.IdentityStatus_ACTIVATED, activateIdentity.Status) + require.Equal(t, api.IdentityStatus_ACTIVATED, activateIdentity.GetStatus()) require.WithinDuration(t, time.Now(), - activateIdentity.UpdatedAt.AsTime(), 2*time.Second) + activateIdentity.GetUpdatedAt().AsTime(), 2*time.Second) ok, counter, err := globalCache.GetI(ctx, key.HOTPCounter( - activateIdentity.OrgId, activateIdentity.AppId, - activateIdentity.Id)) + activateIdentity.GetOrgId(), activateIdentity.GetAppId(), + activateIdentity.GetId())) t.Logf("ok, counter, err: %v, %v, %v", ok, counter, err) require.True(t, ok) require.NoError(t, err) @@ -378,24 +378,24 @@ func TestActivateIdentity(t *testing.T) { // Verify event. event := &api.Event{ OrgId: globalAdminOrgID, - AppId: createIdentity.Identity.AppId, - IdentityId: createIdentity.Identity.Id, + AppId: createIdentity.GetIdentity().GetAppId(), + IdentityId: createIdentity.GetIdentity().GetId(), Status: api.EventStatus_ACTIVATE_SUCCESS, } listEvents, err := globalEvDAO.List(ctx, globalAdminOrgID, - createIdentity.Identity.Id, time.Now(), + createIdentity.GetIdentity().GetId(), time.Now(), time.Now().Add(-testTimeout)) t.Logf("listEvents, err: %+v, %v", listEvents, err) require.NoError(t, err) require.Len(t, listEvents, 2) // Normalize generated trace ID. - event.TraceId = listEvents[0].TraceId + event.TraceId = listEvents[0].GetTraceId() // Normalize timestamp. require.WithinDuration(t, time.Now(), - listEvents[0].CreatedAt.AsTime(), testTimeout) - event.CreatedAt = listEvents[0].CreatedAt + listEvents[0].GetCreatedAt().AsTime(), testTimeout) + event.CreatedAt = listEvents[0].GetCreatedAt() // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -408,7 +408,7 @@ func TestActivateIdentity(t *testing.T) { t.Parallel() identity := random.HOTPIdentity("api-identity", uuid.NewString(), - createApp.Id) + createApp.GetId()) identity.MethodOneof = &api.Identity_SoftwareTotpMethod{} ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -420,7 +420,7 @@ func TestActivateIdentity(t *testing.T) { require.NoError(t, err) base32NoPad := base32.StdEncoding.WithPadding(base32.NoPadding) - secret, err := base32NoPad.DecodeString(createIdentity.Secret) + secret, err := base32NoPad.DecodeString(createIdentity.GetSecret()) require.NoError(t, err) otp := &oath.OTP{ @@ -431,18 +431,18 @@ func TestActivateIdentity(t *testing.T) { activateIdentity, err := aiCli.ActivateIdentity(ctx, &api.ActivateIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), Passcode: passcode, }) t.Logf("activateIdentity, err: %+v, %v", activateIdentity, err) require.NoError(t, err) - require.Equal(t, api.IdentityStatus_ACTIVATED, activateIdentity.Status) + require.Equal(t, api.IdentityStatus_ACTIVATED, activateIdentity.GetStatus()) require.WithinDuration(t, time.Now(), - activateIdentity.UpdatedAt.AsTime(), 2*time.Second) + activateIdentity.GetUpdatedAt().AsTime(), 2*time.Second) ok, counter, err := globalCache.GetI(ctx, ikey.TOTPOffset( - activateIdentity.OrgId, activateIdentity.AppId, - activateIdentity.Id)) + activateIdentity.GetOrgId(), activateIdentity.GetAppId(), + activateIdentity.GetId())) t.Logf("ok, counter, err: %v, %v, %v", ok, counter, err) require.True(t, ok) require.NoError(t, err) @@ -457,7 +457,7 @@ func TestActivateIdentity(t *testing.T) { require.NoError(t, err) identity := random.HOTPIdentity("api-identity", uuid.NewString(), - createApp.Id) + createApp.GetId()) identity.MethodOneof = &api.Identity_HardwareTotpMethod{ HardwareTotpMethod: &api.HardwareTOTPMethod{ Digits: 7, Secret: randKey, @@ -480,18 +480,18 @@ func TestActivateIdentity(t *testing.T) { activateIdentity, err := aiCli.ActivateIdentity(ctx, &api.ActivateIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), Passcode: passcode, }) t.Logf("activateIdentity, err: %+v, %v", activateIdentity, err) require.NoError(t, err) - require.Equal(t, api.IdentityStatus_ACTIVATED, activateIdentity.Status) + require.Equal(t, api.IdentityStatus_ACTIVATED, activateIdentity.GetStatus()) require.WithinDuration(t, time.Now(), - activateIdentity.UpdatedAt.AsTime(), 2*time.Second) + activateIdentity.GetUpdatedAt().AsTime(), 2*time.Second) ok, counter, err := globalCache.GetI(ctx, ikey.TOTPOffset( - activateIdentity.OrgId, activateIdentity.AppId, - activateIdentity.Id)) + activateIdentity.GetOrgId(), activateIdentity.GetAppId(), + activateIdentity.GetId())) t.Logf("ok, counter, err: %v, %v, %v", ok, counter, err) require.True(t, ok) require.NoError(t, err) @@ -507,38 +507,38 @@ func TestActivateIdentity(t *testing.T) { createIdentity, err := aiCli.CreateIdentity(ctx, &api.CreateIdentityRequest{ Identity: random.SMSIdentity("api-identity", uuid.NewString(), - createApp.Id), + createApp.GetId()), }) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) - _, otp, err := globalIdentDAO.Read(ctx, createIdentity.Identity.Id, - createIdentity.Identity.OrgId, createIdentity.Identity.AppId) + _, otp, err := globalIdentDAO.Read(ctx, createIdentity.GetIdentity().GetId(), + createIdentity.GetIdentity().GetOrgId(), createIdentity.GetIdentity().GetAppId()) require.NoError(t, err) passcode, err := otp.HOTP(5) require.NoError(t, err) ok, err := globalCache.SetIfNotExist(ctx, key.Expire( - createIdentity.Identity.OrgId, createIdentity.Identity.AppId, - createIdentity.Identity.Id, passcode), 1) + createIdentity.GetIdentity().GetOrgId(), createIdentity.GetIdentity().GetAppId(), + createIdentity.GetIdentity().GetId(), passcode), 1) require.True(t, ok) require.NoError(t, err) activateIdentity, err := aiCli.ActivateIdentity(ctx, &api.ActivateIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), Passcode: passcode, }) t.Logf("activateIdentity, err: %+v, %v", activateIdentity, err) require.NoError(t, err) - require.Equal(t, api.IdentityStatus_ACTIVATED, activateIdentity.Status) + require.Equal(t, api.IdentityStatus_ACTIVATED, activateIdentity.GetStatus()) require.WithinDuration(t, time.Now(), - activateIdentity.UpdatedAt.AsTime(), 2*time.Second) + activateIdentity.GetUpdatedAt().AsTime(), 2*time.Second) ok, counter, err := globalCache.GetI(ctx, key.HOTPCounter( - activateIdentity.OrgId, activateIdentity.AppId, - activateIdentity.Id)) + activateIdentity.GetOrgId(), activateIdentity.GetAppId(), + activateIdentity.GetId())) t.Logf("ok, counter, err: %v, %v, %v", ok, counter, err) require.True(t, ok) require.NoError(t, err) @@ -590,7 +590,7 @@ func TestActivateIdentity(t *testing.T) { createIdentity, err := aiCli.CreateIdentity(ctx, &api.CreateIdentityRequest{ Identity: random.HOTPIdentity("api-identity", uuid.NewString(), - createApp.Id), + createApp.GetId()), }) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) @@ -598,7 +598,7 @@ func TestActivateIdentity(t *testing.T) { secCli := api.NewAppIdentityServiceClient(secondaryAdminGRPCConn) activateIdentity, err := secCli.ActivateIdentity(ctx, &api.ActivateIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), Passcode: "000000", }) t.Logf("activateIdentity, err: %+v, %v", activateIdentity, err) @@ -616,14 +616,14 @@ func TestActivateIdentity(t *testing.T) { createIdentity, err := aiCli.CreateIdentity(ctx, &api.CreateIdentityRequest{ Identity: random.BackupCodesIdentity("api-identity", - uuid.NewString(), createApp.Id), + uuid.NewString(), createApp.GetId()), }) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) activateIdentity, err := aiCli.ActivateIdentity(ctx, &api.ActivateIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), Passcode: "000000", }) t.Logf("activateIdentity, err: %+v, %v", activateIdentity, err) @@ -634,25 +634,25 @@ func TestActivateIdentity(t *testing.T) { // Verify event. event := &api.Event{ OrgId: globalAdminOrgID, - AppId: createIdentity.Identity.AppId, - IdentityId: createIdentity.Identity.Id, + AppId: createIdentity.GetIdentity().GetAppId(), + IdentityId: createIdentity.GetIdentity().GetId(), Status: api.EventStatus_ACTIVATE_FAIL, Error: "identity is not unverified", } listEvents, err := globalEvDAO.List(ctx, globalAdminOrgID, - createIdentity.Identity.Id, time.Now(), + createIdentity.GetIdentity().GetId(), time.Now(), time.Now().Add(-testTimeout)) t.Logf("listEvents, err: %+v, %v", listEvents, err) require.NoError(t, err) require.Len(t, listEvents, 2) // Normalize generated trace ID. - event.TraceId = listEvents[0].TraceId + event.TraceId = listEvents[0].GetTraceId() // Normalize timestamp. require.WithinDuration(t, time.Now(), - listEvents[0].CreatedAt.AsTime(), testTimeout) - event.CreatedAt = listEvents[0].CreatedAt + listEvents[0].GetCreatedAt().AsTime(), testTimeout) + event.CreatedAt = listEvents[0].GetCreatedAt() // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -670,14 +670,14 @@ func TestActivateIdentity(t *testing.T) { createIdentity, err := aiCli.CreateIdentity(ctx, &api.CreateIdentityRequest{ Identity: random.SMSIdentity("api-identity", uuid.NewString(), - createApp.Id), + createApp.GetId()), }) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) activateIdentity, err := aiCli.ActivateIdentity(ctx, &api.ActivateIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), Passcode: "000000", }) t.Logf("activateIdentity, err: %+v, %v", activateIdentity, err) @@ -695,14 +695,14 @@ func TestActivateIdentity(t *testing.T) { createIdentity, err := aiCli.CreateIdentity(ctx, &api.CreateIdentityRequest{ Identity: random.HOTPIdentity("api-identity", uuid.NewString(), - createApp.Id), + createApp.GetId()), }) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) activateIdentity, err := aiCli.ActivateIdentity(ctx, &api.ActivateIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), Passcode: "0000000", }) t.Logf("activateIdentity, err: %+v, %v", activateIdentity, err) @@ -734,13 +734,13 @@ func TestChallengeIdentity(t *testing.T) { createIdentity, err := aiCli.CreateIdentity(ctx, &api.CreateIdentityRequest{ Identity: random.HOTPIdentity("api-identity", uuid.NewString(), - createApp.Id), + createApp.GetId()), }) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) _, err = aiCli.ChallengeIdentity(ctx, &api.ChallengeIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), }) t.Logf("err: %v", err) require.NoError(t, err) @@ -748,24 +748,24 @@ func TestChallengeIdentity(t *testing.T) { // Verify event. event := &api.Event{ OrgId: globalAdminOrgID, - AppId: createIdentity.Identity.AppId, - IdentityId: createIdentity.Identity.Id, + AppId: createIdentity.GetIdentity().GetAppId(), + IdentityId: createIdentity.GetIdentity().GetId(), Status: api.EventStatus_CHALLENGE_NOOP, } listEvents, err := globalEvDAO.List(ctx, globalAdminOrgID, - createIdentity.Identity.Id, time.Now(), + createIdentity.GetIdentity().GetId(), time.Now(), time.Now().Add(-testTimeout)) t.Logf("listEvents, err: %+v, %v", listEvents, err) require.NoError(t, err) require.Len(t, listEvents, 2) // Normalize generated trace ID. - event.TraceId = listEvents[0].TraceId + event.TraceId = listEvents[0].GetTraceId() // Normalize timestamp. require.WithinDuration(t, time.Now(), - listEvents[0].CreatedAt.AsTime(), testTimeout) - event.CreatedAt = listEvents[0].CreatedAt + listEvents[0].GetCreatedAt().AsTime(), testTimeout) + event.CreatedAt = listEvents[0].GetCreatedAt() // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -781,13 +781,13 @@ func TestChallengeIdentity(t *testing.T) { createIdentity, err := aiCli.CreateIdentity(ctx, &api.CreateIdentityRequest{ Identity: random.SMSIdentity("api-identity", uuid.NewString(), - createApp.Id), + createApp.GetId()), }) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) _, err = aiCli.ChallengeIdentity(ctx, &api.ChallengeIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), }) t.Logf("err: %v", err) require.NoError(t, err) @@ -804,10 +804,10 @@ func TestChallengeIdentity(t *testing.T) { // Normalize generated trace ID. nIn := &message.NotifierIn{ - OrgId: createIdentity.Identity.OrgId, - AppId: createIdentity.Identity.AppId, - IdentityId: createIdentity.Identity.Id, - TraceId: res.TraceId, + OrgId: createIdentity.GetIdentity().GetOrgId(), + AppId: createIdentity.GetIdentity().GetAppId(), + IdentityId: createIdentity.GetIdentity().GetId(), + TraceId: res.GetTraceId(), } // Testify does not currently support protobuf equality: @@ -859,14 +859,14 @@ func TestChallengeIdentity(t *testing.T) { createIdentity, err := aiCli.CreateIdentity(ctx, &api.CreateIdentityRequest{ Identity: random.HOTPIdentity("api-identity", uuid.NewString(), - createApp.Id), + createApp.GetId()), }) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) secCli := api.NewAppIdentityServiceClient(secondaryAdminGRPCConn) _, err = secCli.ChallengeIdentity(ctx, &api.ChallengeIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), }) t.Logf("err: %v", err) require.EqualError(t, err, "rpc error: code = NotFound desc = object "+ @@ -893,7 +893,7 @@ func TestChallengeIdentity(t *testing.T) { createIdentity, err := aiCli.CreateIdentity(ctx, &api.CreateIdentityRequest{ Identity: random.SMSIdentity("api-identity", uuid.NewString(), - createApp.Id), + createApp.GetId()), }) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) @@ -909,10 +909,10 @@ func TestChallengeIdentity(t *testing.T) { }) t.Logf("updateOrg, err: %+v, %v", updateOrg, err) require.NoError(t, err) - require.Equal(t, part.Plan, updateOrg.Plan) + require.Equal(t, part.GetPlan(), updateOrg.GetPlan()) _, err = aiCli.ChallengeIdentity(ctx, &api.ChallengeIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), }) t.Logf("err: %v", err) require.EqualError(t, err, "rpc error: code = PermissionDenied desc = "+ @@ -926,13 +926,13 @@ func TestChallengeIdentity(t *testing.T) { createIdentity, err := aiCli.CreateIdentity(ctx, &api.CreateIdentityRequest{ Identity: random.SMSIdentity("api-identity", uuid.NewString(), - createApp.Id), + createApp.GetId()), }) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) _, err = aiCli.ChallengeIdentity(ctx, &api.ChallengeIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), }) t.Logf("err: %v", err) require.NoError(t, err) @@ -949,10 +949,10 @@ func TestChallengeIdentity(t *testing.T) { // Normalize generated trace ID. nIn := &message.NotifierIn{ - OrgId: createIdentity.Identity.OrgId, - AppId: createIdentity.Identity.AppId, - IdentityId: createIdentity.Identity.Id, - TraceId: res.TraceId, + OrgId: createIdentity.GetIdentity().GetOrgId(), + AppId: createIdentity.GetIdentity().GetAppId(), + IdentityId: createIdentity.GetIdentity().GetId(), + TraceId: res.GetTraceId(), } // Testify does not currently support protobuf equality: @@ -965,7 +965,7 @@ func TestChallengeIdentity(t *testing.T) { } _, err = aiCli.ChallengeIdentity(ctx, &api.ChallengeIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), }) t.Logf("err: %v", err) require.EqualError(t, err, "rpc error: code = Unavailable desc = rate "+ @@ -974,25 +974,25 @@ func TestChallengeIdentity(t *testing.T) { // Verify event. event := &api.Event{ OrgId: globalAdminOrgID, - AppId: createIdentity.Identity.AppId, - IdentityId: createIdentity.Identity.Id, + AppId: createIdentity.GetIdentity().GetAppId(), + IdentityId: createIdentity.GetIdentity().GetId(), Status: api.EventStatus_CHALLENGE_FAIL, Error: "rate limit exceeded", } listEvents, err := globalEvDAO.List(ctx, globalAdminOrgID, - createIdentity.Identity.Id, time.Now(), + createIdentity.GetIdentity().GetId(), time.Now(), time.Now().Add(-testTimeout)) t.Logf("listEvents, err: %+v, %v", listEvents, err) require.NoError(t, err) require.Len(t, listEvents, 2) // Normalize generated trace ID. - event.TraceId = listEvents[0].TraceId + event.TraceId = listEvents[0].GetTraceId() // Normalize timestamp. require.WithinDuration(t, time.Now(), - listEvents[0].CreatedAt.AsTime(), testTimeout) - event.CreatedAt = listEvents[0].CreatedAt + listEvents[0].GetCreatedAt().AsTime(), testTimeout) + event.CreatedAt = listEvents[0].GetCreatedAt() // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -1024,13 +1024,13 @@ func TestVerifyIdentity(t *testing.T) { createIdentity, err := aiCli.CreateIdentity(ctx, &api.CreateIdentityRequest{ Identity: random.HOTPIdentity("api-identity", uuid.NewString(), - createApp.Id), + createApp.GetId()), }) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) base32NoPad := base32.StdEncoding.WithPadding(base32.NoPadding) - secret, err := base32NoPad.DecodeString(createIdentity.Secret) + secret, err := base32NoPad.DecodeString(createIdentity.GetSecret()) require.NoError(t, err) otp := &oath.OTP{ @@ -1041,20 +1041,20 @@ func TestVerifyIdentity(t *testing.T) { activateIdentity, err := aiCli.ActivateIdentity(ctx, &api.ActivateIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), Passcode: passcode, }) t.Logf("activateIdentity, err: %+v, %v", activateIdentity, err) require.NoError(t, err) - require.Equal(t, api.IdentityStatus_ACTIVATED, activateIdentity.Status) + require.Equal(t, api.IdentityStatus_ACTIVATED, activateIdentity.GetStatus()) require.WithinDuration(t, time.Now(), - activateIdentity.UpdatedAt.AsTime(), 2*time.Second) + activateIdentity.GetUpdatedAt().AsTime(), 2*time.Second) passcode, err = otp.HOTP(6) require.NoError(t, err) _, err = aiCli.VerifyIdentity(ctx, &api.VerifyIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), Passcode: passcode, }) t.Logf("err: %v", err) @@ -1063,24 +1063,24 @@ func TestVerifyIdentity(t *testing.T) { // Verify event. event := &api.Event{ OrgId: globalAdminOrgID, - AppId: createIdentity.Identity.AppId, - IdentityId: createIdentity.Identity.Id, + AppId: createIdentity.GetIdentity().GetAppId(), + IdentityId: createIdentity.GetIdentity().GetId(), Status: api.EventStatus_VERIFY_SUCCESS, } listEvents, err := globalEvDAO.List(ctx, globalAdminOrgID, - createIdentity.Identity.Id, time.Now(), + createIdentity.GetIdentity().GetId(), time.Now(), time.Now().Add(-testTimeout)) t.Logf("listEvents, err: %+v, %v", listEvents, err) require.NoError(t, err) require.Len(t, listEvents, 3) // Normalize generated trace ID. - event.TraceId = listEvents[0].TraceId + event.TraceId = listEvents[0].GetTraceId() // Normalize timestamp. require.WithinDuration(t, time.Now(), - listEvents[0].CreatedAt.AsTime(), testTimeout) - event.CreatedAt = listEvents[0].CreatedAt + listEvents[0].GetCreatedAt().AsTime(), testTimeout) + event.CreatedAt = listEvents[0].GetCreatedAt() // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -1093,7 +1093,7 @@ func TestVerifyIdentity(t *testing.T) { t.Parallel() identity := random.HOTPIdentity("api-identity", uuid.NewString(), - createApp.Id) + createApp.GetId()) identity.MethodOneof = &api.Identity_SoftwareTotpMethod{} ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -1105,7 +1105,7 @@ func TestVerifyIdentity(t *testing.T) { require.NoError(t, err) base32NoPad := base32.StdEncoding.WithPadding(base32.NoPadding) - secret, err := base32NoPad.DecodeString(createIdentity.Secret) + secret, err := base32NoPad.DecodeString(createIdentity.GetSecret()) require.NoError(t, err) otp := &oath.OTP{ @@ -1116,20 +1116,20 @@ func TestVerifyIdentity(t *testing.T) { activateIdentity, err := aiCli.ActivateIdentity(ctx, &api.ActivateIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), Passcode: passcode, }) t.Logf("activateIdentity, err: %+v, %v", activateIdentity, err) require.NoError(t, err) - require.Equal(t, api.IdentityStatus_ACTIVATED, activateIdentity.Status) + require.Equal(t, api.IdentityStatus_ACTIVATED, activateIdentity.GetStatus()) require.WithinDuration(t, time.Now(), - activateIdentity.UpdatedAt.AsTime(), 2*time.Second) + activateIdentity.GetUpdatedAt().AsTime(), 2*time.Second) passcode, err = otp.TOTP(time.Now()) require.NoError(t, err) _, err = aiCli.VerifyIdentity(ctx, &api.VerifyIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), Passcode: passcode, }) t.Logf("err: %v", err) @@ -1144,7 +1144,7 @@ func TestVerifyIdentity(t *testing.T) { require.NoError(t, err) identity := random.HOTPIdentity("api-identity", uuid.NewString(), - createApp.Id) + createApp.GetId()) identity.MethodOneof = &api.Identity_HardwareTotpMethod{ HardwareTotpMethod: &api.HardwareTOTPMethod{ Digits: 7, Secret: randKey, @@ -1167,20 +1167,20 @@ func TestVerifyIdentity(t *testing.T) { activateIdentity, err := aiCli.ActivateIdentity(ctx, &api.ActivateIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), Passcode: passcode, }) t.Logf("activateIdentity, err: %+v, %v", activateIdentity, err) require.NoError(t, err) - require.Equal(t, api.IdentityStatus_ACTIVATED, activateIdentity.Status) + require.Equal(t, api.IdentityStatus_ACTIVATED, activateIdentity.GetStatus()) require.WithinDuration(t, time.Now(), - activateIdentity.UpdatedAt.AsTime(), 2*time.Second) + activateIdentity.GetUpdatedAt().AsTime(), 2*time.Second) passcode, err = otp.TOTP(time.Now().Add(-60 * time.Second)) require.NoError(t, err) _, err = aiCli.VerifyIdentity(ctx, &api.VerifyIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), Passcode: passcode, }) t.Logf("err: %v", err) @@ -1196,46 +1196,46 @@ func TestVerifyIdentity(t *testing.T) { createIdentity, err := aiCli.CreateIdentity(ctx, &api.CreateIdentityRequest{ Identity: random.SMSIdentity("api-identity", uuid.NewString(), - createApp.Id), + createApp.GetId()), }) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) - _, otp, err := globalIdentDAO.Read(ctx, createIdentity.Identity.Id, - createIdentity.Identity.OrgId, createIdentity.Identity.AppId) + _, otp, err := globalIdentDAO.Read(ctx, createIdentity.GetIdentity().GetId(), + createIdentity.GetIdentity().GetOrgId(), createIdentity.GetIdentity().GetAppId()) require.NoError(t, err) passcode, err := otp.HOTP(5) require.NoError(t, err) ok, err := globalCache.SetIfNotExist(ctx, key.Expire( - createIdentity.Identity.OrgId, createIdentity.Identity.AppId, - createIdentity.Identity.Id, passcode), 1) + createIdentity.GetIdentity().GetOrgId(), createIdentity.GetIdentity().GetAppId(), + createIdentity.GetIdentity().GetId(), passcode), 1) require.True(t, ok) require.NoError(t, err) activateIdentity, err := aiCli.ActivateIdentity(ctx, &api.ActivateIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), Passcode: passcode, }) t.Logf("activateIdentity, err: %+v, %v", activateIdentity, err) require.NoError(t, err) - require.Equal(t, api.IdentityStatus_ACTIVATED, activateIdentity.Status) + require.Equal(t, api.IdentityStatus_ACTIVATED, activateIdentity.GetStatus()) require.WithinDuration(t, time.Now(), - activateIdentity.UpdatedAt.AsTime(), 2*time.Second) + activateIdentity.GetUpdatedAt().AsTime(), 2*time.Second) passcode, err = otp.HOTP(6) require.NoError(t, err) ok, err = globalCache.SetIfNotExist(ctx, key.Expire( - createIdentity.Identity.OrgId, createIdentity.Identity.AppId, - createIdentity.Identity.Id, passcode), 1) + createIdentity.GetIdentity().GetOrgId(), createIdentity.GetIdentity().GetAppId(), + createIdentity.GetIdentity().GetId(), passcode), 1) require.True(t, ok) require.NoError(t, err) _, err = aiCli.VerifyIdentity(ctx, &api.VerifyIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), Passcode: passcode, }) t.Logf("err: %v", err) @@ -1251,16 +1251,16 @@ func TestVerifyIdentity(t *testing.T) { createIdentity, err := aiCli.CreateIdentity(ctx, &api.CreateIdentityRequest{ Identity: random.BackupCodesIdentity("api-identity", - uuid.NewString(), createApp.Id), + uuid.NewString(), createApp.GetId()), }) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) // Verify out of order. - for i := len(createIdentity.Passcodes) - 1; i >= 0; i-- { + for i := len(createIdentity.GetPasscodes()) - 1; i >= 0; i-- { _, err = aiCli.VerifyIdentity(ctx, &api.VerifyIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, - Passcode: createIdentity.Passcodes[i], + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), + Passcode: createIdentity.GetPasscodes()[i], }) t.Logf("err: %v", err) require.NoError(t, err) @@ -1271,7 +1271,7 @@ func TestVerifyIdentity(t *testing.T) { t.Parallel() identity := random.SecurityQuestionsIdentity("api-identity", - uuid.NewString(), createApp.Id) + uuid.NewString(), createApp.GetId()) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() @@ -1282,8 +1282,8 @@ func TestVerifyIdentity(t *testing.T) { require.NoError(t, err) _, err = aiCli.VerifyIdentity(ctx, &api.VerifyIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, - Passcode: identity.GetSecurityQuestionsMethod().Answer, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), + Passcode: identity.GetSecurityQuestionsMethod().GetAnswer(), }) t.Logf("err: %v", err) require.NoError(t, err) @@ -1330,7 +1330,7 @@ func TestVerifyIdentity(t *testing.T) { createIdentity, err := aiCli.CreateIdentity(ctx, &api.CreateIdentityRequest{ Identity: random.HOTPIdentity("api-identity", uuid.NewString(), - createApp.Id), + createApp.GetId()), }) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) @@ -1354,13 +1354,13 @@ func TestVerifyIdentity(t *testing.T) { createIdentity, err := aiCli.CreateIdentity(ctx, &api.CreateIdentityRequest{ Identity: random.HOTPIdentity("api-identity", uuid.NewString(), - createApp.Id), + createApp.GetId()), }) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) base32NoPad := base32.StdEncoding.WithPadding(base32.NoPadding) - secret, err := base32NoPad.DecodeString(createIdentity.Secret) + secret, err := base32NoPad.DecodeString(createIdentity.GetSecret()) require.NoError(t, err) otp := &oath.OTP{ @@ -1370,7 +1370,7 @@ func TestVerifyIdentity(t *testing.T) { require.NoError(t, err) _, err = aiCli.VerifyIdentity(ctx, &api.VerifyIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), Passcode: passcode, }) t.Logf("err:%v", err) @@ -1380,25 +1380,25 @@ func TestVerifyIdentity(t *testing.T) { // Verify event. event := &api.Event{ OrgId: globalAdminOrgID, - AppId: createIdentity.Identity.AppId, - IdentityId: createIdentity.Identity.Id, + AppId: createIdentity.GetIdentity().GetAppId(), + IdentityId: createIdentity.GetIdentity().GetId(), Status: api.EventStatus_VERIFY_FAIL, Error: "identity is not activated", } listEvents, err := globalEvDAO.List(ctx, globalAdminOrgID, - createIdentity.Identity.Id, time.Now(), + createIdentity.GetIdentity().GetId(), time.Now(), time.Now().Add(-testTimeout)) t.Logf("listEvents, err: %+v, %v", listEvents, err) require.NoError(t, err) require.Len(t, listEvents, 2) // Normalize generated trace ID. - event.TraceId = listEvents[0].TraceId + event.TraceId = listEvents[0].GetTraceId() // Normalize timestamp. require.WithinDuration(t, time.Now(), - listEvents[0].CreatedAt.AsTime(), testTimeout) - event.CreatedAt = listEvents[0].CreatedAt + listEvents[0].GetCreatedAt().AsTime(), testTimeout) + event.CreatedAt = listEvents[0].GetCreatedAt() // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -1416,40 +1416,40 @@ func TestVerifyIdentity(t *testing.T) { createIdentity, err := aiCli.CreateIdentity(ctx, &api.CreateIdentityRequest{ Identity: random.SMSIdentity("api-identity", uuid.NewString(), - createApp.Id), + createApp.GetId()), }) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) - _, otp, err := globalIdentDAO.Read(ctx, createIdentity.Identity.Id, - createIdentity.Identity.OrgId, createIdentity.Identity.AppId) + _, otp, err := globalIdentDAO.Read(ctx, createIdentity.GetIdentity().GetId(), + createIdentity.GetIdentity().GetOrgId(), createIdentity.GetIdentity().GetAppId()) require.NoError(t, err) passcode, err := otp.HOTP(5) require.NoError(t, err) ok, err := globalCache.SetIfNotExist(ctx, key.Expire( - createIdentity.Identity.OrgId, createIdentity.Identity.AppId, - createIdentity.Identity.Id, passcode), 1) + createIdentity.GetIdentity().GetOrgId(), createIdentity.GetIdentity().GetAppId(), + createIdentity.GetIdentity().GetId(), passcode), 1) require.True(t, ok) require.NoError(t, err) activateIdentity, err := aiCli.ActivateIdentity(ctx, &api.ActivateIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), Passcode: passcode, }) t.Logf("activateIdentity, err: %+v, %v", activateIdentity, err) require.NoError(t, err) - require.Equal(t, api.IdentityStatus_ACTIVATED, activateIdentity.Status) + require.Equal(t, api.IdentityStatus_ACTIVATED, activateIdentity.GetStatus()) require.WithinDuration(t, time.Now(), - activateIdentity.UpdatedAt.AsTime(), 2*time.Second) + activateIdentity.GetUpdatedAt().AsTime(), 2*time.Second) passcode, err = otp.HOTP(6) require.NoError(t, err) _, err = aiCli.VerifyIdentity(ctx, &api.VerifyIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), Passcode: passcode, }) t.Logf("err: %v", err) @@ -1466,21 +1466,21 @@ func TestVerifyIdentity(t *testing.T) { createIdentity, err := aiCli.CreateIdentity(ctx, &api.CreateIdentityRequest{ Identity: random.BackupCodesIdentity("api-identity", - uuid.NewString(), createApp.Id), + uuid.NewString(), createApp.GetId()), }) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) _, err = aiCli.VerifyIdentity(ctx, &api.VerifyIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, - Passcode: createIdentity.Passcodes[0], + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), + Passcode: createIdentity.GetPasscodes()[0], }) t.Logf("err: %v", err) require.NoError(t, err) _, err = aiCli.VerifyIdentity(ctx, &api.VerifyIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, - Passcode: createIdentity.Passcodes[0], + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), + Passcode: createIdentity.GetPasscodes()[0], }) t.Logf("err: %v", err) require.EqualError(t, err, "rpc error: code = InvalidArgument desc = "+ @@ -1491,7 +1491,7 @@ func TestVerifyIdentity(t *testing.T) { t.Parallel() identity := random.HOTPIdentity("api-identity", uuid.NewString(), - createApp.Id) + createApp.GetId()) identity.MethodOneof = &api.Identity_SoftwareTotpMethod{} ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -1503,7 +1503,7 @@ func TestVerifyIdentity(t *testing.T) { require.NoError(t, err) base32NoPad := base32.StdEncoding.WithPadding(base32.NoPadding) - secret, err := base32NoPad.DecodeString(createIdentity.Secret) + secret, err := base32NoPad.DecodeString(createIdentity.GetSecret()) require.NoError(t, err) otp := &oath.OTP{ @@ -1514,17 +1514,17 @@ func TestVerifyIdentity(t *testing.T) { activateIdentity, err := aiCli.ActivateIdentity(ctx, &api.ActivateIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), Passcode: passcode, }) t.Logf("activateIdentity, err: %+v, %v", activateIdentity, err) require.NoError(t, err) - require.Equal(t, api.IdentityStatus_ACTIVATED, activateIdentity.Status) + require.Equal(t, api.IdentityStatus_ACTIVATED, activateIdentity.GetStatus()) require.WithinDuration(t, time.Now(), - activateIdentity.UpdatedAt.AsTime(), 2*time.Second) + activateIdentity.GetUpdatedAt().AsTime(), 2*time.Second) _, err = aiCli.VerifyIdentity(ctx, &api.VerifyIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), Passcode: "000000", }) t.Logf("err: %v", err) @@ -1541,13 +1541,13 @@ func TestVerifyIdentity(t *testing.T) { createIdentity, err := aiCli.CreateIdentity(ctx, &api.CreateIdentityRequest{ Identity: random.SecurityQuestionsIdentity("api-identity", - uuid.NewString(), createApp.Id), + uuid.NewString(), createApp.GetId()), }) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) _, err = aiCli.VerifyIdentity(ctx, &api.VerifyIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), Passcode: random.String(80), }) t.Logf("err: %v", err) @@ -1571,7 +1571,7 @@ func TestGetIdentity(t *testing.T) { createIdentity, err := aiCli.CreateIdentity(ctx, &api.CreateIdentityRequest{ Identity: random.HOTPIdentity("api-identity", uuid.NewString(), - createApp.Id), + createApp.GetId()), }) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) @@ -1584,15 +1584,15 @@ func TestGetIdentity(t *testing.T) { aiCli := api.NewAppIdentityServiceClient(globalAdminGRPCConn) getIdentity, err := aiCli.GetIdentity(ctx, &api.GetIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), }) t.Logf("getIdentity, err: %+v, %v", getIdentity, err) require.NoError(t, err) // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 - if !proto.Equal(createIdentity.Identity, getIdentity) { - t.Fatalf("\nExpect: %+v\nActual: %+v", createIdentity.Identity, + if !proto.Equal(createIdentity.GetIdentity(), getIdentity) { + t.Fatalf("\nExpect: %+v\nActual: %+v", createIdentity.GetIdentity(), getIdentity) } }) @@ -1605,7 +1605,7 @@ func TestGetIdentity(t *testing.T) { aiCli := api.NewAppIdentityServiceClient(globalAdminGRPCConn) getIdentity, err := aiCli.GetIdentity(ctx, - &api.GetIdentityRequest{Id: uuid.NewString(), AppId: createApp.Id}) + &api.GetIdentityRequest{Id: uuid.NewString(), AppId: createApp.GetId()}) t.Logf("getIdentity, err: %+v, %v", getIdentity, err) require.Nil(t, getIdentity) require.EqualError(t, err, "rpc error: code = NotFound desc = object "+ @@ -1620,7 +1620,7 @@ func TestGetIdentity(t *testing.T) { secCli := api.NewAppIdentityServiceClient(secondaryAdminGRPCConn) getIdentity, err := secCli.GetIdentity(ctx, &api.GetIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), }) t.Logf("getIdentity, err: %+v, %v", getIdentity, err) require.Nil(t, getIdentity) @@ -1648,13 +1648,13 @@ func TestDeleteIdentity(t *testing.T) { createIdentity, err := aiCli.CreateIdentity(ctx, &api.CreateIdentityRequest{ Identity: random.HOTPIdentity("api-identity", uuid.NewString(), - createApp.Id), + createApp.GetId()), }) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) _, err = aiCli.DeleteIdentity(ctx, &api.DeleteIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), }) t.Logf("err: %v", err) require.NoError(t, err) @@ -1662,24 +1662,24 @@ func TestDeleteIdentity(t *testing.T) { // Verify event. event := &api.Event{ OrgId: globalAdminOrgID, - AppId: createIdentity.Identity.AppId, - IdentityId: createIdentity.Identity.Id, + AppId: createIdentity.GetIdentity().GetAppId(), + IdentityId: createIdentity.GetIdentity().GetId(), Status: api.EventStatus_IDENTITY_DELETED, } listEvents, err := globalEvDAO.List(ctx, globalAdminOrgID, - createIdentity.Identity.Id, time.Now(), + createIdentity.GetIdentity().GetId(), time.Now(), time.Now().Add(-testTimeout)) t.Logf("listEvents, err: %+v, %v", listEvents, err) require.NoError(t, err) require.Len(t, listEvents, 2) // Normalize generated trace ID. - event.TraceId = listEvents[0].TraceId + event.TraceId = listEvents[0].GetTraceId() // Normalize timestamp. require.WithinDuration(t, time.Now(), - listEvents[0].CreatedAt.AsTime(), testTimeout) - event.CreatedAt = listEvents[0].CreatedAt + listEvents[0].GetCreatedAt().AsTime(), testTimeout) + event.CreatedAt = listEvents[0].GetCreatedAt() // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -1696,7 +1696,7 @@ func TestDeleteIdentity(t *testing.T) { aiCli := api.NewAppIdentityServiceClient(globalAdminKeyGRPCConn) getIdentity, err := aiCli.GetIdentity(ctx, &api.GetIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: uuid.NewString(), + Id: createIdentity.GetIdentity().GetId(), AppId: uuid.NewString(), }) t.Logf("getIdentity, err: %+v, %v", getIdentity, err) require.Nil(t, getIdentity) @@ -1751,14 +1751,14 @@ func TestDeleteIdentity(t *testing.T) { createIdentity, err := aiCli.CreateIdentity(ctx, &api.CreateIdentityRequest{ Identity: random.HOTPIdentity("api-identity", uuid.NewString(), - createApp.Id), + createApp.GetId()), }) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) secCli := api.NewAppIdentityServiceClient(secondaryAdminGRPCConn) _, err = secCli.DeleteIdentity(ctx, &api.DeleteIdentityRequest{ - Id: createIdentity.Identity.Id, AppId: createApp.Id, + Id: createIdentity.GetIdentity().GetId(), AppId: createApp.GetId(), }) t.Logf("err: %v", err) require.EqualError(t, err, "rpc error: code = NotFound desc = object "+ @@ -1783,7 +1783,7 @@ func TestListIdentities(t *testing.T) { identityComments := []string{} for i := 0; i < 3; i++ { identity := random.HOTPIdentity("api-identity", uuid.NewString(), - createApp.Id) + createApp.GetId()) aiCli := api.NewAppIdentityServiceClient(globalAdminGRPCConn) createIdentity, err := aiCli.CreateIdentity(ctx, @@ -1791,9 +1791,9 @@ func TestListIdentities(t *testing.T) { t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) - identityIDs = append(identityIDs, createIdentity.Identity.Id) + identityIDs = append(identityIDs, createIdentity.GetIdentity().GetId()) identityComments = append(identityComments, - createIdentity.Identity.Comment) + createIdentity.GetIdentity().GetComment()) } t.Run("List identities by valid org ID", func(t *testing.T) { @@ -1807,13 +1807,13 @@ func TestListIdentities(t *testing.T) { &api.ListIdentitiesRequest{PageSize: 250}) t.Logf("listIdentities, err: %+v, %v", listIdentities, err) require.NoError(t, err) - require.GreaterOrEqual(t, len(listIdentities.Identities), 3) - require.GreaterOrEqual(t, listIdentities.TotalSize, int32(3)) + require.GreaterOrEqual(t, len(listIdentities.GetIdentities()), 3) + require.GreaterOrEqual(t, listIdentities.GetTotalSize(), int32(3)) var found bool - for _, identity := range listIdentities.Identities { - if identity.Id == identityIDs[len(identityIDs)-1] && - identity.Comment == identityComments[len(identityComments)-1] { + for _, identity := range listIdentities.GetIdentities() { + if identity.GetId() == identityIDs[len(identityIDs)-1] && + identity.GetComment() == identityComments[len(identityComments)-1] { found = true } } @@ -1831,18 +1831,18 @@ func TestListIdentities(t *testing.T) { &api.ListIdentitiesRequest{PageSize: 2}) t.Logf("listIdentities, err: %+v, %v", listIdentities, err) require.NoError(t, err) - require.Len(t, listIdentities.Identities, 2) - require.NotEmpty(t, listIdentities.NextPageToken) - require.GreaterOrEqual(t, listIdentities.TotalSize, int32(3)) + require.Len(t, listIdentities.GetIdentities(), 2) + require.NotEmpty(t, listIdentities.GetNextPageToken()) + require.GreaterOrEqual(t, listIdentities.GetTotalSize(), int32(3)) nextIdentities, err := aiCli.ListIdentities(ctx, &api.ListIdentitiesRequest{ - PageSize: 2, PageToken: listIdentities.NextPageToken, + PageSize: 2, PageToken: listIdentities.GetNextPageToken(), }) t.Logf("nextIdentities, err: %+v, %v", nextIdentities, err) require.NoError(t, err) - require.GreaterOrEqual(t, len(nextIdentities.Identities), 1) - require.GreaterOrEqual(t, nextIdentities.TotalSize, int32(3)) + require.GreaterOrEqual(t, len(nextIdentities.GetIdentities()), 1) + require.GreaterOrEqual(t, nextIdentities.GetTotalSize(), int32(3)) }) t.Run("List identities with app filter", func(t *testing.T) { @@ -1853,16 +1853,16 @@ func TestListIdentities(t *testing.T) { aiCli := api.NewAppIdentityServiceClient(globalAdminGRPCConn) listIdentities, err := aiCli.ListIdentities(ctx, - &api.ListIdentitiesRequest{AppId: createApp.Id}) + &api.ListIdentitiesRequest{AppId: createApp.GetId()}) t.Logf("listIdentities, err: %+v, %v", listIdentities, err) require.NoError(t, err) - require.Len(t, listIdentities.Identities, 3) - require.Equal(t, int32(3), listIdentities.TotalSize) + require.Len(t, listIdentities.GetIdentities(), 3) + require.Equal(t, int32(3), listIdentities.GetTotalSize()) var found bool - for _, identity := range listIdentities.Identities { - if identity.Id == identityIDs[len(identityIDs)-1] && - identity.Comment == identityComments[len(identityComments)-1] { + for _, identity := range listIdentities.GetIdentities() { + if identity.GetId() == identityIDs[len(identityIDs)-1] && + identity.GetComment() == identityComments[len(identityComments)-1] { found = true } } @@ -1880,8 +1880,8 @@ func TestListIdentities(t *testing.T) { &api.ListIdentitiesRequest{}) t.Logf("listIdentities, err: %+v, %v", listIdentities, err) require.NoError(t, err) - require.Len(t, listIdentities.Identities, 0) - require.Equal(t, int32(0), listIdentities.TotalSize) + require.Len(t, listIdentities.GetIdentities(), 0) + require.Equal(t, int32(0), listIdentities.GetTotalSize()) }) t.Run("List identities by invalid page token", func(t *testing.T) { diff --git a/internal/hermes-api/test/org_test.go b/internal/hermes-api/test/org_test.go index 23745c1a..7b478ee5 100644 --- a/internal/hermes-api/test/org_test.go +++ b/internal/hermes-api/test/org_test.go @@ -32,11 +32,11 @@ func TestCreateOrg(t *testing.T) { &api.CreateOrgRequest{Org: org}) t.Logf("createOrg, err: %+v, %v", createOrg, err) require.NoError(t, err) - require.NotEqual(t, org.Id, createOrg.Id) - require.Equal(t, org.Name, createOrg.Name) - require.WithinDuration(t, time.Now(), createOrg.CreatedAt.AsTime(), + require.NotEqual(t, org.GetId(), createOrg.GetId()) + require.Equal(t, org.GetName(), createOrg.GetName()) + require.WithinDuration(t, time.Now(), createOrg.GetCreatedAt().AsTime(), 2*time.Second) - require.WithinDuration(t, time.Now(), createOrg.UpdatedAt.AsTime(), + require.WithinDuration(t, time.Now(), createOrg.GetUpdatedAt().AsTime(), 2*time.Second) }) @@ -44,7 +44,7 @@ func TestCreateOrg(t *testing.T) { t.Parallel() org := random.Org("api-org") - org.Name = strings.ToUpper(org.Name) + org.Name = strings.ToUpper(org.GetName()) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() @@ -54,11 +54,11 @@ func TestCreateOrg(t *testing.T) { &api.CreateOrgRequest{Org: org}) t.Logf("createOrg, err: %+v, %v", createOrg, err) require.NoError(t, err) - require.NotEqual(t, org.Id, createOrg.Id) - require.Equal(t, strings.ToLower(org.Name), createOrg.Name) - require.WithinDuration(t, time.Now(), createOrg.CreatedAt.AsTime(), + require.NotEqual(t, org.GetId(), createOrg.GetId()) + require.Equal(t, strings.ToLower(org.GetName()), createOrg.GetName()) + require.WithinDuration(t, time.Now(), createOrg.GetCreatedAt().AsTime(), 2*time.Second) - require.WithinDuration(t, time.Now(), createOrg.UpdatedAt.AsTime(), + require.WithinDuration(t, time.Now(), createOrg.GetUpdatedAt().AsTime(), 2*time.Second) }) @@ -117,7 +117,7 @@ func TestGetOrg(t *testing.T) { defer cancel() orgCli := api.NewOrgServiceClient(secondarySysAdminGRPCConn) - getOrg, err := orgCli.GetOrg(ctx, &api.GetOrgRequest{Id: createOrg.Id}) + getOrg, err := orgCli.GetOrg(ctx, &api.GetOrgRequest{Id: createOrg.GetId()}) t.Logf("getOrg, err: %+v, %v", getOrg, err) require.NoError(t, err) @@ -136,7 +136,7 @@ func TestGetOrg(t *testing.T) { orgCli := api.NewOrgServiceClient(globalAdminGRPCConn) getOrg, err := orgCli.GetOrg(ctx, - &api.GetOrgRequest{Id: createOrg.Id}) + &api.GetOrgRequest{Id: createOrg.GetId()}) t.Logf("getOrg, err: %+v, %v", getOrg, err) require.Nil(t, getOrg) require.EqualError(t, err, "rpc error: code = PermissionDenied desc = "+ @@ -183,16 +183,16 @@ func TestUpdateOrg(t *testing.T) { &api.UpdateOrgRequest{Org: createOrg}) t.Logf("updateOrg, err: %+v, %v", updateOrg, err) require.NoError(t, err) - require.Equal(t, createOrg.Name, updateOrg.Name) - require.Equal(t, createOrg.Status, updateOrg.Status) - require.Equal(t, createOrg.Plan, updateOrg.Plan) - require.True(t, updateOrg.UpdatedAt.AsTime().After( - updateOrg.CreatedAt.AsTime())) - require.WithinDuration(t, createOrg.CreatedAt.AsTime(), - updateOrg.UpdatedAt.AsTime(), 2*time.Second) + require.Equal(t, createOrg.GetName(), updateOrg.GetName()) + require.Equal(t, createOrg.GetStatus(), updateOrg.GetStatus()) + require.Equal(t, createOrg.GetPlan(), updateOrg.GetPlan()) + require.True(t, updateOrg.GetUpdatedAt().AsTime().After( + updateOrg.GetCreatedAt().AsTime())) + require.WithinDuration(t, createOrg.GetCreatedAt().AsTime(), + updateOrg.GetUpdatedAt().AsTime(), 2*time.Second) getOrg, err := orgCli.GetOrg(ctx, - &api.GetOrgRequest{Id: createOrg.Id}) + &api.GetOrgRequest{Id: createOrg.GetId()}) t.Logf("getOrg, err: %+v, %v", getOrg, err) require.NoError(t, err) @@ -217,7 +217,7 @@ func TestUpdateOrg(t *testing.T) { // Update org fields. part := &api.Org{ - Id: createOrg.Id, Name: "api-org-" + random.String(10), + Id: createOrg.GetId(), Name: "api-org-" + random.String(10), Status: api.Status_DISABLED, } @@ -228,14 +228,14 @@ func TestUpdateOrg(t *testing.T) { }) t.Logf("updateOrg, err: %+v, %v", updateOrg, err) require.NoError(t, err) - require.Equal(t, part.Name, updateOrg.Name) - require.Equal(t, part.Status, updateOrg.Status) - require.True(t, updateOrg.UpdatedAt.AsTime().After( - updateOrg.CreatedAt.AsTime())) - require.WithinDuration(t, createOrg.CreatedAt.AsTime(), - updateOrg.UpdatedAt.AsTime(), 2*time.Second) - - getOrg, err := orgCli.GetOrg(ctx, &api.GetOrgRequest{Id: createOrg.Id}) + require.Equal(t, part.GetName(), updateOrg.GetName()) + require.Equal(t, part.GetStatus(), updateOrg.GetStatus()) + require.True(t, updateOrg.GetUpdatedAt().AsTime().After( + updateOrg.GetCreatedAt().AsTime())) + require.WithinDuration(t, createOrg.GetCreatedAt().AsTime(), + updateOrg.GetUpdatedAt().AsTime(), 2*time.Second) + + getOrg, err := orgCli.GetOrg(ctx, &api.GetOrgRequest{Id: createOrg.GetId()}) t.Logf("getOrg, err: %+v, %v", getOrg, err) require.NoError(t, err) @@ -268,7 +268,7 @@ func TestUpdateOrg(t *testing.T) { }) t.Logf("updateOrg, err: %+v, %v", updateOrg, err) require.NoError(t, err) - require.Equal(t, part.Status, updateOrg.Status) + require.Equal(t, part.GetStatus(), updateOrg.GetStatus()) updateOrg, err = orgCli.UpdateOrg(ctx, &api.UpdateOrgRequest{ Org: part, UpdateMask: &fieldmaskpb.FieldMask{ @@ -402,7 +402,7 @@ func TestDeleteOrg(t *testing.T) { t.Logf("createOrg, err: %+v, %v", createOrg, err) require.NoError(t, err) - _, err = orgCli.DeleteOrg(ctx, &api.DeleteOrgRequest{Id: createOrg.Id}) + _, err = orgCli.DeleteOrg(ctx, &api.DeleteOrgRequest{Id: createOrg.GetId()}) t.Logf("err: %v", err) require.NoError(t, err) @@ -415,7 +415,7 @@ func TestDeleteOrg(t *testing.T) { orgCli := api.NewOrgServiceClient(secondarySysAdminGRPCConn) getOrg, err := orgCli.GetOrg(ctx, - &api.GetOrgRequest{Id: createOrg.Id}) + &api.GetOrgRequest{Id: createOrg.GetId()}) t.Logf("getOrg, err: %+v, %v", getOrg, err) require.Nil(t, getOrg) require.EqualError(t, err, "rpc error: code = NotFound desc = "+ @@ -468,9 +468,9 @@ func TestListOrgs(t *testing.T) { t.Logf("createOrg, err: %+v, %v", createOrg, err) require.NoError(t, err) - orgIDs = append(orgIDs, createOrg.Id) - orgNames = append(orgNames, createOrg.Name) - orgPlans = append(orgPlans, createOrg.Plan) + orgIDs = append(orgIDs, createOrg.GetId()) + orgNames = append(orgNames, createOrg.GetName()) + orgPlans = append(orgPlans, createOrg.GetPlan()) } t.Run("List orgs by valid org ID", func(t *testing.T) { @@ -484,14 +484,14 @@ func TestListOrgs(t *testing.T) { &api.ListOrgsRequest{PageSize: 250}) t.Logf("listOrgs, err: %+v, %v", listOrgs, err) require.NoError(t, err) - require.GreaterOrEqual(t, len(listOrgs.Orgs), 3) - require.GreaterOrEqual(t, listOrgs.TotalSize, int32(3)) + require.GreaterOrEqual(t, len(listOrgs.GetOrgs()), 3) + require.GreaterOrEqual(t, listOrgs.GetTotalSize(), int32(3)) var found bool - for _, org := range listOrgs.Orgs { - if org.Id == orgIDs[len(orgIDs)-1] && - org.Name == orgNames[len(orgNames)-1] && - org.Plan == orgPlans[len(orgPlans)-1] { + for _, org := range listOrgs.GetOrgs() { + if org.GetId() == orgIDs[len(orgIDs)-1] && + org.GetName() == orgNames[len(orgNames)-1] && + org.GetPlan() == orgPlans[len(orgPlans)-1] { found = true } } @@ -508,17 +508,17 @@ func TestListOrgs(t *testing.T) { listOrgs, err := orgCli.ListOrgs(ctx, &api.ListOrgsRequest{PageSize: 2}) t.Logf("listOrgs, err: %+v, %v", listOrgs, err) require.NoError(t, err) - require.Len(t, listOrgs.Orgs, 2) - require.NotEmpty(t, listOrgs.NextPageToken) - require.GreaterOrEqual(t, listOrgs.TotalSize, int32(3)) + require.Len(t, listOrgs.GetOrgs(), 2) + require.NotEmpty(t, listOrgs.GetNextPageToken()) + require.GreaterOrEqual(t, listOrgs.GetTotalSize(), int32(3)) nextOrgs, err := orgCli.ListOrgs(ctx, &api.ListOrgsRequest{ - PageSize: 2, PageToken: listOrgs.NextPageToken, + PageSize: 2, PageToken: listOrgs.GetNextPageToken(), }) t.Logf("nextOrgs, err: %+v, %v", nextOrgs, err) require.NoError(t, err) - require.GreaterOrEqual(t, len(nextOrgs.Orgs), 1) - require.GreaterOrEqual(t, nextOrgs.TotalSize, int32(3)) + require.GreaterOrEqual(t, len(nextOrgs.GetOrgs()), 1) + require.GreaterOrEqual(t, nextOrgs.GetTotalSize(), int32(3)) }) t.Run("List orgs with insufficient role", func(t *testing.T) { @@ -531,8 +531,8 @@ func TestListOrgs(t *testing.T) { listOrgs, err := secCli.ListOrgs(ctx, &api.ListOrgsRequest{}) t.Logf("listOrgs, err: %+v, %v", listOrgs, err) require.NoError(t, err) - require.Len(t, listOrgs.Orgs, 1) - require.Equal(t, int32(1), listOrgs.TotalSize) + require.Len(t, listOrgs.GetOrgs(), 1) + require.Equal(t, int32(1), listOrgs.GetTotalSize()) }) t.Run("List orgs by invalid page token", func(t *testing.T) { diff --git a/internal/hermes-api/test/session_test.go b/internal/hermes-api/test/session_test.go index 91867f73..f6a96e98 100644 --- a/internal/hermes-api/test/session_test.go +++ b/internal/hermes-api/test/session_test.go @@ -30,14 +30,14 @@ func TestLogin(t *testing.T) { t.Logf("createOrg, err: %+v, %v", createOrg, err) require.NoError(t, err) - user := random.User("api-session", createOrg.Id) + user := random.User("api-session", createOrg.GetId()) user.Role = api.Role_ADMIN user.Status = api.Status_ACTIVE createUser, err := globalUserDAO.Create(ctx, user) t.Logf("createUser, err: %+v, %v", createUser, err) require.NoError(t, err) - err = globalUserDAO.UpdatePassword(ctx, createUser.Id, createOrg.Id, + err = globalUserDAO.UpdatePassword(ctx, createUser.GetId(), createOrg.GetId(), globalHash) t.Logf("err: %v", err) require.NoError(t, err) @@ -49,29 +49,29 @@ func TestLogin(t *testing.T) { require.NoError(t, err) createDisOrgUser, err := globalUserDAO.Create(ctx, - random.User("api-session", createDisOrg.Id)) + random.User("api-session", createDisOrg.GetId())) t.Logf("createDisOrgUser, err: %+v, %v", createDisOrgUser, err) require.NoError(t, err) - disUser := random.User("api-session", createOrg.Id) + disUser := random.User("api-session", createOrg.GetId()) disUser.Status = api.Status_DISABLED createDisUser, err := globalUserDAO.Create(ctx, disUser) t.Logf("createDisUser, err: %+v, %v", createDisUser, err) require.NoError(t, err) - err = globalUserDAO.UpdatePassword(ctx, createDisUser.Id, createOrg.Id, + err = globalUserDAO.UpdatePassword(ctx, createDisUser.GetId(), createOrg.GetId(), globalHash) t.Logf("err: %v", err) require.NoError(t, err) - unspecUser := random.User("api-session", createOrg.Id) + unspecUser := random.User("api-session", createOrg.GetId()) unspecUser.Role = api.Role_ROLE_UNSPECIFIED unspecUser.Status = api.Status_ACTIVE createUnspecUser, err := globalUserDAO.Create(ctx, unspecUser) t.Logf("createUnspecUser, err: %+v, %v", createUnspecUser, err) require.NoError(t, err) - err = globalUserDAO.UpdatePassword(ctx, createUnspecUser.Id, createOrg.Id, + err = globalUserDAO.UpdatePassword(ctx, createUnspecUser.GetId(), createOrg.GetId(), globalHash) t.Logf("err: %v", err) require.NoError(t, err) @@ -84,14 +84,14 @@ func TestLogin(t *testing.T) { sessCli := api.NewSessionServiceClient(globalNoAuthGRPCConn) login, err := sessCli.Login(ctx, &api.LoginRequest{ - Email: createUser.Email, OrgName: createOrg.Name, + Email: createUser.GetEmail(), OrgName: createOrg.GetName(), Password: globalPass, }) t.Logf("loginResp, err: %+v, %v", login, err) require.NoError(t, err) - require.Greater(t, len(login.Token), 90) + require.Greater(t, len(login.GetToken()), 90) require.WithinDuration(t, time.Now().Add( - session.WebTokenExp*time.Second), login.ExpiresAt.AsTime(), + session.WebTokenExp*time.Second), login.GetExpiresAt().AsTime(), 2*time.Second) }) @@ -103,7 +103,7 @@ func TestLogin(t *testing.T) { sessCli := api.NewSessionServiceClient(globalNoAuthGRPCConn) login, err := sessCli.Login(ctx, &api.LoginRequest{ - Email: createDisOrgUser.Email, OrgName: createDisOrg.Name, + Email: createDisOrgUser.GetEmail(), OrgName: createDisOrg.GetName(), Password: random.String(10), }) t.Logf("loginResp, err: %+v, %v", login, err) @@ -137,7 +137,7 @@ func TestLogin(t *testing.T) { sessCli := api.NewSessionServiceClient(globalNoAuthGRPCConn) login, err := sessCli.Login(ctx, &api.LoginRequest{ - Email: createUser.Email, OrgName: createOrg.Name, + Email: createUser.GetEmail(), OrgName: createOrg.GetName(), Password: random.String(10), }) t.Logf("loginResp, err: %+v, %v", login, err) @@ -154,7 +154,7 @@ func TestLogin(t *testing.T) { sessCli := api.NewSessionServiceClient(globalNoAuthGRPCConn) login, err := sessCli.Login(ctx, &api.LoginRequest{ - Email: createDisUser.Email, OrgName: createOrg.Name, + Email: createDisUser.GetEmail(), OrgName: createOrg.GetName(), Password: globalPass, }) t.Logf("loginResp, err: %+v, %v", login, err) @@ -171,7 +171,7 @@ func TestLogin(t *testing.T) { sessCli := api.NewSessionServiceClient(globalNoAuthGRPCConn) login, err := sessCli.Login(ctx, &api.LoginRequest{ - Email: createUnspecUser.Email, OrgName: createOrg.Name, + Email: createUnspecUser.GetEmail(), OrgName: createOrg.GetName(), Password: globalPass, }) t.Logf("loginResp, err: %+v, %v", login, err) @@ -198,10 +198,10 @@ func TestCreateKey(t *testing.T) { &api.CreateKeyRequest{Key: key}) t.Logf("createKey, err: %+v, %v", createKey, err) require.NoError(t, err) - require.NotEqual(t, key.Id, createKey.Key.Id) - require.WithinDuration(t, time.Now(), createKey.Key.CreatedAt.AsTime(), + require.NotEqual(t, key.GetId(), createKey.GetKey().GetId()) + require.WithinDuration(t, time.Now(), createKey.GetKey().GetCreatedAt().AsTime(), 2*time.Second) - require.NotEmpty(t, createKey.Token) + require.NotEmpty(t, createKey.GetToken()) }) t.Run("Create valid key with insufficient role", func(t *testing.T) { @@ -277,7 +277,7 @@ func TestDeleteKey(t *testing.T) { require.NoError(t, err) _, err = sessCli.DeleteKey(ctx, - &api.DeleteKeyRequest{Id: createKey.Key.Id}) + &api.DeleteKeyRequest{Id: createKey.GetKey().GetId()}) t.Logf("err: %v", err) require.NoError(t, err) @@ -290,7 +290,7 @@ func TestDeleteKey(t *testing.T) { sessCli := api.NewSessionServiceClient(globalAdminKeyGRPCConn) _, err := sessCli.DeleteKey(ctx, - &api.DeleteKeyRequest{Id: createKey.Key.Id}) + &api.DeleteKeyRequest{Id: createKey.GetKey().GetId()}) t.Logf("err: %v", err) require.EqualError(t, err, "rpc error: code = NotFound desc = "+ "object not found") @@ -317,19 +317,19 @@ func TestDeleteKey(t *testing.T) { grpc.WithBlock(), grpc.FailOnNonTempDialError(true), grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithPerRPCCredentials(&credential{token: createKey.Token}), + grpc.WithPerRPCCredentials(&credential{token: createKey.GetToken()}), } keyConn, err := grpc.Dial(iapi.GRPCHost+iapi.GRPCPort, opts...) require.NoError(t, err) sessCli = api.NewSessionServiceClient(keyConn) _, err = sessCli.DeleteKey(ctx, - &api.DeleteKeyRequest{Id: createKey.Key.Id}) + &api.DeleteKeyRequest{Id: createKey.GetKey().GetId()}) t.Logf("err: %v", err) require.NoError(t, err) _, err = sessCli.DeleteKey(ctx, - &api.DeleteKeyRequest{Id: createKey.Key.Id}) + &api.DeleteKeyRequest{Id: createKey.GetKey().GetId()}) t.Logf("err: %v", err) require.EqualError(t, err, "rpc error: code = Unauthenticated desc = "+ "unauthorized") @@ -380,7 +380,7 @@ func TestDeleteKey(t *testing.T) { secCli := api.NewSessionServiceClient(secondaryAdminGRPCConn) _, err = secCli.DeleteKey(ctx, - &api.DeleteKeyRequest{Id: createKey.Key.Id}) + &api.DeleteKeyRequest{Id: createKey.GetKey().GetId()}) t.Logf("err: %v", err) require.EqualError(t, err, "rpc error: code = NotFound desc = object "+ "not found") @@ -406,9 +406,9 @@ func TestListKeys(t *testing.T) { t.Logf("createKey, err: %+v, %v", createKey, err) require.NoError(t, err) - keyIDs = append(keyIDs, createKey.Key.Id) - keyNames = append(keyNames, createKey.Key.Name) - keyRoles = append(keyRoles, createKey.Key.Role) + keyIDs = append(keyIDs, createKey.GetKey().GetId()) + keyNames = append(keyNames, createKey.GetKey().GetName()) + keyRoles = append(keyRoles, createKey.GetKey().GetRole()) } t.Run("List keys by valid org ID", func(t *testing.T) { @@ -421,14 +421,14 @@ func TestListKeys(t *testing.T) { listKeys, err := sessCli.ListKeys(ctx, &api.ListKeysRequest{}) t.Logf("listKeys, err: %+v, %v", listKeys, err) require.NoError(t, err) - require.GreaterOrEqual(t, len(listKeys.Keys), 3) - require.GreaterOrEqual(t, listKeys.TotalSize, int32(3)) + require.GreaterOrEqual(t, len(listKeys.GetKeys()), 3) + require.GreaterOrEqual(t, listKeys.GetTotalSize(), int32(3)) var found bool - for _, key := range listKeys.Keys { - if key.Id == keyIDs[len(keyIDs)-1] && - key.Name == keyNames[len(keyNames)-1] && - key.Role == keyRoles[len(keyRoles)-1] { + for _, key := range listKeys.GetKeys() { + if key.GetId() == keyIDs[len(keyIDs)-1] && + key.GetName() == keyNames[len(keyNames)-1] && + key.GetRole() == keyRoles[len(keyRoles)-1] { found = true } } @@ -446,17 +446,17 @@ func TestListKeys(t *testing.T) { &api.ListKeysRequest{PageSize: 2}) t.Logf("listKeys, err: %+v, %v", listKeys, err) require.NoError(t, err) - require.Len(t, listKeys.Keys, 2) - require.NotEmpty(t, listKeys.NextPageToken) - require.GreaterOrEqual(t, listKeys.TotalSize, int32(3)) + require.Len(t, listKeys.GetKeys(), 2) + require.NotEmpty(t, listKeys.GetNextPageToken()) + require.GreaterOrEqual(t, listKeys.GetTotalSize(), int32(3)) nextKeys, err := sessCli.ListKeys(ctx, &api.ListKeysRequest{ - PageSize: 2, PageToken: listKeys.NextPageToken, + PageSize: 2, PageToken: listKeys.GetNextPageToken(), }) t.Logf("nextKeys, err: %+v, %v", nextKeys, err) require.NoError(t, err) - require.GreaterOrEqual(t, len(nextKeys.Keys), 1) - require.GreaterOrEqual(t, nextKeys.TotalSize, int32(3)) + require.GreaterOrEqual(t, len(nextKeys.GetKeys()), 1) + require.GreaterOrEqual(t, nextKeys.GetTotalSize(), int32(3)) }) t.Run("List keys with insufficient role", func(t *testing.T) { @@ -483,8 +483,8 @@ func TestListKeys(t *testing.T) { listKeys, err := secCli.ListKeys(ctx, &api.ListKeysRequest{}) t.Logf("listKeys, err: %+v, %v", listKeys, err) require.NoError(t, err) - require.Len(t, listKeys.Keys, 1) - require.Equal(t, int32(1), listKeys.TotalSize) + require.Len(t, listKeys.GetKeys(), 1) + require.Equal(t, int32(1), listKeys.GetTotalSize()) }) t.Run("List keys by invalid page token", func(t *testing.T) { diff --git a/internal/hermes-api/test/user_test.go b/internal/hermes-api/test/user_test.go index 59dd1f2a..6e208e71 100644 --- a/internal/hermes-api/test/user_test.go +++ b/internal/hermes-api/test/user_test.go @@ -33,10 +33,10 @@ func TestCreateUser(t *testing.T) { &api.CreateUserRequest{User: user}) t.Logf("createUser, err: %+v, %v", createUser, err) require.NoError(t, err) - require.NotEqual(t, user.Id, createUser.Id) - require.WithinDuration(t, time.Now(), createUser.CreatedAt.AsTime(), + require.NotEqual(t, user.GetId(), createUser.GetId()) + require.WithinDuration(t, time.Now(), createUser.GetCreatedAt().AsTime(), 2*time.Second) - require.WithinDuration(t, time.Now(), createUser.UpdatedAt.AsTime(), + require.WithinDuration(t, time.Now(), createUser.GetUpdatedAt().AsTime(), 2*time.Second) }) @@ -118,7 +118,7 @@ func TestGetUser(t *testing.T) { userCli := api.NewUserServiceClient(globalAdminGRPCConn) getUser, err := userCli.GetUser(ctx, - &api.GetUserRequest{Id: createUser.Id}) + &api.GetUserRequest{Id: createUser.GetId()}) t.Logf("getUser, err: %+v, %v", getUser, err) require.NoError(t, err) @@ -137,7 +137,7 @@ func TestGetUser(t *testing.T) { userCli := api.NewUserServiceClient(secondaryViewerGRPCConn) getUser, err := userCli.GetUser(ctx, - &api.GetUserRequest{Id: createUser.Id}) + &api.GetUserRequest{Id: createUser.GetId()}) t.Logf("getUser, err: %+v, %v", getUser, err) require.Nil(t, getUser) require.EqualError(t, err, "rpc error: code = PermissionDenied desc = "+ @@ -152,7 +152,7 @@ func TestGetUser(t *testing.T) { userCli := api.NewUserServiceClient(secondaryViewerKeyGRPCConn) getUser, err := userCli.GetUser(ctx, - &api.GetUserRequest{Id: createUser.Id}) + &api.GetUserRequest{Id: createUser.GetId()}) t.Logf("getUser, err: %+v, %v", getUser, err) require.Nil(t, getUser) require.EqualError(t, err, "rpc error: code = PermissionDenied desc = "+ @@ -182,7 +182,7 @@ func TestGetUser(t *testing.T) { secCli := api.NewUserServiceClient(secondaryAdminGRPCConn) getUser, err := secCli.GetUser(ctx, - &api.GetUserRequest{Id: createUser.Id}) + &api.GetUserRequest{Id: createUser.GetId()}) t.Logf("getUser, err: %+v, %v", getUser, err) require.Nil(t, getUser) require.EqualError(t, err, "rpc error: code = NotFound desc = object "+ @@ -218,17 +218,17 @@ func TestUpdateUser(t *testing.T) { &api.UpdateUserRequest{User: createUser}) t.Logf("updateUser, err: %+v, %v", updateUser, err) require.NoError(t, err) - require.Equal(t, createUser.Name, updateUser.Name) - require.Equal(t, createUser.Email, updateUser.Email) - require.Equal(t, createUser.Role, updateUser.Role) - require.Equal(t, createUser.Status, updateUser.Status) - require.True(t, updateUser.UpdatedAt.AsTime().After( - updateUser.CreatedAt.AsTime())) - require.WithinDuration(t, createUser.CreatedAt.AsTime(), - updateUser.UpdatedAt.AsTime(), 2*time.Second) + require.Equal(t, createUser.GetName(), updateUser.GetName()) + require.Equal(t, createUser.GetEmail(), updateUser.GetEmail()) + require.Equal(t, createUser.GetRole(), updateUser.GetRole()) + require.Equal(t, createUser.GetStatus(), updateUser.GetStatus()) + require.True(t, updateUser.GetUpdatedAt().AsTime().After( + updateUser.GetCreatedAt().AsTime())) + require.WithinDuration(t, createUser.GetCreatedAt().AsTime(), + updateUser.GetUpdatedAt().AsTime(), 2*time.Second) getUser, err := userCli.GetUser(ctx, - &api.GetUserRequest{Id: createUser.Id}) + &api.GetUserRequest{Id: createUser.GetId()}) t.Logf("getUser, err: %+v, %v", getUser, err) require.NoError(t, err) @@ -256,7 +256,7 @@ func TestUpdateUser(t *testing.T) { // Update user fields. part := &api.User{ - Id: createUser.Id, Name: "api-user-" + random.String(10), + Id: createUser.GetId(), Name: "api-user-" + random.String(10), Email: "api-user-" + random.Email(), Role: api.Role_ADMIN, Status: api.Status_DISABLED, } @@ -268,17 +268,17 @@ func TestUpdateUser(t *testing.T) { }) t.Logf("updateUser, err: %+v, %v", updateUser, err) require.NoError(t, err) - require.Equal(t, part.Name, updateUser.Name) - require.Equal(t, part.Email, updateUser.Email) - require.Equal(t, part.Role, updateUser.Role) - require.Equal(t, part.Status, updateUser.Status) - require.True(t, updateUser.UpdatedAt.AsTime().After( - updateUser.CreatedAt.AsTime())) - require.WithinDuration(t, createUser.CreatedAt.AsTime(), - updateUser.UpdatedAt.AsTime(), 2*time.Second) + require.Equal(t, part.GetName(), updateUser.GetName()) + require.Equal(t, part.GetEmail(), updateUser.GetEmail()) + require.Equal(t, part.GetRole(), updateUser.GetRole()) + require.Equal(t, part.GetStatus(), updateUser.GetStatus()) + require.True(t, updateUser.GetUpdatedAt().AsTime().After( + updateUser.GetCreatedAt().AsTime())) + require.WithinDuration(t, createUser.GetCreatedAt().AsTime(), + updateUser.GetUpdatedAt().AsTime(), 2*time.Second) getUser, err := userCli.GetUser(ctx, - &api.GetUserRequest{Id: createUser.Id}) + &api.GetUserRequest{Id: createUser.GetId()}) t.Logf("getUser, err: %+v, %v", getUser, err) require.NoError(t, err) @@ -525,7 +525,7 @@ func TestUpdateUserPassword(t *testing.T) { require.NoError(t, err) _, err = userCli.UpdateUserPassword(ctx, &api.UpdateUserPasswordRequest{ - Id: createUser.Id, Password: random.String(20), + Id: createUser.GetId(), Password: random.String(20), }) t.Logf("err: %v", err) require.NoError(t, err) @@ -579,7 +579,7 @@ func TestUpdateUserPassword(t *testing.T) { require.NoError(t, err) _, err = userCli.UpdateUserPassword(ctx, &api.UpdateUserPasswordRequest{ - Id: createUser.Id, Password: "1234567890", + Id: createUser.GetId(), Password: "1234567890", }) t.Logf("err: %v", err) require.EqualError(t, err, "rpc error: code = InvalidArgument desc = "+ @@ -619,7 +619,7 @@ func TestUpdateUserPassword(t *testing.T) { secCli := api.NewUserServiceClient(secondaryAdminGRPCConn) _, err = secCli.UpdateUserPassword(ctx, &api.UpdateUserPasswordRequest{ - Id: createUser.Id, Password: random.String(20), + Id: createUser.GetId(), Password: random.String(20), }) t.Logf("err: %v", err) require.EqualError(t, err, "rpc error: code = NotFound desc = object "+ @@ -646,7 +646,7 @@ func TestDeleteUser(t *testing.T) { require.NoError(t, err) _, err = userCli.DeleteUser(ctx, - &api.DeleteUserRequest{Id: createUser.Id}) + &api.DeleteUserRequest{Id: createUser.GetId()}) t.Logf("err: %v", err) require.NoError(t, err) @@ -659,7 +659,7 @@ func TestDeleteUser(t *testing.T) { userCli := api.NewUserServiceClient(globalAdminKeyGRPCConn) getUser, err := userCli.GetUser(ctx, - &api.GetUserRequest{Id: createUser.Id}) + &api.GetUserRequest{Id: createUser.GetId()}) t.Logf("getUser, err: %+v, %v", getUser, err) require.Nil(t, getUser) require.EqualError(t, err, "rpc error: code = NotFound desc = "+ @@ -712,7 +712,7 @@ func TestDeleteUser(t *testing.T) { secCli := api.NewUserServiceClient(secondaryAdminGRPCConn) _, err = secCli.DeleteUser(ctx, - &api.DeleteUserRequest{Id: createUser.Id}) + &api.DeleteUserRequest{Id: createUser.GetId()}) t.Logf("err: %v", err) require.EqualError(t, err, "rpc error: code = NotFound desc = object "+ "not found") @@ -739,10 +739,10 @@ func TestListUsers(t *testing.T) { t.Logf("createUser, err: %+v, %v", createUser, err) require.NoError(t, err) - userIDs = append(userIDs, createUser.Id) - userNames = append(userNames, createUser.Name) - userRoles = append(userRoles, createUser.Role) - userStatuses = append(userStatuses, createUser.Status) + userIDs = append(userIDs, createUser.GetId()) + userNames = append(userNames, createUser.GetName()) + userRoles = append(userRoles, createUser.GetRole()) + userStatuses = append(userStatuses, createUser.GetStatus()) } t.Run("List users by valid org ID", func(t *testing.T) { @@ -755,15 +755,15 @@ func TestListUsers(t *testing.T) { listUsers, err := userCli.ListUsers(ctx, &api.ListUsersRequest{}) t.Logf("listUsers, err: %+v, %v", listUsers, err) require.NoError(t, err) - require.GreaterOrEqual(t, len(listUsers.Users), 3) - require.GreaterOrEqual(t, listUsers.TotalSize, int32(3)) + require.GreaterOrEqual(t, len(listUsers.GetUsers()), 3) + require.GreaterOrEqual(t, listUsers.GetTotalSize(), int32(3)) var found bool - for _, user := range listUsers.Users { - if user.Id == userIDs[len(userIDs)-1] && - user.Name == userNames[len(userNames)-1] && - user.Role == userRoles[len(userRoles)-1] && - user.Status == userStatuses[len(userStatuses)-1] { + for _, user := range listUsers.GetUsers() { + if user.GetId() == userIDs[len(userIDs)-1] && + user.GetName() == userNames[len(userNames)-1] && + user.GetRole() == userRoles[len(userRoles)-1] && + user.GetStatus() == userStatuses[len(userStatuses)-1] { found = true } } @@ -781,17 +781,17 @@ func TestListUsers(t *testing.T) { &api.ListUsersRequest{PageSize: 2}) t.Logf("listUsers, err: %+v, %v", listUsers, err) require.NoError(t, err) - require.Len(t, listUsers.Users, 2) - require.NotEmpty(t, listUsers.NextPageToken) - require.GreaterOrEqual(t, listUsers.TotalSize, int32(3)) + require.Len(t, listUsers.GetUsers(), 2) + require.NotEmpty(t, listUsers.GetNextPageToken()) + require.GreaterOrEqual(t, listUsers.GetTotalSize(), int32(3)) nextUsers, err := userCli.ListUsers(ctx, &api.ListUsersRequest{ - PageSize: 2, PageToken: listUsers.NextPageToken, + PageSize: 2, PageToken: listUsers.GetNextPageToken(), }) t.Logf("nextUsers, err: %+v, %v", nextUsers, err) require.NoError(t, err) - require.GreaterOrEqual(t, len(nextUsers.Users), 1) - require.GreaterOrEqual(t, nextUsers.TotalSize, int32(3)) + require.GreaterOrEqual(t, len(nextUsers.GetUsers()), 1) + require.GreaterOrEqual(t, nextUsers.GetTotalSize(), int32(3)) }) t.Run("List no users by key role", func(t *testing.T) { @@ -804,8 +804,8 @@ func TestListUsers(t *testing.T) { listUsers, err := secCli.ListUsers(ctx, &api.ListUsersRequest{}) t.Logf("listUsers, err: %+v, %v", listUsers, err) require.NoError(t, err) - require.Len(t, listUsers.Users, 0) - require.Equal(t, int32(0), listUsers.TotalSize) + require.Len(t, listUsers.GetUsers(), 0) + require.Equal(t, int32(0), listUsers.GetTotalSize()) }) t.Run("List own user with non-admin role", func(t *testing.T) { @@ -818,8 +818,8 @@ func TestListUsers(t *testing.T) { listUsers, err := secCli.ListUsers(ctx, &api.ListUsersRequest{}) t.Logf("listUsers, err: %+v, %v", listUsers, err) require.NoError(t, err) - require.Len(t, listUsers.Users, 1) - require.Equal(t, int32(1), listUsers.TotalSize) + require.Len(t, listUsers.GetUsers(), 1) + require.Equal(t, int32(1), listUsers.GetTotalSize()) }) t.Run("Lists are isolated by org ID", func(t *testing.T) { @@ -832,8 +832,8 @@ func TestListUsers(t *testing.T) { listUsers, err := secCli.ListUsers(ctx, &api.ListUsersRequest{}) t.Logf("listUsers, err: %+v, %v", listUsers, err) require.NoError(t, err) - require.Len(t, listUsers.Users, 1) - require.Equal(t, int32(1), listUsers.TotalSize) + require.Len(t, listUsers.GetUsers(), 1) + require.Equal(t, int32(1), listUsers.GetTotalSize()) }) t.Run("List users by invalid page token", func(t *testing.T) { diff --git a/internal/hermes-notifier/notifier/notify.go b/internal/hermes-notifier/notifier/notify.go index 2b797d6f..decccbb4 100644 --- a/internal/hermes-notifier/notifier/notify.go +++ b/internal/hermes-notifier/notifier/notify.go @@ -46,19 +46,19 @@ func (not *Notifier) notifyMessages() { // Trace IDs have been authenticated and are safe to copy. var traceID uuid.UUID - copy(traceID[:], nIn.TraceId) + copy(traceID[:], nIn.GetTraceId()) // Set up logging fields. logger := hlog. WithField("traceID", traceID.String()). - WithField("orgID", nIn.OrgId). - WithField("appID", nIn.AppId). - WithField("identityID", nIn.IdentityId) + WithField("orgID", nIn.GetOrgId()). + WithField("appID", nIn.GetAppId()). + WithField("identityID", nIn.GetIdentityId()) // Retrieve identity. ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - identity, otp, err := not.identDAO.Read(ctx, nIn.IdentityId, - nIn.OrgId, nIn.AppId) + identity, otp, err := not.identDAO.Read(ctx, nIn.GetIdentityId(), + nIn.GetOrgId(), nIn.GetAppId()) cancel() if err != nil { msg.Requeue() @@ -74,8 +74,8 @@ func (not *Notifier) notifyMessages() { // successful verifications. var counter int64 ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second) - counter, err = not.cache.Incr(ctx, key.HOTPCounter(identity.OrgId, - identity.AppId, identity.Id)) + counter, err = not.cache.Incr(ctx, key.HOTPCounter(identity.GetOrgId(), + identity.GetAppId(), identity.GetId())) cancel() if err != nil { msg.Requeue() @@ -97,7 +97,7 @@ func (not *Notifier) notifyMessages() { // Retrieve app. ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second) - app, err := not.appDAO.Read(ctx, nIn.AppId, nIn.OrgId) + app, err := not.appDAO.Read(ctx, nIn.GetAppId(), nIn.GetOrgId()) cancel() if err != nil { msg.Requeue() @@ -112,9 +112,9 @@ func (not *Notifier) notifyMessages() { // event is non-fatal, but should be logged for investigation. writeEvent := func(status api.EventStatus, err string) { event := &api.Event{ - OrgId: nIn.OrgId, - AppId: nIn.AppId, - IdentityId: nIn.IdentityId, + OrgId: nIn.GetOrgId(), + AppId: nIn.GetAppId(), + IdentityId: nIn.GetIdentityId(), Status: status, Error: err, TraceId: traceID.String(), @@ -142,13 +142,13 @@ func (not *Notifier) notifyMessages() { // Set the passcode expiration. It is not necessary to check for // collisions here, but if one was found, that would be notable. expire := smsPushoverExpire - if _, ok := identity.MethodOneof.(*api.Identity_EmailMethod); ok { + if _, ok := identity.GetMethodOneof().(*api.Identity_EmailMethod); ok { expire = emailExpire } ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second) - ok, err := not.cache.SetIfNotExistTTL(ctx, key.Expire(identity.OrgId, - identity.AppId, identity.Id, passcode), 1, expire) + ok, err := not.cache.SetIfNotExistTTL(ctx, key.Expire(identity.GetOrgId(), + identity.GetAppId(), identity.GetId(), passcode), 1, expire) cancel() if err != nil || !ok { msg.Requeue() @@ -161,21 +161,21 @@ func (not *Notifier) notifyMessages() { // Send notification. ctx, cancel = context.WithTimeout(context.Background(), time.Minute) - switch m := identity.MethodOneof.(type) { + switch m := identity.GetMethodOneof().(type) { case *api.Identity_SmsMethod: - err = not.notify.SMS(ctx, m.SmsMethod.Phone, app.DisplayName, + err = not.notify.SMS(ctx, m.SmsMethod.GetPhone(), app.GetDisplayName(), passcode) case *api.Identity_PushoverMethod: - if app.PushoverKey == "" { - err = not.notify.Pushover(ctx, m.PushoverMethod.PushoverKey, - app.DisplayName, passcode) + if app.GetPushoverKey() == "" { + err = not.notify.Pushover(ctx, m.PushoverMethod.GetPushoverKey(), + app.GetDisplayName(), passcode) } else { - err = not.notify.PushoverByApp(ctx, app.PushoverKey, - m.PushoverMethod.PushoverKey, subj, body) + err = not.notify.PushoverByApp(ctx, app.GetPushoverKey(), + m.PushoverMethod.GetPushoverKey(), subj, body) } case *api.Identity_EmailMethod: - err = not.notify.Email(ctx, app.DisplayName, app.Email, - m.EmailMethod.Email, subj, body, htmlBody) + err = not.notify.Email(ctx, app.GetDisplayName(), app.GetEmail(), + m.EmailMethod.GetEmail(), subj, body, htmlBody) } cancel() if err != nil { @@ -203,24 +203,24 @@ func (not *Notifier) notifyMessages() { func genTemplates(app *api.App, passcode string) ( string, string, string, error, ) { - subj, err := template.Generate(app.DisplayName, passcode, - app.SubjectTemplate) + subj, err := template.Generate(app.GetDisplayName(), passcode, + app.GetSubjectTemplate()) if err != nil { metric.Incr("error", map[string]string{"func": "gensubject"}) return "", "", "", err } - body, err := template.Generate(app.DisplayName, passcode, - app.TextBodyTemplate) + body, err := template.Generate(app.GetDisplayName(), passcode, + app.GetTextBodyTemplate()) if err != nil { metric.Incr("error", map[string]string{"func": "genbody"}) return "", "", "", err } - htmlBody, err := template.Generate(app.DisplayName, passcode, - string(app.HtmlBodyTemplate)) + htmlBody, err := template.Generate(app.GetDisplayName(), passcode, + string(app.GetHtmlBodyTemplate())) if err != nil { metric.Incr("error", map[string]string{"func": "genhtmlbody"}) diff --git a/internal/hermes-notifier/notifier/notify_test.go b/internal/hermes-notifier/notifier/notify_test.go index 8b661416..41ce610b 100644 --- a/internal/hermes-notifier/notifier/notify_test.go +++ b/internal/hermes-notifier/notifier/notify_test.go @@ -32,14 +32,14 @@ func TestNotifyMessages(t *testing.T) { app := random.App("not", uuid.NewString()) app.PushoverKey = "" - smsIdentity := random.SMSIdentity("not", app.OrgId, app.Id) - pushoverIdentity := random.PushoverIdentity("not", app.OrgId, app.Id) - emailIdentity := random.EmailIdentity("not", app.OrgId, app.Id) + smsIdentity := random.SMSIdentity("not", app.GetOrgId(), app.GetId()) + pushoverIdentity := random.PushoverIdentity("not", app.GetOrgId(), app.GetId()) + emailIdentity := random.EmailIdentity("not", app.GetOrgId(), app.GetId()) traceID := uuid.New() appByKey := random.App("not", uuid.NewString()) appByKey.PushoverKey = random.String(30) - identityByKey := random.PushoverIdentity("not", appByKey.OrgId, appByKey.Id) + identityByKey := random.PushoverIdentity("not", appByKey.GetOrgId(), appByKey.GetId()) knownKey, err := hex.DecodeString("b76c5da0d71b5646ed38b483532cded2622d07" + "2a5d175030b6540169b7380d58") @@ -57,25 +57,25 @@ func TestNotifyMessages(t *testing.T) { }{ { &message.NotifierIn{ - OrgId: app.OrgId, AppId: app.Id, IdentityId: smsIdentity.Id, + OrgId: app.GetOrgId(), AppId: app.GetId(), IdentityId: smsIdentity.GetId(), TraceId: traceID[:], }, app, smsIdentity, smsPushoverExpire, 1, 0, 0, 0, }, { &message.NotifierIn{ - OrgId: app.OrgId, AppId: app.Id, - IdentityId: pushoverIdentity.Id, TraceId: traceID[:], + OrgId: app.GetOrgId(), AppId: app.GetId(), + IdentityId: pushoverIdentity.GetId(), TraceId: traceID[:], }, app, pushoverIdentity, smsPushoverExpire, 0, 1, 0, 0, }, { &message.NotifierIn{ - OrgId: appByKey.OrgId, AppId: appByKey.Id, - IdentityId: identityByKey.Id, TraceId: traceID[:], + OrgId: appByKey.GetOrgId(), AppId: appByKey.GetId(), + IdentityId: identityByKey.GetId(), TraceId: traceID[:], }, appByKey, identityByKey, smsPushoverExpire, 0, 0, 1, 0, }, { &message.NotifierIn{ - OrgId: app.OrgId, AppId: app.Id, IdentityId: emailIdentity.Id, + OrgId: app.GetOrgId(), AppId: app.GetId(), IdentityId: emailIdentity.GetId(), TraceId: traceID[:], }, app, emailIdentity, emailExpire, 0, 0, 0, 1, }, @@ -101,36 +101,36 @@ func TestNotifyMessages(t *testing.T) { ctrl := gomock.NewController(t) identityer := NewMockidentityer(ctrl) - identityer.EXPECT().Read(gomock.Any(), lTest.inpNIn.IdentityId, - lTest.inpNIn.OrgId, lTest.inpNIn.AppId). + identityer.EXPECT().Read(gomock.Any(), lTest.inpNIn.GetIdentityId(), + lTest.inpNIn.GetOrgId(), lTest.inpNIn.GetAppId()). Return(lTest.inpIdentity, otp, nil).Times(1) cacher := cache.NewMockCacher(ctrl) cacher.EXPECT().Incr(gomock.Any(), key.HOTPCounter( - lTest.inpNIn.OrgId, lTest.inpNIn.AppId, - lTest.inpNIn.IdentityId)).Return(int64(5), nil).Times(1) + lTest.inpNIn.GetOrgId(), lTest.inpNIn.GetAppId(), + lTest.inpNIn.GetIdentityId())).Return(int64(5), nil).Times(1) cacher.EXPECT().SetIfNotExistTTL(gomock.Any(), key.Expire( - lTest.inpNIn.OrgId, lTest.inpNIn.AppId, lTest.inpNIn.IdentityId, + lTest.inpNIn.GetOrgId(), lTest.inpNIn.GetAppId(), lTest.inpNIn.GetIdentityId(), "861821"), 1, lTest.inpExpire).Return(true, nil).Times(1) apper := NewMockapper(ctrl) - apper.EXPECT().Read(gomock.Any(), lTest.inpNIn.AppId, - lTest.inpNIn.OrgId).Return(lTest.inpApp, nil).Times(1) + apper.EXPECT().Read(gomock.Any(), lTest.inpNIn.GetAppId(), + lTest.inpNIn.GetOrgId()).Return(lTest.inpApp, nil).Times(1) notifier := notify.NewMockNotifier(ctrl) notifier.EXPECT().SMS(gomock.Any(), - smsIdentity.GetSmsMethod().Phone, lTest.inpApp.DisplayName, + smsIdentity.GetSmsMethod().GetPhone(), lTest.inpApp.GetDisplayName(), "861821").Return(nil).Times(lTest.inpSMSTimes) notifier.EXPECT().Pushover(gomock.Any(), - pushoverIdentity.GetPushoverMethod().PushoverKey, - lTest.inpApp.DisplayName, "861821").Return(nil). + pushoverIdentity.GetPushoverMethod().GetPushoverKey(), + lTest.inpApp.GetDisplayName(), "861821").Return(nil). Times(lTest.inpPushoverTimes) notifier.EXPECT().PushoverByApp(gomock.Any(), - lTest.inpApp.PushoverKey, - identityByKey.GetPushoverMethod().PushoverKey, gomock.Any(), + lTest.inpApp.GetPushoverKey(), + identityByKey.GetPushoverMethod().GetPushoverKey(), gomock.Any(), gomock.Any()).Return(nil).Times(lTest.inpPushoverByAppTimes) - notifier.EXPECT().Email(gomock.Any(), lTest.inpApp.DisplayName, - lTest.inpApp.Email, emailIdentity.GetEmailMethod().Email, + notifier.EXPECT().Email(gomock.Any(), lTest.inpApp.GetDisplayName(), + lTest.inpApp.GetEmail(), emailIdentity.GetEmailMethod().GetEmail(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil). Times(lTest.inpEmailTimes) @@ -172,9 +172,9 @@ func TestNotifyMessagesError(t *testing.T) { app := random.App("not", uuid.NewString()) app.PushoverKey = "" - smsIdentity := random.SMSIdentity("not", app.OrgId, app.Id) - pushoverIdentity := random.PushoverIdentity("not", app.OrgId, app.Id) - emailIdentity := random.EmailIdentity("not", app.OrgId, app.Id) + smsIdentity := random.SMSIdentity("not", app.GetOrgId(), app.GetId()) + pushoverIdentity := random.PushoverIdentity("not", app.GetOrgId(), app.GetId()) + emailIdentity := random.EmailIdentity("not", app.GetOrgId(), app.GetId()) badTemplApp := random.App("not", uuid.NewString()) badTemplApp.SubjectTemplate = `{{if` @@ -295,7 +295,7 @@ func TestNotifyMessagesError(t *testing.T) { notifier := notify.NewMockNotifier(ctrl) notifier.EXPECT().SMS(gomock.Any(), - smsIdentity.GetSmsMethod().Phone, app.DisplayName, "861821"). + smsIdentity.GetSmsMethod().GetPhone(), app.GetDisplayName(), "861821"). DoAndReturn(func( ctx interface{}, phone interface{}, displayName interface{}, passcode interface{}, @@ -305,8 +305,8 @@ func TestNotifyMessagesError(t *testing.T) { return lTest.inpSMSErr }).Times(lTest.inpSMSTimes) notifier.EXPECT().Pushover(gomock.Any(), - pushoverIdentity.GetPushoverMethod().PushoverKey, - app.DisplayName, "861821").DoAndReturn(func( + pushoverIdentity.GetPushoverMethod().GetPushoverKey(), + app.GetDisplayName(), "861821").DoAndReturn(func( ctx interface{}, userKey interface{}, displayName interface{}, passcode interface{}, ) error { @@ -314,8 +314,8 @@ func TestNotifyMessagesError(t *testing.T) { return lTest.inpPushoverErr }).Times(lTest.inpPushoverTimes) - notifier.EXPECT().Email(gomock.Any(), app.DisplayName, app.Email, - emailIdentity.GetEmailMethod().Email, gomock.Any(), + notifier.EXPECT().Email(gomock.Any(), app.GetDisplayName(), app.GetEmail(), + emailIdentity.GetEmailMethod().GetEmail(), gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(func( ctx interface{}, displayName interface{}, from interface{}, to interface{}, subject interface{}, body interface{}, diff --git a/internal/hermes-notifier/test/notifier_test.go b/internal/hermes-notifier/test/notifier_test.go index 0b9d3cda..83f1428e 100644 --- a/internal/hermes-notifier/test/notifier_test.go +++ b/internal/hermes-notifier/test/notifier_test.go @@ -31,35 +31,35 @@ func TestNotifyMessages(t *testing.T) { t.Logf("createOrg, err: %+v, %v", createOrg, err) require.NoError(t, err) - app := random.App("not", createOrg.Id) + app := random.App("not", createOrg.GetId()) app.PushoverKey = "" createApp, err := globalAppDAO.Create(ctx, app) t.Logf("createApp, err: %+v, %v", createApp, err) require.NoError(t, err) createSMSIdentity, _, _, err := globalIdentDAO.Create(ctx, - random.SMSIdentity("not", createOrg.Id, createApp.Id)) + random.SMSIdentity("not", createOrg.GetId(), createApp.GetId())) t.Logf("createSMSIdentity, err: %+v, %v", createSMSIdentity, err) require.NoError(t, err) createPushoverIdentity, _, _, err := globalIdentDAO.Create(ctx, - random.PushoverIdentity("not", createOrg.Id, createApp.Id)) + random.PushoverIdentity("not", createOrg.GetId(), createApp.GetId())) t.Logf("createPushoverIdentity, err: %+v, %v", createPushoverIdentity, err) require.NoError(t, err) createEmailIdentity, _, _, err := globalIdentDAO.Create(ctx, - random.EmailIdentity("not", createOrg.Id, createApp.Id)) + random.EmailIdentity("not", createOrg.GetId(), createApp.GetId())) t.Logf("createEmailIdentity, err: %+v, %v", createEmailIdentity, err) require.NoError(t, err) - appByKey := random.App("not", createOrg.Id) + appByKey := random.App("not", createOrg.GetId()) appByKey.PushoverKey = random.String(30) createAppByKey, err := globalAppDAO.Create(ctx, appByKey) t.Logf("createAppByKey, err: %+v, %v", createAppByKey, err) require.NoError(t, err) createIdentityByKey, _, _, err := globalIdentDAO.Create(ctx, - random.PushoverIdentity("not", createOrg.Id, createAppByKey.Id)) + random.PushoverIdentity("not", createOrg.GetId(), createAppByKey.GetId())) t.Logf("createIdentityByKey, err: %+v, %v", createIdentityByKey, err) require.NoError(t, err) @@ -68,26 +68,26 @@ func TestNotifyMessages(t *testing.T) { }{ { &message.NotifierIn{ - OrgId: createOrg.Id, AppId: createApp.Id, - IdentityId: createSMSIdentity.Id, TraceId: traceID[:], + OrgId: createOrg.GetId(), AppId: createApp.GetId(), + IdentityId: createSMSIdentity.GetId(), TraceId: traceID[:], }, }, { &message.NotifierIn{ - OrgId: createOrg.Id, AppId: createApp.Id, - IdentityId: createPushoverIdentity.Id, TraceId: traceID[:], + OrgId: createOrg.GetId(), AppId: createApp.GetId(), + IdentityId: createPushoverIdentity.GetId(), TraceId: traceID[:], }, }, { &message.NotifierIn{ - OrgId: createOrg.Id, AppId: createAppByKey.Id, - IdentityId: createIdentityByKey.Id, TraceId: traceID[:], + OrgId: createOrg.GetId(), AppId: createAppByKey.GetId(), + IdentityId: createIdentityByKey.GetId(), TraceId: traceID[:], }, }, { &message.NotifierIn{ - OrgId: createOrg.Id, AppId: createApp.Id, - IdentityId: createEmailIdentity.Id, TraceId: traceID[:], + OrgId: createOrg.GetId(), AppId: createApp.GetId(), + IdentityId: createEmailIdentity.GetId(), TraceId: traceID[:], }, }, } @@ -107,9 +107,9 @@ func TestNotifyMessages(t *testing.T) { // Verify event. event := &api.Event{ - OrgId: lTest.inp.OrgId, - AppId: lTest.inp.AppId, - IdentityId: lTest.inp.IdentityId, + OrgId: lTest.inp.GetOrgId(), + AppId: lTest.inp.GetAppId(), + IdentityId: lTest.inp.GetIdentityId(), Status: api.EventStatus_CHALLENGE_SENT, TraceId: traceID.String(), } @@ -118,16 +118,16 @@ func TestNotifyMessages(t *testing.T) { testTimeout) defer cancel() - listEvents, err := globalEvDAO.List(ctx, lTest.inp.OrgId, - lTest.inp.IdentityId, time.Now(), time.Now().Add(-testTimeout)) + listEvents, err := globalEvDAO.List(ctx, lTest.inp.GetOrgId(), + lTest.inp.GetIdentityId(), time.Now(), time.Now().Add(-testTimeout)) t.Logf("listEvents, err: %+v, %v", listEvents, err) require.NoError(t, err) require.Len(t, listEvents, 1) // Normalize timestamp. require.WithinDuration(t, time.Now(), - listEvents[0].CreatedAt.AsTime(), testTimeout) - event.CreatedAt = listEvents[0].CreatedAt + listEvents[0].GetCreatedAt().AsTime(), testTimeout) + event.CreatedAt = listEvents[0].GetCreatedAt() // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -150,11 +150,11 @@ func TestNotifyMessagesError(t *testing.T) { t.Logf("createOrg, err: %+v, %v", createOrg, err) require.NoError(t, err) - createApp, err := globalAppDAO.Create(ctx, random.App("not", createOrg.Id)) + createApp, err := globalAppDAO.Create(ctx, random.App("not", createOrg.GetId())) t.Logf("createApp, err: %+v, %v", createApp, err) require.NoError(t, err) - badOTPIdentity := random.HOTPIdentity("not", createOrg.Id, createApp.Id) + badOTPIdentity := random.HOTPIdentity("not", createOrg.GetId(), createApp.GetId()) badOTPIdentity.MethodOneof = &api.Identity_HardwareHotpMethod{ HardwareHotpMethod: &api.HardwareHOTPMethod{}, } @@ -163,7 +163,7 @@ func TestNotifyMessagesError(t *testing.T) { require.NoError(t, err) createExpIdentity, otp, _, err := globalIdentDAO.Create(ctx, - random.SMSIdentity("not", createOrg.Id, createApp.Id)) + random.SMSIdentity("not", createOrg.GetId(), createApp.GetId())) t.Logf("createExpIdentity, otp, err: %+v, %#v, %v", createExpIdentity, otp, err) require.NoError(t, err) @@ -171,19 +171,19 @@ func TestNotifyMessagesError(t *testing.T) { passcode, err := otp.HOTP(1) require.NoError(t, err) - ok, err := globalCache.SetIfNotExist(ctx, key.Expire(createOrg.Id, - createApp.Id, createExpIdentity.Id, passcode), 1) + ok, err := globalCache.SetIfNotExist(ctx, key.Expire(createOrg.GetId(), + createApp.GetId(), createExpIdentity.GetId(), passcode), 1) require.True(t, ok) require.NoError(t, err) - badTemplApp := random.App("not", createOrg.Id) + badTemplApp := random.App("not", createOrg.GetId()) badTemplApp.SubjectTemplate = `{{if` createBadTemplApp, err := globalAppDAO.Create(ctx, badTemplApp) t.Logf("createBadTemplApp, err: %+v, %v", createBadTemplApp, err) require.NoError(t, err) createBadTemplIdentity, _, _, err := globalIdentDAO.Create(ctx, - random.PushoverIdentity("not", createOrg.Id, createBadTemplApp.Id)) + random.PushoverIdentity("not", createOrg.GetId(), createBadTemplApp.GetId())) t.Logf("createBadTemplIdentity, err: %+v, %v", createBadTemplIdentity, err) require.NoError(t, err) @@ -197,22 +197,22 @@ func TestNotifyMessagesError(t *testing.T) { // OTP error. { &message.NotifierIn{ - OrgId: createOrg.Id, AppId: createApp.Id, - IdentityId: createBadOTPIdentity.Id, TraceId: traceID[:], + OrgId: createOrg.GetId(), AppId: createApp.GetId(), + IdentityId: createBadOTPIdentity.GetId(), TraceId: traceID[:], }, false, "", }, // Expiration collision. { &message.NotifierIn{ - OrgId: createOrg.Id, AppId: createApp.Id, - IdentityId: createExpIdentity.Id, TraceId: traceID[:], + OrgId: createOrg.GetId(), AppId: createApp.GetId(), + IdentityId: createExpIdentity.GetId(), TraceId: traceID[:], }, false, "", }, // Templates error. { &message.NotifierIn{ - OrgId: createOrg.Id, AppId: createBadTemplApp.Id, - IdentityId: createBadTemplIdentity.Id, TraceId: traceID[:], + OrgId: createOrg.GetId(), AppId: createBadTemplApp.GetId(), + IdentityId: createBadTemplIdentity.GetId(), TraceId: traceID[:], }, true, "template: template:1: unclosed action", }, } @@ -238,9 +238,9 @@ func TestNotifyMessagesError(t *testing.T) { // Verify event. event := &api.Event{ - OrgId: lTest.inpNIn.OrgId, - AppId: lTest.inpNIn.AppId, - IdentityId: lTest.inpNIn.IdentityId, + OrgId: lTest.inpNIn.GetOrgId(), + AppId: lTest.inpNIn.GetAppId(), + IdentityId: lTest.inpNIn.GetIdentityId(), Status: api.EventStatus_CHALLENGE_FAIL, Error: lTest.inpEventErr, TraceId: traceID.String(), @@ -250,8 +250,8 @@ func TestNotifyMessagesError(t *testing.T) { testTimeout) defer cancel() - listEvents, err := globalEvDAO.List(ctx, lTest.inpNIn.OrgId, - lTest.inpNIn.IdentityId, time.Now(), + listEvents, err := globalEvDAO.List(ctx, lTest.inpNIn.GetOrgId(), + lTest.inpNIn.GetIdentityId(), time.Now(), time.Now().Add(-testTimeout)) t.Logf("listEvents, err: %+v, %v", listEvents, err) require.NoError(t, err) @@ -259,8 +259,8 @@ func TestNotifyMessagesError(t *testing.T) { // Normalize timestamp. require.WithinDuration(t, time.Now(), - listEvents[0].CreatedAt.AsTime(), testTimeout) - event.CreatedAt = listEvents[0].CreatedAt + listEvents[0].GetCreatedAt().AsTime(), testTimeout) + event.CreatedAt = listEvents[0].GetCreatedAt() // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 diff --git a/pkg/dao/app/crudl.go b/pkg/dao/app/crudl.go index eb344ce8..a5943ec6 100644 --- a/pkg/dao/app/crudl.go +++ b/pkg/dao/app/crudl.go @@ -25,9 +25,9 @@ func (d *DAO) Create(ctx context.Context, app *api.App) (*api.App, error) { app.CreatedAt = timestamppb.New(now) app.UpdatedAt = timestamppb.New(now) - if err := d.pg.QueryRowContext(ctx, createApp, app.OrgId, app.Name, - app.DisplayName, app.Email, app.PushoverKey, app.SubjectTemplate, - app.TextBodyTemplate, app.HtmlBodyTemplate, now).Scan( + if err := d.pg.QueryRowContext(ctx, createApp, app.GetOrgId(), app.GetName(), + app.GetDisplayName(), app.GetEmail(), app.GetPushoverKey(), app.GetSubjectTemplate(), + app.GetTextBodyTemplate(), app.GetHtmlBodyTemplate(), now).Scan( &app.Id); err != nil { return nil, dao.DBToSentinel(err) } @@ -76,9 +76,9 @@ func (d *DAO) Update(ctx context.Context, app *api.App) (*api.App, error) { updatedAt := time.Now().UTC().Truncate(time.Microsecond) app.UpdatedAt = timestamppb.New(updatedAt) - if err := d.pg.QueryRowContext(ctx, updateApp, app.Name, app.DisplayName, - app.Email, app.PushoverKey, app.SubjectTemplate, app.TextBodyTemplate, - app.HtmlBodyTemplate, updatedAt, app.Id, app.OrgId).Scan( + if err := d.pg.QueryRowContext(ctx, updateApp, app.GetName(), app.GetDisplayName(), + app.GetEmail(), app.GetPushoverKey(), app.GetSubjectTemplate(), app.GetTextBodyTemplate(), + app.GetHtmlBodyTemplate(), updatedAt, app.GetId(), app.GetOrgId()).Scan( &createdAt); err != nil { return nil, dao.DBToSentinel(err) } diff --git a/pkg/dao/app/crudl_test.go b/pkg/dao/app/crudl_test.go index 08601186..521f4911 100644 --- a/pkg/dao/app/crudl_test.go +++ b/pkg/dao/app/crudl_test.go @@ -30,7 +30,7 @@ func TestCreate(t *testing.T) { t.Run("Create valid app", func(t *testing.T) { t.Parallel() - app := random.App("dao-app", createOrg.Id) + app := random.App("dao-app", createOrg.GetId()) createApp, _ := proto.Clone(app).(*api.App) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -39,17 +39,17 @@ func TestCreate(t *testing.T) { createApp, err := globalAppDAO.Create(ctx, createApp) t.Logf("app, createApp, err: %+v, %+v, %v", app, createApp, err) require.NoError(t, err) - require.NotEqual(t, app.Id, createApp.Id) - require.WithinDuration(t, time.Now(), createApp.CreatedAt.AsTime(), + require.NotEqual(t, app.GetId(), createApp.GetId()) + require.WithinDuration(t, time.Now(), createApp.GetCreatedAt().AsTime(), 2*time.Second) - require.WithinDuration(t, time.Now(), createApp.UpdatedAt.AsTime(), + require.WithinDuration(t, time.Now(), createApp.GetUpdatedAt().AsTime(), 2*time.Second) }) t.Run("Create invalid app", func(t *testing.T) { t.Parallel() - app := random.App("dao-app", createOrg.Id) + app := random.App("dao-app", createOrg.GetId()) app.Name = "dao-app-" + random.String(40) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -73,7 +73,7 @@ func TestRead(t *testing.T) { require.NoError(t, err) createApp, err := globalAppDAO.Create(ctx, random.App("dao-app", - createOrg.Id)) + createOrg.GetId())) t.Logf("createApp, err: %+v, %v", createApp, err) require.NoError(t, err) @@ -83,7 +83,7 @@ func TestRead(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() - readApp, err := globalAppDAO.Read(ctx, createApp.Id, createApp.OrgId) + readApp, err := globalAppDAO.Read(ctx, createApp.GetId(), createApp.GetOrgId()) t.Logf("readApp, err: %+v, %v", readApp, err) require.NoError(t, err) require.Equal(t, createApp, readApp) @@ -108,7 +108,7 @@ func TestRead(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() - readApp, err := globalAppDAO.Read(ctx, createApp.Id, + readApp, err := globalAppDAO.Read(ctx, createApp.GetId(), uuid.NewString()) t.Logf("readApp, err: %+v, %v", readApp, err) require.Nil(t, readApp) @@ -122,7 +122,7 @@ func TestRead(t *testing.T) { defer cancel() readApp, err := globalAppDAO.Read(ctx, random.String(10), - createApp.OrgId) + createApp.GetOrgId()) t.Logf("readApp, err: %+v, %v", readApp, err) require.Nil(t, readApp) require.ErrorIs(t, err, dao.ErrInvalidFormat) @@ -146,7 +146,7 @@ func TestUpdate(t *testing.T) { defer cancel() createApp, err := globalAppDAO.Create(ctx, random.App("dao-app", - createOrg.Id)) + createOrg.GetId())) t.Logf("createApp, err: %+v, %v", createApp, err) require.NoError(t, err) @@ -161,16 +161,16 @@ func TestUpdate(t *testing.T) { t.Logf("createApp, updateApp, err: %+v, %+v, %v", createApp, updateApp, err) require.NoError(t, err) - require.Equal(t, createApp.Name, updateApp.Name) - require.Equal(t, createApp.DisplayName, updateApp.DisplayName) - require.Equal(t, createApp.Email, updateApp.Email) - require.Equal(t, createApp.PushoverKey, updateApp.PushoverKey) - require.True(t, updateApp.UpdatedAt.AsTime().After( - updateApp.CreatedAt.AsTime())) - require.WithinDuration(t, createApp.CreatedAt.AsTime(), - updateApp.UpdatedAt.AsTime(), 2*time.Second) - - readApp, err := globalAppDAO.Read(ctx, createApp.Id, createApp.OrgId) + require.Equal(t, createApp.GetName(), updateApp.GetName()) + require.Equal(t, createApp.GetDisplayName(), updateApp.GetDisplayName()) + require.Equal(t, createApp.GetEmail(), updateApp.GetEmail()) + require.Equal(t, createApp.GetPushoverKey(), updateApp.GetPushoverKey()) + require.True(t, updateApp.GetUpdatedAt().AsTime().After( + updateApp.GetCreatedAt().AsTime())) + require.WithinDuration(t, createApp.GetCreatedAt().AsTime(), + updateApp.GetUpdatedAt().AsTime(), 2*time.Second) + + readApp, err := globalAppDAO.Read(ctx, createApp.GetId(), createApp.GetOrgId()) t.Logf("readApp, err: %+v, %v", readApp, err) require.NoError(t, err) require.Equal(t, updateApp, readApp) @@ -183,7 +183,7 @@ func TestUpdate(t *testing.T) { defer cancel() updateApp, err := globalAppDAO.Update(ctx, random.App("dao-app", - createOrg.Id)) + createOrg.GetId())) t.Logf("updateApp, err: %+v, %v", updateApp, err) require.Nil(t, updateApp) require.Equal(t, dao.ErrNotFound, err) @@ -196,7 +196,7 @@ func TestUpdate(t *testing.T) { defer cancel() createApp, err := globalAppDAO.Create(ctx, random.App("dao-app", - createOrg.Id)) + createOrg.GetId())) t.Logf("createApp, err: %+v, %v", createApp, err) require.NoError(t, err) @@ -218,7 +218,7 @@ func TestUpdate(t *testing.T) { defer cancel() createApp, err := globalAppDAO.Create(ctx, random.App("dao-app", - createOrg.Id)) + createOrg.GetId())) t.Logf("createApp, err: %+v, %v", createApp, err) require.NoError(t, err) @@ -250,11 +250,11 @@ func TestDelete(t *testing.T) { defer cancel() createApp, err := globalAppDAO.Create(ctx, random.App("dao-app", - createOrg.Id)) + createOrg.GetId())) t.Logf("createApp, err: %+v, %v", createApp, err) require.NoError(t, err) - err = globalAppDAO.Delete(ctx, createApp.Id, createOrg.Id) + err = globalAppDAO.Delete(ctx, createApp.GetId(), createOrg.GetId()) t.Logf("err: %v", err) require.NoError(t, err) @@ -265,8 +265,8 @@ func TestDelete(t *testing.T) { testTimeout) defer cancel() - readApp, err := globalAppDAO.Read(ctx, createApp.Id, - createOrg.Id) + readApp, err := globalAppDAO.Read(ctx, createApp.GetId(), + createOrg.GetId()) t.Logf("readApp, err: %+v, %v", readApp, err) require.Nil(t, readApp) require.Equal(t, dao.ErrNotFound, err) @@ -279,7 +279,7 @@ func TestDelete(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() - err := globalAppDAO.Delete(ctx, uuid.NewString(), createOrg.Id) + err := globalAppDAO.Delete(ctx, uuid.NewString(), createOrg.GetId()) t.Logf("err: %v", err) require.Equal(t, dao.ErrNotFound, err) }) @@ -291,11 +291,11 @@ func TestDelete(t *testing.T) { defer cancel() createApp, err := globalAppDAO.Create(ctx, random.App("dao-app", - createOrg.Id)) + createOrg.GetId())) t.Logf("createApp, err: %+v, %v", createApp, err) require.NoError(t, err) - err = globalAppDAO.Delete(ctx, createApp.Id, uuid.NewString()) + err = globalAppDAO.Delete(ctx, createApp.GetId(), uuid.NewString()) t.Logf("err: %v", err) require.Equal(t, dao.ErrNotFound, err) }) @@ -318,15 +318,15 @@ func TestList(t *testing.T) { appTSes := []time.Time{} for i := 0; i < 3; i++ { createApp, err := globalAppDAO.Create(ctx, random.App("dao-app", - createOrg.Id)) + createOrg.GetId())) t.Logf("createApp, err: %+v, %v", createApp, err) require.NoError(t, err) - appIDs = append(appIDs, createApp.Id) - appNames = append(appNames, createApp.Name) - appEmails = append(appEmails, createApp.Email) - appPushoverKeys = append(appPushoverKeys, createApp.PushoverKey) - appTSes = append(appTSes, createApp.CreatedAt.AsTime()) + appIDs = append(appIDs, createApp.GetId()) + appNames = append(appNames, createApp.GetName()) + appEmails = append(appEmails, createApp.GetEmail()) + appPushoverKeys = append(appPushoverKeys, createApp.GetPushoverKey()) + appTSes = append(appTSes, createApp.GetCreatedAt().AsTime()) } t.Run("List apps by valid org ID", func(t *testing.T) { @@ -335,7 +335,7 @@ func TestList(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() - listApps, listCount, err := globalAppDAO.List(ctx, createOrg.Id, + listApps, listCount, err := globalAppDAO.List(ctx, createOrg.GetId(), time.Time{}, "", 0) t.Logf("listApps, listCount, err: %+v, %v, %v", listApps, listCount, err) @@ -345,10 +345,10 @@ func TestList(t *testing.T) { var found bool for _, app := range listApps { - if app.Id == appIDs[len(appIDs)-1] && - app.Name == appNames[len(appNames)-1] && - app.Email == appEmails[len(appEmails)-1] && - app.PushoverKey == appPushoverKeys[len(appPushoverKeys)-1] { + if app.GetId() == appIDs[len(appIDs)-1] && + app.GetName() == appNames[len(appNames)-1] && + app.GetEmail() == appEmails[len(appEmails)-1] && + app.GetPushoverKey() == appPushoverKeys[len(appPushoverKeys)-1] { found = true } } @@ -361,7 +361,7 @@ func TestList(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() - listApps, listCount, err := globalAppDAO.List(ctx, createOrg.Id, + listApps, listCount, err := globalAppDAO.List(ctx, createOrg.GetId(), appTSes[0], appIDs[0], 5) t.Logf("listApps, listCount, err: %+v, %v, %v", listApps, listCount, err) @@ -371,10 +371,10 @@ func TestList(t *testing.T) { var found bool for _, app := range listApps { - if app.Id == appIDs[len(appIDs)-1] && - app.Name == appNames[len(appNames)-1] && - app.Email == appEmails[len(appEmails)-1] && - app.PushoverKey == appPushoverKeys[len(appPushoverKeys)-1] { + if app.GetId() == appIDs[len(appIDs)-1] && + app.GetName() == appNames[len(appNames)-1] && + app.GetEmail() == appEmails[len(appEmails)-1] && + app.GetPushoverKey() == appPushoverKeys[len(appPushoverKeys)-1] { found = true } } @@ -387,7 +387,7 @@ func TestList(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() - listApps, listCount, err := globalAppDAO.List(ctx, createOrg.Id, + listApps, listCount, err := globalAppDAO.List(ctx, createOrg.GetId(), time.Time{}, "", 1) t.Logf("listApps, listCount, err: %+v, %v, %v", listApps, listCount, err) diff --git a/pkg/dao/event/crudl.go b/pkg/dao/event/crudl.go index 3c1c1d55..2e07c266 100644 --- a/pkg/dao/event/crudl.go +++ b/pkg/dao/event/crudl.go @@ -22,9 +22,9 @@ func (d *DAO) Create(ctx context.Context, event *api.Event) error { now := time.Now().UTC().Truncate(time.Microsecond) event.CreatedAt = timestamppb.New(now) - _, err := d.pg.ExecContext(ctx, createEvent, event.OrgId, event.AppId, - event.IdentityId, event.Status.String(), event.Error, now, - event.TraceId) + _, err := d.pg.ExecContext(ctx, createEvent, event.GetOrgId(), event.GetAppId(), + event.GetIdentityId(), event.GetStatus().String(), event.GetError(), now, + event.GetTraceId()) return dao.DBToSentinel(err) } diff --git a/pkg/dao/event/crudl_test.go b/pkg/dao/event/crudl_test.go index d6f7ca30..ba2fbda7 100644 --- a/pkg/dao/event/crudl_test.go +++ b/pkg/dao/event/crudl_test.go @@ -34,7 +34,7 @@ func TestCreate(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() - err = globalEvDAO.Create(ctx, random.Event("dao-event", createOrg.Id)) + err = globalEvDAO.Create(ctx, random.Event("dao-event", createOrg.GetId())) t.Logf("err: %v", err) require.NoError(t, err) }) @@ -42,7 +42,7 @@ func TestCreate(t *testing.T) { t.Run("Create invalid event", func(t *testing.T) { t.Parallel() - event := random.Event("dao-event", createOrg.Id) + event := random.Event("dao-event", createOrg.GetId()) event.Error = "dao-event-" + random.String(255) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -72,7 +72,7 @@ func TestList(t *testing.T) { events := []*api.Event{} for i := 0; i < 5; i++ { - event := random.Event("dao-event", createOrg.Id) + event := random.Event("dao-event", createOrg.GetId()) event.IdentityId = identityID events = append(events, event) @@ -86,17 +86,17 @@ func TestList(t *testing.T) { } sort.Slice(events, func(i, j int) bool { - return events[i].CreatedAt.AsTime().After( - events[j].CreatedAt.AsTime()) + return events[i].GetCreatedAt().AsTime().After( + events[j].GetCreatedAt().AsTime()) }) ctx, cancel = context.WithTimeout(context.Background(), testTimeout) defer cancel() // Verify results. - listEvents, err := globalEvDAO.List(ctx, createOrg.Id, identityID, - events[0].CreatedAt.AsTime(), - events[len(events)-1].CreatedAt.AsTime().Add(-time.Millisecond)) + listEvents, err := globalEvDAO.List(ctx, createOrg.GetId(), identityID, + events[0].GetCreatedAt().AsTime(), + events[len(events)-1].GetCreatedAt().AsTime().Add(-time.Millisecond)) t.Logf("listEvents, err: %+v, %v", listEvents, err) require.NoError(t, err) require.Len(t, listEvents, len(events)) @@ -120,15 +120,15 @@ func TestList(t *testing.T) { t.Logf("createOrg, err: %+v, %v", createOrg, err) require.NoError(t, err) - event := random.Event("dao-event", createOrg.Id) + event := random.Event("dao-event", createOrg.GetId()) err = globalEvDAO.Create(ctx, event) t.Logf("err: %#v", err) require.NoError(t, err) listEvents, err := globalEvDAO.List(ctx, uuid.NewString(), - event.IdentityId, event.CreatedAt.AsTime(), - event.CreatedAt.AsTime().Add(-time.Millisecond)) + event.GetIdentityId(), event.GetCreatedAt().AsTime(), + event.GetCreatedAt().AsTime().Add(-time.Millisecond)) t.Logf("listEvents, err: %+v, %v", listEvents, err) require.NoError(t, err) require.Len(t, listEvents, 0) @@ -164,7 +164,7 @@ func TestLatest(t *testing.T) { events := []*api.Event{} for i := 0; i < 5; i++ { - event := random.Event("dao-event", createOrg.Id) + event := random.Event("dao-event", createOrg.GetId()) events = append(events, event) ctx, cancel := context.WithTimeout(context.Background(), @@ -177,15 +177,15 @@ func TestLatest(t *testing.T) { } sort.Slice(events, func(i, j int) bool { - return events[i].CreatedAt.AsTime().After( - events[j].CreatedAt.AsTime()) + return events[i].GetCreatedAt().AsTime().After( + events[j].GetCreatedAt().AsTime()) }) ctx, cancel = context.WithTimeout(context.Background(), testTimeout) defer cancel() // Verify results. - latEvents, err := globalEvDAO.Latest(ctx, createOrg.Id, "", "") + latEvents, err := globalEvDAO.Latest(ctx, createOrg.GetId(), "", "") t.Logf("latEvents, err: %+v, %v", latEvents, err) require.NoError(t, err) require.Len(t, latEvents, len(events)) @@ -199,8 +199,8 @@ func TestLatest(t *testing.T) { } // Verify results by app ID and identity ID. - latEventsAppIDIdentityID, err := globalEvDAO.Latest(ctx, createOrg.Id, - events[len(events)-1].AppId, events[len(events)-1].IdentityId) + latEventsAppIDIdentityID, err := globalEvDAO.Latest(ctx, createOrg.GetId(), + events[len(events)-1].GetAppId(), events[len(events)-1].GetIdentityId()) t.Logf("latEventsAppIDIdentityID, err: %+v, %v", latEventsAppIDIdentityID, err) require.NoError(t, err) @@ -214,8 +214,8 @@ func TestLatest(t *testing.T) { } // Verify results by app ID. - latEventsAppID, err := globalEvDAO.Latest(ctx, createOrg.Id, - events[0].AppId, "") + latEventsAppID, err := globalEvDAO.Latest(ctx, createOrg.GetId(), + events[0].GetAppId(), "") t.Logf("latEventsAppID, err: %+v, %v", latEventsAppID, err) require.NoError(t, err) require.Len(t, latEventsAppID, 1) @@ -227,8 +227,8 @@ func TestLatest(t *testing.T) { } // Verify results by identity ID. - latEventsIdentityID, err := globalEvDAO.Latest(ctx, createOrg.Id, "", - events[1].IdentityId) + latEventsIdentityID, err := globalEvDAO.Latest(ctx, createOrg.GetId(), "", + events[1].GetIdentityId()) t.Logf("latEventsIdentityID, err: %+v, %v", latEventsIdentityID, err) require.NoError(t, err) require.Len(t, latEventsIdentityID, 1) @@ -251,14 +251,14 @@ func TestLatest(t *testing.T) { t.Logf("createOrg, err: %+v, %v", createOrg, err) require.NoError(t, err) - event := random.Event("dao-event", createOrg.Id) + event := random.Event("dao-event", createOrg.GetId()) err = globalEvDAO.Create(ctx, event) t.Logf("err: %#v", err) require.NoError(t, err) - latEvents, err := globalEvDAO.Latest(ctx, uuid.NewString(), event.AppId, - event.IdentityId) + latEvents, err := globalEvDAO.Latest(ctx, uuid.NewString(), event.GetAppId(), + event.GetIdentityId()) t.Logf("latEvents, err: %+v, %v", latEvents, err) require.NoError(t, err) require.Len(t, latEvents, 0) diff --git a/pkg/dao/identity/crudl.go b/pkg/dao/identity/crudl.go index 3c2e4b48..54fec611 100644 --- a/pkg/dao/identity/crudl.go +++ b/pkg/dao/identity/crudl.go @@ -27,7 +27,7 @@ func (d *DAO) Create(ctx context.Context, identity *api.Identity) ( *api.Identity, *oath.OTP, bool, error, ) { // Backup codes and security questions methods do not require activation. - switch identity.MethodOneof.(type) { + switch identity.GetMethodOneof().(type) { case *api.Identity_BackupCodesMethod, *api.Identity_SecurityQuestionsMethod: identity.Status = api.IdentityStatus_ACTIVATED default: @@ -56,8 +56,8 @@ func (d *DAO) Create(ctx context.Context, identity *api.Identity) ( } } - if err := d.pg.QueryRowContext(ctx, createIdentity, identity.OrgId, - identity.AppId, identity.Comment, identity.Status.String(), + if err := d.pg.QueryRowContext(ctx, createIdentity, identity.GetOrgId(), + identity.GetAppId(), identity.GetComment(), identity.GetStatus().String(), otp.Algorithm, hashCryptoToAPI[otp.Hash].String(), otp.Digits, secretEnc, meta.phone, meta.pushoverKey, meta.email, meta.backupCodes, answerEnc, now).Scan(&identity.Id); err != nil { diff --git a/pkg/dao/identity/crudl_test.go b/pkg/dao/identity/crudl_test.go index 3db51d3e..249c1eca 100644 --- a/pkg/dao/identity/crudl_test.go +++ b/pkg/dao/identity/crudl_test.go @@ -28,15 +28,15 @@ func TestCreate(t *testing.T) { require.NoError(t, err) createApp, err := globalAppDAO.Create(ctx, random.App("dao-identity", - createOrg.Id)) + createOrg.GetId())) t.Logf("createApp, err: %+v, %v", createApp, err) require.NoError(t, err) t.Run("Create valid HOTP identity", func(t *testing.T) { t.Parallel() - identity := random.HOTPIdentity("dao-identity", createOrg.Id, - createApp.Id) + identity := random.HOTPIdentity("dao-identity", createOrg.GetId(), + createApp.GetId()) createIdentity, _ := proto.Clone(identity).(*api.Identity) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -48,11 +48,11 @@ func TestCreate(t *testing.T) { "%+v, %#v, %v, %v", identity, createIdentity, createOTP, retSecret, err) require.NoError(t, err) - require.NotEqual(t, identity.Id, createIdentity.Id) - require.Equal(t, api.IdentityStatus_UNVERIFIED, createIdentity.Status) - require.WithinDuration(t, time.Now(), createIdentity.CreatedAt.AsTime(), + require.NotEqual(t, identity.GetId(), createIdentity.GetId()) + require.Equal(t, api.IdentityStatus_UNVERIFIED, createIdentity.GetStatus()) + require.WithinDuration(t, time.Now(), createIdentity.GetCreatedAt().AsTime(), 2*time.Second) - require.WithinDuration(t, time.Now(), createIdentity.UpdatedAt.AsTime(), + require.WithinDuration(t, time.Now(), createIdentity.GetUpdatedAt().AsTime(), 2*time.Second) require.NotNil(t, createOTP) require.True(t, retSecret) @@ -61,8 +61,8 @@ func TestCreate(t *testing.T) { t.Run("Create valid SMS identity", func(t *testing.T) { t.Parallel() - identity := random.SMSIdentity("dao-identity", createOrg.Id, - createApp.Id) + identity := random.SMSIdentity("dao-identity", createOrg.GetId(), + createApp.GetId()) createIdentity, _ := proto.Clone(identity).(*api.Identity) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -74,11 +74,11 @@ func TestCreate(t *testing.T) { "%+v, %#v, %v, %v", identity, createIdentity, createOTP, retSecret, err) require.NoError(t, err) - require.NotEqual(t, identity.Id, createIdentity.Id) - require.Equal(t, api.IdentityStatus_UNVERIFIED, createIdentity.Status) - require.WithinDuration(t, time.Now(), createIdentity.CreatedAt.AsTime(), + require.NotEqual(t, identity.GetId(), createIdentity.GetId()) + require.Equal(t, api.IdentityStatus_UNVERIFIED, createIdentity.GetStatus()) + require.WithinDuration(t, time.Now(), createIdentity.GetCreatedAt().AsTime(), 2*time.Second) - require.WithinDuration(t, time.Now(), createIdentity.UpdatedAt.AsTime(), + require.WithinDuration(t, time.Now(), createIdentity.GetUpdatedAt().AsTime(), 2*time.Second) require.NotNil(t, createOTP) require.False(t, retSecret) @@ -87,8 +87,8 @@ func TestCreate(t *testing.T) { t.Run("Create valid Pushover identity", func(t *testing.T) { t.Parallel() - identity := random.PushoverIdentity("dao-identity", createOrg.Id, - createApp.Id) + identity := random.PushoverIdentity("dao-identity", createOrg.GetId(), + createApp.GetId()) createIdentity, _ := proto.Clone(identity).(*api.Identity) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -100,11 +100,11 @@ func TestCreate(t *testing.T) { "%+v, %#v, %v, %v", identity, createIdentity, createOTP, retSecret, err) require.NoError(t, err) - require.NotEqual(t, identity.Id, createIdentity.Id) - require.Equal(t, api.IdentityStatus_UNVERIFIED, createIdentity.Status) - require.WithinDuration(t, time.Now(), createIdentity.CreatedAt.AsTime(), + require.NotEqual(t, identity.GetId(), createIdentity.GetId()) + require.Equal(t, api.IdentityStatus_UNVERIFIED, createIdentity.GetStatus()) + require.WithinDuration(t, time.Now(), createIdentity.GetCreatedAt().AsTime(), 2*time.Second) - require.WithinDuration(t, time.Now(), createIdentity.UpdatedAt.AsTime(), + require.WithinDuration(t, time.Now(), createIdentity.GetUpdatedAt().AsTime(), 2*time.Second) require.NotNil(t, createOTP) require.False(t, retSecret) @@ -113,8 +113,8 @@ func TestCreate(t *testing.T) { t.Run("Create valid email identity", func(t *testing.T) { t.Parallel() - identity := random.EmailIdentity("dao-identity", createOrg.Id, - createApp.Id) + identity := random.EmailIdentity("dao-identity", createOrg.GetId(), + createApp.GetId()) createIdentity, _ := proto.Clone(identity).(*api.Identity) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -126,11 +126,11 @@ func TestCreate(t *testing.T) { "%+v, %#v, %v, %v", identity, createIdentity, createOTP, retSecret, err) require.NoError(t, err) - require.NotEqual(t, identity.Id, createIdentity.Id) - require.Equal(t, api.IdentityStatus_UNVERIFIED, createIdentity.Status) - require.WithinDuration(t, time.Now(), createIdentity.CreatedAt.AsTime(), + require.NotEqual(t, identity.GetId(), createIdentity.GetId()) + require.Equal(t, api.IdentityStatus_UNVERIFIED, createIdentity.GetStatus()) + require.WithinDuration(t, time.Now(), createIdentity.GetCreatedAt().AsTime(), 2*time.Second) - require.WithinDuration(t, time.Now(), createIdentity.UpdatedAt.AsTime(), + require.WithinDuration(t, time.Now(), createIdentity.GetUpdatedAt().AsTime(), 2*time.Second) require.NotNil(t, createOTP) require.False(t, retSecret) @@ -139,8 +139,8 @@ func TestCreate(t *testing.T) { t.Run("Create valid backup codes identity", func(t *testing.T) { t.Parallel() - identity := random.BackupCodesIdentity("dao-identity", createOrg.Id, - createApp.Id) + identity := random.BackupCodesIdentity("dao-identity", createOrg.GetId(), + createApp.GetId()) createIdentity, _ := proto.Clone(identity).(*api.Identity) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -152,11 +152,11 @@ func TestCreate(t *testing.T) { "%+v, %#v, %v, %v", identity, createIdentity, createOTP, retSecret, err) require.NoError(t, err) - require.NotEqual(t, identity.Id, createIdentity.Id) - require.Equal(t, api.IdentityStatus_ACTIVATED, createIdentity.Status) - require.WithinDuration(t, time.Now(), createIdentity.CreatedAt.AsTime(), + require.NotEqual(t, identity.GetId(), createIdentity.GetId()) + require.Equal(t, api.IdentityStatus_ACTIVATED, createIdentity.GetStatus()) + require.WithinDuration(t, time.Now(), createIdentity.GetCreatedAt().AsTime(), 2*time.Second) - require.WithinDuration(t, time.Now(), createIdentity.UpdatedAt.AsTime(), + require.WithinDuration(t, time.Now(), createIdentity.GetUpdatedAt().AsTime(), 2*time.Second) require.NotNil(t, createOTP) require.False(t, retSecret) @@ -166,7 +166,7 @@ func TestCreate(t *testing.T) { t.Parallel() identity := random.SecurityQuestionsIdentity("dao-identity", - createOrg.Id, createApp.Id) + createOrg.GetId(), createApp.GetId()) createIdentity, _ := proto.Clone(identity).(*api.Identity) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -178,13 +178,13 @@ func TestCreate(t *testing.T) { "%+v, %#v, %v, %v", identity, createIdentity, createOTP, retSecret, err) require.NoError(t, err) - require.NotEqual(t, identity.Id, createIdentity.Id) - require.Equal(t, api.IdentityStatus_ACTIVATED, createIdentity.Status) + require.NotEqual(t, identity.GetId(), createIdentity.GetId()) + require.Equal(t, api.IdentityStatus_ACTIVATED, createIdentity.GetStatus()) require.Equal(t, defaultAnswer, - createIdentity.GetSecurityQuestionsMethod().Answer) - require.WithinDuration(t, time.Now(), createIdentity.CreatedAt.AsTime(), + createIdentity.GetSecurityQuestionsMethod().GetAnswer()) + require.WithinDuration(t, time.Now(), createIdentity.GetCreatedAt().AsTime(), 2*time.Second) - require.WithinDuration(t, time.Now(), createIdentity.UpdatedAt.AsTime(), + require.WithinDuration(t, time.Now(), createIdentity.GetUpdatedAt().AsTime(), 2*time.Second) require.NotNil(t, createOTP) require.False(t, retSecret) @@ -193,8 +193,8 @@ func TestCreate(t *testing.T) { t.Run("Create invalid identity", func(t *testing.T) { t.Parallel() - identity := random.HOTPIdentity("dao-identity", createOrg.Id, - createApp.Id) + identity := random.HOTPIdentity("dao-identity", createOrg.GetId(), + createApp.GetId()) identity.Comment = "dao-identity-" + random.String(80) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -218,7 +218,7 @@ func TestCreate(t *testing.T) { defer cancel() createIdentity, createOTP, retSecret, err := globalIdentDAO.Create( - ctx, random.HOTPIdentity("dao-identity", createOrg.Id, + ctx, random.HOTPIdentity("dao-identity", createOrg.GetId(), uuid.NewString())) t.Logf("createIdentity, createOTP, retSecret, err: %+v, %#v, %v, %v", createIdentity, createOTP, retSecret, err) @@ -240,12 +240,12 @@ func TestRead(t *testing.T) { require.NoError(t, err) createApp, err := globalAppDAO.Create(ctx, random.App("dao-identity", - createOrg.Id)) + createOrg.GetId())) t.Logf("createApp, err: %+v, %v", createApp, err) require.NoError(t, err) createIdentity, createOTP, _, err := globalIdentDAO.Create(ctx, - random.HOTPIdentity("dao-identity", createOrg.Id, createApp.Id)) + random.HOTPIdentity("dao-identity", createOrg.GetId(), createApp.GetId())) t.Logf("createIdentity, createOTP, err: %+v, %#v, %v", createIdentity, createOTP, err) require.NoError(t, err) @@ -257,7 +257,7 @@ func TestRead(t *testing.T) { defer cancel() readIdentity, readOTP, err := globalIdentDAO.Read(ctx, - createIdentity.Id, createIdentity.OrgId, createIdentity.AppId) + createIdentity.GetId(), createIdentity.GetOrgId(), createIdentity.GetAppId()) t.Logf("readIdentity, readOTP, err: %+v, %#v, %v", readIdentity, readOTP, err) require.NoError(t, err) @@ -269,9 +269,9 @@ func TestRead(t *testing.T) { } require.Equal(t, createOTP, readOTP) - require.Equal(t, createIdentity.GetSoftwareHotpMethod().Hash, + require.Equal(t, createIdentity.GetSoftwareHotpMethod().GetHash(), hashCryptoToAPI[readOTP.Hash]) - require.Equal(t, createIdentity.GetSoftwareHotpMethod().Digits, + require.Equal(t, createIdentity.GetSoftwareHotpMethod().GetDigits(), int32(readOTP.Digits)) }) @@ -282,13 +282,13 @@ func TestRead(t *testing.T) { defer cancel() createIdentity, createOTP, _, err := globalIdentDAO.Create(ctx, - random.SMSIdentity("dao-identity", createOrg.Id, createApp.Id)) + random.SMSIdentity("dao-identity", createOrg.GetId(), createApp.GetId())) t.Logf("createIdentity, createOTP, err: %+v, %#v, %v", createIdentity, createOTP, err) require.NoError(t, err) readIdentity, readOTP, err := globalIdentDAO.Read(ctx, - createIdentity.Id, createIdentity.OrgId, createIdentity.AppId) + createIdentity.GetId(), createIdentity.GetOrgId(), createIdentity.GetAppId()) t.Logf("readIdentity, readOTP, err: %+v, %#v, %v", readIdentity, readOTP, err) require.NoError(t, err) @@ -310,13 +310,13 @@ func TestRead(t *testing.T) { defer cancel() createIdentity, createOTP, _, err := globalIdentDAO.Create(ctx, - random.PushoverIdentity("dao-identity", createOrg.Id, createApp.Id)) + random.PushoverIdentity("dao-identity", createOrg.GetId(), createApp.GetId())) t.Logf("createIdentity, createOTP, err: %+v, %#v, %v", createIdentity, createOTP, err) require.NoError(t, err) readIdentity, readOTP, err := globalIdentDAO.Read(ctx, - createIdentity.Id, createIdentity.OrgId, createIdentity.AppId) + createIdentity.GetId(), createIdentity.GetOrgId(), createIdentity.GetAppId()) t.Logf("readIdentity, readOTP, err: %+v, %#v, %v", readIdentity, readOTP, err) require.NoError(t, err) @@ -338,13 +338,13 @@ func TestRead(t *testing.T) { defer cancel() createIdentity, createOTP, _, err := globalIdentDAO.Create(ctx, - random.EmailIdentity("dao-identity", createOrg.Id, createApp.Id)) + random.EmailIdentity("dao-identity", createOrg.GetId(), createApp.GetId())) t.Logf("createIdentity, createOTP, err: %+v, %#v, %v", createIdentity, createOTP, err) require.NoError(t, err) readIdentity, readOTP, err := globalIdentDAO.Read(ctx, - createIdentity.Id, createIdentity.OrgId, createIdentity.AppId) + createIdentity.GetId(), createIdentity.GetOrgId(), createIdentity.GetAppId()) t.Logf("readIdentity, readOTP, err: %+v, %#v, %v", readIdentity, readOTP, err) require.NoError(t, err) @@ -366,14 +366,14 @@ func TestRead(t *testing.T) { defer cancel() createIdentity, createOTP, _, err := globalIdentDAO.Create(ctx, - random.BackupCodesIdentity("dao-identity", createOrg.Id, - createApp.Id)) + random.BackupCodesIdentity("dao-identity", createOrg.GetId(), + createApp.GetId())) t.Logf("createIdentity, createOTP, err: %+v, %#v, %v", createIdentity, createOTP, err) require.NoError(t, err) readIdentity, readOTP, err := globalIdentDAO.Read(ctx, - createIdentity.Id, createIdentity.OrgId, createIdentity.AppId) + createIdentity.GetId(), createIdentity.GetOrgId(), createIdentity.GetAppId()) t.Logf("readIdentity, readOTP, err: %+v, %#v, %v", readIdentity, readOTP, err) require.NoError(t, err) @@ -395,14 +395,14 @@ func TestRead(t *testing.T) { defer cancel() createIdentity, createOTP, _, err := globalIdentDAO.Create(ctx, - random.SecurityQuestionsIdentity("dao-identity", createOrg.Id, - createApp.Id)) + random.SecurityQuestionsIdentity("dao-identity", createOrg.GetId(), + createApp.GetId())) t.Logf("createIdentity, createOTP, err: %+v, %#v, %v", createIdentity, createOTP, err) require.NoError(t, err) readIdentity, readOTP, err := globalIdentDAO.Read(ctx, - createIdentity.Id, createIdentity.OrgId, createIdentity.AppId) + createIdentity.GetId(), createIdentity.GetOrgId(), createIdentity.GetAppId()) t.Logf("readIdentity, readOTP, err: %+v, %#v, %v", readIdentity, readOTP, err) require.NoError(t, err) @@ -424,7 +424,7 @@ func TestRead(t *testing.T) { defer cancel() readIdentity, readOTP, err := globalIdentDAO.Read(ctx, - uuid.NewString(), createIdentity.OrgId, createIdentity.AppId) + uuid.NewString(), createIdentity.GetOrgId(), createIdentity.GetAppId()) t.Logf("readIdentity, readOTP, err: %+v, %#v, %v", readIdentity, readOTP, err) require.Nil(t, readIdentity) @@ -439,7 +439,7 @@ func TestRead(t *testing.T) { defer cancel() readIdentity, readOTP, err := globalIdentDAO.Read(ctx, - createIdentity.Id, createIdentity.OrgId, uuid.NewString()) + createIdentity.GetId(), createIdentity.GetOrgId(), uuid.NewString()) t.Logf("readIdentity, readOTP, err: %+v, %#v, %v", readIdentity, readOTP, err) require.Nil(t, readIdentity) @@ -454,7 +454,7 @@ func TestRead(t *testing.T) { defer cancel() readIdentity, readOTP, err := globalIdentDAO.Read(ctx, - createIdentity.Id, uuid.NewString(), createIdentity.AppId) + createIdentity.GetId(), uuid.NewString(), createIdentity.GetAppId()) t.Logf("readIdentity, readOTP, err: %+v, %#v, %v", readIdentity, readOTP, err) require.Nil(t, readIdentity) @@ -469,7 +469,7 @@ func TestRead(t *testing.T) { defer cancel() readIdentity, readOTP, err := globalIdentDAO.Read(ctx, - random.String(10), createIdentity.OrgId, createIdentity.AppId) + random.String(10), createIdentity.GetOrgId(), createIdentity.GetAppId()) t.Logf("readIdentity, readOTP, err: %+v, %#v, %v", readIdentity, readOTP, err) require.Nil(t, readIdentity) @@ -489,7 +489,7 @@ func TestUpdateStatus(t *testing.T) { require.NoError(t, err) createApp, err := globalAppDAO.Create(ctx, random.App("dao-identity", - createOrg.Id)) + createOrg.GetId())) t.Logf("createApp, err: %+v, %v", createApp, err) require.NoError(t, err) @@ -500,17 +500,17 @@ func TestUpdateStatus(t *testing.T) { defer cancel() createIdentity, _, _, err := globalIdentDAO.Create(ctx, - random.HOTPIdentity("dao-identity", createOrg.Id, createApp.Id)) + random.HOTPIdentity("dao-identity", createOrg.GetId(), createApp.GetId())) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) updateIdentity, err := globalIdentDAO.UpdateStatus(ctx, - createIdentity.Id, createOrg.Id, createApp.Id, + createIdentity.GetId(), createOrg.GetId(), createApp.GetId(), api.IdentityStatus_ACTIVATED) t.Logf("updateIdentity, err: %+v, %v", updateIdentity, err) require.NoError(t, err) - require.Equal(t, api.IdentityStatus_ACTIVATED, updateIdentity.Status) - require.WithinDuration(t, time.Now(), createIdentity.UpdatedAt.AsTime(), + require.Equal(t, api.IdentityStatus_ACTIVATED, updateIdentity.GetStatus()) + require.WithinDuration(t, time.Now(), createIdentity.GetUpdatedAt().AsTime(), 2*time.Second) }) @@ -521,7 +521,7 @@ func TestUpdateStatus(t *testing.T) { defer cancel() updateIdentity, err := globalIdentDAO.UpdateStatus(ctx, - uuid.NewString(), createOrg.Id, createApp.Id, + uuid.NewString(), createOrg.GetId(), createApp.GetId(), api.IdentityStatus_ACTIVATED) t.Logf("updateIdentity, err: %+v, %v", updateIdentity, err) require.Nil(t, updateIdentity) @@ -535,12 +535,12 @@ func TestUpdateStatus(t *testing.T) { defer cancel() createIdentity, _, _, err := globalIdentDAO.Create(ctx, - random.HOTPIdentity("dao-identity", createOrg.Id, createApp.Id)) + random.HOTPIdentity("dao-identity", createOrg.GetId(), createApp.GetId())) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) updateIdentity, err := globalIdentDAO.UpdateStatus(ctx, - createIdentity.Id, uuid.NewString(), createApp.Id, + createIdentity.GetId(), uuid.NewString(), createApp.GetId(), api.IdentityStatus_ACTIVATED) t.Logf("updateIdentity, err: %+v, %v", updateIdentity, err) require.Nil(t, updateIdentity) @@ -559,7 +559,7 @@ func TestDelete(t *testing.T) { require.NoError(t, err) createApp, err := globalAppDAO.Create(ctx, random.App("dao-identity", - createOrg.Id)) + createOrg.GetId())) t.Logf("createApp, err: %+v, %v", createApp, err) require.NoError(t, err) @@ -570,12 +570,12 @@ func TestDelete(t *testing.T) { defer cancel() createIdentity, _, _, err := globalIdentDAO.Create(ctx, - random.HOTPIdentity("dao-identity", createOrg.Id, createApp.Id)) + random.HOTPIdentity("dao-identity", createOrg.GetId(), createApp.GetId())) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) - err = globalIdentDAO.Delete(ctx, createIdentity.Id, createOrg.Id, - createIdentity.AppId) + err = globalIdentDAO.Delete(ctx, createIdentity.GetId(), createOrg.GetId(), + createIdentity.GetAppId()) t.Logf("err: %v", err) require.NoError(t, err) @@ -587,7 +587,7 @@ func TestDelete(t *testing.T) { defer cancel() readIdentity, readOTP, err := globalIdentDAO.Read(ctx, - createIdentity.Id, createOrg.Id, createIdentity.AppId) + createIdentity.GetId(), createOrg.GetId(), createIdentity.GetAppId()) t.Logf("readIdentity, readOTP, err: %+v, %#v, %v", readIdentity, readOTP, err) require.Nil(t, readIdentity) @@ -602,8 +602,8 @@ func TestDelete(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() - err := globalIdentDAO.Delete(ctx, uuid.NewString(), createOrg.Id, - createApp.Id) + err := globalIdentDAO.Delete(ctx, uuid.NewString(), createOrg.GetId(), + createApp.GetId()) t.Logf("err: %v", err) require.Equal(t, dao.ErrNotFound, err) }) @@ -615,11 +615,11 @@ func TestDelete(t *testing.T) { defer cancel() createIdentity, _, _, err := globalIdentDAO.Create(ctx, - random.HOTPIdentity("dao-identity", createOrg.Id, createApp.Id)) + random.HOTPIdentity("dao-identity", createOrg.GetId(), createApp.GetId())) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) - err = globalIdentDAO.Delete(ctx, createIdentity.Id, createOrg.Id, + err = globalIdentDAO.Delete(ctx, createIdentity.GetId(), createOrg.GetId(), uuid.NewString()) t.Logf("err: %v", err) require.Equal(t, dao.ErrNotFound, err) @@ -632,12 +632,12 @@ func TestDelete(t *testing.T) { defer cancel() createIdentity, _, _, err := globalIdentDAO.Create(ctx, - random.HOTPIdentity("dao-identity", createOrg.Id, createApp.Id)) + random.HOTPIdentity("dao-identity", createOrg.GetId(), createApp.GetId())) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) - err = globalIdentDAO.Delete(ctx, createIdentity.Id, uuid.NewString(), - createApp.Id) + err = globalIdentDAO.Delete(ctx, createIdentity.GetId(), uuid.NewString(), + createApp.GetId()) t.Logf("err: %v", err) require.Equal(t, dao.ErrNotFound, err) }) @@ -654,7 +654,7 @@ func TestList(t *testing.T) { require.NoError(t, err) createApp, err := globalAppDAO.Create(ctx, random.App("dao-identity", - createOrg.Id)) + createOrg.GetId())) t.Logf("createApp, err: %+v, %v", createApp, err) require.NoError(t, err) @@ -663,60 +663,60 @@ func TestList(t *testing.T) { identityTSes := []time.Time{} for i := 0; i < 3; i++ { createIdentity, _, _, err := globalIdentDAO.Create(ctx, - random.HOTPIdentity("dao-identity", createOrg.Id, createApp.Id)) + random.HOTPIdentity("dao-identity", createOrg.GetId(), createApp.GetId())) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) - identityIDs = append(identityIDs, createIdentity.Id) - identityComments = append(identityComments, createIdentity.Comment) - identityTSes = append(identityTSes, createIdentity.CreatedAt.AsTime()) + identityIDs = append(identityIDs, createIdentity.GetId()) + identityComments = append(identityComments, createIdentity.GetComment()) + identityTSes = append(identityTSes, createIdentity.GetCreatedAt().AsTime()) createIdentity, _, _, err = globalIdentDAO.Create(ctx, - random.SMSIdentity("dao-identity", createOrg.Id, createApp.Id)) + random.SMSIdentity("dao-identity", createOrg.GetId(), createApp.GetId())) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) - identityIDs = append(identityIDs, createIdentity.Id) - identityComments = append(identityComments, createIdentity.Comment) - identityTSes = append(identityTSes, createIdentity.CreatedAt.AsTime()) + identityIDs = append(identityIDs, createIdentity.GetId()) + identityComments = append(identityComments, createIdentity.GetComment()) + identityTSes = append(identityTSes, createIdentity.GetCreatedAt().AsTime()) createIdentity, _, _, err = globalIdentDAO.Create(ctx, - random.PushoverIdentity("dao-identity", createOrg.Id, createApp.Id)) + random.PushoverIdentity("dao-identity", createOrg.GetId(), createApp.GetId())) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) - identityIDs = append(identityIDs, createIdentity.Id) - identityComments = append(identityComments, createIdentity.Comment) - identityTSes = append(identityTSes, createIdentity.CreatedAt.AsTime()) + identityIDs = append(identityIDs, createIdentity.GetId()) + identityComments = append(identityComments, createIdentity.GetComment()) + identityTSes = append(identityTSes, createIdentity.GetCreatedAt().AsTime()) createIdentity, _, _, err = globalIdentDAO.Create(ctx, - random.EmailIdentity("dao-identity", createOrg.Id, createApp.Id)) + random.EmailIdentity("dao-identity", createOrg.GetId(), createApp.GetId())) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) - identityIDs = append(identityIDs, createIdentity.Id) - identityComments = append(identityComments, createIdentity.Comment) - identityTSes = append(identityTSes, createIdentity.CreatedAt.AsTime()) + identityIDs = append(identityIDs, createIdentity.GetId()) + identityComments = append(identityComments, createIdentity.GetComment()) + identityTSes = append(identityTSes, createIdentity.GetCreatedAt().AsTime()) createIdentity, _, _, err = globalIdentDAO.Create(ctx, - random.BackupCodesIdentity("dao-identity", createOrg.Id, - createApp.Id)) + random.BackupCodesIdentity("dao-identity", createOrg.GetId(), + createApp.GetId())) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) - identityIDs = append(identityIDs, createIdentity.Id) - identityComments = append(identityComments, createIdentity.Comment) - identityTSes = append(identityTSes, createIdentity.CreatedAt.AsTime()) + identityIDs = append(identityIDs, createIdentity.GetId()) + identityComments = append(identityComments, createIdentity.GetComment()) + identityTSes = append(identityTSes, createIdentity.GetCreatedAt().AsTime()) createIdentity, _, _, err = globalIdentDAO.Create(ctx, - random.SecurityQuestionsIdentity("dao-identity", createOrg.Id, - createApp.Id)) + random.SecurityQuestionsIdentity("dao-identity", createOrg.GetId(), + createApp.GetId())) t.Logf("createIdentity, err: %+v, %v", createIdentity, err) require.NoError(t, err) - identityIDs = append(identityIDs, createIdentity.Id) - identityComments = append(identityComments, createIdentity.Comment) - identityTSes = append(identityTSes, createIdentity.CreatedAt.AsTime()) + identityIDs = append(identityIDs, createIdentity.GetId()) + identityComments = append(identityComments, createIdentity.GetComment()) + identityTSes = append(identityTSes, createIdentity.GetCreatedAt().AsTime()) } t.Run("List identities by valid org ID", func(t *testing.T) { @@ -726,7 +726,7 @@ func TestList(t *testing.T) { defer cancel() listIdentities, listCount, err := globalIdentDAO.List(ctx, - createOrg.Id, time.Time{}, "", 0, "") + createOrg.GetId(), time.Time{}, "", 0, "") t.Logf("listIdentities, listCount, err: %+v, %v, %v", listIdentities, listCount, err) require.NoError(t, err) @@ -735,8 +735,8 @@ func TestList(t *testing.T) { var found bool for _, identity := range listIdentities { - if identity.Id == identityIDs[len(identityIDs)-1] && - identity.Comment == identityComments[len(identityComments)-1] { + if identity.GetId() == identityIDs[len(identityIDs)-1] && + identity.GetComment() == identityComments[len(identityComments)-1] { found = true } } @@ -750,7 +750,7 @@ func TestList(t *testing.T) { defer cancel() listIdentities, listCount, err := globalIdentDAO.List(ctx, - createOrg.Id, identityTSes[0], identityIDs[0], 23, "") + createOrg.GetId(), identityTSes[0], identityIDs[0], 23, "") t.Logf("listIdentities, listCount, err: %+v, %v, %v", listIdentities, listCount, err) require.NoError(t, err) @@ -759,8 +759,8 @@ func TestList(t *testing.T) { var found bool for _, identity := range listIdentities { - if identity.Id == identityIDs[len(identityIDs)-1] && - identity.Comment == identityComments[len(identityComments)-1] { + if identity.GetId() == identityIDs[len(identityIDs)-1] && + identity.GetComment() == identityComments[len(identityComments)-1] { found = true } } @@ -774,7 +774,7 @@ func TestList(t *testing.T) { defer cancel() listIdentities, listCount, err := globalIdentDAO.List(ctx, - createOrg.Id, time.Time{}, "", 1, "") + createOrg.GetId(), time.Time{}, "", 1, "") t.Logf("listIdentities, listCount, err: %+v, %v, %v", listIdentities, listCount, err) require.NoError(t, err) @@ -789,7 +789,7 @@ func TestList(t *testing.T) { defer cancel() listIdentities, listCount, err := globalIdentDAO.List(ctx, - createOrg.Id, time.Time{}, "", 0, createApp.Id) + createOrg.GetId(), time.Time{}, "", 0, createApp.GetId()) t.Logf("listIdentities, listCount, err: %+v, %v, %v", listIdentities, listCount, err) require.NoError(t, err) @@ -798,8 +798,8 @@ func TestList(t *testing.T) { var found bool for _, identity := range listIdentities { - if identity.Id == identityIDs[len(identityIDs)-1] && - identity.Comment == identityComments[len(identityComments)-1] { + if identity.GetId() == identityIDs[len(identityIDs)-1] && + identity.GetComment() == identityComments[len(identityComments)-1] { found = true } } @@ -813,7 +813,7 @@ func TestList(t *testing.T) { defer cancel() listIdentities, listCount, err := globalIdentDAO.List(ctx, - createOrg.Id, identityTSes[0], identityIDs[0], 23, createApp.Id) + createOrg.GetId(), identityTSes[0], identityIDs[0], 23, createApp.GetId()) t.Logf("listIdentities, listCount, err: %+v, %v, %v", listIdentities, listCount, err) require.NoError(t, err) @@ -822,8 +822,8 @@ func TestList(t *testing.T) { var found bool for _, identity := range listIdentities { - if identity.Id == identityIDs[len(identityIDs)-1] && - identity.Comment == identityComments[len(identityComments)-1] { + if identity.GetId() == identityIDs[len(identityIDs)-1] && + identity.GetComment() == identityComments[len(identityComments)-1] { found = true } } diff --git a/pkg/dao/identity/method.go b/pkg/dao/identity/method.go index 56cfc912..4a094928 100644 --- a/pkg/dao/identity/method.go +++ b/pkg/dao/identity/method.go @@ -52,51 +52,51 @@ func methodToOTP(identity *api.Identity) (*oath.OTP, *otpMeta, error) { otp := &oath.OTP{Algorithm: oath.HOTP, Key: secret} meta := &otpMeta{retSecret: true} - switch m := identity.MethodOneof.(type) { + switch m := identity.GetMethodOneof().(type) { case *api.Identity_SoftwareHotpMethod: - otp.Hash = hashAPIToCrypto[m.SoftwareHotpMethod.Hash] - otp.AccountName = m.SoftwareHotpMethod.AccountName + otp.Hash = hashAPIToCrypto[m.SoftwareHotpMethod.GetHash()] + otp.AccountName = m.SoftwareHotpMethod.GetAccountName() - if m.SoftwareHotpMethod.Digits == 0 { + if m.SoftwareHotpMethod.GetDigits() == 0 { m.SoftwareHotpMethod.Digits = defaultDigits } - otp.Digits = int(m.SoftwareHotpMethod.Digits) + otp.Digits = int(m.SoftwareHotpMethod.GetDigits()) case *api.Identity_SoftwareTotpMethod: otp.Algorithm = oath.TOTP - otp.Hash = hashAPIToCrypto[m.SoftwareTotpMethod.Hash] - otp.AccountName = m.SoftwareTotpMethod.AccountName + otp.Hash = hashAPIToCrypto[m.SoftwareTotpMethod.GetHash()] + otp.AccountName = m.SoftwareTotpMethod.GetAccountName() - if m.SoftwareTotpMethod.Digits == 0 { + if m.SoftwareTotpMethod.GetDigits() == 0 { m.SoftwareTotpMethod.Digits = defaultDigits } - otp.Digits = int(m.SoftwareTotpMethod.Digits) + otp.Digits = int(m.SoftwareTotpMethod.GetDigits()) case *api.Identity_GoogleAuthHotpMethod: otp.Hash = crypto.SHA1 otp.Digits = 6 - otp.AccountName = m.GoogleAuthHotpMethod.AccountName + otp.AccountName = m.GoogleAuthHotpMethod.GetAccountName() case *api.Identity_GoogleAuthTotpMethod: otp.Algorithm = oath.TOTP otp.Hash = crypto.SHA1 otp.Digits = 6 - otp.AccountName = m.GoogleAuthTotpMethod.AccountName + otp.AccountName = m.GoogleAuthTotpMethod.GetAccountName() case *api.Identity_AppleIosTotpMethod: otp.Algorithm = oath.TOTP otp.Hash = crypto.SHA512 otp.Digits = defaultDigits case *api.Identity_HardwareHotpMethod: - otp.Hash = hashAPIToCrypto[m.HardwareHotpMethod.Hash] - otp.Digits = int(m.HardwareHotpMethod.Digits) + otp.Hash = hashAPIToCrypto[m.HardwareHotpMethod.GetHash()] + otp.Digits = int(m.HardwareHotpMethod.GetDigits()) - otp.Key = m.HardwareHotpMethod.Secret + otp.Key = m.HardwareHotpMethod.GetSecret() m.HardwareHotpMethod.Secret = nil meta.retSecret = false case *api.Identity_HardwareTotpMethod: otp.Algorithm = oath.TOTP - otp.Hash = hashAPIToCrypto[m.HardwareTotpMethod.Hash] - otp.Digits = int(m.HardwareTotpMethod.Digits) + otp.Hash = hashAPIToCrypto[m.HardwareTotpMethod.GetHash()] + otp.Digits = int(m.HardwareTotpMethod.GetDigits()) - otp.Key = m.HardwareTotpMethod.Secret + otp.Key = m.HardwareTotpMethod.GetSecret() m.HardwareTotpMethod.Secret = nil meta.retSecret = false @@ -104,31 +104,31 @@ func methodToOTP(identity *api.Identity) (*oath.OTP, *otpMeta, error) { otp.Hash = crypto.SHA512 otp.Digits = defaultDigits - meta.phone = m.SmsMethod.Phone + meta.phone = m.SmsMethod.GetPhone() meta.retSecret = false case *api.Identity_PushoverMethod: otp.Hash = crypto.SHA512 otp.Digits = defaultDigits - meta.pushoverKey = m.PushoverMethod.PushoverKey + meta.pushoverKey = m.PushoverMethod.GetPushoverKey() meta.retSecret = false case *api.Identity_EmailMethod: otp.Hash = crypto.SHA512 otp.Digits = defaultDigits - meta.email = m.EmailMethod.Email + meta.email = m.EmailMethod.GetEmail() meta.retSecret = false case *api.Identity_BackupCodesMethod: otp.Hash = crypto.SHA512 otp.Digits = defaultDigits - meta.backupCodes = m.BackupCodesMethod.Passcodes + meta.backupCodes = m.BackupCodesMethod.GetPasscodes() meta.retSecret = false case *api.Identity_SecurityQuestionsMethod: otp.Hash = crypto.SHA512 otp.Digits = defaultDigits - otp.Answer = strings.ToLower(m.SecurityQuestionsMethod.Answer) + otp.Answer = strings.ToLower(m.SecurityQuestionsMethod.GetAnswer()) m.SecurityQuestionsMethod.Answer = defaultAnswer meta.retSecret = false diff --git a/pkg/dao/identity/method_test.go b/pkg/dao/identity/method_test.go index 21ea4376..3fa561d3 100644 --- a/pkg/dao/identity/method_test.go +++ b/pkg/dao/identity/method_test.go @@ -154,7 +154,7 @@ func TestMethodToOTP(t *testing.T) { identity := random.HOTPIdentity("dao-identity", uuid.NewString(), uuid.NewString()) - identity.MethodOneof = lTest.inp.MethodOneof + identity.MethodOneof = lTest.inp.GetMethodOneof() otp, meta, err := methodToOTP(identity) t.Logf("otp, meta, err: %#v, %#v, %v", otp, meta, err) diff --git a/pkg/dao/key/crudl.go b/pkg/dao/key/crudl.go index 5e8f9ad0..e12fdcc8 100644 --- a/pkg/dao/key/crudl.go +++ b/pkg/dao/key/crudl.go @@ -22,8 +22,8 @@ func (d *DAO) Create(ctx context.Context, key *api.Key) (*api.Key, error) { now := time.Now().UTC().Truncate(time.Microsecond) key.CreatedAt = timestamppb.New(now) - if err := d.pg.QueryRowContext(ctx, createKey, key.OrgId, key.Name, - key.Role.String(), now).Scan(&key.Id); err != nil { + if err := d.pg.QueryRowContext(ctx, createKey, key.GetOrgId(), key.GetName(), + key.GetRole().String(), now).Scan(&key.Id); err != nil { return nil, dao.DBToSentinel(err) } diff --git a/pkg/dao/key/crudl_test.go b/pkg/dao/key/crudl_test.go index 7e3704cc..71449514 100644 --- a/pkg/dao/key/crudl_test.go +++ b/pkg/dao/key/crudl_test.go @@ -30,7 +30,7 @@ func TestCreate(t *testing.T) { t.Run("Create valid key", func(t *testing.T) { t.Parallel() - key := random.Key("dao-key", createOrg.Id) + key := random.Key("dao-key", createOrg.GetId()) createKey, _ := proto.Clone(key).(*api.Key) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -39,15 +39,15 @@ func TestCreate(t *testing.T) { createKey, err := globalKeyDAO.Create(ctx, createKey) t.Logf("key, createKey, err: %+v, %+v, %v", key, createKey, err) require.NoError(t, err) - require.NotEqual(t, key.Id, createKey.Id) - require.WithinDuration(t, time.Now(), createKey.CreatedAt.AsTime(), + require.NotEqual(t, key.GetId(), createKey.GetId()) + require.WithinDuration(t, time.Now(), createKey.GetCreatedAt().AsTime(), 2*time.Second) }) t.Run("Create invalid key", func(t *testing.T) { t.Parallel() - key := random.Key("dao-key", createOrg.Id) + key := random.Key("dao-key", createOrg.GetId()) key.Name = "dao-key-" + random.String(80) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -71,7 +71,7 @@ func TestRead(t *testing.T) { require.NoError(t, err) createKey, err := globalKeyDAO.Create(ctx, random.Key("dao-key", - createOrg.Id)) + createOrg.GetId())) t.Logf("createKey, err: %+v, %v", createKey, err) require.NoError(t, err) @@ -81,7 +81,7 @@ func TestRead(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() - readKey, err := globalKeyDAO.read(ctx, createKey.Id, createKey.OrgId) + readKey, err := globalKeyDAO.read(ctx, createKey.GetId(), createKey.GetOrgId()) t.Logf("readKey, err: %+v, %v", readKey, err) require.NoError(t, err) require.Equal(t, createKey, readKey) @@ -106,7 +106,7 @@ func TestRead(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() - readKey, err := globalKeyDAO.read(ctx, createKey.Id, + readKey, err := globalKeyDAO.read(ctx, createKey.GetId(), uuid.NewString()) t.Logf("readKey, err: %+v, %v", readKey, err) require.Nil(t, readKey) @@ -120,7 +120,7 @@ func TestRead(t *testing.T) { defer cancel() readKey, err := globalKeyDAO.read(ctx, random.String(10), - createKey.OrgId) + createKey.GetOrgId()) t.Logf("readKey, err: %+v, %v", readKey, err) require.Nil(t, readKey) require.ErrorIs(t, err, dao.ErrInvalidFormat) @@ -144,11 +144,11 @@ func TestDelete(t *testing.T) { defer cancel() createKey, err := globalKeyDAO.Create(ctx, random.Key("dao-key", - createOrg.Id)) + createOrg.GetId())) t.Logf("createKey, err: %+v, %v", createKey, err) require.NoError(t, err) - err = globalKeyDAO.Delete(ctx, createKey.Id, createOrg.Id) + err = globalKeyDAO.Delete(ctx, createKey.GetId(), createOrg.GetId()) t.Logf("err: %v", err) require.NoError(t, err) @@ -159,8 +159,8 @@ func TestDelete(t *testing.T) { testTimeout) defer cancel() - readKey, err := globalKeyDAO.read(ctx, createKey.Id, - createOrg.Id) + readKey, err := globalKeyDAO.read(ctx, createKey.GetId(), + createOrg.GetId()) t.Logf("readKey, err: %+v, %v", readKey, err) require.Nil(t, readKey) require.Equal(t, dao.ErrNotFound, err) @@ -173,7 +173,7 @@ func TestDelete(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() - err := globalKeyDAO.Delete(ctx, uuid.NewString(), createOrg.Id) + err := globalKeyDAO.Delete(ctx, uuid.NewString(), createOrg.GetId()) t.Logf("err: %v", err) require.Equal(t, dao.ErrNotFound, err) }) @@ -185,11 +185,11 @@ func TestDelete(t *testing.T) { defer cancel() createKey, err := globalKeyDAO.Create(ctx, random.Key("dao-key", - createOrg.Id)) + createOrg.GetId())) t.Logf("createKey, err: %+v, %v", createKey, err) require.NoError(t, err) - err = globalKeyDAO.Delete(ctx, createKey.Id, uuid.NewString()) + err = globalKeyDAO.Delete(ctx, createKey.GetId(), uuid.NewString()) t.Logf("err: %v", err) require.Equal(t, dao.ErrNotFound, err) }) @@ -211,14 +211,14 @@ func TestList(t *testing.T) { keyTSes := []time.Time{} for i := 0; i < 3; i++ { createKey, err := globalKeyDAO.Create(ctx, random.Key("dao-key", - createOrg.Id)) + createOrg.GetId())) t.Logf("createKey, err: %+v, %v", createKey, err) require.NoError(t, err) - keyIDs = append(keyIDs, createKey.Id) - keyNames = append(keyNames, createKey.Name) - keyRoles = append(keyRoles, createKey.Role) - keyTSes = append(keyTSes, createKey.CreatedAt.AsTime()) + keyIDs = append(keyIDs, createKey.GetId()) + keyNames = append(keyNames, createKey.GetName()) + keyRoles = append(keyRoles, createKey.GetRole()) + keyTSes = append(keyTSes, createKey.GetCreatedAt().AsTime()) } t.Run("List keys by valid org ID", func(t *testing.T) { @@ -227,7 +227,7 @@ func TestList(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() - listKeys, listCount, err := globalKeyDAO.List(ctx, createOrg.Id, + listKeys, listCount, err := globalKeyDAO.List(ctx, createOrg.GetId(), time.Time{}, "", 0) t.Logf("listKeys, listCount, err: %+v, %v, %v", listKeys, listCount, err) @@ -237,9 +237,9 @@ func TestList(t *testing.T) { var found bool for _, key := range listKeys { - if key.Id == keyIDs[len(keyIDs)-1] && - key.Name == keyNames[len(keyNames)-1] && - key.Role == keyRoles[len(keyRoles)-1] { + if key.GetId() == keyIDs[len(keyIDs)-1] && + key.GetName() == keyNames[len(keyNames)-1] && + key.GetRole() == keyRoles[len(keyRoles)-1] { found = true } } @@ -252,7 +252,7 @@ func TestList(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() - listKeys, listCount, err := globalKeyDAO.List(ctx, createOrg.Id, + listKeys, listCount, err := globalKeyDAO.List(ctx, createOrg.GetId(), keyTSes[0], keyIDs[0], 5) t.Logf("listKeys, listCount, err: %+v, %v, %v", listKeys, listCount, err) @@ -262,9 +262,9 @@ func TestList(t *testing.T) { var found bool for _, key := range listKeys { - if key.Id == keyIDs[len(keyIDs)-1] && - key.Name == keyNames[len(keyNames)-1] && - key.Role == keyRoles[len(keyRoles)-1] { + if key.GetId() == keyIDs[len(keyIDs)-1] && + key.GetName() == keyNames[len(keyNames)-1] && + key.GetRole() == keyRoles[len(keyRoles)-1] { found = true } } @@ -277,7 +277,7 @@ func TestList(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() - listKeys, listCount, err := globalKeyDAO.List(ctx, createOrg.Id, + listKeys, listCount, err := globalKeyDAO.List(ctx, createOrg.GetId(), time.Time{}, "", 1) t.Logf("listKeys, listCount, err: %+v, %v, %v", listKeys, listCount, err) diff --git a/pkg/dao/org/crudl.go b/pkg/dao/org/crudl.go index 8c73661e..4066163f 100644 --- a/pkg/dao/org/crudl.go +++ b/pkg/dao/org/crudl.go @@ -21,13 +21,13 @@ RETURNING id // Create creates an organization in the database. func (d *DAO) Create(ctx context.Context, org *api.Org) (*api.Org, error) { - org.Name = strings.ToLower(org.Name) + org.Name = strings.ToLower(org.GetName()) now := time.Now().UTC().Truncate(time.Microsecond) org.CreatedAt = timestamppb.New(now) org.UpdatedAt = timestamppb.New(now) - if err := d.pg.QueryRowContext(ctx, createOrg, org.Name, - org.Status.String(), org.Plan.String(), now).Scan(&org.Id); err != nil { + if err := d.pg.QueryRowContext(ctx, createOrg, org.GetName(), + org.GetStatus().String(), org.GetPlan().String(), now).Scan(&org.Id); err != nil { return nil, dao.DBToSentinel(err) } @@ -101,13 +101,13 @@ RETURNING created_at // Update updates an organization in the database. CreatedAt should not // update, so it is safe to override it at the DAO level. func (d *DAO) Update(ctx context.Context, org *api.Org) (*api.Org, error) { - org.Name = strings.ToLower(org.Name) + org.Name = strings.ToLower(org.GetName()) var createdAt time.Time updatedAt := time.Now().UTC().Truncate(time.Microsecond) org.UpdatedAt = timestamppb.New(updatedAt) - if err := d.pg.QueryRowContext(ctx, updateOrg, org.Name, - org.Status.String(), org.Plan.String(), updatedAt, org.Id).Scan( + if err := d.pg.QueryRowContext(ctx, updateOrg, org.GetName(), + org.GetStatus().String(), org.GetPlan().String(), updatedAt, org.GetId()).Scan( &createdAt); err != nil { return nil, dao.DBToSentinel(err) } @@ -116,7 +116,7 @@ func (d *DAO) Update(ctx context.Context, org *api.Org) (*api.Org, error) { // Invalidate cache on update. if d.cache != nil { - if err := d.cache.Del(ctx, orgKey(org.Id)); err != nil { + if err := d.cache.Del(ctx, orgKey(org.GetId())); err != nil { logger := hlog.FromContext(ctx) logger.Errorf("Update d.cache.Del: %v", err) } diff --git a/pkg/dao/org/crudl_test.go b/pkg/dao/org/crudl_test.go index 5eacdd67..a5710df2 100644 --- a/pkg/dao/org/crudl_test.go +++ b/pkg/dao/org/crudl_test.go @@ -33,11 +33,11 @@ func TestCreate(t *testing.T) { createOrg, err := globalOrgDAO.Create(ctx, createOrg) t.Logf("org, createOrg, err: %+v, %+v, %v", org, createOrg, err) require.NoError(t, err) - require.NotEqual(t, org.Id, createOrg.Id) - require.Equal(t, org.Name, createOrg.Name) - require.WithinDuration(t, time.Now(), createOrg.CreatedAt.AsTime(), + require.NotEqual(t, org.GetId(), createOrg.GetId()) + require.Equal(t, org.GetName(), createOrg.GetName()) + require.WithinDuration(t, time.Now(), createOrg.GetCreatedAt().AsTime(), 2*time.Second) - require.WithinDuration(t, time.Now(), createOrg.UpdatedAt.AsTime(), + require.WithinDuration(t, time.Now(), createOrg.GetUpdatedAt().AsTime(), 2*time.Second) }) @@ -45,7 +45,7 @@ func TestCreate(t *testing.T) { t.Parallel() org := random.Org("dao-org") - org.Name = strings.ToUpper(org.Name) + org.Name = strings.ToUpper(org.GetName()) createOrg, _ := proto.Clone(org).(*api.Org) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -54,11 +54,11 @@ func TestCreate(t *testing.T) { createOrg, err := globalOrgDAO.Create(ctx, createOrg) t.Logf("org, createOrg, err: %+v, %+v, %v", org, createOrg, err) require.NoError(t, err) - require.NotEqual(t, org.Id, createOrg.Id) - require.Equal(t, strings.ToLower(org.Name), createOrg.Name) - require.WithinDuration(t, time.Now(), createOrg.CreatedAt.AsTime(), + require.NotEqual(t, org.GetId(), createOrg.GetId()) + require.Equal(t, strings.ToLower(org.GetName()), createOrg.GetName()) + require.WithinDuration(t, time.Now(), createOrg.GetCreatedAt().AsTime(), 2*time.Second) - require.WithinDuration(t, time.Now(), createOrg.UpdatedAt.AsTime(), + require.WithinDuration(t, time.Now(), createOrg.GetUpdatedAt().AsTime(), 2*time.Second) }) @@ -91,7 +91,7 @@ func TestRead(t *testing.T) { t.Logf("createOrg, err: %+v, %v", createOrg, err) require.NoError(t, err) - readOrg, err := globalOrgDAO.Read(ctx, createOrg.Id) + readOrg, err := globalOrgDAO.Read(ctx, createOrg.GetId()) t.Logf("readOrg, err: %+v, %v", readOrg, err) require.NoError(t, err) require.Equal(t, createOrg, readOrg) @@ -135,7 +135,7 @@ func TestReadUpdateDeleteCache(t *testing.T) { t.Logf("createOrg, err: %+v, %v", createOrg, err) require.NoError(t, err) - readOrg, err := globalOrgDAOCache.Read(ctx, createOrg.Id) + readOrg, err := globalOrgDAOCache.Read(ctx, createOrg.GetId()) t.Logf("readOrg, err: %+v, %v", readOrg, err) require.NoError(t, err) @@ -145,7 +145,7 @@ func TestReadUpdateDeleteCache(t *testing.T) { t.Fatalf("\nExpect: %+v\nActual: %+v", createOrg, readOrg) } - readOrg, err = globalOrgDAOCache.Read(ctx, createOrg.Id) + readOrg, err = globalOrgDAOCache.Read(ctx, createOrg.GetId()) t.Logf("readOrg, err: %+v, %v", readOrg, err) require.NoError(t, err) @@ -176,15 +176,15 @@ func TestReadUpdateDeleteCache(t *testing.T) { t.Logf("createOrg, updateOrg, err: %+v, %+v, %v", createOrg, updateOrg, err) require.NoError(t, err) - require.Equal(t, createOrg.Name, updateOrg.Name) - require.Equal(t, createOrg.Status, updateOrg.Status) - require.Equal(t, createOrg.Plan, updateOrg.Plan) - require.True(t, updateOrg.UpdatedAt.AsTime().After( - updateOrg.CreatedAt.AsTime())) - require.WithinDuration(t, createOrg.CreatedAt.AsTime(), - updateOrg.UpdatedAt.AsTime(), 2*time.Second) - - readOrg, err := globalOrgDAOCache.Read(ctx, createOrg.Id) + require.Equal(t, createOrg.GetName(), updateOrg.GetName()) + require.Equal(t, createOrg.GetStatus(), updateOrg.GetStatus()) + require.Equal(t, createOrg.GetPlan(), updateOrg.GetPlan()) + require.True(t, updateOrg.GetUpdatedAt().AsTime().After( + updateOrg.GetCreatedAt().AsTime())) + require.WithinDuration(t, createOrg.GetCreatedAt().AsTime(), + updateOrg.GetUpdatedAt().AsTime(), 2*time.Second) + + readOrg, err := globalOrgDAOCache.Read(ctx, createOrg.GetId()) t.Logf("readOrg, err: %+v, %v", readOrg, err) require.NoError(t, err) @@ -205,7 +205,7 @@ func TestReadUpdateDeleteCache(t *testing.T) { t.Logf("createOrg, err: %+v, %v", createOrg, err) require.NoError(t, err) - readOrg, err := globalOrgDAOCache.Read(ctx, createOrg.Id) + readOrg, err := globalOrgDAOCache.Read(ctx, createOrg.GetId()) t.Logf("readOrg, err: %+v, %v", readOrg, err) require.NoError(t, err) @@ -215,11 +215,11 @@ func TestReadUpdateDeleteCache(t *testing.T) { t.Fatalf("\nExpect: %+v\nActual: %+v", createOrg, readOrg) } - err = globalOrgDAOCache.Delete(ctx, createOrg.Id) + err = globalOrgDAOCache.Delete(ctx, createOrg.GetId()) t.Logf("err: %v", err) require.NoError(t, err) - readOrg, err = globalOrgDAOCache.Read(ctx, createOrg.Id) + readOrg, err = globalOrgDAOCache.Read(ctx, createOrg.GetId()) t.Logf("readOrg, err: %+v, %v", readOrg, err) require.Nil(t, readOrg) require.Equal(t, dao.ErrNotFound, err) @@ -273,15 +273,15 @@ func TestUpdate(t *testing.T) { t.Logf("createOrg, updateOrg, err: %+v, %+v, %v", createOrg, updateOrg, err) require.NoError(t, err) - require.Equal(t, createOrg.Name, updateOrg.Name) - require.Equal(t, createOrg.Status, updateOrg.Status) - require.Equal(t, createOrg.Plan, updateOrg.Plan) - require.True(t, updateOrg.UpdatedAt.AsTime().After( - updateOrg.CreatedAt.AsTime())) - require.WithinDuration(t, createOrg.CreatedAt.AsTime(), - updateOrg.UpdatedAt.AsTime(), 2*time.Second) - - readOrg, err := globalOrgDAO.Read(ctx, createOrg.Id) + require.Equal(t, createOrg.GetName(), updateOrg.GetName()) + require.Equal(t, createOrg.GetStatus(), updateOrg.GetStatus()) + require.Equal(t, createOrg.GetPlan(), updateOrg.GetPlan()) + require.True(t, updateOrg.GetUpdatedAt().AsTime().After( + updateOrg.GetCreatedAt().AsTime())) + require.WithinDuration(t, createOrg.GetCreatedAt().AsTime(), + updateOrg.GetUpdatedAt().AsTime(), 2*time.Second) + + readOrg, err := globalOrgDAO.Read(ctx, createOrg.GetId()) t.Logf("readOrg, err: %+v, %v", readOrg, err) require.NoError(t, err) require.Equal(t, updateOrg, readOrg) @@ -334,7 +334,7 @@ func TestDelete(t *testing.T) { t.Logf("createOrg, err: %+v, %v", createOrg, err) require.NoError(t, err) - err = globalOrgDAO.Delete(ctx, createOrg.Id) + err = globalOrgDAO.Delete(ctx, createOrg.GetId()) t.Logf("err: %v", err) require.NoError(t, err) @@ -345,7 +345,7 @@ func TestDelete(t *testing.T) { testTimeout) defer cancel() - readOrg, err := globalOrgDAO.Read(ctx, createOrg.Id) + readOrg, err := globalOrgDAO.Read(ctx, createOrg.GetId()) t.Logf("readOrg, err: %+v, %v", readOrg, err) require.Nil(t, readOrg) require.Equal(t, dao.ErrNotFound, err) @@ -379,10 +379,10 @@ func TestList(t *testing.T) { t.Logf("createOrg, err: %+v, %v", createOrg, err) require.NoError(t, err) - orgIDs = append(orgIDs, createOrg.Id) - orgNames = append(orgNames, createOrg.Name) - orgPlans = append(orgPlans, createOrg.Plan) - orgTSes = append(orgTSes, createOrg.CreatedAt.AsTime()) + orgIDs = append(orgIDs, createOrg.GetId()) + orgNames = append(orgNames, createOrg.GetName()) + orgPlans = append(orgPlans, createOrg.GetPlan()) + orgTSes = append(orgTSes, createOrg.GetCreatedAt().AsTime()) } t.Run("List orgs", func(t *testing.T) { @@ -400,9 +400,9 @@ func TestList(t *testing.T) { var found bool for _, org := range listOrgs { - if org.Id == orgIDs[len(orgIDs)-1] && - org.Name == orgNames[len(orgNames)-1] && - org.Plan == orgPlans[len(orgPlans)-1] { + if org.GetId() == orgIDs[len(orgIDs)-1] && + org.GetName() == orgNames[len(orgNames)-1] && + org.GetPlan() == orgPlans[len(orgPlans)-1] { found = true } } diff --git a/pkg/dao/user/crudl.go b/pkg/dao/user/crudl.go index 8280d2c9..28e2fd8e 100644 --- a/pkg/dao/user/crudl.go +++ b/pkg/dao/user/crudl.go @@ -23,8 +23,8 @@ func (d *DAO) Create(ctx context.Context, user *api.User) (*api.User, error) { user.CreatedAt = timestamppb.New(now) user.UpdatedAt = timestamppb.New(now) - if err := d.pg.QueryRowContext(ctx, createUser, user.OrgId, user.Name, - user.Email, user.Role.String(), user.Status.String(), now).Scan( + if err := d.pg.QueryRowContext(ctx, createUser, user.GetOrgId(), user.GetName(), + user.GetEmail(), user.GetRole().String(), user.GetStatus().String(), now).Scan( &user.Id); err != nil { return nil, dao.DBToSentinel(err) } @@ -106,9 +106,9 @@ func (d *DAO) Update(ctx context.Context, user *api.User) (*api.User, error) { updatedAt := time.Now().UTC().Truncate(time.Microsecond) user.UpdatedAt = timestamppb.New(updatedAt) - if err := d.pg.QueryRowContext(ctx, updateUser, user.Name, user.Email, - user.Role.String(), user.Status.String(), updatedAt, user.Id, - user.OrgId).Scan(&createdAt); err != nil { + if err := d.pg.QueryRowContext(ctx, updateUser, user.GetName(), user.GetEmail(), + user.GetRole().String(), user.GetStatus().String(), updatedAt, user.GetId(), + user.GetOrgId()).Scan(&createdAt); err != nil { return nil, dao.DBToSentinel(err) } diff --git a/pkg/dao/user/crudl_test.go b/pkg/dao/user/crudl_test.go index 84230d4c..796b1645 100644 --- a/pkg/dao/user/crudl_test.go +++ b/pkg/dao/user/crudl_test.go @@ -30,7 +30,7 @@ func TestCreate(t *testing.T) { t.Run("Create valid user", func(t *testing.T) { t.Parallel() - user := random.User("dao-user", createOrg.Id) + user := random.User("dao-user", createOrg.GetId()) createUser, _ := proto.Clone(user).(*api.User) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -39,17 +39,17 @@ func TestCreate(t *testing.T) { createUser, err := globalUserDAO.Create(ctx, createUser) t.Logf("user, createUser, err: %+v, %+v, %v", user, createUser, err) require.NoError(t, err) - require.NotEqual(t, user.Id, createUser.Id) - require.WithinDuration(t, time.Now(), createUser.CreatedAt.AsTime(), + require.NotEqual(t, user.GetId(), createUser.GetId()) + require.WithinDuration(t, time.Now(), createUser.GetCreatedAt().AsTime(), 2*time.Second) - require.WithinDuration(t, time.Now(), createUser.UpdatedAt.AsTime(), + require.WithinDuration(t, time.Now(), createUser.GetUpdatedAt().AsTime(), 2*time.Second) }) t.Run("Create invalid user", func(t *testing.T) { t.Parallel() - user := random.User("dao-user", createOrg.Id) + user := random.User("dao-user", createOrg.GetId()) user.Email = "dao-user-" + random.String(80) createUser, _ := proto.Clone(user).(*api.User) @@ -74,7 +74,7 @@ func TestRead(t *testing.T) { require.NoError(t, err) createUser, err := globalUserDAO.Create(ctx, random.User("dao-user", - createOrg.Id)) + createOrg.GetId())) t.Logf("createUser, err: %+v, %v", createUser, err) require.NoError(t, err) @@ -84,8 +84,8 @@ func TestRead(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() - readUser, err := globalUserDAO.Read(ctx, createUser.Id, - createUser.OrgId) + readUser, err := globalUserDAO.Read(ctx, createUser.GetId(), + createUser.GetOrgId()) t.Logf("readUser, err: %+v, %v", readUser, err) require.NoError(t, err) require.Equal(t, createUser, readUser) @@ -110,7 +110,7 @@ func TestRead(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() - readUser, err := globalUserDAO.Read(ctx, createUser.Id, + readUser, err := globalUserDAO.Read(ctx, createUser.GetId(), uuid.NewString()) t.Logf("readUser, err: %+v, %v", readUser, err) require.Nil(t, readUser) @@ -124,7 +124,7 @@ func TestRead(t *testing.T) { defer cancel() readUser, err := globalUserDAO.Read(ctx, random.String(10), - createUser.OrgId) + createUser.GetOrgId()) t.Logf("readUser, err: %+v, %v", readUser, err) require.Nil(t, readUser) require.ErrorIs(t, err, dao.ErrInvalidFormat) @@ -145,13 +145,13 @@ func TestReadByEmail(t *testing.T) { t.Logf("createOrg, err: %+v, %v", createOrg, err) require.NoError(t, err) - user := random.User("dao-user", createOrg.Id) + user := random.User("dao-user", createOrg.GetId()) user.Status = api.Status_ACTIVE createUser, err := globalUserDAO.Create(ctx, user) t.Logf("createUser, err: %+v, %v", createUser, err) require.NoError(t, err) - err = globalUserDAO.UpdatePassword(ctx, createUser.Id, createOrg.Id, + err = globalUserDAO.UpdatePassword(ctx, createUser.GetId(), createOrg.GetId(), hash) t.Logf("err: %v", err) require.NoError(t, err) @@ -163,17 +163,17 @@ func TestReadByEmail(t *testing.T) { defer cancel() readUser, readHash, err := globalUserDAO.ReadByEmail(ctx, - createUser.Email, createOrg.Name) + createUser.GetEmail(), createOrg.GetName()) t.Logf("readUser, readHash, err: %+v, %s, %v", readUser, readHash, err) require.NoError(t, err) require.Equal(t, hash, readHash) // Normalize timestamp. - require.True(t, readUser.UpdatedAt.AsTime().After( - createUser.CreatedAt.AsTime())) - require.WithinDuration(t, readUser.UpdatedAt.AsTime(), - createUser.UpdatedAt.AsTime(), 2*time.Second) - createUser.UpdatedAt = readUser.UpdatedAt + require.True(t, readUser.GetUpdatedAt().AsTime().After( + createUser.GetCreatedAt().AsTime())) + require.WithinDuration(t, readUser.GetUpdatedAt().AsTime(), + createUser.GetUpdatedAt().AsTime(), 2*time.Second) + createUser.UpdatedAt = readUser.GetUpdatedAt() // Testify does not currently support protobuf equality: // https://github.com/stretchr/testify/issues/758 @@ -188,7 +188,7 @@ func TestReadByEmail(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() - user := random.User("dao-user", createOrg.Id) + user := random.User("dao-user", createOrg.GetId()) user.Status = api.Status_DISABLED createUser, err := globalUserDAO.Create(ctx, user) t.Logf("createUser, err: %+v, %v", createUser, err) @@ -216,7 +216,7 @@ func TestReadByEmail(t *testing.T) { require.NoError(t, err) createUser, err := globalUserDAO.Create(ctx, random.User("dao-user", - createOrg.Id)) + createOrg.GetId())) t.Logf("createUser, err: %+v, %v", createUser, err) require.NoError(t, err) @@ -249,7 +249,7 @@ func TestReadByEmail(t *testing.T) { defer cancel() readUser, readHash, err := globalUserDAO.ReadByEmail(ctx, - createUser.Email, random.String(10)) + createUser.GetEmail(), random.String(10)) t.Logf("readUser, readHash, err: %+v, %s, %v", readUser, readHash, err) require.Nil(t, readUser) require.Nil(t, readHash) @@ -274,7 +274,7 @@ func TestUpdate(t *testing.T) { defer cancel() createUser, err := globalUserDAO.Create(ctx, random.User("dao-user", - createOrg.Id)) + createOrg.GetId())) t.Logf("createUser, err: %+v, %v", createUser, err) require.NoError(t, err) @@ -289,17 +289,17 @@ func TestUpdate(t *testing.T) { t.Logf("createUser, updateUser, err: %+v, %+v, %v", createUser, updateUser, err) require.NoError(t, err) - require.Equal(t, createUser.Name, updateUser.Name) - require.Equal(t, createUser.Email, updateUser.Email) - require.Equal(t, createUser.Role, updateUser.Role) - require.Equal(t, createUser.Status, updateUser.Status) - require.True(t, updateUser.UpdatedAt.AsTime().After( - updateUser.CreatedAt.AsTime())) - require.WithinDuration(t, createUser.CreatedAt.AsTime(), - updateUser.UpdatedAt.AsTime(), 2*time.Second) - - readUser, err := globalUserDAO.Read(ctx, createUser.Id, - createUser.OrgId) + require.Equal(t, createUser.GetName(), updateUser.GetName()) + require.Equal(t, createUser.GetEmail(), updateUser.GetEmail()) + require.Equal(t, createUser.GetRole(), updateUser.GetRole()) + require.Equal(t, createUser.GetStatus(), updateUser.GetStatus()) + require.True(t, updateUser.GetUpdatedAt().AsTime().After( + updateUser.GetCreatedAt().AsTime())) + require.WithinDuration(t, createUser.GetCreatedAt().AsTime(), + updateUser.GetUpdatedAt().AsTime(), 2*time.Second) + + readUser, err := globalUserDAO.Read(ctx, createUser.GetId(), + createUser.GetOrgId()) t.Logf("readUser, err: %+v, %v", readUser, err) require.NoError(t, err) require.Equal(t, updateUser, readUser) @@ -312,7 +312,7 @@ func TestUpdate(t *testing.T) { defer cancel() updateUser, err := globalUserDAO.Update(ctx, random.User("dao-user", - createOrg.Id)) + createOrg.GetId())) t.Logf("updateUser, err: %+v, %v", updateUser, err) require.Nil(t, updateUser) require.Equal(t, dao.ErrNotFound, err) @@ -325,7 +325,7 @@ func TestUpdate(t *testing.T) { defer cancel() createUser, err := globalUserDAO.Create(ctx, random.User("dao-user", - createOrg.Id)) + createOrg.GetId())) t.Logf("createUser, err: %+v, %v", createUser, err) require.NoError(t, err) @@ -348,7 +348,7 @@ func TestUpdate(t *testing.T) { defer cancel() createUser, err := globalUserDAO.Create(ctx, random.User("dao-user", - createOrg.Id)) + createOrg.GetId())) t.Logf("createUser, err: %+v, %v", createUser, err) require.NoError(t, err) @@ -384,11 +384,11 @@ func TestUpdatePassword(t *testing.T) { defer cancel() createUser, err := globalUserDAO.Create(ctx, random.User("dao-user", - createOrg.Id)) + createOrg.GetId())) t.Logf("createUser, err: %+v, %v", createUser, err) require.NoError(t, err) - err = globalUserDAO.UpdatePassword(ctx, createUser.Id, createOrg.Id, + err = globalUserDAO.UpdatePassword(ctx, createUser.GetId(), createOrg.GetId(), hash) t.Logf("err: %v", err) require.NoError(t, err) @@ -401,7 +401,7 @@ func TestUpdatePassword(t *testing.T) { defer cancel() err := globalUserDAO.UpdatePassword(ctx, uuid.NewString(), - createOrg.Id, hash) + createOrg.GetId(), hash) t.Logf("err: %v", err) require.Equal(t, dao.ErrNotFound, err) }) @@ -413,11 +413,11 @@ func TestUpdatePassword(t *testing.T) { defer cancel() createUser, err := globalUserDAO.Create(ctx, random.User("dao-user", - createOrg.Id)) + createOrg.GetId())) t.Logf("createUser, err: %+v, %v", createUser, err) require.NoError(t, err) - err = globalUserDAO.UpdatePassword(ctx, createUser.Id, + err = globalUserDAO.UpdatePassword(ctx, createUser.GetId(), uuid.NewString(), hash) t.Logf("err: %v", err) require.Equal(t, dao.ErrNotFound, err) @@ -441,11 +441,11 @@ func TestDelete(t *testing.T) { defer cancel() createUser, err := globalUserDAO.Create(ctx, random.User("dao-user", - createOrg.Id)) + createOrg.GetId())) t.Logf("createUser, err: %+v, %v", createUser, err) require.NoError(t, err) - err = globalUserDAO.Delete(ctx, createUser.Id, createOrg.Id) + err = globalUserDAO.Delete(ctx, createUser.GetId(), createOrg.GetId()) t.Logf("err: %v", err) require.NoError(t, err) @@ -456,8 +456,8 @@ func TestDelete(t *testing.T) { testTimeout) defer cancel() - readUser, err := globalUserDAO.Read(ctx, createUser.Id, - createOrg.Id) + readUser, err := globalUserDAO.Read(ctx, createUser.GetId(), + createOrg.GetId()) t.Logf("readUser, err: %+v, %v", readUser, err) require.Nil(t, readUser) require.Equal(t, dao.ErrNotFound, err) @@ -470,7 +470,7 @@ func TestDelete(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() - err := globalUserDAO.Delete(ctx, uuid.NewString(), createOrg.Id) + err := globalUserDAO.Delete(ctx, uuid.NewString(), createOrg.GetId()) t.Logf("err: %v", err) require.Equal(t, dao.ErrNotFound, err) }) @@ -482,11 +482,11 @@ func TestDelete(t *testing.T) { defer cancel() createUser, err := globalUserDAO.Create(ctx, random.User("dao-user", - createOrg.Id)) + createOrg.GetId())) t.Logf("createUser, err: %+v, %v", createUser, err) require.NoError(t, err) - err = globalUserDAO.Delete(ctx, createUser.Id, uuid.NewString()) + err = globalUserDAO.Delete(ctx, createUser.GetId(), uuid.NewString()) t.Logf("err: %v", err) require.Equal(t, dao.ErrNotFound, err) }) @@ -508,14 +508,14 @@ func TestList(t *testing.T) { userTSes := []time.Time{} for i := 0; i < 3; i++ { createUser, err := globalUserDAO.Create(ctx, random.User("dao-user", - createOrg.Id)) + createOrg.GetId())) t.Logf("createUser, err: %+v, %v", createUser, err) require.NoError(t, err) - userIDs = append(userIDs, createUser.Id) - userNames = append(userNames, createUser.Name) - userRoles = append(userRoles, createUser.Role) - userTSes = append(userTSes, createUser.CreatedAt.AsTime()) + userIDs = append(userIDs, createUser.GetId()) + userNames = append(userNames, createUser.GetName()) + userRoles = append(userRoles, createUser.GetRole()) + userTSes = append(userTSes, createUser.GetCreatedAt().AsTime()) } t.Run("List users by valid org ID", func(t *testing.T) { @@ -524,7 +524,7 @@ func TestList(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() - listUsers, listCount, err := globalUserDAO.List(ctx, createOrg.Id, + listUsers, listCount, err := globalUserDAO.List(ctx, createOrg.GetId(), time.Time{}, "", 0) t.Logf("listUsers, listCount, err: %+v, %v, %v", listUsers, listCount, err) @@ -534,9 +534,9 @@ func TestList(t *testing.T) { var found bool for _, user := range listUsers { - if user.Id == userIDs[len(userIDs)-1] && - user.Name == userNames[len(userNames)-1] && - user.Role == userRoles[len(userRoles)-1] { + if user.GetId() == userIDs[len(userIDs)-1] && + user.GetName() == userNames[len(userNames)-1] && + user.GetRole() == userRoles[len(userRoles)-1] { found = true } } @@ -549,7 +549,7 @@ func TestList(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() - listUsers, listCount, err := globalUserDAO.List(ctx, createOrg.Id, + listUsers, listCount, err := globalUserDAO.List(ctx, createOrg.GetId(), userTSes[0], userIDs[0], 5) t.Logf("listUsers, listCount, err: %+v, %v, %v", listUsers, listCount, err) @@ -559,9 +559,9 @@ func TestList(t *testing.T) { var found bool for _, user := range listUsers { - if user.Id == userIDs[len(userIDs)-1] && - user.Name == userNames[len(userNames)-1] && - user.Role == userRoles[len(userRoles)-1] { + if user.GetId() == userIDs[len(userIDs)-1] && + user.GetName() == userNames[len(userNames)-1] && + user.GetRole() == userRoles[len(userRoles)-1] { found = true } } @@ -574,7 +574,7 @@ func TestList(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() - listUsers, listCount, err := globalUserDAO.List(ctx, createOrg.Id, + listUsers, listCount, err := globalUserDAO.List(ctx, createOrg.GetId(), time.Time{}, "", 1) t.Logf("listUsers, listCount, err: %+v, %v, %v", listUsers, listCount, err) diff --git a/pkg/test/random/api_test.go b/pkg/test/random/api_test.go index 0122f466..5bf10421 100644 --- a/pkg/test/random/api_test.go +++ b/pkg/test/random/api_test.go @@ -27,8 +27,8 @@ func TestOrg(t *testing.T) { t.Logf("o1, o2: %+v, %+v", o1, o2) require.NotEqual(t, o1, o2) - require.True(t, strings.HasPrefix(o1.Name, prefix)) - require.True(t, strings.HasPrefix(o2.Name, prefix)) + require.True(t, strings.HasPrefix(o1.GetName(), prefix)) + require.True(t, strings.HasPrefix(o2.GetName(), prefix)) }) } } @@ -50,10 +50,10 @@ func TestUser(t *testing.T) { t.Logf("u1, u2: %+v, %+v", u1, u2) require.NotEqual(t, u1, u2) - require.True(t, strings.HasPrefix(u1.Name, prefix)) - require.True(t, strings.HasPrefix(u2.Name, prefix)) - require.True(t, strings.HasPrefix(u1.Email, prefix)) - require.True(t, strings.HasPrefix(u2.Email, prefix)) + require.True(t, strings.HasPrefix(u1.GetName(), prefix)) + require.True(t, strings.HasPrefix(u2.GetName(), prefix)) + require.True(t, strings.HasPrefix(u1.GetEmail(), prefix)) + require.True(t, strings.HasPrefix(u2.GetEmail(), prefix)) }) } } @@ -75,8 +75,8 @@ func TestKey(t *testing.T) { t.Logf("k1, k2: %+v, %+v", k1, k2) require.NotEqual(t, k1, k2) - require.True(t, strings.HasPrefix(k1.Name, prefix)) - require.True(t, strings.HasPrefix(k2.Name, prefix)) + require.True(t, strings.HasPrefix(k1.GetName(), prefix)) + require.True(t, strings.HasPrefix(k2.GetName(), prefix)) }) } } @@ -98,12 +98,12 @@ func TestApp(t *testing.T) { t.Logf("a1, a2: %+v, %+v", a1, a2) require.NotEqual(t, a1, a2) - require.True(t, strings.HasPrefix(a1.Name, prefix)) - require.True(t, strings.HasPrefix(a2.Name, prefix)) - require.True(t, strings.HasPrefix(a1.DisplayName, prefix)) - require.True(t, strings.HasPrefix(a2.DisplayName, prefix)) - require.True(t, strings.HasPrefix(a1.Email, prefix)) - require.True(t, strings.HasPrefix(a2.Email, prefix)) + require.True(t, strings.HasPrefix(a1.GetName(), prefix)) + require.True(t, strings.HasPrefix(a2.GetName(), prefix)) + require.True(t, strings.HasPrefix(a1.GetDisplayName(), prefix)) + require.True(t, strings.HasPrefix(a2.GetDisplayName(), prefix)) + require.True(t, strings.HasPrefix(a1.GetEmail(), prefix)) + require.True(t, strings.HasPrefix(a2.GetEmail(), prefix)) }) } } @@ -126,8 +126,8 @@ func TestHOTPIdentity(t *testing.T) { t.Logf("i1, i2: %+v, %+v", i1, i2) require.NotEqual(t, i1, i2) - require.True(t, strings.HasPrefix(i1.Comment, prefix)) - require.True(t, strings.HasPrefix(i2.Comment, prefix)) + require.True(t, strings.HasPrefix(i1.GetComment(), prefix)) + require.True(t, strings.HasPrefix(i2.GetComment(), prefix)) }) } } @@ -150,8 +150,8 @@ func TestSMSIdentity(t *testing.T) { t.Logf("i1, i2: %+v, %+v", i1, i2) require.NotEqual(t, i1, i2) - require.True(t, strings.HasPrefix(i1.Comment, prefix)) - require.True(t, strings.HasPrefix(i2.Comment, prefix)) + require.True(t, strings.HasPrefix(i1.GetComment(), prefix)) + require.True(t, strings.HasPrefix(i2.GetComment(), prefix)) }) } } @@ -174,8 +174,8 @@ func TestPushoverIdentity(t *testing.T) { t.Logf("i1, i2: %+v, %+v", i1, i2) require.NotEqual(t, i1, i2) - require.True(t, strings.HasPrefix(i1.Comment, prefix)) - require.True(t, strings.HasPrefix(i2.Comment, prefix)) + require.True(t, strings.HasPrefix(i1.GetComment(), prefix)) + require.True(t, strings.HasPrefix(i2.GetComment(), prefix)) }) } } @@ -198,8 +198,8 @@ func TestEmailIdentity(t *testing.T) { t.Logf("i1, i2: %+v, %+v", i1, i2) require.NotEqual(t, i1, i2) - require.True(t, strings.HasPrefix(i1.Comment, prefix)) - require.True(t, strings.HasPrefix(i2.Comment, prefix)) + require.True(t, strings.HasPrefix(i1.GetComment(), prefix)) + require.True(t, strings.HasPrefix(i2.GetComment(), prefix)) }) } } @@ -222,8 +222,8 @@ func TestBackupCodesIdentity(t *testing.T) { t.Logf("i1, i2: %+v, %+v", i1, i2) require.NotEqual(t, i1, i2) - require.True(t, strings.HasPrefix(i1.Comment, prefix)) - require.True(t, strings.HasPrefix(i2.Comment, prefix)) + require.True(t, strings.HasPrefix(i1.GetComment(), prefix)) + require.True(t, strings.HasPrefix(i2.GetComment(), prefix)) }) } } @@ -246,8 +246,8 @@ func TestSecurityQuestionsIdentity(t *testing.T) { t.Logf("i1, i2: %+v, %+v", i1, i2) require.NotEqual(t, i1, i2) - require.True(t, strings.HasPrefix(i1.Comment, prefix)) - require.True(t, strings.HasPrefix(i2.Comment, prefix)) + require.True(t, strings.HasPrefix(i1.GetComment(), prefix)) + require.True(t, strings.HasPrefix(i2.GetComment(), prefix)) }) } } @@ -269,11 +269,11 @@ func TestEvent(t *testing.T) { t.Logf("e1, e2: %+v, %+v", e1, e2) require.NotEqual(t, e1, e2) - if e1.Error != "" { - require.True(t, strings.HasPrefix(e1.Error, prefix)) + if e1.GetError() != "" { + require.True(t, strings.HasPrefix(e1.GetError(), prefix)) } - if e2.Error != "" { - require.True(t, strings.HasPrefix(e2.Error, prefix)) + if e2.GetError() != "" { + require.True(t, strings.HasPrefix(e2.GetError(), prefix)) } }) } diff --git a/tool/hermes-create/main.go b/tool/hermes-create/main.go index 24600015..280e3735 100644 --- a/tool/hermes-create/main.go +++ b/tool/hermes-create/main.go @@ -134,7 +134,7 @@ func main() { cancel() checkErr(err) - orgID = createOrg.Id + orgID = createOrg.GetId() fmt.Fprintf(os.Stdout, "Org: %+v\n", createOrg) fallthrough @@ -157,7 +157,7 @@ func main() { createUser, err := userDAO.Create(ctx, u) checkErr(err) - checkErr(userDAO.UpdatePassword(ctx, createUser.Id, orgID, hash)) + checkErr(userDAO.UpdatePassword(ctx, createUser.GetId(), orgID, hash)) fmt.Fprintf(os.Stdout, "User: %+v\n", createUser) // Generate QR code. case "qr": @@ -177,7 +177,7 @@ func main() { checkErr(err) otp.AccountName = os.Args[0] - qr, err := otp.QR(app.DisplayName) + qr, err := otp.QR(app.GetDisplayName()) checkErr(err) fmt.Fprint(os.Stdout, base64.StdEncoding.EncodeToString(qr)) diff --git a/vendor/google.golang.org/grpc/README.md b/vendor/google.golang.org/grpc/README.md index 1bc92248..ab0fbb79 100644 --- a/vendor/google.golang.org/grpc/README.md +++ b/vendor/google.golang.org/grpc/README.md @@ -1,8 +1,8 @@ # gRPC-Go -[![Build Status](https://travis-ci.org/grpc/grpc-go.svg)](https://travis-ci.org/grpc/grpc-go) [![GoDoc](https://pkg.go.dev/badge/google.golang.org/grpc)][API] [![GoReportCard](https://goreportcard.com/badge/grpc/grpc-go)](https://goreportcard.com/report/github.com/grpc/grpc-go) +[![codecov](https://codecov.io/gh/grpc/grpc-go/graph/badge.svg)](https://codecov.io/gh/grpc/grpc-go) The [Go][] implementation of [gRPC][]: A high performance, open source, general RPC framework that puts mobile and HTTP/2 first. For more information see the diff --git a/vendor/google.golang.org/grpc/attributes/attributes.go b/vendor/google.golang.org/grpc/attributes/attributes.go index 712fef4d..52d530d7 100644 --- a/vendor/google.golang.org/grpc/attributes/attributes.go +++ b/vendor/google.golang.org/grpc/attributes/attributes.go @@ -121,9 +121,9 @@ func (a *Attributes) String() string { return sb.String() } -func str(x any) string { +func str(x any) (s string) { if v, ok := x.(fmt.Stringer); ok { - return v.String() + return fmt.Sprint(v) } else if v, ok := x.(string); ok { return v } diff --git a/vendor/google.golang.org/grpc/balancer/balancer.go b/vendor/google.golang.org/grpc/balancer/balancer.go index b6377f44..d79560a2 100644 --- a/vendor/google.golang.org/grpc/balancer/balancer.go +++ b/vendor/google.golang.org/grpc/balancer/balancer.go @@ -30,6 +30,7 @@ import ( "google.golang.org/grpc/channelz" "google.golang.org/grpc/connectivity" "google.golang.org/grpc/credentials" + "google.golang.org/grpc/grpclog" "google.golang.org/grpc/internal" "google.golang.org/grpc/metadata" "google.golang.org/grpc/resolver" @@ -39,6 +40,8 @@ import ( var ( // m is a map from name to balancer builder. m = make(map[string]Builder) + + logger = grpclog.Component("balancer") ) // Register registers the balancer builder to the balancer map. b.Name @@ -51,6 +54,12 @@ var ( // an init() function), and is not thread-safe. If multiple Balancers are // registered with the same name, the one registered last will take effect. func Register(b Builder) { + if strings.ToLower(b.Name()) != b.Name() { + // TODO: Skip the use of strings.ToLower() to index the map after v1.59 + // is released to switch to case sensitive balancer registry. Also, + // remove this warning and update the docstrings for Register and Get. + logger.Warningf("Balancer registered with name %q. grpc-go will be switching to case sensitive balancer registries soon", b.Name()) + } m[strings.ToLower(b.Name())] = b } @@ -70,6 +79,12 @@ func init() { // Note that the compare is done in a case-insensitive fashion. // If no builder is register with the name, nil will be returned. func Get(name string) Builder { + if strings.ToLower(name) != name { + // TODO: Skip the use of strings.ToLower() to index the map after v1.59 + // is released to switch to case sensitive balancer registry. Also, + // remove this warning and update the docstrings for Register and Get. + logger.Warningf("Balancer retrieved for name %q. grpc-go will be switching to case sensitive balancer registries soon", name) + } if b, ok := m[strings.ToLower(name)]; ok { return b } diff --git a/vendor/google.golang.org/grpc/clientconn.go b/vendor/google.golang.org/grpc/clientconn.go index ff7fea10..429c389e 100644 --- a/vendor/google.golang.org/grpc/clientconn.go +++ b/vendor/google.golang.org/grpc/clientconn.go @@ -337,8 +337,8 @@ func (cc *ClientConn) exitIdleMode() error { return errConnClosing } if cc.idlenessState != ccIdlenessStateIdle { - cc.mu.Unlock() channelz.Infof(logger, cc.channelzID, "ClientConn asked to exit idle mode, current mode is %v", cc.idlenessState) + cc.mu.Unlock() return nil } @@ -404,13 +404,13 @@ func (cc *ClientConn) exitIdleMode() error { // name resolver, load balancer and any subchannels. func (cc *ClientConn) enterIdleMode() error { cc.mu.Lock() + defer cc.mu.Unlock() + if cc.conns == nil { - cc.mu.Unlock() return ErrClientConnClosing } if cc.idlenessState != ccIdlenessStateActive { - channelz.Errorf(logger, cc.channelzID, "ClientConn asked to enter idle mode, current mode is %v", cc.idlenessState) - cc.mu.Unlock() + channelz.Warningf(logger, cc.channelzID, "ClientConn asked to enter idle mode, current mode is %v", cc.idlenessState) return nil } @@ -431,14 +431,14 @@ func (cc *ClientConn) enterIdleMode() error { cc.balancerWrapper.enterIdleMode() cc.csMgr.updateState(connectivity.Idle) cc.idlenessState = ccIdlenessStateIdle - cc.mu.Unlock() + cc.addTraceEvent("entering idle mode") go func() { - cc.addTraceEvent("entering idle mode") for ac := range conns { ac.tearDown(errConnIdling) } }() + return nil } @@ -804,6 +804,12 @@ func init() { internal.SubscribeToConnectivityStateChanges = func(cc *ClientConn, s grpcsync.Subscriber) func() { return cc.csMgr.pubSub.Subscribe(s) } + internal.EnterIdleModeForTesting = func(cc *ClientConn) error { + return cc.enterIdleMode() + } + internal.ExitIdleModeForTesting = func(cc *ClientConn) error { + return cc.exitIdleMode() + } } func (cc *ClientConn) maybeApplyDefaultServiceConfig(addrs []resolver.Address) { diff --git a/vendor/google.golang.org/grpc/dialoptions.go b/vendor/google.golang.org/grpc/dialoptions.go index 1fd0d5c1..cfc9fd85 100644 --- a/vendor/google.golang.org/grpc/dialoptions.go +++ b/vendor/google.golang.org/grpc/dialoptions.go @@ -644,6 +644,7 @@ func defaultDialOptions() dialOptions { UseProxy: true, }, recvBufferPool: nopBufferPool{}, + idleTimeout: 30 * time.Minute, } } @@ -680,8 +681,8 @@ func WithResolvers(rs ...resolver.Builder) DialOption { // channel will exit idle mode when the Connect() method is called or when an // RPC is initiated. // -// By default this feature is disabled, which can also be explicitly configured -// by passing zero to this function. +// A default timeout of 30 minutes will be used if this dial option is not set +// at dial time and idleness can be disabled by passing a timeout of zero. // // # Experimental // diff --git a/vendor/google.golang.org/grpc/encoding/encoding.go b/vendor/google.golang.org/grpc/encoding/encoding.go index 69d5580b..5ebf88d7 100644 --- a/vendor/google.golang.org/grpc/encoding/encoding.go +++ b/vendor/google.golang.org/grpc/encoding/encoding.go @@ -38,6 +38,10 @@ const Identity = "identity" // Compressor is used for compressing and decompressing when sending or // receiving messages. +// +// If a Compressor implements `DecompressedSize(compressedBytes []byte) int`, +// gRPC will invoke it to determine the size of the buffer allocated for the +// result of decompression. A return value of -1 indicates unknown size. type Compressor interface { // Compress writes the data written to wc to w after compressing it. If an // error occurs while initializing the compressor, that error is returned @@ -51,15 +55,6 @@ type Compressor interface { // coding header. The result must be static; the result cannot change // between calls. Name() string - // If a Compressor implements - // DecompressedSize(compressedBytes []byte) int, gRPC will call it - // to determine the size of the buffer allocated for the result of decompression. - // Return -1 to indicate unknown size. - // - // Experimental - // - // Notice: This API is EXPERIMENTAL and may be changed or removed in a - // later release. } var registeredCompressor = make(map[string]Compressor) diff --git a/vendor/google.golang.org/grpc/health/grpc_health_v1/health_grpc.pb.go b/vendor/google.golang.org/grpc/health/grpc_health_v1/health_grpc.pb.go index a01a1b4d..4439cda0 100644 --- a/vendor/google.golang.org/grpc/health/grpc_health_v1/health_grpc.pb.go +++ b/vendor/google.golang.org/grpc/health/grpc_health_v1/health_grpc.pb.go @@ -44,8 +44,15 @@ const ( // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type HealthClient interface { - // If the requested service is unknown, the call will fail with status - // NOT_FOUND. + // Check gets the health of the specified service. If the requested service + // is unknown, the call will fail with status NOT_FOUND. If the caller does + // not specify a service name, the server should respond with its overall + // health status. + // + // Clients should set a deadline when calling Check, and can declare the + // server unhealthy if they do not receive a timely response. + // + // Check implementations should be idempotent and side effect free. Check(ctx context.Context, in *HealthCheckRequest, opts ...grpc.CallOption) (*HealthCheckResponse, error) // Performs a watch for the serving status of the requested service. // The server will immediately send back a message indicating the current @@ -118,8 +125,15 @@ func (x *healthWatchClient) Recv() (*HealthCheckResponse, error) { // All implementations should embed UnimplementedHealthServer // for forward compatibility type HealthServer interface { - // If the requested service is unknown, the call will fail with status - // NOT_FOUND. + // Check gets the health of the specified service. If the requested service + // is unknown, the call will fail with status NOT_FOUND. If the caller does + // not specify a service name, the server should respond with its overall + // health status. + // + // Clients should set a deadline when calling Check, and can declare the + // server unhealthy if they do not receive a timely response. + // + // Check implementations should be idempotent and side effect free. Check(context.Context, *HealthCheckRequest) (*HealthCheckResponse, error) // Performs a watch for the serving status of the requested service. // The server will immediately send back a message indicating the current diff --git a/vendor/google.golang.org/grpc/internal/backoff/backoff.go b/vendor/google.golang.org/grpc/internal/backoff/backoff.go index 5fc0ee3d..fed1c011 100644 --- a/vendor/google.golang.org/grpc/internal/backoff/backoff.go +++ b/vendor/google.golang.org/grpc/internal/backoff/backoff.go @@ -23,6 +23,8 @@ package backoff import ( + "context" + "errors" "time" grpcbackoff "google.golang.org/grpc/backoff" @@ -71,3 +73,37 @@ func (bc Exponential) Backoff(retries int) time.Duration { } return time.Duration(backoff) } + +// ErrResetBackoff is the error to be returned by the function executed by RunF, +// to instruct the latter to reset its backoff state. +var ErrResetBackoff = errors.New("reset backoff state") + +// RunF provides a convenient way to run a function f repeatedly until the +// context expires or f returns a non-nil error that is not ErrResetBackoff. +// When f returns ErrResetBackoff, RunF continues to run f, but resets its +// backoff state before doing so. backoff accepts an integer representing the +// number of retries, and returns the amount of time to backoff. +func RunF(ctx context.Context, f func() error, backoff func(int) time.Duration) { + attempt := 0 + timer := time.NewTimer(0) + for ctx.Err() == nil { + select { + case <-timer.C: + case <-ctx.Done(): + timer.Stop() + return + } + + err := f() + if errors.Is(err, ErrResetBackoff) { + timer.Reset(0) + attempt = 0 + continue + } + if err != nil { + return + } + timer.Reset(backoff(attempt)) + attempt++ + } +} diff --git a/vendor/google.golang.org/grpc/internal/internal.go b/vendor/google.golang.org/grpc/internal/internal.go index c8a8c76d..0d94c63e 100644 --- a/vendor/google.golang.org/grpc/internal/internal.go +++ b/vendor/google.golang.org/grpc/internal/internal.go @@ -175,6 +175,12 @@ var ( // GRPCResolverSchemeExtraMetadata determines when gRPC will add extra // metadata to RPCs. GRPCResolverSchemeExtraMetadata string = "xds" + + // EnterIdleModeForTesting gets the ClientConn to enter IDLE mode. + EnterIdleModeForTesting any // func(*grpc.ClientConn) error + + // ExitIdleModeForTesting gets the ClientConn to exit IDLE mode. + ExitIdleModeForTesting any // func(*grpc.ClientConn) error ) // HealthChecker defines the signature of the client-side LB channel health checking function. diff --git a/vendor/google.golang.org/grpc/internal/status/status.go b/vendor/google.golang.org/grpc/internal/status/status.go index 4cf85cad..03ef2fed 100644 --- a/vendor/google.golang.org/grpc/internal/status/status.go +++ b/vendor/google.golang.org/grpc/internal/status/status.go @@ -43,6 +43,34 @@ type Status struct { s *spb.Status } +// NewWithProto returns a new status including details from statusProto. This +// is meant to be used by the gRPC library only. +func NewWithProto(code codes.Code, message string, statusProto []string) *Status { + if len(statusProto) != 1 { + // No grpc-status-details bin header, or multiple; just ignore. + return &Status{s: &spb.Status{Code: int32(code), Message: message}} + } + st := &spb.Status{} + if err := proto.Unmarshal([]byte(statusProto[0]), st); err != nil { + // Probably not a google.rpc.Status proto; do not provide details. + return &Status{s: &spb.Status{Code: int32(code), Message: message}} + } + if st.Code == int32(code) { + // The codes match between the grpc-status header and the + // grpc-status-details-bin header; use the full details proto. + return &Status{s: st} + } + return &Status{ + s: &spb.Status{ + Code: int32(codes.Internal), + Message: fmt.Sprintf( + "grpc-status-details-bin mismatch: grpc-status=%v, grpc-message=%q, grpc-status-details-bin=%+v", + code, message, st, + ), + }, + } +} + // New returns a Status representing c and msg. func New(c codes.Code, msg string) *Status { return &Status{s: &spb.Status{Code: int32(c), Message: msg}} diff --git a/vendor/google.golang.org/grpc/internal/transport/handler_server.go b/vendor/google.golang.org/grpc/internal/transport/handler_server.go index 98f80e3f..17f7a21b 100644 --- a/vendor/google.golang.org/grpc/internal/transport/handler_server.go +++ b/vendor/google.golang.org/grpc/internal/transport/handler_server.go @@ -220,18 +220,20 @@ func (ht *serverHandlerTransport) WriteStatus(s *Stream, st *status.Status) erro h.Set("Grpc-Message", encodeGrpcMessage(m)) } + s.hdrMu.Lock() if p := st.Proto(); p != nil && len(p.Details) > 0 { + delete(s.trailer, grpcStatusDetailsBinHeader) stBytes, err := proto.Marshal(p) if err != nil { // TODO: return error instead, when callers are able to handle it. panic(err) } - h.Set("Grpc-Status-Details-Bin", encodeBinHeader(stBytes)) + h.Set(grpcStatusDetailsBinHeader, encodeBinHeader(stBytes)) } - if md := s.Trailer(); len(md) > 0 { - for k, vv := range md { + if len(s.trailer) > 0 { + for k, vv := range s.trailer { // Clients don't tolerate reading restricted headers after some non restricted ones were sent. if isReservedHeader(k) { continue @@ -243,6 +245,7 @@ func (ht *serverHandlerTransport) WriteStatus(s *Stream, st *status.Status) erro } } } + s.hdrMu.Unlock() }) if err == nil { // transport has not been closed @@ -287,7 +290,7 @@ func (ht *serverHandlerTransport) writeCommonHeaders(s *Stream) { } // writeCustomHeaders sets custom headers set on the stream via SetHeader -// on the first write call (Write, WriteHeader, or WriteStatus). +// on the first write call (Write, WriteHeader, or WriteStatus) func (ht *serverHandlerTransport) writeCustomHeaders(s *Stream) { h := ht.rw.Header() @@ -344,7 +347,7 @@ func (ht *serverHandlerTransport) WriteHeader(s *Stream, md metadata.MD) error { return err } -func (ht *serverHandlerTransport) HandleStreams(startStream func(*Stream), traceCtx func(context.Context, string) context.Context) { +func (ht *serverHandlerTransport) HandleStreams(startStream func(*Stream)) { // With this transport type there will be exactly 1 stream: this HTTP request. ctx := ht.req.Context() diff --git a/vendor/google.golang.org/grpc/internal/transport/http2_client.go b/vendor/google.golang.org/grpc/internal/transport/http2_client.go index badab8ac..d6f5c493 100644 --- a/vendor/google.golang.org/grpc/internal/transport/http2_client.go +++ b/vendor/google.golang.org/grpc/internal/transport/http2_client.go @@ -1399,7 +1399,6 @@ func (t *http2Client) operateHeaders(frame *http2.MetaHeadersFrame) { mdata = make(map[string][]string) contentTypeErr = "malformed header: missing HTTP content-type" grpcMessage string - statusGen *status.Status recvCompress string httpStatusCode *int httpStatusErr string @@ -1434,12 +1433,6 @@ func (t *http2Client) operateHeaders(frame *http2.MetaHeadersFrame) { rawStatusCode = codes.Code(uint32(code)) case "grpc-message": grpcMessage = decodeGrpcMessage(hf.Value) - case "grpc-status-details-bin": - var err error - statusGen, err = decodeGRPCStatusDetails(hf.Value) - if err != nil { - headerError = fmt.Sprintf("transport: malformed grpc-status-details-bin: %v", err) - } case ":status": if hf.Value == "200" { httpStatusErr = "" @@ -1548,14 +1541,12 @@ func (t *http2Client) operateHeaders(frame *http2.MetaHeadersFrame) { return } - if statusGen == nil { - statusGen = status.New(rawStatusCode, grpcMessage) - } + status := istatus.NewWithProto(rawStatusCode, grpcMessage, mdata[grpcStatusDetailsBinHeader]) // If client received END_STREAM from server while stream was still active, // send RST_STREAM. rstStream := s.getState() == streamActive - t.closeStream(s, io.EOF, rstStream, http2.ErrCodeNo, statusGen, mdata, true) + t.closeStream(s, io.EOF, rstStream, http2.ErrCodeNo, status, mdata, true) } // readServerPreface reads and handles the initial settings frame from the diff --git a/vendor/google.golang.org/grpc/internal/transport/http2_server.go b/vendor/google.golang.org/grpc/internal/transport/http2_server.go index c06db679..6fa1eb41 100644 --- a/vendor/google.golang.org/grpc/internal/transport/http2_server.go +++ b/vendor/google.golang.org/grpc/internal/transport/http2_server.go @@ -342,7 +342,7 @@ func NewServerTransport(conn net.Conn, config *ServerConfig) (_ ServerTransport, // operateHeaders takes action on the decoded headers. Returns an error if fatal // error encountered and transport needs to close, otherwise returns nil. -func (t *http2Server) operateHeaders(frame *http2.MetaHeadersFrame, handle func(*Stream), traceCtx func(context.Context, string) context.Context) error { +func (t *http2Server) operateHeaders(frame *http2.MetaHeadersFrame, handle func(*Stream)) error { // Acquire max stream ID lock for entire duration t.maxStreamMu.Lock() defer t.maxStreamMu.Unlock() @@ -561,7 +561,7 @@ func (t *http2Server) operateHeaders(frame *http2.MetaHeadersFrame, handle func( } if t.inTapHandle != nil { var err error - if s.ctx, err = t.inTapHandle(s.ctx, &tap.Info{FullMethodName: s.method}); err != nil { + if s.ctx, err = t.inTapHandle(s.ctx, &tap.Info{FullMethodName: s.method, Header: mdata}); err != nil { t.mu.Unlock() if t.logger.V(logLevel) { t.logger.Infof("Aborting the stream early due to InTapHandle failure: %v", err) @@ -592,7 +592,6 @@ func (t *http2Server) operateHeaders(frame *http2.MetaHeadersFrame, handle func( s.requestRead = func(n int) { t.adjustWindow(s, uint32(n)) } - s.ctx = traceCtx(s.ctx, s.method) for _, sh := range t.stats { s.ctx = sh.TagRPC(s.ctx, &stats.RPCTagInfo{FullMethodName: s.method}) inHeader := &stats.InHeader{ @@ -630,7 +629,7 @@ func (t *http2Server) operateHeaders(frame *http2.MetaHeadersFrame, handle func( // HandleStreams receives incoming streams using the given handler. This is // typically run in a separate goroutine. // traceCtx attaches trace to ctx and returns the new context. -func (t *http2Server) HandleStreams(handle func(*Stream), traceCtx func(context.Context, string) context.Context) { +func (t *http2Server) HandleStreams(handle func(*Stream)) { defer close(t.readerDone) for { t.controlBuf.throttle() @@ -665,7 +664,7 @@ func (t *http2Server) HandleStreams(handle func(*Stream), traceCtx func(context. } switch frame := frame.(type) { case *http2.MetaHeadersFrame: - if err := t.operateHeaders(frame, handle, traceCtx); err != nil { + if err := t.operateHeaders(frame, handle); err != nil { t.Close(err) break } @@ -1053,12 +1052,15 @@ func (t *http2Server) WriteStatus(s *Stream, st *status.Status) error { headerFields = append(headerFields, hpack.HeaderField{Name: "grpc-message", Value: encodeGrpcMessage(st.Message())}) if p := st.Proto(); p != nil && len(p.Details) > 0 { + // Do not use the user's grpc-status-details-bin (if present) if we are + // even attempting to set our own. + delete(s.trailer, grpcStatusDetailsBinHeader) stBytes, err := proto.Marshal(p) if err != nil { // TODO: return error instead, when callers are able to handle it. t.logger.Errorf("Failed to marshal rpc status: %s, error: %v", pretty.ToJSON(p), err) } else { - headerFields = append(headerFields, hpack.HeaderField{Name: "grpc-status-details-bin", Value: encodeBinHeader(stBytes)}) + headerFields = append(headerFields, hpack.HeaderField{Name: grpcStatusDetailsBinHeader, Value: encodeBinHeader(stBytes)}) } } diff --git a/vendor/google.golang.org/grpc/internal/transport/http_util.go b/vendor/google.golang.org/grpc/internal/transport/http_util.go index 19581400..dc29d590 100644 --- a/vendor/google.golang.org/grpc/internal/transport/http_util.go +++ b/vendor/google.golang.org/grpc/internal/transport/http_util.go @@ -34,12 +34,9 @@ import ( "time" "unicode/utf8" - "github.com/golang/protobuf/proto" "golang.org/x/net/http2" "golang.org/x/net/http2/hpack" - spb "google.golang.org/genproto/googleapis/rpc/status" "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) const ( @@ -88,6 +85,8 @@ var ( } ) +var grpcStatusDetailsBinHeader = "grpc-status-details-bin" + // isReservedHeader checks whether hdr belongs to HTTP2 headers // reserved by gRPC protocol. Any other headers are classified as the // user-specified metadata. @@ -103,7 +102,6 @@ func isReservedHeader(hdr string) bool { "grpc-message", "grpc-status", "grpc-timeout", - "grpc-status-details-bin", // Intentionally exclude grpc-previous-rpc-attempts and // grpc-retry-pushback-ms, which are "reserved", but their API // intentionally works via metadata. @@ -154,18 +152,6 @@ func decodeMetadataHeader(k, v string) (string, error) { return v, nil } -func decodeGRPCStatusDetails(rawDetails string) (*status.Status, error) { - v, err := decodeBinHeader(rawDetails) - if err != nil { - return nil, err - } - st := &spb.Status{} - if err = proto.Unmarshal(v, st); err != nil { - return nil, err - } - return status.FromProto(st), nil -} - type timeoutUnit uint8 const ( diff --git a/vendor/google.golang.org/grpc/internal/transport/transport.go b/vendor/google.golang.org/grpc/internal/transport/transport.go index 74a811fc..aac056e7 100644 --- a/vendor/google.golang.org/grpc/internal/transport/transport.go +++ b/vendor/google.golang.org/grpc/internal/transport/transport.go @@ -698,7 +698,7 @@ type ClientTransport interface { // Write methods for a given Stream will be called serially. type ServerTransport interface { // HandleStreams receives incoming streams using the given handler. - HandleStreams(func(*Stream), func(context.Context, string) context.Context) + HandleStreams(func(*Stream)) // WriteHeader sends the header metadata for the given stream. // WriteHeader may not be called on all streams. diff --git a/vendor/google.golang.org/grpc/server.go b/vendor/google.golang.org/grpc/server.go index eeae92fb..8f60d421 100644 --- a/vendor/google.golang.org/grpc/server.go +++ b/vendor/google.golang.org/grpc/server.go @@ -983,7 +983,7 @@ func (s *Server) serveStreams(st transport.ServerTransport) { f := func() { defer streamQuota.release() defer wg.Done() - s.handleStream(st, stream, s.traceInfo(st, stream)) + s.handleStream(st, stream) } if s.opts.numServerWorkers > 0 { @@ -995,12 +995,6 @@ func (s *Server) serveStreams(st transport.ServerTransport) { } } go f() - }, func(ctx context.Context, method string) context.Context { - if !EnableTracing { - return ctx - } - tr := trace.New("grpc.Recv."+methodFamily(method), method) - return trace.NewContext(ctx, tr) }) wg.Wait() } @@ -1049,30 +1043,6 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { s.serveStreams(st) } -// traceInfo returns a traceInfo and associates it with stream, if tracing is enabled. -// If tracing is not enabled, it returns nil. -func (s *Server) traceInfo(st transport.ServerTransport, stream *transport.Stream) (trInfo *traceInfo) { - if !EnableTracing { - return nil - } - tr, ok := trace.FromContext(stream.Context()) - if !ok { - return nil - } - - trInfo = &traceInfo{ - tr: tr, - firstLine: firstLine{ - client: false, - remoteAddr: st.RemoteAddr(), - }, - } - if dl, ok := stream.Context().Deadline(); ok { - trInfo.firstLine.deadline = time.Until(dl) - } - return trInfo -} - func (s *Server) addConn(addr string, st transport.ServerTransport) bool { s.mu.Lock() defer s.mu.Unlock() @@ -1133,7 +1103,7 @@ func (s *Server) incrCallsFailed() { atomic.AddInt64(&s.czData.callsFailed, 1) } -func (s *Server) sendResponse(t transport.ServerTransport, stream *transport.Stream, msg any, cp Compressor, opts *transport.Options, comp encoding.Compressor) error { +func (s *Server) sendResponse(ctx context.Context, t transport.ServerTransport, stream *transport.Stream, msg any, cp Compressor, opts *transport.Options, comp encoding.Compressor) error { data, err := encode(s.getCodec(stream.ContentSubtype()), msg) if err != nil { channelz.Error(logger, s.channelzID, "grpc: server failed to encode response: ", err) @@ -1152,7 +1122,7 @@ func (s *Server) sendResponse(t transport.ServerTransport, stream *transport.Str err = t.Write(stream, hdr, payload, opts) if err == nil { for _, sh := range s.opts.statsHandlers { - sh.HandleRPC(stream.Context(), outPayload(false, msg, data, payload, time.Now())) + sh.HandleRPC(ctx, outPayload(false, msg, data, payload, time.Now())) } } return err @@ -1194,7 +1164,7 @@ func getChainUnaryHandler(interceptors []UnaryServerInterceptor, curr int, info } } -func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport.Stream, info *serviceInfo, md *MethodDesc, trInfo *traceInfo) (err error) { +func (s *Server) processUnaryRPC(ctx context.Context, t transport.ServerTransport, stream *transport.Stream, info *serviceInfo, md *MethodDesc, trInfo *traceInfo) (err error) { shs := s.opts.statsHandlers if len(shs) != 0 || trInfo != nil || channelz.IsOn() { if channelz.IsOn() { @@ -1208,7 +1178,7 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport. IsClientStream: false, IsServerStream: false, } - sh.HandleRPC(stream.Context(), statsBegin) + sh.HandleRPC(ctx, statsBegin) } if trInfo != nil { trInfo.tr.LazyLog(&trInfo.firstLine, false) @@ -1240,7 +1210,7 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport. if err != nil && err != io.EOF { end.Error = toRPCErr(err) } - sh.HandleRPC(stream.Context(), end) + sh.HandleRPC(ctx, end) } if channelz.IsOn() { @@ -1262,7 +1232,6 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport. } } if len(binlogs) != 0 { - ctx := stream.Context() md, _ := metadata.FromIncomingContext(ctx) logEntry := &binarylog.ClientHeader{ Header: md, @@ -1348,7 +1317,7 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport. return status.Errorf(codes.Internal, "grpc: error unmarshalling request: %v", err) } for _, sh := range shs { - sh.HandleRPC(stream.Context(), &stats.InPayload{ + sh.HandleRPC(ctx, &stats.InPayload{ RecvTime: time.Now(), Payload: v, Length: len(d), @@ -1362,7 +1331,7 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport. Message: d, } for _, binlog := range binlogs { - binlog.Log(stream.Context(), cm) + binlog.Log(ctx, cm) } } if trInfo != nil { @@ -1370,7 +1339,7 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport. } return nil } - ctx := NewContextWithServerTransportStream(stream.Context(), stream) + ctx = NewContextWithServerTransportStream(ctx, stream) reply, appErr := md.Handler(info.serviceImpl, ctx, df, s.opts.unaryInt) if appErr != nil { appStatus, ok := status.FromError(appErr) @@ -1395,7 +1364,7 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport. Header: h, } for _, binlog := range binlogs { - binlog.Log(stream.Context(), sh) + binlog.Log(ctx, sh) } } st := &binarylog.ServerTrailer{ @@ -1403,7 +1372,7 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport. Err: appErr, } for _, binlog := range binlogs { - binlog.Log(stream.Context(), st) + binlog.Log(ctx, st) } } return appErr @@ -1418,7 +1387,7 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport. if stream.SendCompress() != sendCompressorName { comp = encoding.GetCompressor(stream.SendCompress()) } - if err := s.sendResponse(t, stream, reply, cp, opts, comp); err != nil { + if err := s.sendResponse(ctx, t, stream, reply, cp, opts, comp); err != nil { if err == io.EOF { // The entire stream is done (for unary RPC only). return err @@ -1445,8 +1414,8 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport. Err: appErr, } for _, binlog := range binlogs { - binlog.Log(stream.Context(), sh) - binlog.Log(stream.Context(), st) + binlog.Log(ctx, sh) + binlog.Log(ctx, st) } } return err @@ -1460,8 +1429,8 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport. Message: reply, } for _, binlog := range binlogs { - binlog.Log(stream.Context(), sh) - binlog.Log(stream.Context(), sm) + binlog.Log(ctx, sh) + binlog.Log(ctx, sm) } } if channelz.IsOn() { @@ -1479,7 +1448,7 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport. Err: appErr, } for _, binlog := range binlogs { - binlog.Log(stream.Context(), st) + binlog.Log(ctx, st) } } return t.WriteStatus(stream, statusOK) @@ -1521,7 +1490,7 @@ func getChainStreamHandler(interceptors []StreamServerInterceptor, curr int, inf } } -func (s *Server) processStreamingRPC(t transport.ServerTransport, stream *transport.Stream, info *serviceInfo, sd *StreamDesc, trInfo *traceInfo) (err error) { +func (s *Server) processStreamingRPC(ctx context.Context, t transport.ServerTransport, stream *transport.Stream, info *serviceInfo, sd *StreamDesc, trInfo *traceInfo) (err error) { if channelz.IsOn() { s.incrCallsStarted() } @@ -1535,10 +1504,10 @@ func (s *Server) processStreamingRPC(t transport.ServerTransport, stream *transp IsServerStream: sd.ServerStreams, } for _, sh := range shs { - sh.HandleRPC(stream.Context(), statsBegin) + sh.HandleRPC(ctx, statsBegin) } } - ctx := NewContextWithServerTransportStream(stream.Context(), stream) + ctx = NewContextWithServerTransportStream(ctx, stream) ss := &serverStream{ ctx: ctx, t: t, @@ -1574,7 +1543,7 @@ func (s *Server) processStreamingRPC(t transport.ServerTransport, stream *transp end.Error = toRPCErr(err) } for _, sh := range shs { - sh.HandleRPC(stream.Context(), end) + sh.HandleRPC(ctx, end) } } @@ -1616,7 +1585,7 @@ func (s *Server) processStreamingRPC(t transport.ServerTransport, stream *transp logEntry.PeerAddr = peer.Addr } for _, binlog := range ss.binlogs { - binlog.Log(stream.Context(), logEntry) + binlog.Log(ctx, logEntry) } } @@ -1694,7 +1663,7 @@ func (s *Server) processStreamingRPC(t transport.ServerTransport, stream *transp Err: appErr, } for _, binlog := range ss.binlogs { - binlog.Log(stream.Context(), st) + binlog.Log(ctx, st) } } t.WriteStatus(ss.s, appStatus) @@ -1712,33 +1681,50 @@ func (s *Server) processStreamingRPC(t transport.ServerTransport, stream *transp Err: appErr, } for _, binlog := range ss.binlogs { - binlog.Log(stream.Context(), st) + binlog.Log(ctx, st) } } return t.WriteStatus(ss.s, statusOK) } -func (s *Server) handleStream(t transport.ServerTransport, stream *transport.Stream, trInfo *traceInfo) { +func (s *Server) handleStream(t transport.ServerTransport, stream *transport.Stream) { + ctx := stream.Context() + var ti *traceInfo + if EnableTracing { + tr := trace.New("grpc.Recv."+methodFamily(stream.Method()), stream.Method()) + ctx = trace.NewContext(ctx, tr) + ti = &traceInfo{ + tr: tr, + firstLine: firstLine{ + client: false, + remoteAddr: t.RemoteAddr(), + }, + } + if dl, ok := ctx.Deadline(); ok { + ti.firstLine.deadline = time.Until(dl) + } + } + sm := stream.Method() if sm != "" && sm[0] == '/' { sm = sm[1:] } pos := strings.LastIndex(sm, "/") if pos == -1 { - if trInfo != nil { - trInfo.tr.LazyLog(&fmtStringer{"Malformed method name %q", []any{sm}}, true) - trInfo.tr.SetError() + if ti != nil { + ti.tr.LazyLog(&fmtStringer{"Malformed method name %q", []any{sm}}, true) + ti.tr.SetError() } errDesc := fmt.Sprintf("malformed method name: %q", stream.Method()) if err := t.WriteStatus(stream, status.New(codes.Unimplemented, errDesc)); err != nil { - if trInfo != nil { - trInfo.tr.LazyLog(&fmtStringer{"%v", []any{err}}, true) - trInfo.tr.SetError() + if ti != nil { + ti.tr.LazyLog(&fmtStringer{"%v", []any{err}}, true) + ti.tr.SetError() } channelz.Warningf(logger, s.channelzID, "grpc: Server.handleStream failed to write status: %v", err) } - if trInfo != nil { - trInfo.tr.Finish() + if ti != nil { + ti.tr.Finish() } return } @@ -1748,17 +1734,17 @@ func (s *Server) handleStream(t transport.ServerTransport, stream *transport.Str srv, knownService := s.services[service] if knownService { if md, ok := srv.methods[method]; ok { - s.processUnaryRPC(t, stream, srv, md, trInfo) + s.processUnaryRPC(ctx, t, stream, srv, md, ti) return } if sd, ok := srv.streams[method]; ok { - s.processStreamingRPC(t, stream, srv, sd, trInfo) + s.processStreamingRPC(ctx, t, stream, srv, sd, ti) return } } // Unknown service, or known server unknown method. if unknownDesc := s.opts.unknownStreamDesc; unknownDesc != nil { - s.processStreamingRPC(t, stream, nil, unknownDesc, trInfo) + s.processStreamingRPC(ctx, t, stream, nil, unknownDesc, ti) return } var errDesc string @@ -1767,19 +1753,19 @@ func (s *Server) handleStream(t transport.ServerTransport, stream *transport.Str } else { errDesc = fmt.Sprintf("unknown method %v for service %v", method, service) } - if trInfo != nil { - trInfo.tr.LazyPrintf("%s", errDesc) - trInfo.tr.SetError() + if ti != nil { + ti.tr.LazyPrintf("%s", errDesc) + ti.tr.SetError() } if err := t.WriteStatus(stream, status.New(codes.Unimplemented, errDesc)); err != nil { - if trInfo != nil { - trInfo.tr.LazyLog(&fmtStringer{"%v", []any{err}}, true) - trInfo.tr.SetError() + if ti != nil { + ti.tr.LazyLog(&fmtStringer{"%v", []any{err}}, true) + ti.tr.SetError() } channelz.Warningf(logger, s.channelzID, "grpc: Server.handleStream failed to write status: %v", err) } - if trInfo != nil { - trInfo.tr.Finish() + if ti != nil { + ti.tr.Finish() } } diff --git a/vendor/google.golang.org/grpc/tap/tap.go b/vendor/google.golang.org/grpc/tap/tap.go index bfa5dfa4..07f01257 100644 --- a/vendor/google.golang.org/grpc/tap/tap.go +++ b/vendor/google.golang.org/grpc/tap/tap.go @@ -27,6 +27,8 @@ package tap import ( "context" + + "google.golang.org/grpc/metadata" ) // Info defines the relevant information needed by the handles. @@ -34,6 +36,10 @@ type Info struct { // FullMethodName is the string of grpc method (in the format of // /package.service/method). FullMethodName string + + // Header contains the header metadata received. + Header metadata.MD + // TODO: More to be added. } diff --git a/vendor/google.golang.org/grpc/version.go b/vendor/google.golang.org/grpc/version.go index 724ad210..6d2cadd7 100644 --- a/vendor/google.golang.org/grpc/version.go +++ b/vendor/google.golang.org/grpc/version.go @@ -19,4 +19,4 @@ package grpc // Version is the current grpc version. -const Version = "1.58.3" +const Version = "1.59.0" diff --git a/vendor/google.golang.org/grpc/vet.sh b/vendor/google.golang.org/grpc/vet.sh index bbc9e2e3..bb480f1f 100644 --- a/vendor/google.golang.org/grpc/vet.sh +++ b/vendor/google.golang.org/grpc/vet.sh @@ -93,6 +93,9 @@ git grep -l -e 'grpclog.I' --or -e 'grpclog.W' --or -e 'grpclog.E' --or -e 'grpc # - Ensure all ptypes proto packages are renamed when importing. not git grep "\(import \|^\s*\)\"github.com/golang/protobuf/ptypes/" -- "*.go" +# - Ensure all usages of grpc_testing package are renamed when importing. +not git grep "\(import \|^\s*\)\"google.golang.org/grpc/interop/grpc_testing" -- "*.go" + # - Ensure all xds proto imports are renamed to *pb or *grpc. git grep '"github.com/envoyproxy/go-control-plane/envoy' -- '*.go' ':(exclude)*.pb.go' | not grep -v 'pb "\|grpc "' diff --git a/vendor/modules.txt b/vendor/modules.txt index 8ee30647..842ba5d3 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -65,8 +65,8 @@ github.com/mennanov/fmutils # github.com/nsqio/go-nsq v1.1.0 ## explicit; go 1.11 github.com/nsqio/go-nsq -# github.com/ownmfa/api/go v1.0.27 -## explicit; go 1.21.0 +# github.com/ownmfa/api/go v1.0.28 +## explicit; go 1.21.3 github.com/ownmfa/api/go/api # github.com/pmezard/go-difflib v1.0.0 ## explicit @@ -132,18 +132,18 @@ golang.org/x/text/transform golang.org/x/text/unicode/bidi golang.org/x/text/unicode/norm golang.org/x/text/width -# google.golang.org/genproto v0.0.0-20231009173412-8bfb1ae86b6c +# google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b ## explicit; go 1.19 google.golang.org/genproto/internal -# google.golang.org/genproto/googleapis/api v0.0.0-20231009173412-8bfb1ae86b6c +# google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b ## explicit; go 1.19 google.golang.org/genproto/googleapis/api google.golang.org/genproto/googleapis/api/annotations google.golang.org/genproto/googleapis/api/httpbody -# google.golang.org/genproto/googleapis/rpc v0.0.0-20231009173412-8bfb1ae86b6c +# google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b ## explicit; go 1.19 google.golang.org/genproto/googleapis/rpc/status -# google.golang.org/grpc v1.58.3 +# google.golang.org/grpc v1.59.0 ## explicit; go 1.19 google.golang.org/grpc google.golang.org/grpc/attributes diff --git a/web/hermes.swagger.json b/web/hermes.swagger.json index f2f5f7f0..0a6c08ec 100644 --- a/web/hermes.swagger.json +++ b/web/hermes.swagger.json @@ -3,7 +3,7 @@ "info": { "title": "Hermes", "description": "Getting started with the Hermes API:\n- Log in with `/v1/sessions/login` using your provided credentials. Click `Authorize` below and enter the returned token.\n- Create an application with `/v1/applications`. For SMS and software token authentication methods, all template fields can be left empty.\n- (Optional) Create an `AUTHENTICATOR` role API key with `/v1/sessions/keys`. Re-authorize using the returned token.\n\nActivate an identity (single occurrence):\n- Create an identity with `/v1/applications/{identity.appID}/identities`. Only one method field is supported when creating an identity.\n- Issue the returned identity a challenge with `/v1/applications/{appID}/identities/{id}/challenge`.\n- Activate the identity with `/v1/applications/{appID}/identities/{id}/activate` using the received or generated challenge.\n\nVerify an identity (ongoing):\n- Issue the identity a challenge with `/v1/applications/{appID}/identities/{id}/challenge`.\n- Verify the identity with `/v1/applications/{appID}/identities/{id}/verify` using the received or generated challenge.", - "version": "1.0.27", + "version": "1.0.28", "contact": { "name": "OwnMFA", "url": "https://www.ownmfa.com/",