@@ -302,7 +302,10 @@ func TestFetchTargetAliasProxyServerCertificate(t *testing.T) {
302
302
}
303
303
}
304
304
305
- func Test_FetchCertsWithinLookupTargetForSessionAuthorization (t * testing.T ) {
305
+ // Test_LookupTargetForSessionAuthorization tests looking up a target for session both with and without an alias.
306
+ // The target used in this test does not have a proxy server certificate because TCP targets do not currently support proxy server certificates.
307
+ // Fetching the proxy server certificate is tested in other enterprise tests.
308
+ func Test_LookupTargetForSessionAuthorization (t * testing.T ) {
306
309
t .Parallel ()
307
310
ctx := context .Background ()
308
311
conn , _ := db .TestSetup (t , "postgres" )
@@ -312,74 +315,50 @@ func Test_FetchCertsWithinLookupTargetForSessionAuthorization(t *testing.T) {
312
315
_ , proj := iam .TestScopes (t , iam .TestRepo (t , conn , wrapper ))
313
316
repo , err := target .NewRepository (context .Background (), rw , rw , testKms )
314
317
require .NoError (t , err )
315
- databaseWrapper , err := testKms .GetWrapper (ctx , proj .PublicId , kms .KeyPurposeDatabase )
316
- require .NoError (t , err )
317
318
318
319
tar := targettest .TestNewTestTarget (ctx , t , conn , proj .PublicId , "test-target" )
319
- tar2 := targettest .TestNewTestTarget (ctx , t , conn , proj .PublicId , "test-target2" )
320
320
321
321
// Create an alias
322
322
aliasValue := "test-alias"
323
323
alias := talias .TestAlias (t , rw , aliasValue , talias .WithDestinationId (tar .GetPublicId ()))
324
- require .NoError (t , err )
325
324
require .NotNil (t , alias )
326
325
327
- // Create our default localhost target cert
328
- cer , err := target .NewTargetProxyCertificate (ctx , target .WithTargetId (tar .GetPublicId ()))
329
- require .NoError (t , err )
330
- require .NotNil (t , cer )
331
- id , err := db .NewPublicId (ctx , globals .ProxyServerCertificatePrefix )
332
- require .NoError (t , err )
333
- cer .PublicId = id
334
- err = cer .Encrypt (ctx , databaseWrapper )
335
- require .NoError (t , err )
336
- err = rw .Create (ctx , cer )
337
- require .NoError (t , err )
338
-
339
326
tests := []struct {
340
327
name string
341
328
publicId string
342
329
opt []target.Option
343
- wantCert bool
330
+ wantErr bool
344
331
}{
345
332
{
346
- name : "success-get-target-with-certificate " ,
333
+ name : "success-get-target-no-cert " ,
347
334
publicId : tar .GetPublicId (),
348
- wantCert : true ,
335
+ wantErr : false ,
349
336
},
350
337
{
351
- name : "success-get-target-with-alias-certificate " ,
338
+ name : "success-get-target-no-cert- with-alias" ,
352
339
publicId : tar .GetPublicId (),
353
340
opt : []target.Option {
354
341
target .WithAlias (alias ),
355
342
},
356
- wantCert : true ,
357
- },
358
- {
359
- name : "success-get-target-no-cert" ,
360
- publicId : tar2 .GetPublicId (),
361
- wantCert : false ,
343
+ wantErr : false ,
362
344
},
363
345
{
364
- name : "success-get-target-no-cert-with-alias" ,
365
- publicId : tar2 .GetPublicId (),
366
- opt : []target.Option {
367
- target .WithAlias (alias ),
368
- },
369
- wantCert : false ,
346
+ name : "fail-missing-target-id" ,
347
+ publicId : "" ,
348
+ wantErr : true ,
370
349
},
371
350
}
372
351
for _ , tt := range tests {
373
352
t .Run (tt .name , func (t * testing.T ) {
374
353
assert , require := assert .New (t ), require .New (t )
375
354
got , err := repo .LookupTargetForSessionAuthorization (ctx , tt .publicId , proj .PublicId , tt .opt ... )
376
- require .NoError (err )
377
- assert .NotNil (got )
378
- if tt .wantCert {
379
- assert .NotNil (got .GetProxyServerCertificate ())
380
- } else {
381
- assert .Nil (got .GetProxyServerCertificate ())
355
+ if tt .wantErr {
356
+ require .Error (err )
357
+ return
382
358
}
359
+ require .NoError (err )
360
+ require .NotNil (got )
361
+ assert .Nil (got .GetProxyServerCertificate ())
383
362
})
384
363
}
385
364
}
0 commit comments