@@ -1298,152 +1298,3 @@ func TestTemplateInjectionYAMLParsingEdgeCases(t *testing.T) {
12981298 })
12991299 }
13001300}
1301-
1302- // TestHasUnsafeExpressionInRunContent tests the fast text-based pre-flight check
1303- // that gates full YAML parsing in generateAndValidateYAML.
1304- func TestHasUnsafeExpressionInRunContent (t * testing.T ) {
1305- tests := []struct {
1306- name string
1307- yaml string
1308- expected bool
1309- desc string
1310- }{
1311- {
1312- name : "empty yaml" ,
1313- yaml : "" ,
1314- expected : false ,
1315- desc : "empty input has no violations" ,
1316- },
1317- {
1318- name : "no unsafe expressions" ,
1319- yaml : `jobs:
1320- test:
1321- steps:
1322- - run: echo "hello"` ,
1323- expected : false ,
1324- desc : "no unsafe expressions anywhere" ,
1325- },
1326- {
1327- name : "unsafe expression only in env block - common compiler pattern" ,
1328- yaml : `jobs:
1329- test:
1330- steps:
1331- - name: Step
1332- env:
1333- VALUE: ${{ github.event.issue.title }}
1334- run: |
1335- echo "$VALUE"` ,
1336- expected : false ,
1337- desc : "compiler puts expressions in env: blocks, not run: – no violation" ,
1338- },
1339- {
1340- name : "unsafe expression in concurrency group - not in run block" ,
1341- yaml : `concurrency:
1342- group: "ci-${{ github.event.pull_request.number }}"
1343- jobs:
1344- test:
1345- steps:
1346- - name: Step
1347- env:
1348- PR: ${{ github.event.pull_request.number }}
1349- run: |
1350- echo "$PR"` ,
1351- expected : false ,
1352- desc : "expressions in concurrency.group are not in run: blocks" ,
1353- },
1354- {
1355- name : "unsafe expression directly in inline run value" ,
1356- yaml : `jobs:
1357- test:
1358- steps:
1359- - run: echo "${{ github.event.issue.title }}"` ,
1360- expected : true ,
1361- desc : "direct expression use in inline run: is unsafe" ,
1362- },
1363- {
1364- name : "unsafe expression in block scalar run content" ,
1365- yaml : `jobs:
1366- test:
1367- steps:
1368- - run: |
1369- echo "${{ github.event.issue.title }}"` ,
1370- expected : true ,
1371- desc : "direct expression use in run: block scalar is unsafe" ,
1372- },
1373- {
1374- name : "unsafe expression in folded block run content" ,
1375- yaml : `jobs:
1376- test:
1377- steps:
1378- - run: >
1379- echo "${{ github.event.issue.title }}"` ,
1380- expected : true ,
1381- desc : "direct expression use in run: folded block is unsafe" ,
1382- },
1383- {
1384- name : "unsafe expression in steps outputs context" ,
1385- yaml : `jobs:
1386- test:
1387- steps:
1388- - run: |
1389- echo "${{ steps.prior.outputs.data }}"` ,
1390- expected : true ,
1391- desc : "steps.outputs expression in run: is unsafe" ,
1392- },
1393- {
1394- name : "unsafe expression in inputs context" ,
1395- yaml : `jobs:
1396- test:
1397- steps:
1398- - run: |
1399- echo "${{ inputs.user_data }}"` ,
1400- expected : true ,
1401- desc : "inputs expression in run: is unsafe" ,
1402- },
1403- {
1404- name : "expression in env block above run block - not in run content" ,
1405- yaml : `jobs:
1406- test:
1407- steps:
1408- - name: Multi-step with env
1409- env:
1410- A: ${{ github.event.issue.title }}
1411- B: ${{ steps.prior.outputs.val }}
1412- run: |
1413- echo "$A $B"
1414- - run: echo "done"` ,
1415- expected : false ,
1416- desc : "expressions in env: before run: are not inside run: content" ,
1417- },
1418- {
1419- name : "multiple steps - only one has unsafe run content" ,
1420- yaml : `jobs:
1421- test:
1422- steps:
1423- - env:
1424- V: ${{ github.event.issue.title }}
1425- run: echo "$V"
1426- - run: |
1427- echo "${{ github.event.issue.title }}"` ,
1428- expected : true ,
1429- desc : "second step has unsafe expression directly in run: block" ,
1430- },
1431- {
1432- name : "chomping indicator |- still detected" ,
1433- yaml : `jobs:
1434- test:
1435- steps:
1436- - run: |-
1437- echo "${{ github.event.issue.title }}"` ,
1438- expected : true ,
1439- desc : "chomping indicators don't prevent detection" ,
1440- },
1441- }
1442-
1443- for _ , tt := range tests {
1444- t .Run (tt .name , func (t * testing.T ) {
1445- got := hasUnsafeExpressionInRunContent (tt .yaml )
1446- assert .Equal (t , tt .expected , got , tt .desc )
1447- })
1448- }
1449- }
0 commit comments