-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from GitGuardian/salomevoltz/scrt-4987-allow-s…
…elf-signed-certificates Add optional 'allow self signed' option in settings
- Loading branch information
Showing
8 changed files
with
147 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { getBinaryAbsolutePath } from "./ggshield-resolver-utils"; | ||
import { ExtensionContext, workspace } from "vscode"; | ||
import * as os from "os"; | ||
import { GGShieldConfiguration } from "./ggshield-configuration"; | ||
|
||
const apiUrlDefault = "https://dashboard.gitguardian.com/"; | ||
|
||
/** | ||
* Retrieve configuration from settings | ||
* | ||
* TODO: Check with Mathieu if this behaviour is expected | ||
* @returns {GGShieldConfiguration} from the extension settings | ||
*/ | ||
export function getConfiguration( | ||
context: ExtensionContext | ||
): GGShieldConfiguration { | ||
const config = workspace.getConfiguration("gitguardian"); | ||
|
||
const ggshieldPath: string | undefined = config.get("GGShieldPath"); | ||
const apiUrl: string | undefined = config.get("apiUrl"); | ||
const apiKey: string | undefined = config.get("apiKey"); | ||
const allowSelfSigned: boolean = config.get("allowSelfSigned", false); | ||
return new GGShieldConfiguration( | ||
ggshieldPath | ||
? ggshieldPath | ||
: getBinaryAbsolutePath(os.platform(), os.arch(), context), | ||
apiUrl || apiUrlDefault, | ||
apiKey || "", | ||
allowSelfSigned || false | ||
); | ||
} | ||
|
||
export function setApiKey( | ||
configuration: GGShieldConfiguration, | ||
apiKey: string | undefined | ||
): void { | ||
configuration.apiKey = apiKey ? apiKey : ""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,18 @@ | ||
import { getBinaryAbsolutePath } from "./ggshield-resolver-utils"; | ||
import { ExtensionContext, workspace } from "vscode"; | ||
import * as os from "os"; | ||
|
||
const apiUrlDefault = "https://dashboard.gitguardian.com/"; | ||
|
||
export class GGShieldConfiguration { | ||
ggshieldPath: string; | ||
apiUrl: string; | ||
apiKey: string; | ||
allowSelfSigned: boolean; | ||
|
||
constructor( | ||
ggshieldPath: string = "", | ||
apiUrl: string = "", | ||
apiKey: string = "" | ||
apiKey: string = "", | ||
allowSelfSigned: boolean = false | ||
) { | ||
this.ggshieldPath = ggshieldPath; | ||
this.apiUrl = apiUrl; | ||
this.apiKey = apiKey; | ||
this.allowSelfSigned = allowSelfSigned; | ||
} | ||
} | ||
|
||
/** | ||
* Retrieve configuration from settings | ||
* | ||
* TODO: Check with Mathieu if this behaviour is expected | ||
* @returns {GGShieldConfiguration} from the extension settings | ||
*/ | ||
export function getConfiguration( | ||
context: ExtensionContext | ||
): GGShieldConfiguration { | ||
const config = workspace.getConfiguration("gitguardian"); | ||
|
||
const ggshieldPath: string | undefined = config.get("GGShieldPath"); | ||
const apiUrl: string | undefined = config.get("apiUrl"); | ||
const apiKey: string | undefined = config.get("apiKey"); | ||
|
||
return new GGShieldConfiguration( | ||
ggshieldPath | ||
? ggshieldPath | ||
: getBinaryAbsolutePath(os.platform(), os.arch(), context), | ||
apiUrl ? apiUrl : apiUrlDefault, | ||
apiKey ? apiKey : "" | ||
); | ||
} | ||
|
||
export function setApiKey( | ||
configuration: GGShieldConfiguration, | ||
apiKey: string | undefined | ||
): void { | ||
configuration.apiKey = apiKey ? apiKey : ""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import * as simple from "simple-mock"; | ||
import assert = require("assert"); | ||
import { ExtensionContext, workspace } from "vscode"; | ||
import { getConfiguration } from "../../../lib/ggshield-configuration-utils"; | ||
|
||
suite("getConfiguration", () => { | ||
let getConfigurationMock: simple.Stub<Function>; | ||
|
||
setup(() => { | ||
// Mock workspace.getConfiguration | ||
getConfigurationMock = simple.mock(workspace, "getConfiguration"); | ||
}); | ||
|
||
teardown(() => { | ||
simple.restore(); | ||
}); | ||
|
||
test("Vscode settings are correctly read", async () => { | ||
getConfigurationMock.returnWith({ | ||
get: (key: string) => { | ||
if (key === "GGShieldPath") { | ||
return "path/to/ggshield"; | ||
} | ||
if (key === "apiUrl") { | ||
return "https://custom-url.com"; | ||
} | ||
if (key === "apiKey") { | ||
return "test-api-key"; | ||
} | ||
if (key === "allowSelfSigned") { | ||
return true; | ||
} | ||
}, | ||
}); | ||
const configuration = getConfiguration({} as ExtensionContext); | ||
|
||
// Assert both workspace.getConfiguration and GGShieldConfiguration constructor were called | ||
assert( | ||
getConfigurationMock.called, | ||
"getConfiguration should be called once" | ||
); | ||
|
||
// Assert that the configuration has the expected values | ||
assert.strictEqual(configuration.ggshieldPath, "path/to/ggshield"); | ||
assert.strictEqual(configuration.apiUrl, "https://custom-url.com"); | ||
assert.strictEqual(configuration.apiKey, "test-api-key"); | ||
assert.strictEqual(configuration.allowSelfSigned, true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters