@@ -557,16 +557,14 @@ func TestExternalServicesStore_Update(t *testing.T) {
557
557
}
558
558
}
559
559
560
- func TestUpsertAuthorizationToExternalService (t * testing.T ) {
560
+ func TestDisablePermsSyncingForExternalService (t * testing.T ) {
561
561
tests := []struct {
562
562
name string
563
- kind string
564
563
config string
565
564
want string
566
565
}{
567
566
{
568
567
name : "github with authorization" ,
569
- kind : extsvc .KindGitHub ,
570
568
config : `
571
569
{
572
570
// Useful comments
@@ -580,13 +578,11 @@ func TestUpsertAuthorizationToExternalService(t *testing.T) {
580
578
// Useful comments
581
579
"url": "https://github.com",
582
580
"repositoryQuery": ["none"],
583
- "token": "def",
584
- "authorization": {}
581
+ "token": "def"
585
582
}` ,
586
583
},
587
584
{
588
585
name : "github without authorization" ,
589
- kind : extsvc .KindGitHub ,
590
586
config : `
591
587
{
592
588
// Useful comments
@@ -599,61 +595,48 @@ func TestUpsertAuthorizationToExternalService(t *testing.T) {
599
595
// Useful comments
600
596
"url": "https://github.com",
601
597
"repositoryQuery": ["none"],
602
- "token": "def",
603
- "authorization": {}
598
+ "token": "def"
604
599
}` ,
605
600
},
606
601
{
607
- name : "gitlab with authorization" ,
608
- kind : extsvc .KindGitLab ,
602
+ name : "azure devops with enforce permissions" ,
609
603
config : `
610
604
{
611
605
// Useful comments
612
- "url": "https://gitlab .com",
613
- "projectQuery ": ["none"] ,
606
+ "url": "https://dev.azure .com",
607
+ "username ": "horse" ,
614
608
"token": "abc",
615
- "authorization ": {}
609
+ "enforcePermissions ": true
616
610
}` ,
617
611
want : `
618
612
{
619
613
// Useful comments
620
- "url": "https://gitlab.com",
621
- "projectQuery": ["none"],
622
- "token": "abc",
623
- "authorization": {
624
- "identityProvider": {
625
- "type": "oauth"
626
- }
627
- }
614
+ "url": "https://dev.azure.com",
615
+ "username": "horse",
616
+ "token": "abc"
628
617
}` ,
629
618
},
630
619
{
631
- name : "gitlab without authorization" ,
632
- kind : extsvc .KindGitLab ,
620
+ name : "azure devops without enforce permissions" ,
633
621
config : `
634
622
{
635
623
// Useful comments
636
- "url": "https://gitlab .com",
637
- "projectQuery ": ["none"] ,
624
+ "url": "https://dev.azure .com",
625
+ "username ": "horse" ,
638
626
"token": "abc"
639
627
}` ,
640
628
want : `
641
629
{
642
630
// Useful comments
643
- "url": "https://gitlab.com",
644
- "projectQuery": ["none"],
645
- "token": "abc",
646
- "authorization": {
647
- "identityProvider": {
648
- "type": "oauth"
649
- }
650
- }
631
+ "url": "https://dev.azure.com",
632
+ "username": "horse",
633
+ "token": "abc"
651
634
}` ,
652
635
},
653
636
}
654
637
for _ , test := range tests {
655
638
t .Run (test .name , func (t * testing.T ) {
656
- got , err := upsertAuthorizationToExternalService ( test . kind , test .config )
639
+ got , err := disablePermsSyncingForExternalService ( test .config )
657
640
if err != nil {
658
641
t .Fatal (err )
659
642
}
@@ -666,9 +649,9 @@ func TestUpsertAuthorizationToExternalService(t *testing.T) {
666
649
}
667
650
668
651
// This test ensures under Sourcegraph.com mode, every call of `Create`,
669
- // `Upsert` and `Update` has the "authorization" field presented in the external
652
+ // `Upsert` and `Update` removes the "authorization" field in the external
670
653
// service config automatically.
671
- func TestExternalServicesStore_upsertAuthorizationToExternalService (t * testing.T ) {
654
+ func TestExternalServicesStore_DisablePermsSyncingForExternalService (t * testing.T ) {
672
655
if testing .Short () {
673
656
t .Skip ()
674
657
}
@@ -688,7 +671,7 @@ func TestExternalServicesStore_upsertAuthorizationToExternalService(t *testing.T
688
671
es := & types.ExternalService {
689
672
Kind : extsvc .KindGitHub ,
690
673
DisplayName : "GITHUB #1" ,
691
- Config : extsvc .NewUnencryptedConfig (`{"url": "https://github.com", "repositoryQuery": ["none"], "token": "abc"}` ),
674
+ Config : extsvc .NewUnencryptedConfig (`{"url": "https://github.com", "repositoryQuery": ["none"], "token": "abc", "authorization": {} }` ),
692
675
}
693
676
err := externalServices .Create (ctx , confGet , es )
694
677
require .NoError (t , err )
@@ -700,10 +683,10 @@ func TestExternalServicesStore_upsertAuthorizationToExternalService(t *testing.T
700
683
t .Fatal (err )
701
684
}
702
685
exists := gjson .Get (cfg , "authorization" ).Exists ()
703
- assert .True (t , exists , `"authorization" field exists` )
686
+ assert .False (t , exists , `"authorization" field exists, but should not ` )
704
687
705
688
// Reset Config field and test Upsert method
706
- es .Config .Set (`{"url": "https://github.com", "repositoryQuery": ["none"], "token": "abc"}` )
689
+ es .Config .Set (`{"url": "https://github.com", "repositoryQuery": ["none"], "token": "abc", "authorization": {} }` )
707
690
err = externalServices .Upsert (ctx , es )
708
691
require .NoError (t , err )
709
692
@@ -714,10 +697,10 @@ func TestExternalServicesStore_upsertAuthorizationToExternalService(t *testing.T
714
697
t .Fatal (err )
715
698
}
716
699
exists = gjson .Get (cfg , "authorization" ).Exists ()
717
- assert .True (t , exists , `"authorization" field exists` )
700
+ assert .False (t , exists , `"authorization" field exists, but should not ` )
718
701
719
702
// Reset Config field and test Update method
720
- es .Config .Set (`{"url": "https://github.com", "repositoryQuery": ["none"], "token": "abc"}` )
703
+ es .Config .Set (`{"url": "https://github.com", "repositoryQuery": ["none"], "token": "abc", "authorization": {} }` )
721
704
err = externalServices .Update (ctx ,
722
705
conf .Get ().AuthProviders ,
723
706
es .ID ,
@@ -734,7 +717,7 @@ func TestExternalServicesStore_upsertAuthorizationToExternalService(t *testing.T
734
717
t .Fatal (err )
735
718
}
736
719
exists = gjson .Get (cfg , "authorization" ).Exists ()
737
- assert .True (t , exists , `"authorization" field exists` )
720
+ assert .False (t , exists , `"authorization" field exists, but should not ` )
738
721
}
739
722
740
723
func TestCountRepoCount (t * testing.T ) {
0 commit comments