============================================================================= DoS Prevention Tests ============================================================================= TestSecurityDoSViaLargeInputs validates that excessively large inputs are handled without causing denial of service.
(t *testing.T)
| 217 | // TestSecurityDoSViaLargeInputs validates that excessively large inputs |
| 218 | // are handled without causing denial of service. |
| 219 | func TestSecurityDoSViaLargeInputs(t *testing.T) { |
| 220 | tests := []struct { |
| 221 | name string |
| 222 | contentFunc func() string |
| 223 | description string |
| 224 | }{ |
| 225 | { |
| 226 | name: "very_long_expression", |
| 227 | contentFunc: func() string { |
| 228 | // Create a very long but valid expression |
| 229 | expr := "${{ " |
| 230 | for i := 0; i < 100; i++ { |
| 231 | expr += "github.workflow && " |
| 232 | } |
| 233 | expr += "github.repository }}" |
| 234 | return expr |
| 235 | }, |
| 236 | description: "Very long expression should be handled", |
| 237 | }, |
| 238 | { |
| 239 | name: "many_expressions", |
| 240 | contentFunc: func() string { |
| 241 | // Many repeated expressions |
| 242 | var sb strings.Builder |
| 243 | for i := 0; i < 1000; i++ { |
| 244 | sb.WriteString("${{ github.workflow }} ") |
| 245 | } |
| 246 | return sb.String() |
| 247 | }, |
| 248 | description: "Many expressions should be handled", |
| 249 | }, |
| 250 | { |
| 251 | name: "excessive_whitespace", |
| 252 | contentFunc: func() string { |
| 253 | return "${{" + strings.Repeat(" ", 10000) + "github.workflow" + strings.Repeat(" ", 10000) + "}}" |
| 254 | }, |
| 255 | description: "Excessive whitespace should be handled", |
| 256 | }, |
| 257 | } |
| 258 | |
| 259 | for _, tt := range tests { |
| 260 | t.Run(tt.name, func(t *testing.T) { |
| 261 | content := tt.contentFunc() |
| 262 | |
| 263 | // The parser should handle these without panic or timeout |
| 264 | // We don't require a specific result, just that it doesn't hang |
| 265 | err := validateExpressionSafety(content) |
| 266 | _ = err // We don't care about the result, just that it completes |
| 267 | }) |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | // TestSecurityDoSViaNestedYAML validates that deeply nested YAML structures |
| 272 | // don't cause stack overflow or excessive resource consumption. |
nothing calls this directly
no test coverage detected