Skip to content

Commit

Permalink
Support non-gogo objects for auth service events. (gravitational#29056)
Browse files Browse the repository at this point in the history
* Support non-gogo objects for auth service events.

Auth service events will now support non-gogo objects. This was done by
generating the events and associated objects with regular go protobuf
instead of gogo and then correcting the code for the differences in
code generation.

* Correct lock copying in event protobuf.

* Temporarily ignore event.proto in buf breaking.

* Attempt to keep buf breaking from breaking.

* Remove comment.

* Rename gproto to googleproto.

* Rename api/client/proto import to authpb and googleproto to proto.

* Correct comment, add in test exercising proto.Equal.

* GCI.

* Events test actually does work.
  • Loading branch information
mdwn authored Jul 17, 2023
1 parent 000cc84 commit 983e0cc
Show file tree
Hide file tree
Showing 11 changed files with 3,495 additions and 5,945 deletions.
2 changes: 1 addition & 1 deletion api/client/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func EventTypeToGRPC(in types.OpType) (proto.Operation, error) {
}

// EventFromGRPC converts proto.Event to types.Event
func EventFromGRPC(in proto.Event) (*types.Event, error) {
func EventFromGRPC(in *proto.Event) (*types.Event, error) {
eventType, err := EventTypeFromGRPC(in.Type)
if err != nil {
return nil, trace.Wrap(err)
Expand Down
112 changes: 112 additions & 0 deletions api/client/events_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Copyright 2023 Gravitational, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package client

import (
"testing"

"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"

authpb "github.com/gravitational/teleport/api/client/proto"
"github.com/gravitational/teleport/api/types"
)

// TestEventEqual will test an event object against a google proto.Equal. This is
// primarily to catch potential issues with using our "mixed" gogo + regular protobuf
// strategy.
func TestEventEqual(t *testing.T) {
app1, err := types.NewAppV3(types.Metadata{
Name: "app1",
}, types.AppSpecV3{
URI: "https://uri.com",
PublicAddr: "https://public-addr.com",
})
require.NoError(t, err)

app2, err := types.NewAppV3(types.Metadata{
Name: "app2",
}, types.AppSpecV3{
URI: "https://uri.com",
PublicAddr: "https://public-addr.com",
})
require.NoError(t, err)

tests := []struct {
name string
event1 *authpb.Event
event2 *authpb.Event
expected bool
}{
{
name: "empty equal",
event1: &authpb.Event{},
event2: &authpb.Event{},
expected: true,
},
{
name: "empty not equal",
event1: &authpb.Event{},
event2: &authpb.Event{
Type: authpb.Operation_PUT,
Resource: &authpb.Event_App{
App: app1,
},
},
expected: false,
},
{
name: "gogo oneof equal",
event1: &authpb.Event{
Type: authpb.Operation_PUT,
Resource: &authpb.Event_App{
App: app1,
},
},
event2: &authpb.Event{
Type: authpb.Operation_PUT,
Resource: &authpb.Event_App{
App: app1,
},
},
expected: true,
},
{
name: "gogo oneof not equal",
event1: &authpb.Event{
Type: authpb.Operation_PUT,
Resource: &authpb.Event_App{
App: app1,
},
},
event2: &authpb.Event{
Type: authpb.Operation_PUT,
Resource: &authpb.Event_App{
App: app2,
},
},
expected: false,
},
}

for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()

require.Equal(t, test.expected, proto.Equal(test.event1, test.event2))
})
}
}
Loading

0 comments on commit 983e0cc

Please sign in to comment.