use strict equality rather than starts with and mock a sha for the revparse mock.

This commit is contained in:
davidapierce
2026-07-16 19:34:46 +00:00
parent 52d48b43d9
commit 2e3954109d
2 changed files with 7 additions and 2 deletions
+6 -1
View File
@@ -57,7 +57,9 @@ const mockGit = {
fetch: vi.fn(),
checkout: vi.fn(),
listRemote: vi.fn(),
revparse: vi.fn(),
revparse: vi
.fn()
.mockResolvedValue('mock-sha-1234567890123456789012345678901234567890'),
// Not a part of the actual API, but we need to use this to do the correct
// file system interactions.
path: vi.fn(),
@@ -170,6 +172,9 @@ describe('extension tests', () => {
beforeEach(() => {
vi.clearAllMocks();
mockGit.revparse.mockResolvedValue(
'mock-sha-1234567890123456789012345678901234567890',
);
resetSettingsCacheForTesting();
keychainData = {};
mockKeychainStorage = {
+1 -1
View File
@@ -88,7 +88,7 @@ export async function cloneFromGit(
// This prevents short hex-only branch/tag names (e.g. ticket numbers or 'deadbeef') from triggering false-positive security errors.
const hexRegex = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
if (hexRegex.test(refLower)) {
if (!checkedOutSha.toLowerCase().startsWith(refLower)) {
if (checkedOutSha.toLowerCase() !== refLower) {
throw new Error(
`Security verification failed: checked out SHA (${checkedOutSha}) does not match the requested pin (${installMetadata.ref}).`,
);