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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +9 -0
- data/LICENSE.txt +21 -0
- data/README.md +94 -0
- data/bin/roda +11 -0
- data/lib/roda-gen.rb +3 -0
- data/lib/roda_gen/app_name.rb +29 -0
- data/lib/roda_gen/cli.rb +122 -0
- data/lib/roda_gen/generators/daemon.rb +78 -0
- data/lib/roda_gen/generators/migration.rb +68 -0
- data/lib/roda_gen/generators/migration_numbering.rb +21 -0
- data/lib/roda_gen/generators/model.rb +75 -0
- data/lib/roda_gen/generators/project.rb +145 -0
- data/lib/roda_gen/generators/route.rb +71 -0
- data/lib/roda_gen/generators/templates/daemon/bin/%daemon_name%.tt +13 -0
- data/lib/roda_gen/generators/templates/daemon/lib/daemon/%daemon_name%.rb.tt +22 -0
- data/lib/roda_gen/generators/templates/daemon/spec/daemons/%daemon_name%_spec.rb.tt +18 -0
- data/lib/roda_gen/generators/templates/migration/db/migrate/%migration_filename%.rb.tt +6 -0
- data/lib/roda_gen/generators/templates/model/db/migrate/%migration_filename%.rb.tt +12 -0
- data/lib/roda_gen/generators/templates/model/models/%resource_name%.rb.tt +5 -0
- data/lib/roda_gen/generators/templates/model/spec/models/%resource_name%_spec.rb.tt +18 -0
- data/lib/roda_gen/generators/templates/project/%app_name%.rb.tt +43 -0
- data/lib/roda_gen/generators/templates/project/.bundle/config.tt +3 -0
- data/lib/roda_gen/generators/templates/project/.erb_lint.yml.tt +29 -0
- data/lib/roda_gen/generators/templates/project/.gitignore.tt +19 -0
- data/lib/roda_gen/generators/templates/project/.reek.yml.tt +45 -0
- data/lib/roda_gen/generators/templates/project/.rspec.tt +4 -0
- data/lib/roda_gen/generators/templates/project/.rubocop.yml.tt +119 -0
- data/lib/roda_gen/generators/templates/project/.ruby-version.tt +1 -0
- data/lib/roda_gen/generators/templates/project/.rubycritic.yml.tt +15 -0
- data/lib/roda_gen/generators/templates/project/Gemfile.tt +109 -0
- data/lib/roda_gen/generators/templates/project/Procfile.dev.tt +7 -0
- data/lib/roda_gen/generators/templates/project/README.md.tt +891 -0
- data/lib/roda_gen/generators/templates/project/Rakefile.tt +3 -0
- data/lib/roda_gen/generators/templates/project/assets/javascripts/admin.js.tt +84 -0
- data/lib/roda_gen/generators/templates/project/assets/javascripts/app.js.tt +29 -0
- data/lib/roda_gen/generators/templates/project/assets/javascripts/push.js.tt +53 -0
- data/lib/roda_gen/generators/templates/project/assets/javascripts/upload.js.tt +200 -0
- data/lib/roda_gen/generators/templates/project/assets/stylesheets/app.css.tt +52 -0
- data/lib/roda_gen/generators/templates/project/assets/stylesheets/typography.css.tt +85 -0
- data/lib/roda_gen/generators/templates/project/bin/console.tt +2 -0
- data/lib/roda_gen/generators/templates/project/bin/dev.tt +8 -0
- data/lib/roda_gen/generators/templates/project/bin/gdpr_worker.tt +13 -0
- data/lib/roda_gen/generators/templates/project/bin/push_sender.tt +13 -0
- data/lib/roda_gen/generators/templates/project/bin/setup.tt +224 -0
- data/lib/roda_gen/generators/templates/project/bin/shrine_clean_cache.tt +13 -0
- data/lib/roda_gen/generators/templates/project/config/boot.rb.tt +23 -0
- data/lib/roda_gen/generators/templates/project/config/console.rb.tt +20 -0
- data/lib/roda_gen/generators/templates/project/config/database.rb.tt +45 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/00_environments.rb.tt +5 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/01_logger.rb.tt +46 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/02_app_config.rb.tt +19 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/10_database.rb.tt +3 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/15_mail.rb.tt +53 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/20_redis.rb.tt +13 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/25_rack_attack.rb.tt +96 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/30_i18n.rb.tt +37 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/35_listen_job.rb.tt +4 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/37_shrine.rb.tt +20 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/40_routing.rb.tt +20 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/41_render.rb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/43_static.rb.tt +30 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/44_sessions.rb.tt +62 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/45_security.rb.tt +49 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/46_flash.rb.tt +5 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/47_json.rb.tt +8 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/48_errors.rb.tt +43 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/49_misc.rb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/50_mailer.rb.tt +52 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/51_locale_kit.rb.tt +29 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/52_consent_kit.rb.tt +28 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/55_audit_log.rb.tt +16 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/56_form_helper.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/57_rodauth.rb.tt +304 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/60_web_push.rb.tt +12 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/61_flipper.rb.tt +15 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/62_split.rb.tt +15 -0
- data/lib/roda_gen/generators/templates/project/config/puma.rb.tt +24 -0
- data/lib/roda_gen/generators/templates/project/config/settings/development.yml.tt +9 -0
- data/lib/roda_gen/generators/templates/project/config/settings/production.yml.tt +13 -0
- data/lib/roda_gen/generators/templates/project/config/settings/test.yml.tt +9 -0
- data/lib/roda_gen/generators/templates/project/config/settings.yml.tt +45 -0
- data/lib/roda_gen/generators/templates/project/config.ru.tt +36 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_account_profiles.rb.tt +66 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_accounts.rb.tt +70 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_audit_log.rb.tt +185 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_authorization.rb.tt +68 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_countries.rb.tt +13 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_country_calling_codes.rb.tt +15 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_country_exit_codes.rb.tt +13 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_country_languages.rb.tt +19 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_country_time_zones.rb.tt +11 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_currencies.rb.tt +12 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_gdpr_requests.rb.tt +43 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_languages.rb.tt +11 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_push_subscriptions.rb.tt +16 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_rodauth_features.rb.tt +105 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_settings.rb.tt +60 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/01_countries.csv.tt +250 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/01_currencies.csv.tt +162 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/01_languages.csv.tt +144 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/02_country_calling_codes.csv.tt +237 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/02_country_exit_codes.csv.tt +239 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/02_country_languages.csv.tt +226 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/02_country_time_zones.csv.tt +369 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/03_setting_system_defaults.yml.tt +35 -0
- data/lib/roda_gen/generators/templates/project/db/seeds.rb.tt +69 -0
- data/lib/roda_gen/generators/templates/project/deploy/Caddyfile.tt +69 -0
- data/lib/roda_gen/generators/templates/project/deploy/logrotate/%app_name%-caddy.tt +11 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-audit-partition.service.tt +21 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-audit-partition.timer.tt +16 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-gdpr-worker.service.tt +25 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-push-sender.service.tt +25 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-shrine-cleanup.service.tt +21 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-shrine-cleanup.timer.tt +16 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%.service.tt +36 -0
- data/lib/roda_gen/generators/templates/project/helpers/audit_helper.rb.tt +59 -0
- data/lib/roda_gen/generators/templates/project/helpers/authorization_helper.rb.tt +25 -0
- data/lib/roda_gen/generators/templates/project/helpers/current_account_helper.rb.tt +33 -0
- data/lib/roda_gen/generators/templates/project/helpers/feature_flag_helper.rb.tt +34 -0
- data/lib/roda_gen/generators/templates/project/helpers/form_helper.rb.tt +50 -0
- data/lib/roda_gen/generators/templates/project/helpers/http_cache_helper.rb.tt +15 -0
- data/lib/roda_gen/generators/templates/project/helpers/logger_helper.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/helpers/split_helper.rb.tt +22 -0
- data/lib/roda_gen/generators/templates/project/lib/audit_context.rb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/lib/audit_lookup.rb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/lib/daemon/base.rb.tt +104 -0
- data/lib/roda_gen/generators/templates/project/lib/daemon/gdpr_worker.rb.tt +53 -0
- data/lib/roda_gen/generators/templates/project/lib/daemon/push_sender.rb.tt +47 -0
- data/lib/roda_gen/generators/templates/project/lib/daemon/shrine_cache_cleaner.rb.tt +22 -0
- data/lib/roda_gen/generators/templates/project/lib/deploy_check.rb.tt +96 -0
- data/lib/roda_gen/generators/templates/project/lib/filtered_logger.rb.tt +54 -0
- data/lib/roda_gen/generators/templates/project/lib/gdpr.rb.tt +106 -0
- data/lib/roda_gen/generators/templates/project/lib/rbac_audit.rb.tt +47 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/.rubocop.yml.tt +4 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/audit.rake.tt +85 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/console.rake.tt +8 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/db.rake.tt +104 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/deploy.rake.tt +38 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/flags.rake.tt +47 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/gdpr.rake.tt +31 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/parser_current_shim.rb.tt +13 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/quality.rake.tt +84 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/secrets.rake.tt +154 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/spec.rake.tt +136 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/split.rake.tt +27 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/tailwind.rake.tt +35 -0
- data/lib/roda_gen/generators/templates/project/locales/de.yml.tt +325 -0
- data/lib/roda_gen/generators/templates/project/locales/en.yml.tt +321 -0
- data/lib/roda_gen/generators/templates/project/locales/es.yml.tt +326 -0
- data/lib/roda_gen/generators/templates/project/locales/fr.yml.tt +329 -0
- data/lib/roda_gen/generators/templates/project/locales/it.yml.tt +325 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/de.yml.tt +5 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/en.yml.tt +6 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/es.yml.tt +5 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/fr.yml.tt +5 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/it.yml.tt +5 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/sv.yml.tt +274 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/tru.yml.tt +274 -0
- data/lib/roda_gen/generators/templates/project/locales/sv.yml.tt +319 -0
- data/lib/roda_gen/generators/templates/project/locales/tru.yml.tt +294 -0
- data/lib/roda_gen/generators/templates/project/log/.keep.tt +0 -0
- data/lib/roda_gen/generators/templates/project/models/account.rb.tt +50 -0
- data/lib/roda_gen/generators/templates/project/models/account_privilege.rb.tt +15 -0
- data/lib/roda_gen/generators/templates/project/models/account_profile.rb.tt +115 -0
- data/lib/roda_gen/generators/templates/project/models/account_role.rb.tt +14 -0
- data/lib/roda_gen/generators/templates/project/models/audit_action.rb.tt +23 -0
- data/lib/roda_gen/generators/templates/project/models/audit_actor_type.rb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/models/audit_log.rb.tt +257 -0
- data/lib/roda_gen/generators/templates/project/models/audit_status.rb.tt +9 -0
- data/lib/roda_gen/generators/templates/project/models/country.rb.tt +17 -0
- data/lib/roda_gen/generators/templates/project/models/country_calling_code.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/models/country_exit_code.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/models/country_language.rb.tt +8 -0
- data/lib/roda_gen/generators/templates/project/models/country_time_zone.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/models/currency.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/models/gdpr_request.rb.tt +32 -0
- data/lib/roda_gen/generators/templates/project/models/gender.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/models/language.rb.tt +13 -0
- data/lib/roda_gen/generators/templates/project/models/privilege.rb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/models/push_subscription.rb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/models/role.rb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/models/role_privilege.rb.tt +14 -0
- data/lib/roda_gen/generators/templates/project/models/setting_system_default.rb.tt +11 -0
- data/lib/roda_gen/generators/templates/project/models/setting_user_value.rb.tt +12 -0
- data/lib/roda_gen/generators/templates/project/models/settings.rb.tt +22 -0
- data/lib/roda_gen/generators/templates/project/models/signup_form_data.rb.tt +61 -0
- data/lib/roda_gen/generators/templates/project/models.rb.tt +6 -0
- data/lib/roda_gen/generators/templates/project/package.json.tt +13 -0
- data/lib/roda_gen/generators/templates/project/public/apple-touch-icon.png +0 -0
- data/lib/roda_gen/generators/templates/project/public/favicon.ico +0 -0
- data/lib/roda_gen/generators/templates/project/public/favicon.svg.tt +5 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/JetBrainsMono-Italic-Variable.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/JetBrainsMono-Variable.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/Lato-Bold.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/Lato-BoldItalic.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/Lato-Italic.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/Lato-Regular.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/NOTICE.md +17 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/NotoSansSyriac-Bold.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/NotoSansSyriac-Regular.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/NotoSansSyriacWestern-Bold.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/NotoSansSyriacWestern-Regular.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/manifest.webmanifest.tt +12 -0
- data/lib/roda_gen/generators/templates/project/public/robots.txt.tt +4 -0
- data/lib/roda_gen/generators/templates/project/public/service-worker.js.tt +27 -0
- data/lib/roda_gen/generators/templates/project/routes/account.rb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/routes/admin.rb.tt +118 -0
- data/lib/roda_gen/generators/templates/project/routes/gdpr.rb.tt +32 -0
- data/lib/roda_gen/generators/templates/project/routes/heartbeat.rb.tt +35 -0
- data/lib/roda_gen/generators/templates/project/routes/legal.rb.tt +20 -0
- data/lib/roda_gen/generators/templates/project/routes/profile.rb.tt +56 -0
- data/lib/roda_gen/generators/templates/project/routes/push.rb.tt +25 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/role_boundary_spec.rb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/spec_helper.rb.tt +146 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/support/auth_helpers.rb.tt +71 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/uat/auth_spec.rb.tt +25 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/uat/consent_nojs_spec.rb.tt +60 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/uat/create_account_form_spec.rb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/uat/otp_lifecycle_spec.rb.tt +67 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/uat/profile_form_spec.rb.tt +17 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/uat/upload_spec.rb.tt +102 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/wcag/auth_pages_spec.rb.tt +61 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/wcag/legal_pages_spec.rb.tt +33 -0
- data/lib/roda_gen/generators/templates/project/spec/daemons/base_spec.rb.tt +106 -0
- data/lib/roda_gen/generators/templates/project/spec/daemons/gdpr_worker_spec.rb.tt +72 -0
- data/lib/roda_gen/generators/templates/project/spec/daemons/push_sender_spec.rb.tt +74 -0
- data/lib/roda_gen/generators/templates/project/spec/locale_parity_spec.rb.tt +58 -0
- data/lib/roda_gen/generators/templates/project/spec/models/account_profile_spec.rb.tt +180 -0
- data/lib/roda_gen/generators/templates/project/spec/models/account_spec.rb.tt +104 -0
- data/lib/roda_gen/generators/templates/project/spec/models/audit_actor_type_spec.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/spec/models/audit_log_spec.rb.tt +398 -0
- data/lib/roda_gen/generators/templates/project/spec/models/audit_status_spec.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/spec/models/authorization_spec.rb.tt +82 -0
- data/lib/roda_gen/generators/templates/project/spec/models/country_calling_code_spec.rb.tt +11 -0
- data/lib/roda_gen/generators/templates/project/spec/models/country_exit_code_spec.rb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/spec/models/country_language_spec.rb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/spec/models/country_spec.rb.tt +29 -0
- data/lib/roda_gen/generators/templates/project/spec/models/country_time_zone_spec.rb.tt +9 -0
- data/lib/roda_gen/generators/templates/project/spec/models/currency_spec.rb.tt +9 -0
- data/lib/roda_gen/generators/templates/project/spec/models/deploy_check_spec.rb.tt +143 -0
- data/lib/roda_gen/generators/templates/project/spec/models/gdpr_spec.rb.tt +110 -0
- data/lib/roda_gen/generators/templates/project/spec/models/language_spec.rb.tt +15 -0
- data/lib/roda_gen/generators/templates/project/spec/models/rbac_audit_spec.rb.tt +110 -0
- data/lib/roda_gen/generators/templates/project/spec/models/setting_system_default_spec.rb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/spec/models/setting_user_value_spec.rb.tt +33 -0
- data/lib/roda_gen/generators/templates/project/spec/models/settings_spec.rb.tt +63 -0
- data/lib/roda_gen/generators/templates/project/spec/models/signup_form_data_spec.rb.tt +22 -0
- data/lib/roda_gen/generators/templates/project/spec/spec_helper.rb.tt +93 -0
- data/lib/roda_gen/generators/templates/project/spec/support/audit_log_helpers.rb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/spec/support/audit_lookup_shared_examples.rb.tt +19 -0
- data/lib/roda_gen/generators/templates/project/spec/support/auth_helpers.rb.tt +62 -0
- data/lib/roda_gen/generators/templates/project/spec/support/faker.rb.tt +30 -0
- data/lib/roda_gen/generators/templates/project/spec/web/admin_spec.rb.tt +155 -0
- data/lib/roda_gen/generators/templates/project/spec/web/audit_log_spec.rb.tt +159 -0
- data/lib/roda_gen/generators/templates/project/spec/web/auth_spec.rb.tt +492 -0
- data/lib/roda_gen/generators/templates/project/spec/web/authorization_spec.rb.tt +110 -0
- data/lib/roda_gen/generators/templates/project/spec/web/boot_spec.rb.tt +27 -0
- data/lib/roda_gen/generators/templates/project/spec/web/consent_banner_spec.rb.tt +46 -0
- data/lib/roda_gen/generators/templates/project/spec/web/feature_flag_helper_spec.rb.tt +33 -0
- data/lib/roda_gen/generators/templates/project/spec/web/flags_spec.rb.tt +67 -0
- data/lib/roda_gen/generators/templates/project/spec/web/gdpr_spec.rb.tt +55 -0
- data/lib/roda_gen/generators/templates/project/spec/web/heartbeat_spec.rb.tt +65 -0
- data/lib/roda_gen/generators/templates/project/spec/web/host_allowlist_spec.rb.tt +27 -0
- data/lib/roda_gen/generators/templates/project/spec/web/legal_spec.rb.tt +61 -0
- data/lib/roda_gen/generators/templates/project/spec/web/locale_resolver_spec.rb.tt +34 -0
- data/lib/roda_gen/generators/templates/project/spec/web/logger_helper_spec.rb.tt +23 -0
- data/lib/roda_gen/generators/templates/project/spec/web/logger_spec.rb.tt +82 -0
- data/lib/roda_gen/generators/templates/project/spec/web/otp_audit_spec.rb.tt +147 -0
- data/lib/roda_gen/generators/templates/project/spec/web/profile_spec.rb.tt +97 -0
- data/lib/roda_gen/generators/templates/project/spec/web/push_spec.rb.tt +55 -0
- data/lib/roda_gen/generators/templates/project/spec/web/rack_attack_runtime_spec.rb.tt +52 -0
- data/lib/roda_gen/generators/templates/project/spec/web/rack_attack_spec.rb.tt +81 -0
- data/lib/roda_gen/generators/templates/project/spec/web/rbac_audit_spec.rb.tt +62 -0
- data/lib/roda_gen/generators/templates/project/spec/web/request_id_spec.rb.tt +62 -0
- data/lib/roda_gen/generators/templates/project/spec/web/role_boundary_spec.rb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/spec/web/session_skip_spec.rb.tt +74 -0
- data/lib/roda_gen/generators/templates/project/spec/web/split_helper_spec.rb.tt +38 -0
- data/lib/roda_gen/generators/templates/project/spec/web/type_routing_spec.rb.tt +55 -0
- data/lib/roda_gen/generators/templates/project/spec/web/upload_zone_spec.rb.tt +91 -0
- data/lib/roda_gen/generators/templates/project/tmp/.keep.tt +0 -0
- data/lib/roda_gen/generators/templates/project/vendor/.keep.tt +0 -0
- data/lib/roda_gen/generators/templates/project/views/403.erb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/views/404.erb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/views/500.erb.tt +12 -0
- data/lib/roda_gen/generators/templates/project/views/_head_meta.erb.tt +29 -0
- data/lib/roda_gen/generators/templates/project/views/_impersonate_picker.erb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/views/_language_switcher.erb.tt +22 -0
- data/lib/roda_gen/generators/templates/project/views/_locked_accounts.erb.tt +18 -0
- data/lib/roda_gen/generators/templates/project/views/_upload_zone.erb.tt +35 -0
- data/lib/roda_gen/generators/templates/project/views/account/profile.erb.tt +149 -0
- data/lib/roda_gen/generators/templates/project/views/admin/flags.erb.tt +51 -0
- data/lib/roda_gen/generators/templates/project/views/consent_kit/_banner.erb.tt +59 -0
- data/lib/roda_gen/generators/templates/project/views/consent_kit/_preferences.erb.tt +87 -0
- data/lib/roda_gen/generators/templates/project/views/gdpr/erased.erb.tt +6 -0
- data/lib/roda_gen/generators/templates/project/views/gdpr/index.erb.tt +28 -0
- data/lib/roda_gen/generators/templates/project/views/layout.erb.tt +112 -0
- data/lib/roda_gen/generators/templates/project/views/legal/contact.erb.tt +44 -0
- data/lib/roda_gen/generators/templates/project/views/legal/cookies.erb.tt +47 -0
- data/lib/roda_gen/generators/templates/project/views/legal/disclaimer.erb.tt +19 -0
- data/lib/roda_gen/generators/templates/project/views/legal/privacy.erb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/views/mailers/account_unlocked.erb.tt +5 -0
- data/lib/roda_gen/generators/templates/project/views/mailers/data_erased.erb.tt +5 -0
- data/lib/roda_gen/generators/templates/project/views/mailers/data_export.erb.tt +5 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/add-recovery-codes.erb.tt +30 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/change-login.erb.tt +44 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/change-password.erb.tt +41 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/close-account.erb.tt +27 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/confirm-password.erb.tt +23 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/create-account.erb.tt +183 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/login.erb.tt +51 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/logout.erb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/otp-auth.erb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/otp-disable.erb.tt +27 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/otp-setup.erb.tt +48 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/otp-unlock-not-available.erb.tt +18 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/otp-unlock.erb.tt +28 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/recovery-auth.erb.tt +23 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/recovery-codes.erb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/remember.erb.tt +35 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/reset-password-request.erb.tt +27 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/reset-password.erb.tt +30 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/two-factor-auth.erb.tt +8 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/two-factor-disable.erb.tt +20 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/two-factor-manage.erb.tt +36 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/unlock-account-request.erb.tt +13 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/unlock-account.erb.tt +23 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/verify-account-resend.erb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/verify-account.erb.tt +32 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/verify-login-change.erb.tt +8 -0
- data/lib/roda_gen/generators/templates/route/routes/%plural%.rb.tt +19 -0
- data/lib/roda_gen/generators/templates/route/spec/web/%plural%_spec.rb.tt +36 -0
- data/lib/roda_gen/generators/templates/route/views/%plural%/index.erb.tt +11 -0
- data/lib/roda_gen/generators/templates/route/views/%plural%/show.erb.tt +7 -0
- data/lib/roda_gen/generators/templates/upload/db/migrate/%migration_filename%.rb.tt +13 -0
- data/lib/roda_gen/generators/templates/upload/helpers/upload_serving.rb.tt +43 -0
- data/lib/roda_gen/generators/templates/upload/models/%resource_name%.rb.tt +11 -0
- data/lib/roda_gen/generators/templates/upload/models/%resource_name%_uploader.rb.tt +19 -0
- data/lib/roda_gen/generators/templates/upload/routes/%plural%.rb.tt +44 -0
- data/lib/roda_gen/generators/templates/upload/spec/web/%plural%_spec.rb.tt +56 -0
- data/lib/roda_gen/generators/templates/upload/views/%plural%/index.erb.tt +18 -0
- data/lib/roda_gen/generators/upload.rb +83 -0
- data/lib/roda_gen/project_context.rb +30 -0
- data/lib/roda_gen/version.rb +5 -0
- data/lib/roda_gen.rb +16 -0
- metadata +497 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe '/account/profile' do
|
|
6
|
+
let!(:account) { sign_up_and_log_in }
|
|
7
|
+
|
|
8
|
+
describe 'GET' do
|
|
9
|
+
it 'renders the form populated from the signed-in account profile' do
|
|
10
|
+
get '/account/profile'
|
|
11
|
+
follow_redirect! while last_response.redirect?
|
|
12
|
+
expect(last_response.status).to eq(200)
|
|
13
|
+
expect(last_response.body).to include(account.profile.first_name)
|
|
14
|
+
expect(last_response.body).to include(%(name="mobile_number"))
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe 'POST validation failure' do
|
|
19
|
+
# canon_phone_number strips '()' to '', so validates_presence fires
|
|
20
|
+
def post_rejected_mobile
|
|
21
|
+
profile = account.profile
|
|
22
|
+
post_csrf('/account/profile',
|
|
23
|
+
'first_name' => profile.first_name,
|
|
24
|
+
'last_name' => profile.last_name,
|
|
25
|
+
'address' => profile.address,
|
|
26
|
+
'postal_code' => profile.postal_code,
|
|
27
|
+
'city' => profile.city,
|
|
28
|
+
'country' => profile.country,
|
|
29
|
+
'language' => profile.language,
|
|
30
|
+
'time_zone' => profile.time_zone,
|
|
31
|
+
'mobile_number' => '()')
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'renders the inline error message + aria wiring under the rejected input' do
|
|
35
|
+
post_rejected_mobile
|
|
36
|
+
expect(last_response.status).to eq(200)
|
|
37
|
+
expect(last_response.body).to match(%r{<p id="field-error-mobile_number"[^>]*>[^<]+</p>})
|
|
38
|
+
expect(last_response.body).to include('aria-describedby="field-error-mobile_number"')
|
|
39
|
+
expect(last_response.body).to include('aria-invalid="true"')
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'renders the top-of-form summary linking to the rejected input and leaves state unchanged' do
|
|
43
|
+
original_mobile = account.profile.mobile_number
|
|
44
|
+
post_rejected_mobile
|
|
45
|
+
expect(last_response.body).to match(/role="alert".*?<a class="link" href="#field-mobile_number">/m)
|
|
46
|
+
expect(account.profile.reload.mobile_number).to eq(original_mobile)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'does not render the summary block when there are no errors' do
|
|
50
|
+
get '/account/profile'
|
|
51
|
+
follow_redirect! while last_response.redirect?
|
|
52
|
+
expect(last_response.body).not_to include('role="alert"')
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe 'POST success paths' do
|
|
57
|
+
# Truthy branch of the optional.call('gender') lambda in routes/profile.rb, the other specs hit blank-to-nil
|
|
58
|
+
it 'persists a non-empty gender selection' do # rubocop:disable RSpec/ExampleLength -- 9-field POST + assertion needs the room
|
|
59
|
+
profile = account.profile
|
|
60
|
+
post_csrf('/account/profile',
|
|
61
|
+
'first_name' => profile.first_name,
|
|
62
|
+
'last_name' => profile.last_name,
|
|
63
|
+
'address' => profile.address,
|
|
64
|
+
'postal_code' => profile.postal_code,
|
|
65
|
+
'city' => profile.city,
|
|
66
|
+
'country' => profile.country,
|
|
67
|
+
'language' => profile.language,
|
|
68
|
+
'time_zone' => profile.time_zone,
|
|
69
|
+
'mobile_number' => profile.mobile_number,
|
|
70
|
+
'gender' => 'male')
|
|
71
|
+
expect(last_response.status).to eq(302)
|
|
72
|
+
expect(profile.reload.gender).to eq('male')
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'skips the audit insert when the POST matches the current state (no-op)' do # rubocop:disable RSpec/ExampleLength -- 9-field POST + before/after audit-count compare needs the room
|
|
76
|
+
profile = account.profile
|
|
77
|
+
audit_count_before = ADMIN_DB[Sequel[:audit_log][:audit_log]]
|
|
78
|
+
.where(actor_id: account.id, action_id: AuditAction.id_for!('user.profile.update'))
|
|
79
|
+
.count
|
|
80
|
+
post_csrf('/account/profile',
|
|
81
|
+
'first_name' => profile.first_name,
|
|
82
|
+
'last_name' => profile.last_name,
|
|
83
|
+
'address' => profile.address,
|
|
84
|
+
'postal_code' => profile.postal_code,
|
|
85
|
+
'city' => profile.city,
|
|
86
|
+
'country' => profile.country,
|
|
87
|
+
'language' => profile.language,
|
|
88
|
+
'time_zone' => profile.time_zone,
|
|
89
|
+
'mobile_number' => profile.mobile_number)
|
|
90
|
+
expect(last_response.status).to eq(302)
|
|
91
|
+
audit_count_after = ADMIN_DB[Sequel[:audit_log][:audit_log]]
|
|
92
|
+
.where(actor_id: account.id, action_id: AuditAction.id_for!('user.profile.update'))
|
|
93
|
+
.count
|
|
94
|
+
expect(audit_count_after).to eq(audit_count_before)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
# The scaffold POSTs these from client JS with a data-csrf token, so an app subclass skips the global
|
|
6
|
+
# check_csrf!, rodauth.require_authentication inside the push branch still fires
|
|
7
|
+
RSpec.describe 'web push routes' do
|
|
8
|
+
let(:app) do
|
|
9
|
+
Class.new(<%= @app.camel %>) do
|
|
10
|
+
route do |r|
|
|
11
|
+
r.on 'account' do
|
|
12
|
+
r.rodauth
|
|
13
|
+
r.pass
|
|
14
|
+
end
|
|
15
|
+
r.hash_branches
|
|
16
|
+
end
|
|
17
|
+
end.freeze.app
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
let(:endpoint) { "https://push.example.com/#{SecureRandom.hex(8)}" }
|
|
21
|
+
let(:sub) do
|
|
22
|
+
{ 'endpoint' => endpoint, 'p256dh' => SecureRandom.base64(65), 'auth' => SecureRandom.base64(16) }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'requires authentication' do
|
|
26
|
+
post '/push/subscribe', sub
|
|
27
|
+
expect(last_response.status).not_to eq(204)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'stores a subscription (204) and upserts on the same endpoint' do
|
|
31
|
+
account = sign_up_and_log_in
|
|
32
|
+
post '/push/subscribe', sub
|
|
33
|
+
expect(last_response.status).to eq(204)
|
|
34
|
+
expect(PushSubscription.where(account_id: account.id, endpoint: endpoint).count).to eq(1)
|
|
35
|
+
|
|
36
|
+
post '/push/subscribe', sub.merge('p256dh' => 'refreshed')
|
|
37
|
+
expect(PushSubscription.where(endpoint: endpoint).count).to eq(1)
|
|
38
|
+
expect(PushSubscription.first(endpoint: endpoint).p256dh).to eq('refreshed')
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'rejects a subscription missing required fields (422)' do
|
|
42
|
+
sign_up_and_log_in
|
|
43
|
+
post '/push/subscribe', sub.merge('endpoint' => '')
|
|
44
|
+
expect(last_response.status).to eq(422)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'unsubscribes (204) and deletes the row' do
|
|
48
|
+
account = sign_up_and_log_in
|
|
49
|
+
PushSubscription.create(account_id: account.id, endpoint: endpoint,
|
|
50
|
+
p256dh: sub['p256dh'], auth_key: sub['auth'])
|
|
51
|
+
post '/push/unsubscribe', 'endpoint' => endpoint
|
|
52
|
+
expect(last_response.status).to eq(204)
|
|
53
|
+
expect(PushSubscription.where(endpoint: endpoint).count).to eq(0)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'securerandom'
|
|
5
|
+
|
|
6
|
+
# The matcher spec covers auth_post?; this drives the configured rules
|
|
7
|
+
# through Rack::Attack itself: counters in Redis, the 429 responder with
|
|
8
|
+
# its ratelimit headers. Unique IPs and logins per run keep the shared
|
|
9
|
+
# Redis counters from bleeding between runs.
|
|
10
|
+
RSpec.describe 'Rack::Attack runtime' do
|
|
11
|
+
let(:app) { Rack::Attack.new(->(_env) { [200, {}, ['ok']] }) }
|
|
12
|
+
|
|
13
|
+
def post_login(ip:, login:)
|
|
14
|
+
app.call(Rack::MockRequest.env_for('/account/login', method: 'POST',
|
|
15
|
+
params: { 'login' => login },
|
|
16
|
+
'REMOTE_ADDR' => ip))
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'throttles the sixth auth POST from one IP and sets ratelimit headers' do
|
|
20
|
+
ip = "10.99.#{rand(256)}.#{rand(1..254)}"
|
|
21
|
+
allow(<%= @app.camel %>.logger).to receive(:warn).and_call_original
|
|
22
|
+
responses = Array.new(6) { post_login(ip: ip, login: "t#{SecureRandom.hex(4)}@example.com") }
|
|
23
|
+
expect(<%= @app.camel %>.logger).to have_received(:warn)
|
|
24
|
+
.with(a_string_matching(/\Arack-attack throttle=auth-post/)).at_least(:once)
|
|
25
|
+
statuses = responses.map(&:first)
|
|
26
|
+
|
|
27
|
+
expect(statuses.take(5)).to all(eq(200))
|
|
28
|
+
expect(statuses.last).to eq(429)
|
|
29
|
+
|
|
30
|
+
headers = responses.last[1]
|
|
31
|
+
expect(headers['ratelimit-reset'].to_i).to be > 0
|
|
32
|
+
expect(headers['retry-after'].to_i).to be > 0
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'passes non-auth traffic through the auth throttles untouched' do
|
|
36
|
+
env = Rack::MockRequest.env_for('/some/page', 'REMOTE_ADDR' => "10.97.#{rand(256)}.#{rand(1..254)}")
|
|
37
|
+
expect(app.call(env).first).to eq(200)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'does not count an auth POST without a login param against the per-email rule' do
|
|
41
|
+
env = Rack::MockRequest.env_for('/account/login', method: 'POST',
|
|
42
|
+
'REMOTE_ADDR' => "10.96.#{rand(256)}.#{rand(1..254)}")
|
|
43
|
+
expect(app.call(env).first).to eq(200)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'throttles one login name across rotating IPs' do
|
|
47
|
+
login = "victim-#{SecureRandom.hex(4)}@example.com"
|
|
48
|
+
statuses = Array.new(7) { |i| post_login(ip: "10.98.#{rand(256)}.#{i + 1}", login: login).first }
|
|
49
|
+
|
|
50
|
+
expect(statuses.last).to eq(429)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'rack/attack'
|
|
5
|
+
|
|
6
|
+
# Rack::Attack is configure :production gated, but AUTH_POST_PATHS and Rack::Attack.auth_post? are
|
|
7
|
+
# defined at file load and reachable in test
|
|
8
|
+
RSpec.describe 'Rack::Attack auth-throttle matcher' do
|
|
9
|
+
def synthetic(path, method: 'POST')
|
|
10
|
+
env = Rack::MockRequest.env_for(path, method: method)
|
|
11
|
+
Rack::Attack::Request.new(env)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe '.auth_post?' do
|
|
15
|
+
it 'matches a bare /account/login POST' do
|
|
16
|
+
expect(Rack::Attack.auth_post?(synthetic('/account/login'))).to be true
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'matches a locale-prefixed /sv/account/login POST' do
|
|
20
|
+
expect(Rack::Attack.auth_post?(synthetic('/sv/account/login'))).to be true
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'matches /account/recovery-auth' do
|
|
24
|
+
expect(Rack::Attack.auth_post?(synthetic('/account/recovery-auth'))).to be true
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'matches /account/otp-auth under a locale prefix' do
|
|
28
|
+
expect(Rack::Attack.auth_post?(synthetic('/en/account/otp-auth'))).to be true
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Session-protected routes belong on the throttle list too, session theft + spray hits them
|
|
32
|
+
%w[
|
|
33
|
+
/account/change-password
|
|
34
|
+
/account/change-login
|
|
35
|
+
/account/close-account
|
|
36
|
+
/account/confirm-password
|
|
37
|
+
/account/otp-setup
|
|
38
|
+
/account/otp-disable
|
|
39
|
+
/account/recovery-codes
|
|
40
|
+
].each do |path|
|
|
41
|
+
it "matches #{path}" do
|
|
42
|
+
expect(Rack::Attack.auth_post?(synthetic(path))).to be true
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'does not match GETs to credential paths' do
|
|
47
|
+
expect(Rack::Attack.auth_post?(synthetic('/account/login', method: 'GET'))).to be false
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it 'does not match non-credential paths' do
|
|
51
|
+
expect(Rack::Attack.auth_post?(synthetic('/legal/privacy'))).to be false
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe 'AUTH_POST_PATHS' do
|
|
56
|
+
# A new credential-bearing Rodauth path goes in AUTH_POST_PATHS in 25_rack_attack.rb and in this list
|
|
57
|
+
it 'covers every Rodauth feature-enabled credential POST' do # rubocop:disable RSpec/ExampleLength -- literal expected array dominates the line count
|
|
58
|
+
expect(AUTH_POST_PATHS).to match_array(%w[
|
|
59
|
+
/account/login
|
|
60
|
+
/account/create-account
|
|
61
|
+
/account/confirm-password
|
|
62
|
+
/account/change-password
|
|
63
|
+
/account/change-login
|
|
64
|
+
/account/close-account
|
|
65
|
+
/account/reset-password-request
|
|
66
|
+
/account/reset-password
|
|
67
|
+
/account/verify-account
|
|
68
|
+
/account/verify-account-resend
|
|
69
|
+
/account/verify-login-change
|
|
70
|
+
/account/unlock-account-request
|
|
71
|
+
/account/unlock-account
|
|
72
|
+
/account/otp-setup
|
|
73
|
+
/account/otp-auth
|
|
74
|
+
/account/otp-disable
|
|
75
|
+
/account/otp-unlock
|
|
76
|
+
/account/recovery-codes
|
|
77
|
+
/account/recovery-auth
|
|
78
|
+
])
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe 'RBAC audit attribution in a request' 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
|
|
10
|
+
r.is('grant') do
|
|
11
|
+
session['account_id'] = Integer(r.params['account_id'])
|
|
12
|
+
session['impersonating_as'] = Integer(r.params['as']) if r.params['as']
|
|
13
|
+
AccountPrivilege.create(account_id: Integer(r.params['target']), privilege_id: 'flags.read')
|
|
14
|
+
'granted'
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end.freeze.app
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
let(:account) do
|
|
21
|
+
Account.create(email: Faker::Internet.email(name: "granter-#{SecureRandom.hex(4)}"), status_id: 2)
|
|
22
|
+
end
|
|
23
|
+
let(:target) do
|
|
24
|
+
Account.create(email: Faker::Internet.email(name: "grantee-#{SecureRandom.hex(4)}"), status_id: 2)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'attributes the grant to the signed-in account' do
|
|
28
|
+
get "/en/grant?account_id=#{account.id}&target=#{target.id}"
|
|
29
|
+
row = last_audit('rbac.account_privilege.grant', request_id: last_request_id)
|
|
30
|
+
expect(row[:actor_id]).to eq(account.id)
|
|
31
|
+
expect(row[:actor_label]).to eq(account.email)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'carries the request context the model hook could not know' do
|
|
35
|
+
get "/en/grant?account_id=#{account.id}&target=#{target.id}"
|
|
36
|
+
row = last_audit('rbac.account_privilege.grant', request_id: last_request_id)
|
|
37
|
+
expect(row[:request_id]).to eq(last_request_id)
|
|
38
|
+
expect(row[:ip_address]).not_to be_nil
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'records the payload identifying who was granted what' do
|
|
42
|
+
get "/en/grant?account_id=#{account.id}&target=#{target.id}"
|
|
43
|
+
row = last_audit('rbac.account_privilege.grant', request_id: last_request_id)
|
|
44
|
+
# JSONBHash composes Hash rather than subclassing it and RSpec's include misreads it, so slice to a plain Hash
|
|
45
|
+
expect(row[:payload].slice('account_id', 'privilege_id'))
|
|
46
|
+
.to eq('account_id' => target.id, 'privilege_id' => 'flags.read')
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'names the impersonated account as actor and the admin as impersonator' do
|
|
50
|
+
impersonated = Account.create(email: Faker::Internet.email(name: "imp-#{SecureRandom.hex(4)}"), status_id: 2)
|
|
51
|
+
get "/en/grant?account_id=#{account.id}&as=#{impersonated.id}&target=#{target.id}"
|
|
52
|
+
|
|
53
|
+
row = last_audit('rbac.account_privilege.grant', request_id: last_request_id)
|
|
54
|
+
expect(row[:actor_id]).to eq(impersonated.id)
|
|
55
|
+
expect(row[:metadata]['impersonator_id']).to eq(account.id)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it 'clears the resolver after the request so it cannot leak onto the next one' do
|
|
59
|
+
get "/en/grant?account_id=#{account.id}&target=#{target.id}"
|
|
60
|
+
expect(AuditContext.resolver).to be_nil
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
UUID_RE = /\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/i
|
|
6
|
+
|
|
7
|
+
RSpec.describe 'X-Request-Id middleware' do
|
|
8
|
+
it 'mints a UUID when the client did not send X-Request-Id' do
|
|
9
|
+
get '/heartbeat/live'
|
|
10
|
+
expect(last_response.headers['X-Request-Id']).to match(UUID_RE)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'passes a sane inbound id through unchanged (printable ASCII, within length cap)' do
|
|
14
|
+
inbound = 'abc-123-from-caddy'
|
|
15
|
+
header 'X-Request-Id', inbound
|
|
16
|
+
get '/heartbeat/live'
|
|
17
|
+
expect(last_response.headers['X-Request-Id']).to eq(inbound)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'strips non-printable bytes from an inbound id' do
|
|
21
|
+
header 'X-Request-Id', "abc\x00\x01def"
|
|
22
|
+
get '/heartbeat/live'
|
|
23
|
+
expect(last_response.headers['X-Request-Id']).to eq('abcdef')
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'truncates an over-long inbound id to 64 chars' do
|
|
27
|
+
header 'X-Request-Id', 'a' * 200
|
|
28
|
+
get '/heartbeat/live'
|
|
29
|
+
expect(last_response.headers['X-Request-Id'].length).to eq(64)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'replaces an empty / all-bad inbound id with a fresh UUID' do
|
|
33
|
+
header 'X-Request-Id', "\x00\x01"
|
|
34
|
+
get '/heartbeat/live'
|
|
35
|
+
expect(last_response.headers['X-Request-Id']).to match(UUID_RE)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Regression, a non-UUID X-Request-Id crashed the audit insert on PG type-cast for known accounts (failed
|
|
39
|
+
# login audits) but never reached it for unknown ones, a 500 vs 401 split
|
|
40
|
+
describe 'no longer an account-enumeration oracle' do
|
|
41
|
+
let(:email) { Faker::Internet.email(name: "exists-#{SecureRandom.hex(4)}") }
|
|
42
|
+
let(:password) { 'correct horse battery staple' }
|
|
43
|
+
|
|
44
|
+
before do
|
|
45
|
+
sign_up(email: email, password: password)
|
|
46
|
+
verify(Account.first(email: email))
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'returns matching statuses for known vs unknown logins when X-Request-Id is malformed' do
|
|
50
|
+
header 'X-Request-Id', 'abc-123-from-caddy'
|
|
51
|
+
log_in(email: email, password: 'wrong')
|
|
52
|
+
known_status = last_response.status
|
|
53
|
+
|
|
54
|
+
header 'X-Request-Id', 'abc-123-from-caddy'
|
|
55
|
+
log_in(email: Faker::Internet.email(name: "unknown-#{SecureRandom.hex(4)}"), password: 'wrong')
|
|
56
|
+
unknown_status = last_response.status
|
|
57
|
+
|
|
58
|
+
expect(known_status).to eq(unknown_status)
|
|
59
|
+
expect(known_status).not_to eq(500)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe 'web role boundary' do
|
|
6
|
+
it 'web specs talk to the DB as the foo_web role' do
|
|
7
|
+
role = DB[Sequel.lit('SELECT current_user')].get(:current_user)
|
|
8
|
+
expect(role).to end_with('_web')
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it 'web role has no SELECT on audit_log.audit_log' do
|
|
12
|
+
expect { DB[Sequel[:audit_log][:audit_log]].count }
|
|
13
|
+
.to raise_error(Sequel::DatabaseError, /permission denied/i)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'ADMIN_DB is connected as the app role and can SELECT audit_log.audit_log' do
|
|
17
|
+
role = ADMIN_DB[Sequel.lit('SELECT current_user')].get(:current_user)
|
|
18
|
+
expect(role).to end_with('_app')
|
|
19
|
+
expect { ADMIN_DB[Sequel[:audit_log][:audit_log]].count }.not_to raise_error
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
# The route block in <%= @app.snake %>.rb gates rodauth.check_* behind the same predicate, both layers must agree
|
|
6
|
+
RSpec.describe 'session-skip middleware optimisation' do
|
|
7
|
+
describe <%= @app.camel %>::SessionlessPaths do
|
|
8
|
+
describe '.add_prefixes' do
|
|
9
|
+
it 'extends the prefix set for host-registered paths' do
|
|
10
|
+
prefixes = described_class.instance_variable_get(:@prefixes)
|
|
11
|
+
pairs = described_class.instance_variable_get(:@prefix_pairs)
|
|
12
|
+
described_class.add_prefixes(['/zz-metrics', ''])
|
|
13
|
+
expect(described_class.match?('/zz-metrics/sub')).to be true
|
|
14
|
+
ensure
|
|
15
|
+
described_class.instance_variable_set(:@prefixes, prefixes)
|
|
16
|
+
described_class.instance_variable_set(:@prefix_pairs, pairs)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe '.match?' do
|
|
21
|
+
it 'matches a bare prefix (exact)' do
|
|
22
|
+
expect(described_class.match?('/heartbeat')).to be true
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'matches under a prefix' do
|
|
26
|
+
expect(described_class.match?('/heartbeat/db')).to be true
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Regression, a bare start_with? matched /heartbeats too
|
|
30
|
+
it 'does not match a sibling that merely shares the prefix bytes' do
|
|
31
|
+
expect(described_class.match?('/heartbeats')).to be false
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'rejects a nil path' do
|
|
35
|
+
expect(described_class.match?(nil)).to be false
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'matches an exact-path entry (no child path exists)' do
|
|
39
|
+
expect(described_class.match?('/favicon.svg')).to be true
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'does not match an auth path (sanity)' do
|
|
43
|
+
expect(described_class.match?('/account/login')).to be false
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'covers every static-content + heartbeat prefix we ship' do
|
|
47
|
+
%w[
|
|
48
|
+
/heartbeat /assets /fonts
|
|
49
|
+
/favicon.svg /favicon.ico /apple-touch-icon.png
|
|
50
|
+
/manifest.webmanifest /robots.txt /service-worker.js
|
|
51
|
+
].each do |p|
|
|
52
|
+
expect(described_class.match?(p)).to be(true), "expected #{p.inspect} to match"
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
describe <%= @app.camel %>::ConditionalRedisSession do
|
|
59
|
+
# Rack::Session::Redis adds rack.session to env on the way down
|
|
60
|
+
let(:captures) { [] }
|
|
61
|
+
let(:inner_app) { ->(env) { captures << env and [200, {}, ['ok']] } }
|
|
62
|
+
let(:middleware) { described_class.new(inner_app, redis_server: REDIS_OPTIONS, key: '_spec.sid') }
|
|
63
|
+
|
|
64
|
+
it 'bypasses Rack::Session::Redis for SessionlessPaths' do
|
|
65
|
+
middleware.call(Rack::MockRequest.env_for('/heartbeat/live'))
|
|
66
|
+
expect(captures.last['rack.session']).to be_nil
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it 'runs Rack::Session::Redis for non-sessionless paths' do
|
|
70
|
+
middleware.call(Rack::MockRequest.env_for('/account/login'))
|
|
71
|
+
expect(captures.last['rack.session']).not_to be_nil
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
# No bundled route calls ab_test / ab_finished, so a synthetic route covers both consent branches. Each
|
|
6
|
+
# app overrides #consented? directly, no signed consent cookie to mint
|
|
7
|
+
RSpec.describe SplitHelper do
|
|
8
|
+
def app_with_consent(consent)
|
|
9
|
+
Class.new(<%= @app.camel %>) do
|
|
10
|
+
define_method(:consented?) { |_category| consent }
|
|
11
|
+
|
|
12
|
+
route do |r|
|
|
13
|
+
r.is('ab-check') do
|
|
14
|
+
exp = r.params['e'].to_sym
|
|
15
|
+
ab_test(exp, 'a', 'b').tap { ab_finished(exp) }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end.freeze.app
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
context 'without analytics consent' do
|
|
22
|
+
let(:app) { app_with_consent(false) }
|
|
23
|
+
|
|
24
|
+
it 'returns the control alternative and never touches Split' do
|
|
25
|
+
get '/en/ab-check?e=spec_control'
|
|
26
|
+
expect(last_response.body).to eq('a')
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
context 'with analytics consent' do
|
|
31
|
+
let(:app) { app_with_consent(true) }
|
|
32
|
+
|
|
33
|
+
it 'assigns a variant and records a conversion' do
|
|
34
|
+
get "/en/ab-check?e=spec_ab_#{SecureRandom.hex(4)}"
|
|
35
|
+
expect(last_response.body).to eq('a').or eq('b')
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe 'type_routing content negotiation' do
|
|
6
|
+
let(:app) do
|
|
7
|
+
Class.new(<%= @app.camel %>) do
|
|
8
|
+
route do |r|
|
|
9
|
+
r.is 'orders' do
|
|
10
|
+
r.json { '{"format":"json"}' }
|
|
11
|
+
r.csv { "format,csv\n" }
|
|
12
|
+
'format:html' # default, must be last (no auto-406 on fall-through)
|
|
13
|
+
end
|
|
14
|
+
# Catch-all so the .txt case can assert remaining_path, falling through to the localized 404
|
|
15
|
+
# handler would 500 here since it needs I18n.locale
|
|
16
|
+
"unmatched:#{r.remaining_path}"
|
|
17
|
+
end
|
|
18
|
+
end.freeze.app
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe 'URL extension' do
|
|
22
|
+
it 'routes .json to the json branch with an application/json Content-Type' do
|
|
23
|
+
get '/en/orders.json'
|
|
24
|
+
expect(last_response.status).to eq(200)
|
|
25
|
+
expect(last_response.headers['Content-Type']).to start_with('application/json')
|
|
26
|
+
expect(last_response.body).to eq('{"format":"json"}')
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'routes .csv (a scaffold-added export format) to the csv branch with text/csv' do
|
|
30
|
+
get '/en/orders.csv'
|
|
31
|
+
expect(last_response.headers['Content-Type']).to start_with('text/csv')
|
|
32
|
+
expect(last_response.body).to eq("format,csv\n")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'falls through to the html default when no extension is supplied' do
|
|
36
|
+
get '/en/orders'
|
|
37
|
+
expect(last_response.body).to eq('format:html')
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe 'Accept header' do
|
|
42
|
+
it 'negotiates json and appends Vary: Accept so caches key on the header' do
|
|
43
|
+
get '/en/orders', {}, 'HTTP_ACCEPT' => 'application/json'
|
|
44
|
+
expect(last_response.body).to eq('{"format":"json"}')
|
|
45
|
+
expect(last_response.headers['Vary']).to include('Accept')
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Only allowlisted extensions are stripped, so :public still serves /robots.txt without a skip_paths workaround
|
|
50
|
+
it 'leaves an unregistered .txt extension on the routed path (never stripped)' do
|
|
51
|
+
get '/en/orders.txt'
|
|
52
|
+
expect(last_response.status).to eq(200)
|
|
53
|
+
expect(last_response.body).to include('orders.txt')
|
|
54
|
+
end
|
|
55
|
+
end
|