Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,13 @@
"@types/lodash-es": "4.17.12",
"@types/mapbox-gl": "^2.7.13",
"@types/mime-db": "^1.43.5",
"@types/node": "^20.11.5",
"@types/node": "^26.6.1",
"@types/pako": "^2.0.3",
"@types/pusher-js": "^5.1.0",
"@types/react": "19.2.3",
"@types/react-collapse": "^5.0.1",
"@types/react-dom": "19.2.3",
"@types/react-is": "^18.3.0",
"@types/react-native-web": "0.19.2",
"@types/react-test-renderer": "^19.1.0",
"@types/semver": "^7.5.4",
"@types/setimmediate": "^1.0.2",
Expand Down
15 changes: 13 additions & 2 deletions scripts/utils/Git.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import CONST from '@github/libs/CONST';
import GitHubUtils from '@github/libs/GithubUtils';

import type {ExecSyncOptionsWithStringEncoding, ExecOptions as ExecWithCallbackOptions} from 'child_process';
import type {ExecOptions as ExecWithCallbackOptions, ExecSyncOptionsWithStringEncoding} from 'child_process';

import {context} from '@actions/github';
import {exec as execWithCallback, execSync as originalExecSync} from 'child_process';
Expand All @@ -12,14 +12,25 @@ import {promisify} from 'util';
import {error as logError, warn as logWarn} from './Logger';

type ExecOptions = Omit<ExecWithCallbackOptions, 'encoding'> & {cwd?: ExecWithCallbackOptions['cwd']};

function isStringExecResult(result: {stdout: string | Buffer; stderr: string | Buffer}): result is {stdout: string; stderr: string} {
return typeof result.stdout === 'string' && typeof result.stderr === 'string';
}

function exec(command: string, options?: ExecOptions) {
const optionsWithEncoding = {
encoding: 'utf8',
cwd: process.cwd(),
...options,
};

return promisify(execWithCallback)(command, optionsWithEncoding);
return promisify(execWithCallback)(command, optionsWithEncoding).then((result) => {
if (!isStringExecResult(result)) {
throw new Error('Expected git command output to be text');
}

return result;
});
}

type ExecSyncOptions = Omit<ExecSyncOptionsWithStringEncoding, 'encoding' | 'cwd'> & {
Expand Down
7 changes: 5 additions & 2 deletions tests/unit/CloudflareAccessTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ function resetQAAuthConfig() {
beforeEach(() => {
jest.clearAllMocks();
resetQAAuthConfig();
getWebCrypto.getRandomValues.mockImplementation((array: Uint8Array) => webcrypto.getRandomValues(array));
getWebCrypto.sha256.mockImplementation((data: BufferSource) => webcrypto.subtle.digest('SHA-256', data));
getWebCrypto.getRandomValues.mockImplementation((array: Uint8Array) => webcrypto.getRandomValues(new Uint8Array(array)));
getWebCrypto.sha256.mockImplementation((data: BufferSource) => {
const bytes = ArrayBuffer.isView(data) ? new Uint8Array(data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength)) : new Uint8Array(data.slice(0));
return webcrypto.subtle.digest('SHA-256', bytes);
});
jest.mocked(getAuthServerEndpoints).mockResolvedValue({
authorizationEndpoint: 'https://team.cloudflareaccess.com/cdn-cgi/access/oauth/authorization',
tokenEndpoint: 'https://team.cloudflareaccess.com/cdn-cgi/access/oauth/token',
Expand Down
Loading