(t *testing.T)
| 424 | } |
| 425 | |
| 426 | func TestClassifyStepSecrets(t *testing.T) { |
| 427 | tests := []struct { |
| 428 | name string |
| 429 | step any |
| 430 | expectedUnsafe []string |
| 431 | expectedSafe []string |
| 432 | unorderedSafeMatch bool // use ElementsMatch instead of Equal for safe refs |
| 433 | }{ |
| 434 | { |
| 435 | name: "non-map step classifies all as unsafe", |
| 436 | step: "echo ${{ secrets.TOKEN }}", |
| 437 | expectedUnsafe: []string{"${{ secrets.TOKEN }}"}, |
| 438 | expectedSafe: nil, |
| 439 | }, |
| 440 | { |
| 441 | name: "secret in run field is unsafe", |
| 442 | step: map[string]any{ |
| 443 | "name": "Run step", |
| 444 | "run": "echo ${{ secrets.API_KEY }}", |
| 445 | }, |
| 446 | expectedUnsafe: []string{"${{ secrets.API_KEY }}"}, |
| 447 | expectedSafe: nil, |
| 448 | }, |
| 449 | { |
| 450 | name: "secret in env field is classified as safe", |
| 451 | step: map[string]any{ |
| 452 | "name": "Env step", |
| 453 | "env": map[string]any{ |
| 454 | "TOKEN": "${{ secrets.TOKEN }}", |
| 455 | }, |
| 456 | "run": "echo hi", |
| 457 | }, |
| 458 | expectedUnsafe: nil, |
| 459 | expectedSafe: []string{"${{ secrets.TOKEN }}"}, |
| 460 | }, |
| 461 | { |
| 462 | name: "secrets in both env and run are classified separately", |
| 463 | step: map[string]any{ |
| 464 | "name": "Mixed step", |
| 465 | "env": map[string]any{ |
| 466 | "SAFE": "${{ secrets.SAFE }}", |
| 467 | }, |
| 468 | "run": "curl ${{ secrets.LEAKED }}", |
| 469 | }, |
| 470 | expectedUnsafe: []string{"${{ secrets.LEAKED }}"}, |
| 471 | expectedSafe: []string{"${{ secrets.SAFE }}"}, |
| 472 | }, |
| 473 | { |
| 474 | name: "secret in with field for uses action step is classified as safe", |
| 475 | step: map[string]any{ |
| 476 | "uses": "some/action@v1", |
| 477 | "with": map[string]any{ |
| 478 | "token": "${{ secrets.MY_TOKEN }}", |
| 479 | }, |
| 480 | }, |
| 481 | expectedUnsafe: nil, |
| 482 | expectedSafe: []string{"${{ secrets.MY_TOKEN }}"}, |
| 483 | }, |
nothing calls this directly
no test coverage detected