-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathprovenance.js
More file actions
99 lines (91 loc) · 2.7 KB
/
Copy pathprovenance.js
File metadata and controls
99 lines (91 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
'use strict'
const t = require('tap')
const mockGlobals = require('@npmcli/mock-globals')
const nock = require('nock')
class MockProvenance {
static sigstoreIdToken () {
return `.${Buffer.from(JSON.stringify({
iss: 'https://oauth2.sigstore.dev/auth',
email: 'foo@bar.com',
})).toString('base64')}.`
}
static successfulNock ({
oidcURL,
requestToken,
workflowPath,
repository,
serverUrl,
ref,
sha,
runID,
runAttempt,
runnerEnv,
}) {
mockGlobals(t, {
'process.env': {
CI: true,
GITHUB_ACTIONS: true,
ACTIONS_ID_TOKEN_REQUEST_URL: oidcURL,
ACTIONS_ID_TOKEN_REQUEST_TOKEN: requestToken,
GITHUB_WORKFLOW_REF: `${repository}/${workflowPath}@${ref}`,
GITHUB_REPOSITORY: repository,
GITHUB_SERVER_URL: serverUrl,
GITHUB_REF: ref,
GITHUB_SHA: sha,
GITHUB_RUN_ID: runID,
GITHUB_RUN_ATTEMPT: runAttempt,
RUNNER_ENVIRONMENT: runnerEnv,
},
})
const idToken = this.sigstoreIdToken()
const url = new URL(oidcURL)
nock(url.origin)
.get(url.pathname)
.query({ audience: 'sigstore' })
.matchHeader('authorization', `Bearer ${requestToken}`)
.matchHeader('accept', 'application/json')
.reply(200, { value: idToken })
const leafCertificate = `-----BEGIN CERTIFICATE-----\nabc\n-----END CERTIFICATE-----\n`
// Mock the Fulcio signing certificate endpoint
nock('https://fulcio.sigstore.dev')
.post('/api/v2/signingCert')
.reply(200, {
signedCertificateEmbeddedSct: {
chain: {
certificates: [
leafCertificate,
`-----BEGIN CERTIFICATE-----\nxyz\n-----END CERTIFICATE-----\n`,
],
},
},
})
nock('https://rekor.sigstore.dev')
.post('/api/v1/log/entries')
.reply(201, {
'69e5a0c1663ee4452674a5c9d5050d866c2ee31e2faaf79913aea7cc27293cf6': {
body: Buffer.from(JSON.stringify({
kind: 'hashedrekord',
apiVersion: '0.0.1',
spec: {
signature: {
content: 'ABC123',
publicKey: { content: Buffer.from(leafCertificate).toString('base64') },
},
},
})).toString(
'base64'
),
integratedTime: 1654015743,
logID:
'c0d23d6ad406973f9559f3ba2d1ca01f84147d8ffc5b8445c224f98b9591801d',
logIndex: 2513258,
verification: {
signedEntryTimestamp: 'MEUCIQD6CD7ZNLUipFoxzmSL/L8Ewic4SRkXN77UjfJZ7d/wAAIgatokSuX9Rg0iWxAgSfHMtcsagtDCQalU5IvXdQ+yLEA=',
},
},
})
}
}
module.exports = {
MockProvenance,
}