forked from gravitational/teleport
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support non-gogo objects for auth service events. (gravitational#29056)
* 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
Showing
11 changed files
with
3,495 additions
and
5,945 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
}) | ||
} | ||
} |
Oops, something went wrong.