|
8 | 8 | context "with secure handler names" do |
9 | 9 | it "accepts valid handler names" do |
10 | 10 | valid_configs = [ |
11 | | - { path: "/webhook", handler: "MyHandler" }, |
12 | | - { path: "/webhook", handler: "GitHubHandler" }, |
13 | | - { path: "/webhook", handler: "Team1Handler" }, |
14 | | - { path: "/webhook", handler: "WebhookHandler" }, |
15 | | - { path: "/webhook", handler: "CustomWebhookHandler" }, |
16 | | - { path: "/webhook", handler: "Handler123" }, |
17 | | - { path: "/webhook", handler: "My_Handler" } |
| 11 | + { path: "/webhook", handler: "my_handler" }, |
| 12 | + { path: "/webhook", handler: "github_handler" }, |
| 13 | + { path: "/webhook", handler: "team_1_handler" }, |
| 14 | + { path: "/webhook", handler: "webhook_handler" }, |
| 15 | + { path: "/webhook", handler: "custom_webhook_handler" }, |
| 16 | + { path: "/webhook", handler: "handler_123" }, |
| 17 | + { path: "/webhook", handler: "my_handler" } |
18 | 18 | ] |
19 | 19 |
|
20 | 20 | valid_configs.each do |config| |
|
26 | 26 |
|
27 | 27 | it "rejects dangerous system class names" do |
28 | 28 | dangerous_configs = Hooks::Security::DANGEROUS_CLASSES.map do |class_name| |
29 | | - { path: "/webhook", handler: class_name } |
| 29 | + # Convert PascalCase to snake_case for config |
| 30 | + snake_case_name = class_name.gsub(/([A-Z])/, '_\1').downcase.sub(/^_/, '') |
| 31 | + { path: "/webhook", handler: snake_case_name } |
30 | 32 | end |
31 | 33 |
|
32 | 34 | dangerous_configs.each do |config| |
|
38 | 40 |
|
39 | 41 | it "rejects handler names with invalid format" do |
40 | 42 | invalid_configs = [ |
41 | | - { path: "/webhook", handler: "handler" }, # lowercase start |
42 | | - { path: "/webhook", handler: "123Handler" }, # number start |
43 | | - { path: "/webhook", handler: "_Handler" }, # underscore start |
44 | | - { path: "/webhook", handler: "Handler$Test" }, # special characters |
45 | | - { path: "/webhook", handler: "Handler.Test" }, # dots |
46 | | - { path: "/webhook", handler: "Handler/Test" }, # slashes |
47 | | - { path: "/webhook", handler: "Handler Test" }, # spaces |
48 | | - { path: "/webhook", handler: "Handler\nTest" } # newlines |
| 43 | + { path: "/webhook", handler: "Handler" }, # uppercase start |
| 44 | + { path: "/webhook", handler: "123handler" }, # number start |
| 45 | + { path: "/webhook", handler: "_handler" }, # underscore start |
| 46 | + { path: "/webhook", handler: "handler$test" }, # special characters |
| 47 | + { path: "/webhook", handler: "handler.test" }, # dots |
| 48 | + { path: "/webhook", handler: "handler/test" }, # slashes |
| 49 | + { path: "/webhook", handler: "handler test" }, # spaces |
| 50 | + { path: "/webhook", handler: "handler\ntest" }, # newlines |
| 51 | + { path: "/webhook", handler: "handlerTest" }, # camelCase |
| 52 | + { path: "/webhook", handler: "HandlerTest" } # PascalCase |
49 | 53 | ] |
50 | 54 |
|
51 | 55 | invalid_configs.each do |config| |
|
88 | 92 | context "with endpoint arrays" do |
89 | 93 | it "validates all endpoints in an array and reports the problematic one" do |
90 | 94 | endpoints = [ |
91 | | - { path: "/webhook1", handler: "ValidHandler" }, |
92 | | - { path: "/webhook2", handler: "File" }, # This should fail |
93 | | - { path: "/webhook3", handler: "AnotherValidHandler" } |
| 95 | + { path: "/webhook1", handler: "valid_handler" }, |
| 96 | + { path: "/webhook2", handler: "File" }, # This should fail (PascalCase) |
| 97 | + { path: "/webhook3", handler: "another_valid_handler" } |
94 | 98 | ] |
95 | 99 |
|
96 | 100 | expect do |
|
0 commit comments