roda-gen 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (346) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +9 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +94 -0
  5. data/bin/roda +11 -0
  6. data/lib/roda-gen.rb +3 -0
  7. data/lib/roda_gen/app_name.rb +29 -0
  8. data/lib/roda_gen/cli.rb +122 -0
  9. data/lib/roda_gen/generators/daemon.rb +78 -0
  10. data/lib/roda_gen/generators/migration.rb +68 -0
  11. data/lib/roda_gen/generators/migration_numbering.rb +21 -0
  12. data/lib/roda_gen/generators/model.rb +75 -0
  13. data/lib/roda_gen/generators/project.rb +145 -0
  14. data/lib/roda_gen/generators/route.rb +71 -0
  15. data/lib/roda_gen/generators/templates/daemon/bin/%daemon_name%.tt +13 -0
  16. data/lib/roda_gen/generators/templates/daemon/lib/daemon/%daemon_name%.rb.tt +22 -0
  17. data/lib/roda_gen/generators/templates/daemon/spec/daemons/%daemon_name%_spec.rb.tt +18 -0
  18. data/lib/roda_gen/generators/templates/migration/db/migrate/%migration_filename%.rb.tt +6 -0
  19. data/lib/roda_gen/generators/templates/model/db/migrate/%migration_filename%.rb.tt +12 -0
  20. data/lib/roda_gen/generators/templates/model/models/%resource_name%.rb.tt +5 -0
  21. data/lib/roda_gen/generators/templates/model/spec/models/%resource_name%_spec.rb.tt +18 -0
  22. data/lib/roda_gen/generators/templates/project/%app_name%.rb.tt +43 -0
  23. data/lib/roda_gen/generators/templates/project/.bundle/config.tt +3 -0
  24. data/lib/roda_gen/generators/templates/project/.erb_lint.yml.tt +29 -0
  25. data/lib/roda_gen/generators/templates/project/.gitignore.tt +19 -0
  26. data/lib/roda_gen/generators/templates/project/.reek.yml.tt +45 -0
  27. data/lib/roda_gen/generators/templates/project/.rspec.tt +4 -0
  28. data/lib/roda_gen/generators/templates/project/.rubocop.yml.tt +119 -0
  29. data/lib/roda_gen/generators/templates/project/.ruby-version.tt +1 -0
  30. data/lib/roda_gen/generators/templates/project/.rubycritic.yml.tt +15 -0
  31. data/lib/roda_gen/generators/templates/project/Gemfile.tt +109 -0
  32. data/lib/roda_gen/generators/templates/project/Procfile.dev.tt +7 -0
  33. data/lib/roda_gen/generators/templates/project/README.md.tt +891 -0
  34. data/lib/roda_gen/generators/templates/project/Rakefile.tt +3 -0
  35. data/lib/roda_gen/generators/templates/project/assets/javascripts/admin.js.tt +84 -0
  36. data/lib/roda_gen/generators/templates/project/assets/javascripts/app.js.tt +29 -0
  37. data/lib/roda_gen/generators/templates/project/assets/javascripts/push.js.tt +53 -0
  38. data/lib/roda_gen/generators/templates/project/assets/javascripts/upload.js.tt +200 -0
  39. data/lib/roda_gen/generators/templates/project/assets/stylesheets/app.css.tt +52 -0
  40. data/lib/roda_gen/generators/templates/project/assets/stylesheets/typography.css.tt +85 -0
  41. data/lib/roda_gen/generators/templates/project/bin/console.tt +2 -0
  42. data/lib/roda_gen/generators/templates/project/bin/dev.tt +8 -0
  43. data/lib/roda_gen/generators/templates/project/bin/gdpr_worker.tt +13 -0
  44. data/lib/roda_gen/generators/templates/project/bin/push_sender.tt +13 -0
  45. data/lib/roda_gen/generators/templates/project/bin/setup.tt +224 -0
  46. data/lib/roda_gen/generators/templates/project/bin/shrine_clean_cache.tt +13 -0
  47. data/lib/roda_gen/generators/templates/project/config/boot.rb.tt +23 -0
  48. data/lib/roda_gen/generators/templates/project/config/console.rb.tt +20 -0
  49. data/lib/roda_gen/generators/templates/project/config/database.rb.tt +45 -0
  50. data/lib/roda_gen/generators/templates/project/config/initializers/00_environments.rb.tt +5 -0
  51. data/lib/roda_gen/generators/templates/project/config/initializers/01_logger.rb.tt +46 -0
  52. data/lib/roda_gen/generators/templates/project/config/initializers/02_app_config.rb.tt +19 -0
  53. data/lib/roda_gen/generators/templates/project/config/initializers/10_database.rb.tt +3 -0
  54. data/lib/roda_gen/generators/templates/project/config/initializers/15_mail.rb.tt +53 -0
  55. data/lib/roda_gen/generators/templates/project/config/initializers/20_redis.rb.tt +13 -0
  56. data/lib/roda_gen/generators/templates/project/config/initializers/25_rack_attack.rb.tt +96 -0
  57. data/lib/roda_gen/generators/templates/project/config/initializers/30_i18n.rb.tt +37 -0
  58. data/lib/roda_gen/generators/templates/project/config/initializers/35_listen_job.rb.tt +4 -0
  59. data/lib/roda_gen/generators/templates/project/config/initializers/37_shrine.rb.tt +20 -0
  60. data/lib/roda_gen/generators/templates/project/config/initializers/40_routing.rb.tt +20 -0
  61. data/lib/roda_gen/generators/templates/project/config/initializers/41_render.rb.tt +10 -0
  62. data/lib/roda_gen/generators/templates/project/config/initializers/43_static.rb.tt +30 -0
  63. data/lib/roda_gen/generators/templates/project/config/initializers/44_sessions.rb.tt +62 -0
  64. data/lib/roda_gen/generators/templates/project/config/initializers/45_security.rb.tt +49 -0
  65. data/lib/roda_gen/generators/templates/project/config/initializers/46_flash.rb.tt +5 -0
  66. data/lib/roda_gen/generators/templates/project/config/initializers/47_json.rb.tt +8 -0
  67. data/lib/roda_gen/generators/templates/project/config/initializers/48_errors.rb.tt +43 -0
  68. data/lib/roda_gen/generators/templates/project/config/initializers/49_misc.rb.tt +26 -0
  69. data/lib/roda_gen/generators/templates/project/config/initializers/50_mailer.rb.tt +52 -0
  70. data/lib/roda_gen/generators/templates/project/config/initializers/51_locale_kit.rb.tt +29 -0
  71. data/lib/roda_gen/generators/templates/project/config/initializers/52_consent_kit.rb.tt +28 -0
  72. data/lib/roda_gen/generators/templates/project/config/initializers/55_audit_log.rb.tt +16 -0
  73. data/lib/roda_gen/generators/templates/project/config/initializers/56_form_helper.rb.tt +7 -0
  74. data/lib/roda_gen/generators/templates/project/config/initializers/57_rodauth.rb.tt +304 -0
  75. data/lib/roda_gen/generators/templates/project/config/initializers/60_web_push.rb.tt +12 -0
  76. data/lib/roda_gen/generators/templates/project/config/initializers/61_flipper.rb.tt +15 -0
  77. data/lib/roda_gen/generators/templates/project/config/initializers/62_split.rb.tt +15 -0
  78. data/lib/roda_gen/generators/templates/project/config/puma.rb.tt +24 -0
  79. data/lib/roda_gen/generators/templates/project/config/settings/development.yml.tt +9 -0
  80. data/lib/roda_gen/generators/templates/project/config/settings/production.yml.tt +13 -0
  81. data/lib/roda_gen/generators/templates/project/config/settings/test.yml.tt +9 -0
  82. data/lib/roda_gen/generators/templates/project/config/settings.yml.tt +45 -0
  83. data/lib/roda_gen/generators/templates/project/config.ru.tt +36 -0
  84. data/lib/roda_gen/generators/templates/project/db/migrate/create_account_profiles.rb.tt +66 -0
  85. data/lib/roda_gen/generators/templates/project/db/migrate/create_accounts.rb.tt +70 -0
  86. data/lib/roda_gen/generators/templates/project/db/migrate/create_audit_log.rb.tt +185 -0
  87. data/lib/roda_gen/generators/templates/project/db/migrate/create_authorization.rb.tt +68 -0
  88. data/lib/roda_gen/generators/templates/project/db/migrate/create_countries.rb.tt +13 -0
  89. data/lib/roda_gen/generators/templates/project/db/migrate/create_country_calling_codes.rb.tt +15 -0
  90. data/lib/roda_gen/generators/templates/project/db/migrate/create_country_exit_codes.rb.tt +13 -0
  91. data/lib/roda_gen/generators/templates/project/db/migrate/create_country_languages.rb.tt +19 -0
  92. data/lib/roda_gen/generators/templates/project/db/migrate/create_country_time_zones.rb.tt +11 -0
  93. data/lib/roda_gen/generators/templates/project/db/migrate/create_currencies.rb.tt +12 -0
  94. data/lib/roda_gen/generators/templates/project/db/migrate/create_gdpr_requests.rb.tt +43 -0
  95. data/lib/roda_gen/generators/templates/project/db/migrate/create_languages.rb.tt +11 -0
  96. data/lib/roda_gen/generators/templates/project/db/migrate/create_push_subscriptions.rb.tt +16 -0
  97. data/lib/roda_gen/generators/templates/project/db/migrate/create_rodauth_features.rb.tt +105 -0
  98. data/lib/roda_gen/generators/templates/project/db/migrate/create_settings.rb.tt +60 -0
  99. data/lib/roda_gen/generators/templates/project/db/seeds/01_countries.csv.tt +250 -0
  100. data/lib/roda_gen/generators/templates/project/db/seeds/01_currencies.csv.tt +162 -0
  101. data/lib/roda_gen/generators/templates/project/db/seeds/01_languages.csv.tt +144 -0
  102. data/lib/roda_gen/generators/templates/project/db/seeds/02_country_calling_codes.csv.tt +237 -0
  103. data/lib/roda_gen/generators/templates/project/db/seeds/02_country_exit_codes.csv.tt +239 -0
  104. data/lib/roda_gen/generators/templates/project/db/seeds/02_country_languages.csv.tt +226 -0
  105. data/lib/roda_gen/generators/templates/project/db/seeds/02_country_time_zones.csv.tt +369 -0
  106. data/lib/roda_gen/generators/templates/project/db/seeds/03_setting_system_defaults.yml.tt +35 -0
  107. data/lib/roda_gen/generators/templates/project/db/seeds.rb.tt +69 -0
  108. data/lib/roda_gen/generators/templates/project/deploy/Caddyfile.tt +69 -0
  109. data/lib/roda_gen/generators/templates/project/deploy/logrotate/%app_name%-caddy.tt +11 -0
  110. data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-audit-partition.service.tt +21 -0
  111. data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-audit-partition.timer.tt +16 -0
  112. data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-gdpr-worker.service.tt +25 -0
  113. data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-push-sender.service.tt +25 -0
  114. data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-shrine-cleanup.service.tt +21 -0
  115. data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-shrine-cleanup.timer.tt +16 -0
  116. data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%.service.tt +36 -0
  117. data/lib/roda_gen/generators/templates/project/helpers/audit_helper.rb.tt +59 -0
  118. data/lib/roda_gen/generators/templates/project/helpers/authorization_helper.rb.tt +25 -0
  119. data/lib/roda_gen/generators/templates/project/helpers/current_account_helper.rb.tt +33 -0
  120. data/lib/roda_gen/generators/templates/project/helpers/feature_flag_helper.rb.tt +34 -0
  121. data/lib/roda_gen/generators/templates/project/helpers/form_helper.rb.tt +50 -0
  122. data/lib/roda_gen/generators/templates/project/helpers/http_cache_helper.rb.tt +15 -0
  123. data/lib/roda_gen/generators/templates/project/helpers/logger_helper.rb.tt +7 -0
  124. data/lib/roda_gen/generators/templates/project/helpers/split_helper.rb.tt +22 -0
  125. data/lib/roda_gen/generators/templates/project/lib/audit_context.rb.tt +26 -0
  126. data/lib/roda_gen/generators/templates/project/lib/audit_lookup.rb.tt +21 -0
  127. data/lib/roda_gen/generators/templates/project/lib/daemon/base.rb.tt +104 -0
  128. data/lib/roda_gen/generators/templates/project/lib/daemon/gdpr_worker.rb.tt +53 -0
  129. data/lib/roda_gen/generators/templates/project/lib/daemon/push_sender.rb.tt +47 -0
  130. data/lib/roda_gen/generators/templates/project/lib/daemon/shrine_cache_cleaner.rb.tt +22 -0
  131. data/lib/roda_gen/generators/templates/project/lib/deploy_check.rb.tt +96 -0
  132. data/lib/roda_gen/generators/templates/project/lib/filtered_logger.rb.tt +54 -0
  133. data/lib/roda_gen/generators/templates/project/lib/gdpr.rb.tt +106 -0
  134. data/lib/roda_gen/generators/templates/project/lib/rbac_audit.rb.tt +47 -0
  135. data/lib/roda_gen/generators/templates/project/lib/tasks/.rubocop.yml.tt +4 -0
  136. data/lib/roda_gen/generators/templates/project/lib/tasks/audit.rake.tt +85 -0
  137. data/lib/roda_gen/generators/templates/project/lib/tasks/console.rake.tt +8 -0
  138. data/lib/roda_gen/generators/templates/project/lib/tasks/db.rake.tt +104 -0
  139. data/lib/roda_gen/generators/templates/project/lib/tasks/deploy.rake.tt +38 -0
  140. data/lib/roda_gen/generators/templates/project/lib/tasks/flags.rake.tt +47 -0
  141. data/lib/roda_gen/generators/templates/project/lib/tasks/gdpr.rake.tt +31 -0
  142. data/lib/roda_gen/generators/templates/project/lib/tasks/parser_current_shim.rb.tt +13 -0
  143. data/lib/roda_gen/generators/templates/project/lib/tasks/quality.rake.tt +84 -0
  144. data/lib/roda_gen/generators/templates/project/lib/tasks/secrets.rake.tt +154 -0
  145. data/lib/roda_gen/generators/templates/project/lib/tasks/spec.rake.tt +136 -0
  146. data/lib/roda_gen/generators/templates/project/lib/tasks/split.rake.tt +27 -0
  147. data/lib/roda_gen/generators/templates/project/lib/tasks/tailwind.rake.tt +35 -0
  148. data/lib/roda_gen/generators/templates/project/locales/de.yml.tt +325 -0
  149. data/lib/roda_gen/generators/templates/project/locales/en.yml.tt +321 -0
  150. data/lib/roda_gen/generators/templates/project/locales/es.yml.tt +326 -0
  151. data/lib/roda_gen/generators/templates/project/locales/fr.yml.tt +329 -0
  152. data/lib/roda_gen/generators/templates/project/locales/it.yml.tt +325 -0
  153. data/lib/roda_gen/generators/templates/project/locales/rodauth/de.yml.tt +5 -0
  154. data/lib/roda_gen/generators/templates/project/locales/rodauth/en.yml.tt +6 -0
  155. data/lib/roda_gen/generators/templates/project/locales/rodauth/es.yml.tt +5 -0
  156. data/lib/roda_gen/generators/templates/project/locales/rodauth/fr.yml.tt +5 -0
  157. data/lib/roda_gen/generators/templates/project/locales/rodauth/it.yml.tt +5 -0
  158. data/lib/roda_gen/generators/templates/project/locales/rodauth/sv.yml.tt +274 -0
  159. data/lib/roda_gen/generators/templates/project/locales/rodauth/tru.yml.tt +274 -0
  160. data/lib/roda_gen/generators/templates/project/locales/sv.yml.tt +319 -0
  161. data/lib/roda_gen/generators/templates/project/locales/tru.yml.tt +294 -0
  162. data/lib/roda_gen/generators/templates/project/log/.keep.tt +0 -0
  163. data/lib/roda_gen/generators/templates/project/models/account.rb.tt +50 -0
  164. data/lib/roda_gen/generators/templates/project/models/account_privilege.rb.tt +15 -0
  165. data/lib/roda_gen/generators/templates/project/models/account_profile.rb.tt +115 -0
  166. data/lib/roda_gen/generators/templates/project/models/account_role.rb.tt +14 -0
  167. data/lib/roda_gen/generators/templates/project/models/audit_action.rb.tt +23 -0
  168. data/lib/roda_gen/generators/templates/project/models/audit_actor_type.rb.tt +10 -0
  169. data/lib/roda_gen/generators/templates/project/models/audit_log.rb.tt +257 -0
  170. data/lib/roda_gen/generators/templates/project/models/audit_status.rb.tt +9 -0
  171. data/lib/roda_gen/generators/templates/project/models/country.rb.tt +17 -0
  172. data/lib/roda_gen/generators/templates/project/models/country_calling_code.rb.tt +7 -0
  173. data/lib/roda_gen/generators/templates/project/models/country_exit_code.rb.tt +7 -0
  174. data/lib/roda_gen/generators/templates/project/models/country_language.rb.tt +8 -0
  175. data/lib/roda_gen/generators/templates/project/models/country_time_zone.rb.tt +7 -0
  176. data/lib/roda_gen/generators/templates/project/models/currency.rb.tt +7 -0
  177. data/lib/roda_gen/generators/templates/project/models/gdpr_request.rb.tt +32 -0
  178. data/lib/roda_gen/generators/templates/project/models/gender.rb.tt +7 -0
  179. data/lib/roda_gen/generators/templates/project/models/language.rb.tt +13 -0
  180. data/lib/roda_gen/generators/templates/project/models/privilege.rb.tt +21 -0
  181. data/lib/roda_gen/generators/templates/project/models/push_subscription.rb.tt +10 -0
  182. data/lib/roda_gen/generators/templates/project/models/role.rb.tt +21 -0
  183. data/lib/roda_gen/generators/templates/project/models/role_privilege.rb.tt +14 -0
  184. data/lib/roda_gen/generators/templates/project/models/setting_system_default.rb.tt +11 -0
  185. data/lib/roda_gen/generators/templates/project/models/setting_user_value.rb.tt +12 -0
  186. data/lib/roda_gen/generators/templates/project/models/settings.rb.tt +22 -0
  187. data/lib/roda_gen/generators/templates/project/models/signup_form_data.rb.tt +61 -0
  188. data/lib/roda_gen/generators/templates/project/models.rb.tt +6 -0
  189. data/lib/roda_gen/generators/templates/project/package.json.tt +13 -0
  190. data/lib/roda_gen/generators/templates/project/public/apple-touch-icon.png +0 -0
  191. data/lib/roda_gen/generators/templates/project/public/favicon.ico +0 -0
  192. data/lib/roda_gen/generators/templates/project/public/favicon.svg.tt +5 -0
  193. data/lib/roda_gen/generators/templates/project/public/fonts/JetBrainsMono-Italic-Variable.woff2 +0 -0
  194. data/lib/roda_gen/generators/templates/project/public/fonts/JetBrainsMono-Variable.woff2 +0 -0
  195. data/lib/roda_gen/generators/templates/project/public/fonts/Lato-Bold.woff2 +0 -0
  196. data/lib/roda_gen/generators/templates/project/public/fonts/Lato-BoldItalic.woff2 +0 -0
  197. data/lib/roda_gen/generators/templates/project/public/fonts/Lato-Italic.woff2 +0 -0
  198. data/lib/roda_gen/generators/templates/project/public/fonts/Lato-Regular.woff2 +0 -0
  199. data/lib/roda_gen/generators/templates/project/public/fonts/NOTICE.md +17 -0
  200. data/lib/roda_gen/generators/templates/project/public/fonts/NotoSansSyriac-Bold.woff2 +0 -0
  201. data/lib/roda_gen/generators/templates/project/public/fonts/NotoSansSyriac-Regular.woff2 +0 -0
  202. data/lib/roda_gen/generators/templates/project/public/fonts/NotoSansSyriacWestern-Bold.woff2 +0 -0
  203. data/lib/roda_gen/generators/templates/project/public/fonts/NotoSansSyriacWestern-Regular.woff2 +0 -0
  204. data/lib/roda_gen/generators/templates/project/public/manifest.webmanifest.tt +12 -0
  205. data/lib/roda_gen/generators/templates/project/public/robots.txt.tt +4 -0
  206. data/lib/roda_gen/generators/templates/project/public/service-worker.js.tt +27 -0
  207. data/lib/roda_gen/generators/templates/project/routes/account.rb.tt +10 -0
  208. data/lib/roda_gen/generators/templates/project/routes/admin.rb.tt +118 -0
  209. data/lib/roda_gen/generators/templates/project/routes/gdpr.rb.tt +32 -0
  210. data/lib/roda_gen/generators/templates/project/routes/heartbeat.rb.tt +35 -0
  211. data/lib/roda_gen/generators/templates/project/routes/legal.rb.tt +20 -0
  212. data/lib/roda_gen/generators/templates/project/routes/profile.rb.tt +56 -0
  213. data/lib/roda_gen/generators/templates/project/routes/push.rb.tt +25 -0
  214. data/lib/roda_gen/generators/templates/project/spec/browser/role_boundary_spec.rb.tt +10 -0
  215. data/lib/roda_gen/generators/templates/project/spec/browser/spec_helper.rb.tt +146 -0
  216. data/lib/roda_gen/generators/templates/project/spec/browser/support/auth_helpers.rb.tt +71 -0
  217. data/lib/roda_gen/generators/templates/project/spec/browser/uat/auth_spec.rb.tt +25 -0
  218. data/lib/roda_gen/generators/templates/project/spec/browser/uat/consent_nojs_spec.rb.tt +60 -0
  219. data/lib/roda_gen/generators/templates/project/spec/browser/uat/create_account_form_spec.rb.tt +26 -0
  220. data/lib/roda_gen/generators/templates/project/spec/browser/uat/otp_lifecycle_spec.rb.tt +67 -0
  221. data/lib/roda_gen/generators/templates/project/spec/browser/uat/profile_form_spec.rb.tt +17 -0
  222. data/lib/roda_gen/generators/templates/project/spec/browser/uat/upload_spec.rb.tt +102 -0
  223. data/lib/roda_gen/generators/templates/project/spec/browser/wcag/auth_pages_spec.rb.tt +61 -0
  224. data/lib/roda_gen/generators/templates/project/spec/browser/wcag/legal_pages_spec.rb.tt +33 -0
  225. data/lib/roda_gen/generators/templates/project/spec/daemons/base_spec.rb.tt +106 -0
  226. data/lib/roda_gen/generators/templates/project/spec/daemons/gdpr_worker_spec.rb.tt +72 -0
  227. data/lib/roda_gen/generators/templates/project/spec/daemons/push_sender_spec.rb.tt +74 -0
  228. data/lib/roda_gen/generators/templates/project/spec/locale_parity_spec.rb.tt +58 -0
  229. data/lib/roda_gen/generators/templates/project/spec/models/account_profile_spec.rb.tt +180 -0
  230. data/lib/roda_gen/generators/templates/project/spec/models/account_spec.rb.tt +104 -0
  231. data/lib/roda_gen/generators/templates/project/spec/models/audit_actor_type_spec.rb.tt +7 -0
  232. data/lib/roda_gen/generators/templates/project/spec/models/audit_log_spec.rb.tt +398 -0
  233. data/lib/roda_gen/generators/templates/project/spec/models/audit_status_spec.rb.tt +7 -0
  234. data/lib/roda_gen/generators/templates/project/spec/models/authorization_spec.rb.tt +82 -0
  235. data/lib/roda_gen/generators/templates/project/spec/models/country_calling_code_spec.rb.tt +11 -0
  236. data/lib/roda_gen/generators/templates/project/spec/models/country_exit_code_spec.rb.tt +10 -0
  237. data/lib/roda_gen/generators/templates/project/spec/models/country_language_spec.rb.tt +21 -0
  238. data/lib/roda_gen/generators/templates/project/spec/models/country_spec.rb.tt +29 -0
  239. data/lib/roda_gen/generators/templates/project/spec/models/country_time_zone_spec.rb.tt +9 -0
  240. data/lib/roda_gen/generators/templates/project/spec/models/currency_spec.rb.tt +9 -0
  241. data/lib/roda_gen/generators/templates/project/spec/models/deploy_check_spec.rb.tt +143 -0
  242. data/lib/roda_gen/generators/templates/project/spec/models/gdpr_spec.rb.tt +110 -0
  243. data/lib/roda_gen/generators/templates/project/spec/models/language_spec.rb.tt +15 -0
  244. data/lib/roda_gen/generators/templates/project/spec/models/rbac_audit_spec.rb.tt +110 -0
  245. data/lib/roda_gen/generators/templates/project/spec/models/setting_system_default_spec.rb.tt +26 -0
  246. data/lib/roda_gen/generators/templates/project/spec/models/setting_user_value_spec.rb.tt +33 -0
  247. data/lib/roda_gen/generators/templates/project/spec/models/settings_spec.rb.tt +63 -0
  248. data/lib/roda_gen/generators/templates/project/spec/models/signup_form_data_spec.rb.tt +22 -0
  249. data/lib/roda_gen/generators/templates/project/spec/spec_helper.rb.tt +93 -0
  250. data/lib/roda_gen/generators/templates/project/spec/support/audit_log_helpers.rb.tt +21 -0
  251. data/lib/roda_gen/generators/templates/project/spec/support/audit_lookup_shared_examples.rb.tt +19 -0
  252. data/lib/roda_gen/generators/templates/project/spec/support/auth_helpers.rb.tt +62 -0
  253. data/lib/roda_gen/generators/templates/project/spec/support/faker.rb.tt +30 -0
  254. data/lib/roda_gen/generators/templates/project/spec/web/admin_spec.rb.tt +155 -0
  255. data/lib/roda_gen/generators/templates/project/spec/web/audit_log_spec.rb.tt +159 -0
  256. data/lib/roda_gen/generators/templates/project/spec/web/auth_spec.rb.tt +492 -0
  257. data/lib/roda_gen/generators/templates/project/spec/web/authorization_spec.rb.tt +110 -0
  258. data/lib/roda_gen/generators/templates/project/spec/web/boot_spec.rb.tt +27 -0
  259. data/lib/roda_gen/generators/templates/project/spec/web/consent_banner_spec.rb.tt +46 -0
  260. data/lib/roda_gen/generators/templates/project/spec/web/feature_flag_helper_spec.rb.tt +33 -0
  261. data/lib/roda_gen/generators/templates/project/spec/web/flags_spec.rb.tt +67 -0
  262. data/lib/roda_gen/generators/templates/project/spec/web/gdpr_spec.rb.tt +55 -0
  263. data/lib/roda_gen/generators/templates/project/spec/web/heartbeat_spec.rb.tt +65 -0
  264. data/lib/roda_gen/generators/templates/project/spec/web/host_allowlist_spec.rb.tt +27 -0
  265. data/lib/roda_gen/generators/templates/project/spec/web/legal_spec.rb.tt +61 -0
  266. data/lib/roda_gen/generators/templates/project/spec/web/locale_resolver_spec.rb.tt +34 -0
  267. data/lib/roda_gen/generators/templates/project/spec/web/logger_helper_spec.rb.tt +23 -0
  268. data/lib/roda_gen/generators/templates/project/spec/web/logger_spec.rb.tt +82 -0
  269. data/lib/roda_gen/generators/templates/project/spec/web/otp_audit_spec.rb.tt +147 -0
  270. data/lib/roda_gen/generators/templates/project/spec/web/profile_spec.rb.tt +97 -0
  271. data/lib/roda_gen/generators/templates/project/spec/web/push_spec.rb.tt +55 -0
  272. data/lib/roda_gen/generators/templates/project/spec/web/rack_attack_runtime_spec.rb.tt +52 -0
  273. data/lib/roda_gen/generators/templates/project/spec/web/rack_attack_spec.rb.tt +81 -0
  274. data/lib/roda_gen/generators/templates/project/spec/web/rbac_audit_spec.rb.tt +62 -0
  275. data/lib/roda_gen/generators/templates/project/spec/web/request_id_spec.rb.tt +62 -0
  276. data/lib/roda_gen/generators/templates/project/spec/web/role_boundary_spec.rb.tt +21 -0
  277. data/lib/roda_gen/generators/templates/project/spec/web/session_skip_spec.rb.tt +74 -0
  278. data/lib/roda_gen/generators/templates/project/spec/web/split_helper_spec.rb.tt +38 -0
  279. data/lib/roda_gen/generators/templates/project/spec/web/type_routing_spec.rb.tt +55 -0
  280. data/lib/roda_gen/generators/templates/project/spec/web/upload_zone_spec.rb.tt +91 -0
  281. data/lib/roda_gen/generators/templates/project/tmp/.keep.tt +0 -0
  282. data/lib/roda_gen/generators/templates/project/vendor/.keep.tt +0 -0
  283. data/lib/roda_gen/generators/templates/project/views/403.erb.tt +10 -0
  284. data/lib/roda_gen/generators/templates/project/views/404.erb.tt +10 -0
  285. data/lib/roda_gen/generators/templates/project/views/500.erb.tt +12 -0
  286. data/lib/roda_gen/generators/templates/project/views/_head_meta.erb.tt +29 -0
  287. data/lib/roda_gen/generators/templates/project/views/_impersonate_picker.erb.tt +21 -0
  288. data/lib/roda_gen/generators/templates/project/views/_language_switcher.erb.tt +22 -0
  289. data/lib/roda_gen/generators/templates/project/views/_locked_accounts.erb.tt +18 -0
  290. data/lib/roda_gen/generators/templates/project/views/_upload_zone.erb.tt +35 -0
  291. data/lib/roda_gen/generators/templates/project/views/account/profile.erb.tt +149 -0
  292. data/lib/roda_gen/generators/templates/project/views/admin/flags.erb.tt +51 -0
  293. data/lib/roda_gen/generators/templates/project/views/consent_kit/_banner.erb.tt +59 -0
  294. data/lib/roda_gen/generators/templates/project/views/consent_kit/_preferences.erb.tt +87 -0
  295. data/lib/roda_gen/generators/templates/project/views/gdpr/erased.erb.tt +6 -0
  296. data/lib/roda_gen/generators/templates/project/views/gdpr/index.erb.tt +28 -0
  297. data/lib/roda_gen/generators/templates/project/views/layout.erb.tt +112 -0
  298. data/lib/roda_gen/generators/templates/project/views/legal/contact.erb.tt +44 -0
  299. data/lib/roda_gen/generators/templates/project/views/legal/cookies.erb.tt +47 -0
  300. data/lib/roda_gen/generators/templates/project/views/legal/disclaimer.erb.tt +19 -0
  301. data/lib/roda_gen/generators/templates/project/views/legal/privacy.erb.tt +26 -0
  302. data/lib/roda_gen/generators/templates/project/views/mailers/account_unlocked.erb.tt +5 -0
  303. data/lib/roda_gen/generators/templates/project/views/mailers/data_erased.erb.tt +5 -0
  304. data/lib/roda_gen/generators/templates/project/views/mailers/data_export.erb.tt +5 -0
  305. data/lib/roda_gen/generators/templates/project/views/rodauth/add-recovery-codes.erb.tt +30 -0
  306. data/lib/roda_gen/generators/templates/project/views/rodauth/change-login.erb.tt +44 -0
  307. data/lib/roda_gen/generators/templates/project/views/rodauth/change-password.erb.tt +41 -0
  308. data/lib/roda_gen/generators/templates/project/views/rodauth/close-account.erb.tt +27 -0
  309. data/lib/roda_gen/generators/templates/project/views/rodauth/confirm-password.erb.tt +23 -0
  310. data/lib/roda_gen/generators/templates/project/views/rodauth/create-account.erb.tt +183 -0
  311. data/lib/roda_gen/generators/templates/project/views/rodauth/login.erb.tt +51 -0
  312. data/lib/roda_gen/generators/templates/project/views/rodauth/logout.erb.tt +10 -0
  313. data/lib/roda_gen/generators/templates/project/views/rodauth/otp-auth.erb.tt +26 -0
  314. data/lib/roda_gen/generators/templates/project/views/rodauth/otp-disable.erb.tt +27 -0
  315. data/lib/roda_gen/generators/templates/project/views/rodauth/otp-setup.erb.tt +48 -0
  316. data/lib/roda_gen/generators/templates/project/views/rodauth/otp-unlock-not-available.erb.tt +18 -0
  317. data/lib/roda_gen/generators/templates/project/views/rodauth/otp-unlock.erb.tt +28 -0
  318. data/lib/roda_gen/generators/templates/project/views/rodauth/recovery-auth.erb.tt +23 -0
  319. data/lib/roda_gen/generators/templates/project/views/rodauth/recovery-codes.erb.tt +26 -0
  320. data/lib/roda_gen/generators/templates/project/views/rodauth/remember.erb.tt +35 -0
  321. data/lib/roda_gen/generators/templates/project/views/rodauth/reset-password-request.erb.tt +27 -0
  322. data/lib/roda_gen/generators/templates/project/views/rodauth/reset-password.erb.tt +30 -0
  323. data/lib/roda_gen/generators/templates/project/views/rodauth/two-factor-auth.erb.tt +8 -0
  324. data/lib/roda_gen/generators/templates/project/views/rodauth/two-factor-disable.erb.tt +20 -0
  325. data/lib/roda_gen/generators/templates/project/views/rodauth/two-factor-manage.erb.tt +36 -0
  326. data/lib/roda_gen/generators/templates/project/views/rodauth/unlock-account-request.erb.tt +13 -0
  327. data/lib/roda_gen/generators/templates/project/views/rodauth/unlock-account.erb.tt +23 -0
  328. data/lib/roda_gen/generators/templates/project/views/rodauth/verify-account-resend.erb.tt +26 -0
  329. data/lib/roda_gen/generators/templates/project/views/rodauth/verify-account.erb.tt +32 -0
  330. data/lib/roda_gen/generators/templates/project/views/rodauth/verify-login-change.erb.tt +8 -0
  331. data/lib/roda_gen/generators/templates/route/routes/%plural%.rb.tt +19 -0
  332. data/lib/roda_gen/generators/templates/route/spec/web/%plural%_spec.rb.tt +36 -0
  333. data/lib/roda_gen/generators/templates/route/views/%plural%/index.erb.tt +11 -0
  334. data/lib/roda_gen/generators/templates/route/views/%plural%/show.erb.tt +7 -0
  335. data/lib/roda_gen/generators/templates/upload/db/migrate/%migration_filename%.rb.tt +13 -0
  336. data/lib/roda_gen/generators/templates/upload/helpers/upload_serving.rb.tt +43 -0
  337. data/lib/roda_gen/generators/templates/upload/models/%resource_name%.rb.tt +11 -0
  338. data/lib/roda_gen/generators/templates/upload/models/%resource_name%_uploader.rb.tt +19 -0
  339. data/lib/roda_gen/generators/templates/upload/routes/%plural%.rb.tt +44 -0
  340. data/lib/roda_gen/generators/templates/upload/spec/web/%plural%_spec.rb.tt +56 -0
  341. data/lib/roda_gen/generators/templates/upload/views/%plural%/index.erb.tt +18 -0
  342. data/lib/roda_gen/generators/upload.rb +83 -0
  343. data/lib/roda_gen/project_context.rb +30 -0
  344. data/lib/roda_gen/version.rb +5 -0
  345. data/lib/roda_gen.rb +16 -0
  346. metadata +497 -0
