@@ -21,6 +21,12 @@ import {
21
21
PrebuildSettings ,
22
22
WorkspaceSettings ,
23
23
} from "@gitpod/public-api/lib/gitpod/v1/configuration_pb" ;
24
+ import { AuthProviderEntry , AuthProviderInfo } from "./protocol" ;
25
+ import {
26
+ AuthProvider ,
27
+ AuthProviderDescription ,
28
+ AuthProviderType ,
29
+ } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb" ;
24
30
25
31
describe ( "PublicAPIConverter" , ( ) => {
26
32
const converter = new PublicAPIConverter ( ) ;
@@ -721,4 +727,80 @@ describe("PublicAPIConverter", () => {
721
727
expect ( result ) . to . deep . equal ( new WorkspaceSettings ( ) ) ;
722
728
} ) ;
723
729
} ) ;
730
+
731
+ describe ( "toAuthProviderDescription" , ( ) => {
732
+ const info : AuthProviderInfo = {
733
+ authProviderId : "ap123" ,
734
+ authProviderType : "GitHub" ,
735
+ host : "localhost" ,
736
+ verified : true ,
737
+ icon : "unused icon" ,
738
+ description : "unused description" ,
739
+ settingsUrl : "unused" ,
740
+ ownerId : "unused" ,
741
+ organizationId : "unused" ,
742
+ } ;
743
+ const description = new AuthProviderDescription ( {
744
+ id : info . authProviderId ,
745
+ type : AuthProviderType . GITHUB ,
746
+ host : info . host ,
747
+ icon : info . icon ,
748
+ description : info . description ,
749
+ } ) ;
750
+ it ( "should convert an auth provider info to a description" , ( ) => {
751
+ const result = converter . toAuthProviderDescription ( info ) ;
752
+ expect ( result ) . to . deep . equal ( description ) ;
753
+ } ) ;
754
+ } ) ;
755
+
756
+ describe ( "toAuthProvider" , ( ) => {
757
+ const entry : AuthProviderEntry = {
758
+ id : "ap123" ,
759
+ type : "GitHub" ,
760
+ host : "localhost" ,
761
+ status : "pending" ,
762
+ ownerId : "userId" ,
763
+ organizationId : "orgId123" ,
764
+ oauth : {
765
+ clientId : "clientId123" ,
766
+ clientSecret : "should not appear in result" ,
767
+ callBackUrl : "localhost/callback" ,
768
+ authorizationUrl : "auth.service/authorize" ,
769
+ tokenUrl : "auth.service/token" ,
770
+ } ,
771
+ } ;
772
+ const provider = new AuthProvider ( {
773
+ id : entry . id ,
774
+ type : AuthProviderType . GITHUB ,
775
+ host : entry . host ,
776
+ oauth2Config : {
777
+ clientId : entry . oauth ?. clientId ,
778
+ clientSecret : entry . oauth ?. clientSecret ,
779
+ } ,
780
+ owner : {
781
+ case : "organizationId" ,
782
+ value : entry . organizationId ! ,
783
+ } ,
784
+ } ) ;
785
+ it ( "should convert an auth provider" , ( ) => {
786
+ const result = converter . toAuthProvider ( entry ) ;
787
+ expect ( result ) . to . deep . equal ( provider ) ;
788
+ } ) ;
789
+ } ) ;
790
+
791
+ describe ( "toAuthProviderType" , ( ) => {
792
+ const mapping : { [ key : string ] : number } = {
793
+ GitHub : AuthProviderType . GITHUB ,
794
+ GitLab : AuthProviderType . GITLAB ,
795
+ Bitbucket : AuthProviderType . BITBUCKET ,
796
+ BitbucketServer : AuthProviderType . BITBUCKET_SERVER ,
797
+ Other : AuthProviderType . UNSPECIFIED ,
798
+ } ;
799
+ it ( "should convert auth provider types" , ( ) => {
800
+ for ( const k of Object . getOwnPropertyNames ( mapping ) ) {
801
+ const result = converter . toAuthProviderType ( k ) ;
802
+ expect ( result ) . to . deep . equal ( mapping [ k ] ) ;
803
+ }
804
+ } ) ;
805
+ } ) ;
724
806
} ) ;
0 commit comments