mirror of
https://git.mirrors.martin98.com/https://github.com/actions/toolkit
synced 2025-08-22 01:49:07 +08:00
Instead of using utility method in core lib, use method in both twirp clients
This commit is contained in:
parent
884aa17886
commit
1cd2f8a538
@ -30,24 +30,30 @@ describe('ArtifactHttpClient', () => {
|
|||||||
it('should mask signed_upload_url', () => {
|
it('should mask signed_upload_url', () => {
|
||||||
const response: CreateArtifactResponse = {
|
const response: CreateArtifactResponse = {
|
||||||
ok: true,
|
ok: true,
|
||||||
signedUploadUrl: 'https://example.com/upload?se=2025-03-05T16%3A47%3A23Z&sig=secret-token'
|
signedUploadUrl:
|
||||||
|
'https://example.com/upload?se=2025-03-05T16%3A47%3A23Z&sig=secret-token'
|
||||||
}
|
}
|
||||||
|
|
||||||
client.maskSecretUrls(response)
|
client.maskSecretUrls(response)
|
||||||
|
|
||||||
expect(setSecret).toHaveBeenCalledWith('secret-token')
|
expect(setSecret).toHaveBeenCalledWith('secret-token')
|
||||||
expect(debug).toHaveBeenCalledWith('Masked signed_upload_url: https://example.com/upload?se=2025-03-05T16%3A47%3A23Z&sig=***')
|
expect(debug).toHaveBeenCalledWith(
|
||||||
|
'Masked signed_upload_url: https://example.com/upload?se=2025-03-05T16%3A47%3A23Z&sig=***'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should mask signed_download_url', () => {
|
it('should mask signed_download_url', () => {
|
||||||
const response: GetSignedArtifactURLResponse = {
|
const response: GetSignedArtifactURLResponse = {
|
||||||
signedUrl: 'https://example.com/download?se=2025-03-05T16%3A47%3A23Z&sig=secret-token'
|
signedUrl:
|
||||||
|
'https://example.com/download?se=2025-03-05T16%3A47%3A23Z&sig=secret-token'
|
||||||
}
|
}
|
||||||
|
|
||||||
client.maskSecretUrls(response)
|
client.maskSecretUrls(response)
|
||||||
|
|
||||||
expect(setSecret).toHaveBeenCalledWith('secret-token')
|
expect(setSecret).toHaveBeenCalledWith('secret-token')
|
||||||
expect(debug).toHaveBeenCalledWith('Masked signed_download_url: https://example.com/download?se=2025-03-05T16%3A47%3A23Z&sig=***')
|
expect(debug).toHaveBeenCalledWith(
|
||||||
|
'Masked signed_url: https://example.com/download?se=2025-03-05T16%3A47%3A23Z&sig=***'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should not call setSecret if URLs are missing', () => {
|
it('should not call setSecret if URLs are missing', () => {
|
||||||
@ -61,24 +67,30 @@ describe('ArtifactHttpClient', () => {
|
|||||||
it('should mask only the sensitive token part of signed_upload_url', () => {
|
it('should mask only the sensitive token part of signed_upload_url', () => {
|
||||||
const response: CreateArtifactResponse = {
|
const response: CreateArtifactResponse = {
|
||||||
ok: true,
|
ok: true,
|
||||||
signedUploadUrl: 'https://example.com/upload?se=2025-03-05T16%3A47%3A23Z&sig=secret-token'
|
signedUploadUrl:
|
||||||
|
'https://example.com/upload?se=2025-03-05T16%3A47%3A23Z&sig=secret-token'
|
||||||
}
|
}
|
||||||
|
|
||||||
client.maskSecretUrls(response)
|
client.maskSecretUrls(response)
|
||||||
|
|
||||||
expect(setSecret).toHaveBeenCalledWith('secret-token')
|
expect(setSecret).toHaveBeenCalledWith('secret-token')
|
||||||
expect(debug).toHaveBeenCalledWith('Masked signed_upload_url: https://example.com/upload?se=2025-03-05T16%3A47%3A23Z&sig=***')
|
expect(debug).toHaveBeenCalledWith(
|
||||||
|
'Masked signed_upload_url: https://example.com/upload?se=2025-03-05T16%3A47%3A23Z&sig=***'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should mask only the sensitive token part of signed_download_url', () => {
|
it('should mask only the sensitive token part of signed_download_url', () => {
|
||||||
const response: GetSignedArtifactURLResponse = {
|
const response: GetSignedArtifactURLResponse = {
|
||||||
signedUrl: 'https://example.com/download?se=2025-03-05T16%3A47%3A23Z&sig=secret-token'
|
signedUrl:
|
||||||
|
'https://example.com/download?se=2025-03-05T16%3A47%3A23Z&sig=secret-token'
|
||||||
}
|
}
|
||||||
|
|
||||||
client.maskSecretUrls(response)
|
client.maskSecretUrls(response)
|
||||||
|
|
||||||
expect(setSecret).toHaveBeenCalledWith('secret-token')
|
expect(setSecret).toHaveBeenCalledWith('secret-token')
|
||||||
expect(debug).toHaveBeenCalledWith('Masked signed_download_url: https://example.com/download?se=2025-03-05T16%3A47%3A23Z&sig=***')
|
expect(debug).toHaveBeenCalledWith(
|
||||||
|
'Masked signed_url: https://example.com/download?se=2025-03-05T16%3A47%3A23Z&sig=***'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {HttpClient, HttpClientResponse, HttpCodes} from '@actions/http-client'
|
import {HttpClient, HttpClientResponse, HttpCodes} from '@actions/http-client'
|
||||||
import {BearerCredentialHandler} from '@actions/http-client/lib/auth'
|
import {BearerCredentialHandler} from '@actions/http-client/lib/auth'
|
||||||
import {setSecret, info, debug, maskSigUrl} from '@actions/core'
|
import {setSecret, info, debug} from '@actions/core'
|
||||||
import {ArtifactServiceClientJSON} from '../../generated'
|
import {ArtifactServiceClientJSON} from '../../generated'
|
||||||
import {getResultsServiceUrl, getRuntimeToken} from './config'
|
import {getResultsServiceUrl, getRuntimeToken} from './config'
|
||||||
import {getUserAgentString} from './user-agent'
|
import {getUserAgentString} from './user-agent'
|
||||||
@ -74,14 +74,27 @@ export class ArtifactHttpClient implements Rpc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Masks the `sig` parameter in a URL and sets it as a secret.
|
||||||
|
* @param url The URL containing the `sig` parameter.
|
||||||
|
* @param urlType The type of the URL (e.g., 'signed_upload_url', 'signed_download_url').
|
||||||
|
*/
|
||||||
|
maskSigUrl(url: string, urlType: string): void {
|
||||||
|
const sigMatch = url.match(/[?&]sig=([^&]+)/)
|
||||||
|
if (sigMatch) {
|
||||||
|
setSecret(sigMatch[1])
|
||||||
|
debug(`Masked ${urlType}: ${url.replace(sigMatch[1], '***')}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
maskSecretUrls(
|
maskSecretUrls(
|
||||||
body: CreateArtifactResponse | GetSignedArtifactURLResponse
|
body: CreateArtifactResponse | GetSignedArtifactURLResponse
|
||||||
): void {
|
): void {
|
||||||
if ('signedUploadUrl' in body && body.signedUploadUrl) {
|
if ('signedUploadUrl' in body && body.signedUploadUrl) {
|
||||||
maskSigUrl(body.signedUploadUrl, 'signed_upload_url')
|
this.maskSigUrl(body.signedUploadUrl, 'signed_upload_url')
|
||||||
}
|
}
|
||||||
if ('signedUrl' in body && body.signedUrl) {
|
if ('signedUrl' in body && body.signedUrl) {
|
||||||
maskSigUrl(body.signedUrl, 'signed_url')
|
this.maskSigUrl(body.signedUrl, 'signed_url')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,12 +16,12 @@ describe('CacheServiceClient', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks()
|
jest.clearAllMocks()
|
||||||
process.env['ACTIONS_RUNTIME_TOKEN'] = 'test-token' // <-- set the required env variable
|
process.env['ACTIONS_RUNTIME_TOKEN'] = 'test-token'
|
||||||
client = new CacheServiceClient('test-agent')
|
client = new CacheServiceClient('test-agent')
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
delete process.env['ACTIONS_RUNTIME_TOKEN'] // <-- clean up after tests
|
delete process.env['ACTIONS_RUNTIME_TOKEN']
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('maskSecretUrls', () => {
|
describe('maskSecretUrls', () => {
|
||||||
@ -36,7 +36,7 @@ describe('CacheServiceClient', () => {
|
|||||||
|
|
||||||
expect(setSecret).toHaveBeenCalledWith('secret-token')
|
expect(setSecret).toHaveBeenCalledWith('secret-token')
|
||||||
expect(debug).toHaveBeenCalledWith(
|
expect(debug).toHaveBeenCalledWith(
|
||||||
'Masked signedUploadUrl: https://example.com/upload?se=2025-03-05T16%3A47%3A23Z&sig=***'
|
'Masked signed_upload_url: https://example.com/upload?se=2025-03-05T16%3A47%3A23Z&sig=***'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ describe('CacheServiceClient', () => {
|
|||||||
|
|
||||||
expect(setSecret).toHaveBeenCalledWith('secret-token')
|
expect(setSecret).toHaveBeenCalledWith('secret-token')
|
||||||
expect(debug).toHaveBeenCalledWith(
|
expect(debug).toHaveBeenCalledWith(
|
||||||
'Masked signedDownloadUrl: https://example.com/download?se=2025-03-05T16%3A47%3A23Z&sig=***'
|
'Masked signed_download_url: https://example.com/download?se=2025-03-05T16%3A47%3A23Z&sig=***'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ describe('CacheServiceClient', () => {
|
|||||||
|
|
||||||
expect(setSecret).toHaveBeenCalledWith('secret-token')
|
expect(setSecret).toHaveBeenCalledWith('secret-token')
|
||||||
expect(debug).toHaveBeenCalledWith(
|
expect(debug).toHaveBeenCalledWith(
|
||||||
'Masked signedUploadUrl: https://example.com/upload?se=2025-03-05T16%3A47%3A23Z&sig=***'
|
'Masked signed_upload_url: https://example.com/upload?se=2025-03-05T16%3A47%3A23Z&sig=***'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ describe('CacheServiceClient', () => {
|
|||||||
|
|
||||||
expect(setSecret).toHaveBeenCalledWith('secret-token')
|
expect(setSecret).toHaveBeenCalledWith('secret-token')
|
||||||
expect(debug).toHaveBeenCalledWith(
|
expect(debug).toHaveBeenCalledWith(
|
||||||
'Masked signedDownloadUrl: https://example.com/download?se=2025-03-05T16%3A47%3A23Z&sig=***'
|
'Masked signed_download_url: https://example.com/download?se=2025-03-05T16%3A47%3A23Z&sig=***'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
4
packages/cache/package.json
vendored
4
packages/cache/package.json
vendored
@ -31,7 +31,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"audit-moderate": "npm install && npm audit --json --audit-level=moderate > audit.json",
|
"audit-moderate": "npm install && npm audit --json --audit-level=moderate > audit.json",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1",
|
"test": "echo \"Error: run tests from root\" && exit 1",
|
||||||
"tsc": "tsc"
|
"tsc": "tsc",
|
||||||
|
"clean": "rm -rf node_modules lib"
|
||||||
},
|
},
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/actions/toolkit/issues"
|
"url": "https://github.com/actions/toolkit/issues"
|
||||||
@ -46,6 +47,7 @@
|
|||||||
"@azure/ms-rest-js": "^2.6.0",
|
"@azure/ms-rest-js": "^2.6.0",
|
||||||
"@azure/storage-blob": "^12.13.0",
|
"@azure/storage-blob": "^12.13.0",
|
||||||
"@protobuf-ts/plugin": "^2.9.4",
|
"@protobuf-ts/plugin": "^2.9.4",
|
||||||
|
"@types/node": "^22.13.9",
|
||||||
"semver": "^6.3.1"
|
"semver": "^6.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {info, debug, maskSigUrl} from '@actions/core'
|
import {info, debug, setSecret} from '@actions/core'
|
||||||
import {getUserAgentString} from './user-agent'
|
import {getUserAgentString} from './user-agent'
|
||||||
import {NetworkError, UsageError} from './errors'
|
import {NetworkError, UsageError} from './errors'
|
||||||
import {getCacheServiceURL} from '../config'
|
import {getCacheServiceURL} from '../config'
|
||||||
@ -153,14 +153,27 @@ export class CacheServiceClient implements Rpc {
|
|||||||
throw new Error(`Request failed`)
|
throw new Error(`Request failed`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Masks the `sig` parameter in a URL and sets it as a secret.
|
||||||
|
* @param url The URL containing the `sig` parameter.
|
||||||
|
* @param urlType The type of the URL (e.g., 'signed_upload_url', 'signed_download_url').
|
||||||
|
*/
|
||||||
|
maskSigUrl(url: string, urlType: string): void {
|
||||||
|
const sigMatch = url.match(/[?&]sig=([^&]+)/)
|
||||||
|
if (sigMatch) {
|
||||||
|
setSecret(sigMatch[1])
|
||||||
|
debug(`Masked ${urlType}: ${url.replace(sigMatch[1], '***')}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
maskSecretUrls(
|
maskSecretUrls(
|
||||||
body: CreateCacheEntryResponse | GetCacheEntryDownloadURLResponse
|
body: CreateCacheEntryResponse | GetCacheEntryDownloadURLResponse
|
||||||
): void {
|
): void {
|
||||||
if ('signedUploadUrl' in body && body.signedUploadUrl) {
|
if ('signedUploadUrl' in body && body.signedUploadUrl) {
|
||||||
maskSigUrl(body.signedUploadUrl, 'signedUploadUrl')
|
this.maskSigUrl(body.signedUploadUrl, 'signed_upload_url')
|
||||||
}
|
}
|
||||||
if ('signedDownloadUrl' in body && body.signedDownloadUrl) {
|
if ('signedDownloadUrl' in body && body.signedDownloadUrl) {
|
||||||
maskSigUrl(body.signedDownloadUrl, 'signedDownloadUrl')
|
this.maskSigUrl(body.signedDownloadUrl, 'signed_download_url')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -391,19 +391,3 @@ export {toPosixPath, toWin32Path, toPlatformPath} from './path-utils'
|
|||||||
* Platform utilities exports
|
* Platform utilities exports
|
||||||
*/
|
*/
|
||||||
export * as platform from './platform'
|
export * as platform from './platform'
|
||||||
|
|
||||||
/**
|
|
||||||
* Masks the `sig` parameter in a URL and sets it as a secret.
|
|
||||||
* @param url The URL containing the `sig` parameter.
|
|
||||||
* @param urlType The type of the URL (e.g., 'signed_upload_url', 'signed_download_url').
|
|
||||||
* @returns The URL with the `sig` parameter masked.
|
|
||||||
*/
|
|
||||||
export function maskSigUrl(url: string, urlType: string): string {
|
|
||||||
const sigMatch = url.match(/[?&]sig=([^&]+)/)
|
|
||||||
if (sigMatch) {
|
|
||||||
setSecret(sigMatch[1])
|
|
||||||
debug(`Masked ${urlType}: ${url.replace(sigMatch[1], '***')}`)
|
|
||||||
return url.replace(sigMatch[1], '***')
|
|
||||||
}
|
|
||||||
return url
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user