Skip to content

Commit 94f06b1

Browse files
authored
Update secret-scanning pipeline (#52146)
1 parent 8d57cad commit 94f06b1

File tree

5 files changed

+41
-8
lines changed

5 files changed

+41
-8
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ jobs:
7171
- release-notes
7272
- rest
7373
- search
74+
- secret-scanning
7475
- shielding
7576
- tracking
7677
# - tests

src/secret-scanning/README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
11
# Secret scanning
22

3-
The files in the secret scanning folder support our secret scanning informational pages.
3+
This secret scanning pipeline automates a table displayed on the [Supported secret scanning patterns](https://docs.github.com/code-security/secret-scanning/introduction/supported-secret-scanning-patterns#supported-secrets) page.
4+
5+
Each day a workflow checks if the [data](src/secret-scanning/data/public-docs.yml) is up-to-date. When there are changes, the workflow automatically creates a pull request to update the `src/secret-scanning/data/public-docs.yml` file. The workflow runs `npm run sync-secret-scanning` to check for updates.
6+
7+
This pipeline uses middleware to check if the path of the URL matches the page that contains the table. The middleware decorates the context with the data, which is displayed on the page using a Markdown table and Liquid. For example:
8+
9+
```markdown
10+
<!-- FPT version of table -->
11+
{% ifversion fpt %}
12+
13+
| Provider | Token | Partner | User | Push protection
14+
|----|:----|:----:|:----:|:----:|
15+
{%- for entry in secretScanningData %}
16+
| {{ entry.provider }} | {{ entry.secretType }} | {% if entry.isPublic %}{% octicon "check" aria-label="Supported" %}{% else %}{% octicon "x" aria-label="Unsupported" %}{% endif %} | {% if entry.isPrivateWithGhas %}{% octicon "check" aria-label="Supported" %}{% else %}{% octicon "x" aria-label="Unsupported" %}{% endif %} | {% if entry.hasPushProtection %}{% octicon "check" aria-label="Supported" %}{% else %}{% octicon "x" aria-label="Unsupported" %}{% endif %} |
17+
{%- endfor %}
18+
```

src/secret-scanning/lib/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"sha": "bb86a15b48fe62030cf0ad8c38520508063ec20b",
3-
"blob-sha": "96de8d829b93d371162f193a68ea19ae86ac0d09"
3+
"blob-sha": "96de8d829b93d371162f193a68ea19ae86ac0d09",
4+
"targetFilename": "code-security/secret-scanning/introduction/supported-secret-scanning-patterns"
45
}

src/secret-scanning/middleware/secret-scanning.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@ import { ExtendedRequest, SecretScanningData } from '@/types'
99

1010
const secretScanningPath = 'src/secret-scanning/data/public-docs.yml'
1111

12+
// This is the path to the file that contains the secret scanning data.
13+
// Currently it's:
14+
// code-security/secret-scanning/introduction/supported-secret-scanning-pattern
15+
const { targetFilename } = JSON.parse(
16+
fs.readFileSync('src/secret-scanning/lib/config.json', 'utf-8'),
17+
)
18+
1219
export default async function secretScanning(
1320
req: ExtendedRequest,
1421
res: Response,
1522
next: NextFunction,
1623
) {
17-
if (
18-
!req.pagePath!.endsWith(
19-
'code-security/secret-scanning/introduction/supported-secret-scanning-patterns',
20-
)
21-
)
22-
return next()
24+
if (!req.pagePath!.endsWith(targetFilename)) return next()
2325

2426
const secretScanningData = yaml.load(
2527
fs.readFileSync(secretScanningPath, 'utf-8'),
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { describe, expect, test } from 'vitest'
2+
import { readFileSync } from 'fs'
3+
4+
import { get } from '#src/tests/helpers/e2etest.js'
5+
6+
describe('secret-scanning pipeline', () => {
7+
const { targetFilename } = JSON.parse(readFileSync('src/secret-scanning/lib/config.json'))
8+
// This test ensures that the configured page exists. If the page moves
9+
// this test will fail.
10+
test(`check if ${targetFilename} was moved`, async () => {
11+
const page = await get(`/${targetFilename}`, { followRedirects: true })
12+
expect(page.statusCode).toBe(200)
13+
})
14+
})

0 commit comments

Comments
 (0)