Skip to content

Commit

Permalink
Merge pull request #42 from dependabot/brrygrdn/mask-job-credentials
Browse files Browse the repository at this point in the history
Ensure credentials retrieved from Dependabot are masked
  • Loading branch information
Barry Gordon authored and GitHub committed Nov 1, 2021
2 parents 5968d26 + 15390f3 commit 2cd7786
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 2 deletions.
51 changes: 51 additions & 0 deletions __tests__/api_client.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as core from '@actions/core'
import {ApiClient} from '../src/api-client'

describe('ApiClient', () => {
Expand Down Expand Up @@ -37,4 +38,54 @@ describe('ApiClient', () => {
expect(jobDetails['allowed-updates'].length).toBe(1)
expect(jobDetails['package-manager']).toBe('npm_and_yarn')
})

test('get job credentials', async () => {
const apiResponse = {
data: {
attributes: {
credentials: [
{
type: 'no-creds',
host: 'example.com',
username: 'foo',
password: null,
token: null
},
{
type: 'password',
host: 'example.com',
username: 'bar',
password: 'bar-password',
token: null
},
{
type: 'token',
host: 'example.com',
username: 'baz',
password: null,
token: 'baz-token'
},
{
type: 'both',
host: 'example.com',
username: 'qux',
password: 'qux-password',
token: 'qux-token'
}
]
}
}
}
mockAxios.get.mockResolvedValue({status: 200, data: apiResponse})
jest.spyOn(core, 'setSecret').mockImplementation(jest.fn())

const jobCredentials = await api.getCredentials()
expect(jobCredentials.length).toBe(4)

expect(core.setSecret).toHaveBeenCalledTimes(4)
expect(core.setSecret).toHaveBeenCalledWith('bar-password')
expect(core.setSecret).toHaveBeenCalledWith('baz-token')
expect(core.setSecret).toHaveBeenCalledWith('qux-password')
expect(core.setSecret).toHaveBeenCalledWith('qux-token')
})
})
31 changes: 30 additions & 1 deletion dist/main/index.js

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

2 changes: 1 addition & 1 deletion dist/main/index.js.map

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/api-client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as core from '@actions/core'
import {AxiosInstance} from 'axios'
import {JobParameters} from './inputs'

Expand Down Expand Up @@ -58,6 +59,16 @@ export class ApiClient {
throw new Error(`Unexpected status code: ${res.status}`)
}

// Mask any secrets we've just retrieved from Actions logs
for (const credential of res.data.data.attributes.credentials) {
if (credential.password) {
core.setSecret(credential.password)
}
if (credential.token) {
core.setSecret(credential.token)
}
}

return res.data.data.attributes.credentials
}

Expand Down

0 comments on commit 2cd7786

Please sign in to comment.