@@ -0,0 +1,492 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe 'Rodauth web flow' do
6
+ let(:email) { Faker::Internet.email(name: "auth-#{SecureRandom.hex(4)}") }
7
+ let(:password) { 'correct horse battery staple' }
8
+
9
+ describe 'POST /create-account' do
10
+ it 'creates account + profile atomically (after_create_account hook)' do
11
+ params = sign_up(email: email, password: password)
12
+ account = Account.first(email: email)
13
+ expect(account).not_to be_nil
14
+ expect(account.profile).not_to be_nil
15
+ expect(account.profile.first_name).to eq(params['first_name'])
16
+ expect(account.profile.country).to eq('SE')
17
+ end
18
+
19
+ it 'canonicalises mobile_number via AccountProfile#before_save' do
20
+ sign_up(email: email, password: password, mobile_number: '0701234567')
21
+ expect(Account.first(email: email).profile.mobile_number).to eq('+46701234567')
22
+ end
23
+
24
+ it 'stores an optional gender when one is submitted' do
25
+ sign_up(email: email, password: password, gender: 'non_binary')
26
+ expect(Account.first(email: email).profile.gender).to eq('non_binary')
27
+ end
28
+
29
+ it 'rejects a missing required profile field with 422 (before_create_account validator)' do
30
+ sign_up(email: email, password: password, first_name: '')
31
+ expect(last_response.status).to eq(422)
32
+ expect(Account.first(email: email)).to be_nil
33
+ end
34
+
35
+ it 'rejects an all-same-character password (password_meets_requirements? override)' do
36
+ sign_up(email: email, password: 'a' * 16)
37
+ expect(last_response.status).to eq(422)
38
+ expect(Account.first(email: email)).to be_nil
39
+ end
40
+
41
+ it 'rejects a password shorter than password_minimum_length (12 by default)' do
42
+ sign_up(email: email, password: 'shorty')
43
+ expect(last_response.status).to eq(422)
44
+ expect(Account.first(email: email)).to be_nil
45
+ end
46
+
47
+ it 'rejects a password on the common-passwords blocklist (:disallow_common_passwords)' do
48
+ # password123456 is on Rodauth's bundled common-passwords list, length and complexity pass
49
+ sign_up(email: email, password: 'password123456')
50
+ expect(last_response.status).to eq(422)
51
+ expect(Account.first(email: email)).to be_nil
52
+ end
53
+ end
54
+
55
+ describe ':active_sessions session lifecycle' do
56
+ it 'inserts a row into account_active_session_keys on login and removes it on logout' do
57
+ sign_up(email: email, password: password)
58
+ verify(Account.first(email: email))
59
+ log_in(email: email, password: password)
60
+
61
+ account_id = Account.first(email: email).id
62
+ expect(DB[:account_active_session_keys].where(account_id: account_id).count).to eq(1)
63
+
64
+ post_csrf('/account/logout')
65
+ expect(DB[:account_active_session_keys].where(account_id: account_id).count).to eq(0)
66
+ end
67
+
68
+ it 'invalidates an authenticated request when last_use is past session_inactivity_deadline' do
69
+ sign_up(email: email, password: password)
70
+ verify(Account.first(email: email))
71
+ log_in(email: email, password: password)
72
+ account_id = Account.first(email: email).id
73
+ expect(DB[:account_active_session_keys].where(account_id: account_id).count).to eq(1)
74
+
75
+ # A year back is well past the default 86_400 s session_inactivity_deadline, so
76
+ # check_active_session's remove_inactive_sessions deletes the row
77
+ DB[:account_active_session_keys]
78
+ .where(account_id: account_id)
79
+ .update(last_use: Time.now - (365 * 24 * 60 * 60))
80
+
81
+ # /push/subscribe is auth-gated and in LocaleKit's excluded_paths, so the request reaches the main
82
+ # route's check_active_session. /account/profile would be locale-redirected first
83
+ get '/push/subscribe'
84
+ expect(last_response).to be_redirect
85
+ expect(last_response.location).not_to include('/push')
86
+ end
87
+ end
88
+
89
+ describe 'POST /login' do
90
+ before do
91
+ sign_up(email: email, password: password)
92
+ verify(Account.first(email: email))
93
+ end
94
+
95
+ it 'redirects on valid credentials' do
96
+ log_in(email: email, password: password)
97
+ expect(last_response).to be_redirect
98
+ end
99
+
100
+ it 'does not redirect on an unknown login' do
101
+ log_in(email: 'nope@example.test', password: password)
102
+ expect(last_response).not_to be_redirect
103
+ end
104
+
105
+ it 'does not redirect on a wrong password' do
106
+ log_in(email: email, password: 'wrong-password-attempt')
107
+ expect(last_response).not_to be_redirect
108
+ end
109
+ end
110
+
111
+ describe 'POST /logout' do
112
+ it 'clears the active session row for the logged-in account' do
113
+ sign_up(email: email, password: password)
114
+ verify(Account.first(email: email))
115
+ log_in(email: email, password: password)
116
+ account = Account.first(email: email)
117
+ expect(DB[:account_active_session_keys].where(account_id: account.id).count).to be > 0
118
+
119
+ post_csrf('/account/logout')
120
+ expect(DB[:account_active_session_keys].where(account_id: account.id).count).to eq(0)
121
+ end
122
+ end
123
+
124
+ describe 'POST /reset-password-request' do
125
+ before do
126
+ sign_up(email: email, password: password)
127
+ verify(Account.first(email: email))
128
+ end
129
+
130
+ it 'emails the reset link and stores a reset key for the account' do
131
+ Mail::TestMailer.deliveries.clear
132
+ post_csrf('/account/reset-password-request', 'login' => email)
133
+ account = Account.first(email: email)
134
+ expect(DB[:account_password_reset_keys].where(id: account.id).count).to eq(1)
135
+ expect(Mail::TestMailer.deliveries.size).to eq(1)
136
+ expect(Mail::TestMailer.deliveries.last.to).to include(email)
137
+ end
138
+ end
139
+
140
+ describe 'account lockout' do
141
+ let(:max) { Settings.for_system('max_invalid_logins') }
142
+
143
+ before do
144
+ sign_up(email: email, password: password)
145
+ verify(Account.first(email: email))
146
+ end
147
+
148
+ it 'inserts an account_lockouts row after max_invalid_logins failures' do
149
+ max.times { log_in(email: email, password: 'wrong') }
150
+ account = Account.first(email: email)
151
+ expect(DB[:account_lockouts].where(id: account.id).count).to eq(1)
152
+ end
153
+ end
154
+
155
+ describe 'POST /close-account' do
156
+ before do
157
+ sign_up(email: email, password: password)
158
+ verify(Account.first(email: email))
159
+ log_in(email: email, password: password)
160
+ end
161
+
162
+ it 'flips status_id to Closed (3) when current password is confirmed' do
163
+ post_csrf('/account/close-account', 'password' => password)
164
+ expect(Account.first(email: email).status_id).to eq(3)
165
+ end
166
+ end
167
+
168
+ describe '#account_expired? override' do
169
+ it 'returns false — login still succeeds for an account that would otherwise be inactive' do
170
+ sign_up(email: email, password: password)
171
+ account = Account.first(email: email)
172
+ verify(account)
173
+
174
+ # account_expiration's after_create_account hook already inserted the row at sign-up, so upsert into a stale state
175
+ stale = Time.now - (10 * 365 * 24 * 60 * 60)
176
+ DB[:account_activity_times]
177
+ .insert_conflict(target: :id,
178
+ update: { last_activity_at: stale, last_login_at: stale })
179
+ .insert(id: account.id, last_activity_at: stale, last_login_at: stale)
180
+ log_in(email: email, password: password)
181
+ expect(last_response).to be_redirect
182
+ end
183
+ end
184
+
185
+ describe 'audit emission' do
186
+ it 'user.account.create — fired after_create_account, email in metadata' do
187
+ sign_up(email: email, password: password)
188
+ row = last_audit('user.account.create', actor_label: email)
189
+ expect(row).not_to be_nil
190
+ expect(row[:actor_id]).to eq(Account.first(email: email).id)
191
+ expect(row[:metadata]['email']).to eq(email)
192
+ end
193
+
194
+ it 'user.login — fired on successful login' do
195
+ sign_up(email: email, password: password)
196
+ verify(Account.first(email: email))
197
+ log_in(email: email, password: password)
198
+ row = last_audit('user.login', actor_label: email)
199
+ expect(row).not_to be_nil
200
+ expect(row[:actor_id]).to eq(Account.first(email: email).id)
201
+ end
202
+
203
+ it 'user.login + status :failure — fired on bad password' do
204
+ sign_up(email: email, password: password)
205
+ verify(Account.first(email: email))
206
+ log_in(email: email, password: 'wrong')
207
+ row = last_audit('user.login', status: :failure, actor_label: email)
208
+ expect(row).not_to be_nil
209
+ expect(row[:status_id]).to eq(AuditStatus.id_for!(:failure))
210
+ end
211
+
212
+ it 'user.logout — fired on logout' do
213
+ sign_up(email: email, password: password)
214
+ verify(Account.first(email: email))
215
+ log_in(email: email, password: password)
216
+ post_csrf('/account/logout')
217
+ expect(last_audit('user.logout', actor_label: email)).not_to be_nil
218
+ end
219
+
220
+ it 'user.lockout (status :denied) — fired when the lockout threshold trips' do
221
+ sign_up(email: email, password: password)
222
+ verify(Account.first(email: email))
223
+ Settings.for_system('max_invalid_logins').times do
224
+ log_in(email: email, password: 'wrong')
225
+ end
226
+ row = last_audit('user.lockout', actor_label: email)
227
+ expect(row).not_to be_nil
228
+ expect(row[:status_id]).to eq(AuditStatus.id_for!(:denied))
229
+ end
230
+
231
+ it 'user.password.reset_request — fired when a reset email is requested' do
232
+ sign_up(email: email, password: password)
233
+ verify(Account.first(email: email))
234
+ post_csrf('/account/reset-password-request', 'login' => email)
235
+ expect(last_audit('user.password.reset_request', actor_label: email)).not_to be_nil
236
+ end
237
+
238
+ it 'user.password.reset — fired when the link is followed and a new password is set' do
239
+ sign_up(email: email, password: password)
240
+ verify(Account.first(email: email))
241
+ Mail::TestMailer.deliveries.clear
242
+ post_csrf('/account/reset-password-request', 'login' => email)
243
+
244
+ # account_password_reset_keys holds the HMAC'd key, the email URL carries the raw token the form expects
245
+ key = Mail::TestMailer.deliveries.last.body.decoded[/reset-password\?key=([^"\s]+)/, 1]
246
+ expect(key).not_to be_nil
247
+
248
+ new_password = 'fresh horse battery staple'
249
+ post_csrf("/account/reset-password?key=#{key}",
250
+ 'password' => new_password,
251
+ 'password-confirm' => new_password)
252
+
253
+ expect(last_audit('user.password.reset', actor_label: email)).not_to be_nil
254
+ end
255
+
256
+ it 'user.account.close — fired on /close-account' do
257
+ sign_up(email: email, password: password)
258
+ verify(Account.first(email: email))
259
+ log_in(email: email, password: password)
260
+ post_csrf('/account/close-account', 'password' => password)
261
+ expect(last_audit('user.account.close', actor_label: email)).not_to be_nil
262
+ end
263
+
264
+ it 'requires the password again when /change-password is hit AFTER the grace period' do
265
+ sign_up(email: email, password: password)
266
+ verify(Account.first(email: email))
267
+ log_in(email: email, password: password)
268
+ # Past password_grace_period (600s in 57_rodauth.rb), password_recently_entered? reads Time.now.to_i
269
+ fake_now = Time.now + 700
270
+ allow(Time).to receive(:now).and_return(fake_now)
271
+ original = Account.first(email: email).status_id
272
+ post_csrf('/account/change-password',
273
+ 'new-password' => 'fresh horse battery staple',
274
+ 'password-confirm' => 'fresh horse battery staple')
275
+ # No password field so Rodauth rejects (422), status_id guards against a silent partial acceptance
276
+ expect(last_response.status).to be >= 400
277
+ expect(Account.first(email: email).status_id).to eq(original)
278
+ end
279
+
280
+ it 'user.password.change — fired on /change-password within the grace period' do
281
+ sign_up(email: email, password: password)
282
+ verify(Account.first(email: email))
283
+ log_in(email: email, password: password)
284
+ new_password = 'an entirely different passphrase here'
285
+ # change-password posts new-password / password-confirm (new_password_param + password_confirm_param),
286
+ # not password
287
+ post_csrf('/account/change-password',
288
+ 'new-password' => new_password,
289
+ 'password-confirm' => new_password)
290
+ expect(last_audit('user.password.change', actor_label: email)).not_to be_nil
291
+ end
292
+
293
+ it 'user.account.verify — fired when the verify-account link is followed' do
294
+ Mail::TestMailer.deliveries.clear
295
+ sign_up(email: email, password: password)
296
+ key = Mail::TestMailer.deliveries.last.body.decoded[/verify-account\?key=([^"\s]+)/, 1]
297
+ expect(key).not_to be_nil
298
+ post_csrf("/account/verify-account?key=#{key}")
299
+ expect(last_audit('user.account.verify', actor_label: email)).not_to be_nil
300
+ end
301
+
302
+ it 'user.email.change — fired when /change-login is submitted with grace-period password' do
303
+ sign_up(email: email, password: password)
304
+ verify(Account.first(email: email))
305
+ log_in(email: email, password: password)
306
+ post_csrf('/account/change-login', 'login' => "new-#{email}", 'password' => password)
307
+ expect(last_audit('user.email.change', actor_label: email)).not_to be_nil
308
+ end
309
+
310
+ it 'user.email.verify — fired when the verify-login-change link is followed' do
311
+ sign_up(email: email, password: password)
312
+ verify(Account.first(email: email))
313
+ log_in(email: email, password: password)
314
+ Mail::TestMailer.deliveries.clear
315
+ post_csrf('/account/change-login', 'login' => "new-#{email}", 'password' => password)
316
+ key = Mail::TestMailer.deliveries.last.body.decoded[/verify-login-change\?key=([^"\s]+)/, 1]
317
+ expect(key).not_to be_nil
318
+ post_csrf("/account/verify-login-change?key=#{key}")
319
+ # By the time verify-login-change fires, rodauth's account carries the new login, so scope to the new email
320
+ expect(last_audit('user.email.verify', actor_label: "new-#{email}")).not_to be_nil
321
+ end
322
+
323
+ it 'user.lockout.clear — fired when /unlock-account is submitted with a valid key' do
324
+ sign_up(email: email, password: password)
325
+ verify(Account.first(email: email))
326
+ # 5 wrong passwords is the seeded threshold
327
+ 5.times { log_in(email: email, password: 'wrong') }
328
+ expect(last_audit('user.lockout', actor_label: email)).not_to be_nil
329
+ # Mint the <id>_<HMAC(raw_key)> token the unlock email would carry and POST it straight to
330
+ # /unlock-account, same path and hooks without the email round-trip
331
+ account_id = Account.first(email: email).id
332
+ raw_key = DB[:account_lockouts].where(id: account_id).get(:key)
333
+ hmac_b64 = Base64.urlsafe_encode64(
334
+ OpenSSL::HMAC.digest('SHA256', <%= @app.camel %>Config.rodauth.hmac_secret, raw_key)
335
+ ).delete('=')
336
+ post_csrf("/account/unlock-account?key=#{account_id}_#{hmac_b64}")
337
+ expect(last_audit('user.lockout.clear', actor_label: email)).not_to be_nil
338
+ end
339
+
340
+ it 'user.profile.update — fired when /account/profile is submitted with changes' do
341
+ sign_up(email: email, password: password)
342
+ verify(Account.first(email: email))
343
+ log_in(email: email, password: password)
344
+ post_csrf('/account/profile', profile_params(first_name: 'Updated', city: 'Göteborg'))
345
+ expect(last_audit('user.profile.update', actor_label: email)).not_to be_nil
346
+ end
347
+
348
+ it 'user.remember.set — fired when login is submitted with the remember-me box checked' do
349
+ sign_up(email: email, password: password)
350
+ verify(Account.first(email: email))
351
+ # after_login in 57_rodauth.rb calls remember_login when the remember param is present
352
+ post_csrf('/account/login', 'login' => email, 'password' => password, 'remember' => '1')
353
+ expect(last_audit('user.remember.set', actor_label: email)).not_to be_nil
354
+ end
355
+ end
356
+
357
+ # Rack::Test loses the session between hops of the locale_kit + rodauth verify/reset redirect chain, so read
358
+ # the configured path off an allocated instance. spec/browser/uat/auth_spec.rb drives it end to end
359
+ describe 'rodauth redirect overrides' do
360
+ let(:auth) { <%= @app.camel %>.rodauth.allocate }
361
+
362
+ it 'verify_account_redirect → /account/login (default `/` would 404)' do
363
+ expect(auth.verify_account_redirect).to end_with('/account/login')
364
+ end
365
+
366
+ it 'reset_password_redirect → /account/login' do
367
+ expect(auth.reset_password_redirect).to end_with('/account/login')
368
+ end
369
+ end
370
+
371
+ describe 'change_login_requires_password? { true } — no grace bypass' do
372
+ before do
373
+ sign_up(email: email, password: password)
374
+ verify(Account.first(email: email))
375
+ log_in(email: email, password: password)
376
+ end
377
+
378
+ it 'rejects /change-login without the current password' do
379
+ post_csrf('/account/change-login', 'login' => "new-#{email}")
380
+ expect(last_response.status).not_to be_between(300, 399) # no success-redirect
381
+ expect(Account.first(email: email).email).to eq(email)
382
+ end
383
+
384
+ it 'accepts /change-login when the current password is provided' do
385
+ post_csrf('/account/change-login', 'login' => "new-#{email}", 'password' => password)
386
+ expect(last_response).to be_redirect
387
+ end
388
+ end
389
+
390
+ describe 'after_login require_two_factor_authenticated guard' do
391
+ before do
392
+ sign_up(email: email, password: password)
393
+ verify(Account.first(email: email))
394
+ end
395
+
396
+ it 'does NOT redirect to /otp-auth when the account has no 2FA set up' do
397
+ log_in(email: email, password: password)
398
+ expect(last_response).to be_redirect
399
+ expect(last_response.location).not_to include('/account/otp-auth')
400
+ end
401
+ end
402
+
403
+ describe 'personal_identity_number Luhn validation' do
404
+ it 'accepts a Luhn-valid personnummer' do
405
+ sign_up(email: email, password: password,
406
+ personal_identity_number: Faker::IDNumber.swedish_personal_identity_number)
407
+ expect(Account.first(email: email)).not_to be_nil
408
+ end
409
+
410
+ it 'rejects a 12-digit number that fails the mod-10 check (last digit off by one)' do
411
+ valid = Faker::IDNumber.swedish_personal_identity_number
412
+ invalid = valid[0..-2] + ((valid[-1].to_i + 1) % 10).to_s
413
+ sign_up(email: email, password: password, personal_identity_number: invalid)
414
+ expect(Account.first(email: email)).to be_nil
415
+ end
416
+
417
+ it 'rejects a non-12-digit value at the form layer (DB CHECK + model regex)' do
418
+ sign_up(email: email, password: password, personal_identity_number: '1912')
419
+ expect(Account.first(email: email)).to be_nil
420
+ end
421
+ end
422
+
423
+ describe 'GET /account/profile' do
424
+ it 'redirects an unauthenticated request to /account/login' do
425
+ get '/account/profile'
426
+ # First 302 is locale_kit's /en prefix, the require_authentication redirect comes after
427
+ follow_redirect! while last_response.redirect? && !last_response.location.include?('login')
428
+ expect(last_response.location).to include('account/login')
429
+ end
430
+
431
+ it 'renders the form pre-filled with the current AccountProfile' do
432
+ params = sign_up(email: email, password: password)
433
+ verify(Account.first(email: email))
434
+ log_in(email: email, password: password)
435
+ get '/account/profile'
436
+ follow_redirect! while last_response.redirect?
437
+ expect(last_response.status).to eq(200)
438
+ # postal_code is digits and hyphen and first_name normally letters-only, so neither gets HTML-escaped
439
+ expect(last_response.body).to include(params['first_name'])
440
+ expect(last_response.body).to include(params['postal_code'])
441
+ end
442
+ end
443
+
444
+ describe 'POST /account/profile' do
445
+ before do
446
+ sign_up(email: email, password: password)
447
+ verify(Account.first(email: email))
448
+ log_in(email: email, password: password)
449
+ end
450
+
451
+ def profile_attrs_of(profile)
452
+ fields = %i[first_name last_name address postal_code city country
453
+ language time_zone mobile_number personal_identity_number]
454
+ profile.values.slice(*fields).transform_keys(&:to_s)
455
+ end
456
+
457
+ def profile_update_audits_for(account_id)
458
+ ADMIN_DB[Sequel[:audit_log][:audit_log]]
459
+ .where(action_id: AuditAction.id_for!('user.profile.update'), actor_id: account_id)
460
+ .count
461
+ end
462
+
463
+ it 'updates editable fields' do
464
+ post_csrf(
465
+ '/account/profile',
466
+ profile_params(first_name: 'Updated', last_name: 'User', city: 'Göteborg')
467
+ )
468
+ profile = Account.first(email: email).profile
469
+ expect(profile.first_name).to eq('Updated')
470
+ expect(profile.city).to eq('Göteborg')
471
+ end
472
+
473
+ it 'does not allow updating personal_identity_number (identity fields are read-only)' do
474
+ original = Account.first(email: email).profile.personal_identity_number
475
+ post_csrf('/account/profile', profile_params(personal_identity_number: '202012121211'))
476
+ expect(Account.first(email: email).profile.personal_identity_number).to eq(original)
477
+ end
478
+
479
+ it 'skips the audit when nothing changed (covers the `if changes.any?` else branch)' do
480
+ account = Account.first(email: email)
481
+ same = profile_attrs_of(account.profile)
482
+ expect { post_csrf('/account/profile', same) }
483
+ .not_to(change { profile_update_audits_for(account.id) })
484
+ end
485
+
486
+ it 're-renders the form with field errors when validation fails (covers the else of profile.valid?)' do
487
+ post_csrf('/account/profile', profile_params(first_name: ''))
488
+ expect(last_response.status).to eq(200)
489
+ expect(last_response.body).to include(I18n.t('validation.must_not_be_blank'))
490
+ end
491
+ end
492
+ end
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe 'AuthorizationHelper#require_privilege!' do
6
+ let(:app) do
7
+ Class.new(<%= @app.camel %>) do
8
+ route do |r|
9
+ # account_id param stands in for Rodauth's session, no round-trip through create-account + login
10
+ r.is('admin-only') do
11
+ session['account_id'] = Integer(r.params['account_id']) if r.params['account_id']
12
+ require_privilege!('accounts.read')
13
+ 'admin OK'
14
+ end
15
+
16
+ r.is('multi-priv') do
17
+ session['account_id'] = Integer(r.params['account_id']) if r.params['account_id']
18
+ require_privilege!('accounts.read', 'accounts.update')
19
+ 'multi OK'
20
+ end
21
+
22
+ # Translates the no-arg ArgumentError into a 422 so a GET can assert it
23
+ r.is('empty-priv-probe') do
24
+ response.status = 200
25
+ require_privilege!
26
+ 'unreachable'
27
+ rescue ArgumentError => e
28
+ response.status = 422
29
+ e.message
30
+ end
31
+ end
32
+ end.freeze.app
33
+ end
34
+
35
+ let(:account) do
36
+ Account.create(
37
+ email: Faker::Internet.email(name: "rbac-#{SecureRandom.hex(4)}"),
38
+ status_id: 2 # verified
39
+ )
40
+ end
41
+
42
+ it 'returns 403 and halts the route body for a missing privilege' do
43
+ # Fresh account has no role, so accounts.read is absent
44
+ get "/en/admin-only?account_id=#{account.id}"
45
+ expect(last_response.status).to eq(403)
46
+ expect(last_response.body).not_to include('admin OK')
47
+ end
48
+
49
+ it 'renders the 403 view (status_handler hook + views/403.erb + locale key)' do
50
+ get "/en/admin-only?account_id=#{account.id}"
51
+ expect(last_response.status).to eq(403)
52
+ expect(last_response.body).to include(I18n.t('errors.forbidden.title', locale: :en))
53
+ end
54
+
55
+ it 'emits an authorization.denied audit row — payload carries privileges + granted, metadata carries method + path' do
56
+ get "/en/admin-only?account_id=#{account.id}"
57
+
58
+ row = last_audit('authorization.denied', actor_id: account.id)
59
+ expect(row).not_to be_nil
60
+ expect(row[:status_id]).to eq(AuditStatus.id_for!(:denied))
61
+ expect(row[:payload].slice('privileges', 'granted'))
62
+ .to eq('privileges' => ['accounts.read'], 'granted' => [])
63
+ expect(row[:metadata].slice('method', 'path'))
64
+ .to include('method' => 'GET')
65
+ expect(row[:metadata]['path']).to include('/admin-only')
66
+ end
67
+
68
+ it 'lets the route body run when the account has the privilege' do
69
+ AccountRole.create(account_id: account.id, role_id: 'admin')
70
+ get "/en/admin-only?account_id=#{account.id}"
71
+ expect(last_response.status).to eq(200)
72
+ expect(last_response.body).to include('admin OK')
73
+ end
74
+
75
+ it 'returns 403 with actor_id=nil when no one is logged in (covers current_account&.id nil branch)' do
76
+ get '/en/admin-only'
77
+ expect(last_response.status).to eq(403)
78
+ row = last_audit('authorization.denied', request_id: last_request_id)
79
+ expect(row[:actor_id]).to be_nil
80
+ end
81
+
82
+ context 'with multiple privileges required (all-of semantics)' do
83
+ it 'lets the route body run when the account holds every listed privilege' do
84
+ AccountRole.create(account_id: account.id, role_id: 'admin')
85
+ get "/en/multi-priv?account_id=#{account.id}"
86
+ expect(last_response.status).to eq(200)
87
+ expect(last_response.body).to include('multi OK')
88
+ end
89
+
90
+ it 'returns 403 + audit row showing required privileges AND what the account held' do
91
+ # Only one of the two, the second is the gap
92
+ AccountPrivilege.create(account_id: account.id, privilege_id: 'accounts.read')
93
+
94
+ get "/en/multi-priv?account_id=#{account.id}"
95
+ expect(last_response.status).to eq(403)
96
+
97
+ row = last_audit('authorization.denied', actor_id: account.id)
98
+ # The gap tells an incident responder what was missing without joining tables, even after grants shift
99
+ expect(row[:payload]['privileges']).to eq(['accounts.read', 'accounts.update'])
100
+ expect(row[:payload]['granted']).to eq(['accounts.read'])
101
+ end
102
+ end
103
+
104
+ # Fails closed, the splat method would otherwise silently authorise everyone
105
+ it 'require_privilege!() with no args raises ArgumentError' do
106
+ get '/en/empty-priv-probe'
107
+ expect(last_response.status).to eq(422)
108
+ expect(last_response.body).to include('at least one')
109
+ end
110
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open3'
4
+
5
+ RSpec.describe 'RACK_ENV whitelist (config/boot.rb)' do
6
+ let(:project_root) { File.expand_path('../..', __dir__) }
7
+ # -I. since modern Ruby drops "." from the default $LOAD_PATH
8
+ let(:boot_ruby) { '-I. -rbundler/setup -rconfig/boot -e ""' }
9
+
10
+ def boot_with(rack_env)
11
+ Open3.capture2e({ 'RACK_ENV' => rack_env }, "ruby #{boot_ruby}", chdir: project_root)
12
+ end
13
+
14
+ it 'aborts with a clear error on an unknown RACK_ENV (e.g. "prod")' do
15
+ out, status = boot_with('prod')
16
+ expect(status.exitstatus).not_to eq(0)
17
+ expect(out).to include('RACK_ENV="prod" is not recognised')
18
+ expect(out).to include('development, test, production')
19
+ end
20
+
21
+ %w[development test production].each do |env|
22
+ it "boots cleanly under RACK_ENV=#{env}" do
23
+ _out, status = boot_with(env)
24
+ expect(status.exitstatus).to eq(0)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ # consent_kit renders the banner as an open non-modal <dialog> and the preferences UI as a native popover, no
6
+ # JavaScript. Pins the layout's half so drift in views/consent_kit/_banner.erb fails here rather than in a browser
7
+ RSpec.describe 'consent banner without JavaScript' do
8
+ # Any public layout-rendering page would do
9
+ def layout_page
10
+ get '/legal/disclaimer'
11
+ follow_redirect! while last_response.redirect?
12
+ last_response.body
13
+ end
14
+
15
+ # route_csrf is path-bound, so take the token from the banner's own form, not the first _csrf on the page
16
+ def accept_all
17
+ token = layout_page[/<form id="consent-kit-accept-all-form".*?name="_csrf"\s+value="([^"]+)"/m, 1]
18
+ post '/consent', 'categories[]' => %w[necessary], '_csrf' => token
19
+ end
20
+
21
+ it 'renders the banner open with the two binary-choice buttons while no consent is recorded' do
22
+ html = layout_page
23
+ expect(html).to include('<dialog open id="consent-banner-dialog"')
24
+ expect(html).to match(/<button[^>]+form="consent-kit-only-necessary-form"/)
25
+ expect(html).to match(/<button[^>]+form="consent-kit-accept-all-form"/)
26
+ end
27
+
28
+ it 'ships the two hidden forms the banner buttons submit to' do
29
+ html = layout_page
30
+ expect(html).to match(%r{<form id="consent-kit-only-necessary-form"[^>]+action="/consent"[^>]+method="post"})
31
+ expect(html).to match(%r{<form id="consent-kit-accept-all-form"[^>]+action="/consent"[^>]+method="post"})
32
+ end
33
+
34
+ it 'always renders the preferences popover and a button that opens it' do
35
+ html = layout_page
36
+ expect(html).to include('<div id="consent-preferences" popover')
37
+ expect(html).to match(/<button[^>]+popovertarget="consent-preferences"/)
38
+ end
39
+
40
+ it 'drops the banner once consent is recorded but keeps the popover' do
41
+ accept_all
42
+ html = layout_page
43
+ expect(html).not_to include('id="consent-banner-dialog"')
44
+ expect(html).to include('<div id="consent-preferences" popover')
45
+ end
46
+ end