@@ -14,11 +14,13 @@ import (
1414 "github.com/prometheus/client_golang/prometheus/testutil"
1515 "github.com/stretchr/testify/require"
1616 pb "gitlab.com/gitlab-org/cells/topology-service/clients/go/proto"
17+ types_proto "gitlab.com/gitlab-org/cells/topology-service/clients/go/proto/types/v1"
1718 "gitlab.com/gitlab-org/gitlab-shell/v14/internal/metrics"
1819 "gitlab.com/gitlab-org/gitlab-shell/v14/internal/testhelper"
1920 "gitlab.com/gitlab-org/gitlab-shell/v14/internal/topology/topologytest"
2021 "gitlab.com/gitlab-org/labkit/correlation"
2122 "google.golang.org/grpc"
23+ "google.golang.org/protobuf/proto"
2224)
2325
2426const localhostAddr = "localhost:9090"
@@ -128,11 +130,7 @@ func TestClient_Classify(t *testing.T) {
128130 require .Equal (t , pb .ClassifyAction_PROXY , result .GetAction ())
129131 require .Equal (t , "cell-1.gitlab.com:443" , result .GetProxy ().GetAddress ())
130132
131- // Verify the request was constructed correctly
132- require .NotNil (t , mock .LastRequest .GetClassificationKey ())
133- require .Equal (t , "my-group/my-project" , mock .LastRequest .GetClaim ().GetRoute ())
134- require .Equal (t , pb .ClassifyType_UNSPECIFIED , mock .LastRequest .GetType ())
135- require .Empty (t , mock .LastRequest .GetValue ())
133+ require .Equal (t , "my-group/my-project" , mock .LastClaim (t ).GetRoute ())
136134 })
137135
138136 t .Run ("successful SSH key claim returns proxy info" , func (t * testing.T ) {
@@ -152,7 +150,7 @@ func TestClient_Classify(t *testing.T) {
152150
153151 require .NoError (t , err )
154152 require .Equal (t , pb .ClassifyAction_PROXY , result .GetAction ())
155- require .Equal (t , "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQ" , mock .LastRequest . GetClaim ( ).GetSshKey ())
153+ require .Equal (t , "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQ" , mock .LastClaim ( t ).GetSshKey ())
156154 })
157155
158156 t .Run ("successful project ID claim returns proxy info" , func (t * testing.T ) {
@@ -172,7 +170,46 @@ func TestClient_Classify(t *testing.T) {
172170
173171 require .NoError (t , err )
174172 require .Equal (t , pb .ClassifyAction_PROXY , result .GetAction ())
175- require .Equal (t , int64 (42 ), mock .LastRequest .GetClaim ().GetProjectId ())
173+ require .Equal (t , int64 (42 ), mock .LastClaim (t ).GetProjectId ())
174+ })
175+
176+ t .Run ("sends the claim via the claims chain, not type/value" , func (t * testing.T ) {
177+ mock := & topologytest.MockClassifyServer {}
178+ addr , stop := topologytest .StartMockServer (t , mock )
179+ defer stop ()
180+
181+ client := NewClient (& Config {
182+ Enabled : true ,
183+ Address : addr ,
184+ Timeout : 5 * time .Second ,
185+ })
186+ defer client .Close ()
187+
188+ tests := []struct {
189+ name string
190+ claim * types_proto.Claim
191+ }{
192+ {name : "route" , claim : RouteClaim ("my-group" )},
193+ {name : "ssh_key" , claim : SSHKeyClaim ("ssh-rsa AAAAB3" )},
194+ {name : "ssh_fingerprint" , claim : SSHFingerprintClaim ("W3THTJOKxMaZp0VIOrjVSBVDnFjyzVSMFGMLmSPcaGo" )},
195+ {name : "project_id" , claim : ProjectIDClaim (42 )},
196+ {name : "username" , claim : UsernameClaim ("jane.doe" )},
197+ }
198+
199+ for _ , tt := range tests {
200+ t .Run (tt .name , func (t * testing.T ) {
201+ _ , err := client .Classify (ctx , tt .claim )
202+ require .NoError (t , err )
203+
204+ claims := mock .LastRequest .GetClaims ()
205+ require .Len (t , claims , 1 )
206+ require .True (t , proto .Equal (tt .claim , claims [0 ]),
207+ "claim must be sent unmodified in the claims chain" )
208+
209+ require .Equal (t , pb .ClassifyType_UNSPECIFIED , mock .LastRequest .GetType ())
210+ require .Empty (t , mock .LastRequest .GetValue ())
211+ })
212+ }
176213 })
177214
178215 t .Run ("server error is propagated" , func (t * testing.T ) {
0 commit comments