@@ -27,21 +27,35 @@ suite("getConfiguration", () => {
2727 simple . restore ( ) ;
2828 } ) ;
2929
30+ /**
31+ * Helper class to fake different configurations of the extension
32+ */
33+ class FakeConfiguration {
34+ records : Record < string , any > ;
35+
36+ constructor ( records : Record < string , any > ) {
37+ this . records = records ;
38+ }
39+
40+ public get ( section : string , defaultValue : any ) : any {
41+ if ( this . records . hasOwnProperty ( section ) ) {
42+ return this . records [ section ] ;
43+ }
44+ return defaultValue ;
45+ }
46+ }
47+
3048 test ( "Vscode settings are correctly read" , async ( ) => {
3149 const context = { } as ExtensionContext ;
3250 const outputChannel = window . createOutputChannel ( "GitGuardian" ) ;
3351 simple . mock ( context , "asAbsolutePath" ) . returnWith ( "" ) ;
3452
35- getConfigurationMock . returnWith ( {
36- get : ( key : string ) => {
37- if ( key === "apiUrl" ) {
38- return "https://custom-url.com" ;
39- }
40- if ( key === "allowSelfSigned" ) {
41- return true ;
42- }
43- } ,
44- } ) ;
53+ getConfigurationMock . returnWith (
54+ new FakeConfiguration ( {
55+ apiUrl : "https://custom-url.com" ,
56+ insecure : true ,
57+ } as Record < string , any > ) ,
58+ ) ;
4559 const configuration = await getConfiguration ( context , outputChannel ) ;
4660
4761 // Assert both workspace.getConfiguration and GGShieldConfiguration constructor were called
@@ -52,6 +66,21 @@ suite("getConfiguration", () => {
5266
5367 // Assert that the configuration has the expected values
5468 assert . strictEqual ( configuration . apiUrl , "https://custom-url.com" ) ;
55- assert . strictEqual ( configuration . allowSelfSigned , true ) ;
69+ assert . strictEqual ( configuration . insecure , true ) ;
70+ } ) ;
71+ test ( "insecure falls back on allowSelfSigned" , async ( ) => {
72+ const context = { } as ExtensionContext ;
73+ const outputChannel = window . createOutputChannel ( "GitGuardian" ) ;
74+ simple . mock ( context , "asAbsolutePath" ) . returnWith ( "" ) ;
75+
76+ getConfigurationMock . returnWith (
77+ new FakeConfiguration ( {
78+ allowSelfSigned : true ,
79+ } as Record < string , any > ) ,
80+ ) ;
81+ const configuration = await getConfiguration ( context , outputChannel ) ;
82+
83+ // Assert that the configuration has the expected values
84+ assert . strictEqual ( configuration . insecure , true ) ;
5685 } ) ;
5786} ) ;
0 commit comments