Skip to content

Commit 537820c

Browse files
committed
feat: read insecure config key, fall back to allowSelfSigned
1 parent bd0367a commit 537820c

File tree

2 files changed

+46
-17
lines changed

2 files changed

+46
-17
lines changed

src/lib/ggshield-configuration-utils.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ export async function getConfiguration(
1414
const config = workspace.getConfiguration("gitguardian");
1515

1616
const apiUrl: string | undefined = config.get("apiUrl");
17-
const allowSelfSigned: boolean = config.get("allowSelfSigned", false);
17+
const insecure: boolean = config.get(
18+
"insecure",
19+
// Read allowSelfSigned for backward compatibility
20+
config.get("allowSelfSigned", false),
21+
);
1822

1923
const pathToGGShield: string = await getGGShield(
2024
os.platform(),
2125
os.arch(),
2226
context,
2327
outputChannel,
24-
allowSelfSigned,
28+
insecure,
2529
);
2630

27-
return new GGShieldConfiguration(
28-
pathToGGShield,
29-
apiUrl,
30-
allowSelfSigned || false,
31-
);
31+
return new GGShieldConfiguration(pathToGGShield, apiUrl, insecure || false);
3232
}

src/test/suite/lib/ggshield-configuration-utils.test.ts

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -54,4 +68,19 @@ suite("getConfiguration", () => {
5468
assert.strictEqual(configuration.apiUrl, "https://custom-url.com");
5569
assert.strictEqual(configuration.insecure, true);
5670
});
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);
85+
});
5786
});

0 commit comments

Comments
 (0)