Commit 7c15f6e
authored
Rescue bike attribute assignment instead of 500ing (#4036)
A form filling bot POSTs `/bikes` with every field set to `"1"`.
`frame_material: "1"` isn't a valid enum value, and assigning it raised
`ArgumentError` — [1,441 notices in 7
days](https://app.honeybadger.io/projects/35931/faults/133165943), plus
[a second
fault](https://app.honeybadger.io/projects/35931/faults/133168206) on
the redirect back, where `embed_extended` rebuilds the form from the
same stored b_param and raises again.
- **`BikeServices::Builder.build` assigns the bike's attributes one at a
time and rescues**, adding an error on whichever attribute the model
refused. That's the whole fix — nothing about enums specifically, so
anything else assignment can raise on lands the same way. Assigning
individually is what keeps the rest of the attributes on the bike, so
the re-rendered form still holds what was entered.
- The bike is then invalid through the existing `bike.errors` →
`b_param.bike_errors` path, which every entry point already handles:
`/bikes` redirects to the form, the embed flashes the message, and the
registration flow returns to step 2.
Specs cover the two faulted paths plus the registration flow, which
permits no enum a bot can poison (`cycle_type` is `friendly_find`ed,
`status` is gated by `BParam#status`) but still builds the bike from
whatever the registration holds.1 parent c277172 commit 7c15f6e
5 files changed
Lines changed: 59 additions & 1 deletion
File tree
- app/services/bike_services
- spec
- requests
- bikes
- services/bike_services
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
14 | 20 | | |
15 | 21 | | |
16 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
232 | 244 | | |
233 | 245 | | |
234 | 246 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
234 | 246 | | |
235 | 247 | | |
236 | 248 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
702 | 702 | | |
703 | 703 | | |
704 | 704 | | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
705 | 723 | | |
706 | 724 | | |
707 | 725 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
130 | 140 | | |
131 | 141 | | |
132 | 142 | | |
| |||
0 commit comments