@@ -307,9 +307,9 @@ func TestRegisterWithUserEndpointsEnabled(t *testing.T) {
307
307
pp .GetConfig ().UserEndpointsEnabled = config .UserEndpointsConfigEnum .Enabled
308
308
309
309
Convey ("as admin" , func () {
310
- Convey ("with overwrite disabled" , func () {
310
+ Convey ("with createUserEndpoint disabled" , func () {
311
311
// setup
312
- adminEndpoint := setupMockEndpointRegisterRequest (t , mockAdmin .ConnectedUser , mockV2Info [0 ], "CF Cluster 1" , false )
312
+ adminEndpoint := setupMockEndpointRegisterRequest (t , mockAdmin .ConnectedUser , mockV2Info [0 ], "CF Cluster 1" , false , true )
313
313
314
314
if errSession := pp .setSessionValues (adminEndpoint .EchoContext , mockAdmin .SessionValues ); errSession != nil {
315
315
t .Error (errors .New ("unable to mock/stub user in session object" ))
@@ -341,9 +341,9 @@ func TestRegisterWithUserEndpointsEnabled(t *testing.T) {
341
341
So (dberr , ShouldBeNil )
342
342
})
343
343
})
344
- Convey ("overwrite existing user endpoints" , func () {
344
+ Convey ("create system endpoint over existing user endpoints" , func () {
345
345
// setup
346
- userEndpoint := setupMockEndpointRegisterRequest (t , mockUser1 .ConnectedUser , mockV2Info [0 ], "CF Cluster 1 User" , false )
346
+ userEndpoint := setupMockEndpointRegisterRequest (t , mockUser1 .ConnectedUser , mockV2Info [0 ], "CF Cluster 1 User" , false , false )
347
347
348
348
// mock executions
349
349
mockStratosAuth .
@@ -355,33 +355,24 @@ func TestRegisterWithUserEndpointsEnabled(t *testing.T) {
355
355
rows := sqlmock .NewRows (rowFieldsForCNSI ).AddRow (userEndpoint .QueryArgs ... )
356
356
mock .ExpectQuery (selectAnyFromCNSIs ).WithArgs (mockV2Info [0 ].URL ).WillReturnRows (rows )
357
357
358
+ // save cnsi
359
+ mock .ExpectExec (insertIntoCNSIs ).
360
+ WithArgs (adminEndpoint .InsertArgs ... ).
361
+ WillReturnResult (sqlmock .NewResult (1 , 1 ))
362
+
358
363
// test
359
364
err := pp .RegisterEndpoint (adminEndpoint .EchoContext , getCFPlugin (pp , "cf" ).Info )
360
365
dberr := mock .ExpectationsWereMet ()
361
366
362
367
Convey ("there should be no error" , func () {
363
- So (err , ShouldResemble , interfaces .NewHTTPShadowError (
364
- http .StatusBadRequest ,
365
- "Can not register same endpoint multiple times" ,
366
- "Can not register same endpoint multiple times" ,
367
- ))
368
+ So (err , ShouldBeNil )
368
369
})
369
370
370
371
Convey ("there should be no db error" , func () {
371
372
So (dberr , ShouldBeNil )
372
373
})
373
374
})
374
- })
375
- Convey ("with overwrite enabled" , func () {
376
-
377
- // setup
378
- adminEndpoint := setupMockEndpointRegisterRequest (t , mockAdmin .ConnectedUser , mockV2Info [0 ], "CF Cluster 1" , true )
379
-
380
- if errSession := pp .setSessionValues (adminEndpoint .EchoContext , mockAdmin .SessionValues ); errSession != nil {
381
- t .Error (errors .New ("unable to mock/stub user in session object" ))
382
- }
383
-
384
- Convey ("overwrite existing admin endpoints" , func () {
375
+ Convey ("create system endpoint over existing system endpoints" , func () {
385
376
// mock executions
386
377
mockStratosAuth .
387
378
EXPECT ().
@@ -399,36 +390,38 @@ func TestRegisterWithUserEndpointsEnabled(t *testing.T) {
399
390
Convey ("should fail " , func () {
400
391
So (err , ShouldResemble , interfaces .NewHTTPShadowError (
401
392
http .StatusBadRequest ,
402
- "Can not register same admin endpoint multiple times" ,
403
- "Can not register same admin endpoint multiple times" ,
393
+ "Can not register same system endpoint multiple times" ,
394
+ "Can not register same system endpoint multiple times" ,
404
395
))
405
396
})
406
397
407
398
Convey ("no insert should be executed" , func () {
408
399
So (dberr , ShouldBeNil )
409
400
})
410
401
})
411
- Convey ("overwrite existing user endpoints" , func () {
402
+ })
403
+ Convey ("with createUserEndpoint enabled" , func () {
412
404
413
- // setup
414
- userEndpoint := setupMockEndpointRegisterRequest (t , mockUser1 .ConnectedUser , mockV2Info [0 ], "CF Cluster 1 User" , false )
405
+ // setup
406
+ adminEndpoint := setupMockEndpointRegisterRequest (t , mockAdmin .ConnectedUser , mockV2Info [0 ], "CF Cluster 1" , true , false )
407
+ systemEndpoint := setupMockEndpointRegisterRequest (t , mockAdmin .ConnectedUser , mockV2Info [0 ], "CF Cluster 1" , true , true )
408
+
409
+ if errSession := pp .setSessionValues (adminEndpoint .EchoContext , mockAdmin .SessionValues ); errSession != nil {
410
+ t .Error (errors .New ("unable to mock/stub user in session object" ))
411
+ }
415
412
413
+ Convey ("register personal endpoint over system endpoint" , func () {
416
414
// mock executions
417
415
mockStratosAuth .
418
416
EXPECT ().
419
417
GetUser (gomock .Eq (mockAdmin .ConnectedUser .GUID )).
420
418
Return (mockAdmin .ConnectedUser , nil )
421
419
422
- // return a user endpoint with same apiurl
423
- rows := sqlmock .NewRows (rowFieldsForCNSI ).AddRow (userEndpoint .QueryArgs ... )
420
+ // return a admin endpoint with same apiurl
421
+ rows := sqlmock .NewRows (rowFieldsForCNSI ).AddRow (systemEndpoint .QueryArgs ... )
424
422
mock .ExpectQuery (selectAnyFromCNSIs ).WithArgs (mockV2Info [0 ].URL ).WillReturnRows (rows )
425
423
426
- // user endpoints should be deleted
427
- mock .ExpectExec (deleteFromCNSIs ).
428
- WithArgs (userEndpoint .QueryArgs [0 ]).
429
- WillReturnResult (sqlmock .NewResult (1 , 1 ))
430
-
431
- // a new admin endpoint with same url will be registered
424
+ // save cnsi
432
425
mock .ExpectExec (insertIntoCNSIs ).
433
426
WithArgs (adminEndpoint .InsertArgs ... ).
434
427
WillReturnResult (sqlmock .NewResult (1 , 1 ))
@@ -441,6 +434,33 @@ func TestRegisterWithUserEndpointsEnabled(t *testing.T) {
441
434
So (err , ShouldBeNil )
442
435
})
443
436
437
+ Convey ("there should be no db error" , func () {
438
+ So (dberr , ShouldBeNil )
439
+ })
440
+ })
441
+ Convey ("register personal endpoint twice" , func () {
442
+ // mock executions
443
+ mockStratosAuth .
444
+ EXPECT ().
445
+ GetUser (gomock .Eq (mockAdmin .ConnectedUser .GUID )).
446
+ Return (mockAdmin .ConnectedUser , nil )
447
+
448
+ // return a user endpoint with same apiurl
449
+ rows := sqlmock .NewRows (rowFieldsForCNSI ).AddRow (adminEndpoint .QueryArgs ... )
450
+ mock .ExpectQuery (selectAnyFromCNSIs ).WithArgs (mockV2Info [0 ].URL ).WillReturnRows (rows )
451
+
452
+ // test
453
+ err := pp .RegisterEndpoint (adminEndpoint .EchoContext , getCFPlugin (pp , "cf" ).Info )
454
+ dberr := mock .ExpectationsWereMet ()
455
+
456
+ Convey ("there should be no error" , func () {
457
+ So (err , ShouldResemble , interfaces .NewHTTPShadowError (
458
+ http .StatusBadRequest ,
459
+ "Can not register same endpoint multiple times" ,
460
+ "Can not register same endpoint multiple times" ,
461
+ ))
462
+ })
463
+
444
464
Convey ("there should be no db error" , func () {
445
465
So (dberr , ShouldBeNil )
446
466
})
@@ -449,9 +469,9 @@ func TestRegisterWithUserEndpointsEnabled(t *testing.T) {
449
469
})
450
470
451
471
Convey ("as user" , func () {
452
- Convey ("with overwrite disabled" , func () {
472
+ Convey ("with createUserEndpoint disabled" , func () {
453
473
// setup
454
- userEndpoint := setupMockEndpointRegisterRequest (t , mockUser1 .ConnectedUser , mockV2Info [0 ], "CF Cluster 1" , false )
474
+ userEndpoint := setupMockEndpointRegisterRequest (t , mockUser1 .ConnectedUser , mockV2Info [0 ], "CF Cluster 1" , false , false )
455
475
456
476
if errSession := pp .setSessionValues (userEndpoint .EchoContext , mockUser1 .SessionValues ); errSession != nil {
457
477
t .Error (errors .New ("unable to mock/stub user in session object" ))
@@ -483,7 +503,7 @@ func TestRegisterWithUserEndpointsEnabled(t *testing.T) {
483
503
})
484
504
})
485
505
Convey ("register existing endpoint from different user" , func () {
486
- userEndpoint2 := setupMockEndpointRegisterRequest (t , mockUser2 .ConnectedUser , mockV2Info [0 ], "CF Cluster 2" , false )
506
+ userEndpoint2 := setupMockEndpointRegisterRequest (t , mockUser2 .ConnectedUser , mockV2Info [0 ], "CF Cluster 2" , false , false )
487
507
488
508
// mock executions
489
509
mockStratosAuth .
@@ -535,13 +555,13 @@ func TestRegisterWithUserEndpointsEnabled(t *testing.T) {
535
555
})
536
556
})
537
557
})
538
- Convey ("with overwrite enabled" , func () {
539
- userEndpoint := setupMockEndpointRegisterRequest (t , mockUser1 .ConnectedUser , mockV2Info [0 ], "CF Cluster 1" , false )
558
+ Convey ("with createUserEndpoint enabled" , func () {
559
+ userEndpoint := setupMockEndpointRegisterRequest (t , mockUser1 .ConnectedUser , mockV2Info [0 ], "CF Cluster 1" , true , false )
540
560
541
561
if errSession := pp .setSessionValues (userEndpoint .EchoContext , mockUser1 .SessionValues ); errSession != nil {
542
562
t .Error (errors .New ("unable to mock/stub user in session object" ))
543
563
}
544
- Convey ("overwrite existing endpoints from same user, with overwrite enabled " , func () {
564
+ Convey ("register existing endpoint from same user" , func () {
545
565
// mock executions
546
566
mockStratosAuth .
547
567
EXPECT ().
0 commit comments