config_test.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package base
  2. import (
  3. "testing"
  4. )
  5. func TestConfigAllowlistRegexes(t *testing.T) {
  6. tests := map[string]struct {
  7. invalid []string
  8. valid []string
  9. }{
  10. "general placeholders": {
  11. invalid: []string{
  12. `true`, `True`, `false`, `False`, `null`, `NULL`,
  13. },
  14. },
  15. "interpolated variables - ansible": {
  16. invalid: []string{
  17. `{{ x }}`, `{{ password }}`, `{{password}}`, `{{ data.proxy_password }}`,
  18. `{{ dict1 | ansible.builtin.combine(dict2) }}`,
  19. },
  20. },
  21. "interpolated variables - github actions": {
  22. invalid: []string{
  23. `${{ env.First_Name }}`,
  24. `${{ env.DAY_OF_WEEK == 'Monday' }}`,
  25. `${{env.JAVA_VERSION}}`,
  26. `${{ github.event.issue.title }}`,
  27. `${{ github.repository == "Gattocrucco/lsqfitgp" }}`,
  28. `${{ github.event.pull_request.number || github.ref }}`,
  29. `${{ github.event_name == 'pull_request' && github.event.action == 'unassigned' }}`,
  30. `${{ secrets.SuperSecret }}`,
  31. `${{ vars.JOB_NAME }}`,
  32. `${{ vars.USE_VARIABLES == 'true' }}`,
  33. },
  34. },
  35. "interpolated variables - nuget": {
  36. invalid: []string{
  37. `%MY_PASSWORD%`, `%password%`,
  38. },
  39. },
  40. "interpolated variables - ucd": {
  41. invalid: []string{`@password@`, `@LDAP_PASS@`},
  42. valid: []string{`@username@mastodon.example`},
  43. },
  44. "environment variables": {
  45. invalid: []string{`$2`, `$GIT_PASSWORD`, `${GIT_PASSWORD}`, `$password`},
  46. valid: []string{`$yP@R.@=ibxI`, `$2a6WCust9aE`, `${not_complete1`},
  47. },
  48. }
  49. cfg := CreateGlobalConfig()
  50. allowlist := cfg.Allowlist
  51. for name, cases := range tests {
  52. t.Run(name, func(t *testing.T) {
  53. for _, c := range cases.invalid {
  54. if !allowlist.RegexAllowed(c) {
  55. t.Errorf("invalid value not marked as allowed: %s", c)
  56. }
  57. }
  58. for _, c := range cases.valid {
  59. if allowlist.RegexAllowed(c) {
  60. t.Errorf("valid value marked as allowed: %s", c)
  61. }
  62. }
  63. })
  64. }
  65. }