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,398 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe AuditLog do
|
|
6
|
+
# user.login is migration-seeded, insert_conflict keeps the spec self-contained if the seed moves
|
|
7
|
+
before do
|
|
8
|
+
AuditAction.dataset.insert_conflict.insert(code: 'user.login', category: 'auth')
|
|
9
|
+
AuditAction.refresh_cache!
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# AuditLog.record returns nil (db.run insert_sql, no RETURNING, since the web role has no SELECT
|
|
13
|
+
# on audit_log), so what landed is checked through the dataset
|
|
14
|
+
describe '.record' do
|
|
15
|
+
let(:dataset) { described_class.dataset }
|
|
16
|
+
|
|
17
|
+
# Rows persist across suites within a rake test:all run, so each actor_label embeds the spec description
|
|
18
|
+
|
|
19
|
+
it 'inserts a row and resolves all four lookup codes' do
|
|
20
|
+
described_class.record(
|
|
21
|
+
action: 'user.login',
|
|
22
|
+
actor_type: :user,
|
|
23
|
+
actor_id: 42,
|
|
24
|
+
actor_label: '<spec: AuditLog.record resolves the four lookup codes>',
|
|
25
|
+
status: :success
|
|
26
|
+
)
|
|
27
|
+
row = dataset.where(actor_id: 42).order(Sequel.desc(:occurred_at)).first
|
|
28
|
+
expect(row[:audit_log_id]).to be_a(String) # uuid
|
|
29
|
+
expect(row[:actor_id]).to eq(42)
|
|
30
|
+
expect(row[:action_id]).to eq(AuditAction.id_for!('user.login'))
|
|
31
|
+
expect(row[:status_id]).to eq(AuditStatus.id_for!(:success))
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'defaults actor_type to :system and status to :success' do
|
|
35
|
+
label = '<spec: AuditLog.record defaults actor_type to :system, status to :success>'
|
|
36
|
+
described_class.record(action: 'user.login', actor_label: label)
|
|
37
|
+
row = dataset.where(actor_label: label).order(Sequel.desc(:occurred_at)).first
|
|
38
|
+
expect(row[:actor_type_id]).to eq(AuditActorType.id_for!(:system))
|
|
39
|
+
expect(row[:status_id]).to eq(AuditStatus.id_for!(:success))
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'raises with a copy-pasteable AuditAction.create when the action is unregistered' do
|
|
43
|
+
expect do
|
|
44
|
+
described_class.record(action: 'never.registered')
|
|
45
|
+
end.to raise_error(ArgumentError, /never\.registered.*Register it first.*AuditAction\.create/m)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'raises when actor_type is unknown' do
|
|
49
|
+
expect do
|
|
50
|
+
described_class.record(action: 'user.login', actor_type: :ghost)
|
|
51
|
+
end.to raise_error(ArgumentError, /Unknown audit actor type: :ghost/)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it 'projects metadata.impersonator_id via the virtual generated column' do
|
|
55
|
+
described_class.record(
|
|
56
|
+
action: 'user.login',
|
|
57
|
+
actor_type: :user,
|
|
58
|
+
actor_id: 1,
|
|
59
|
+
actor_label: '<spec: AuditLog projects metadata.impersonator_id via virtual column>',
|
|
60
|
+
metadata: { impersonator_id: 99 }
|
|
61
|
+
)
|
|
62
|
+
row = dataset.where(actor_id: 1).order(Sequel.desc(:occurred_at)).first
|
|
63
|
+
expect(row[:impersonator_id]).to eq(99)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# ip_address is PG inet. Anything not a single IP must become NULL, otherwise the insert crashes
|
|
67
|
+
# and 500-on-known vs 401-on-unknown becomes an account-enumeration oracle
|
|
68
|
+
describe 'ip_address sanitization' do
|
|
69
|
+
def latest_for(label)
|
|
70
|
+
dataset.where(actor_label: label).order(Sequel.desc(:occurred_at)).first
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it 'stores a valid IPv4 untouched' do
|
|
74
|
+
label = '<spec: ip_address sanitization keeps IPv4>'
|
|
75
|
+
described_class.record(action: 'user.login', actor_label: label, ip_address: '203.0.113.9')
|
|
76
|
+
expect(latest_for(label)[:ip_address].to_s).to eq('203.0.113.9')
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it 'stores a valid IPv6 untouched' do
|
|
80
|
+
label = '<spec: ip_address sanitization keeps IPv6>'
|
|
81
|
+
described_class.record(action: 'user.login', actor_label: label, ip_address: '2001:db8::1')
|
|
82
|
+
expect(latest_for(label)[:ip_address].to_s).to eq('2001:db8::1')
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it 'stores NULL for a comma-separated XFF list' do
|
|
86
|
+
label = '<spec: ip_address sanitization rejects XFF list>'
|
|
87
|
+
expect do
|
|
88
|
+
described_class.record(action: 'user.login', actor_label: label,
|
|
89
|
+
ip_address: '203.0.113.9, 198.51.100.7')
|
|
90
|
+
end.not_to raise_error
|
|
91
|
+
expect(latest_for(label)[:ip_address]).to be_nil
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it 'stores NULL for non-IP garbage' do
|
|
95
|
+
label = '<spec: ip_address sanitization rejects non-IP>'
|
|
96
|
+
described_class.record(action: 'user.login', actor_label: label, ip_address: 'not-an-ip')
|
|
97
|
+
expect(latest_for(label)[:ip_address]).to be_nil
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it 'stores NULL for empty / nil / whitespace-only' do
|
|
101
|
+
[nil, '', ' '].each_with_index do |bad, i|
|
|
102
|
+
label = "<spec: ip_address sanitization rejects blank #{i}>"
|
|
103
|
+
described_class.record(action: 'user.login', actor_label: label, ip_address: bad)
|
|
104
|
+
expect(latest_for(label)[:ip_address]).to be_nil
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Specs run as the schema owner with SELECT + UPDATE on audit_log.audit_log, erase itself runs as DATABASE_ROLE=app
|
|
111
|
+
describe '.erase_for_account! — GDPR Art. 17 redaction' do
|
|
112
|
+
let(:account_id) { 4242 }
|
|
113
|
+
let(:row) { described_class.dataset.where(actor_id: account_id).first }
|
|
114
|
+
|
|
115
|
+
def signup_payload
|
|
116
|
+
{
|
|
117
|
+
first_name: 'Alice', last_name: 'Andersson',
|
|
118
|
+
address: 'Storgatan 1', postal_code: '11122', city: 'Stockholm', country: 'SE',
|
|
119
|
+
mobile_number: '+46701234567', personal_identity_number: '198001019876',
|
|
120
|
+
gender: 'female', language: 'sv', email: 'alice@example.test'
|
|
121
|
+
}
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
before do
|
|
125
|
+
AuditAction.dataset.insert_conflict.insert(code: 'user.profile.update', category: 'auth')
|
|
126
|
+
AuditAction.refresh_cache!
|
|
127
|
+
described_class.record(
|
|
128
|
+
action: 'user.account.create', actor_type: :user, actor_id: account_id,
|
|
129
|
+
actor_label: 'alice@example.test',
|
|
130
|
+
metadata: { email: 'alice@example.test' },
|
|
131
|
+
payload: { after: signup_payload }
|
|
132
|
+
)
|
|
133
|
+
described_class.erase_for_account!(account_id)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it 'redacts actor_label + metadata.email' do
|
|
137
|
+
expect(row[:actor_label]).to eq('[redacted]')
|
|
138
|
+
expect(row[:metadata]['email']).to eq('[redacted]')
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it 'redacts every PII key inside payload.after' do
|
|
142
|
+
after = row[:payload]['after']
|
|
143
|
+
%w[email first_name last_name address postal_code city mobile_number personal_identity_number].each do |k|
|
|
144
|
+
expect(after[k]).to eq('[redacted]'), "expected payload.after.#{k} redacted, got #{after[k].inspect}"
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
it 'leaves non-PII keys (gender / language / country) untouched' do
|
|
149
|
+
after = row[:payload]['after']
|
|
150
|
+
expect(after['gender']).to eq('female')
|
|
151
|
+
expect(after['language']).to eq('sv')
|
|
152
|
+
expect(after['country']).to eq('SE')
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
it 'preserves the audit fact — actor_id and action_id' do
|
|
156
|
+
expect(row[:actor_id]).to eq(account_id)
|
|
157
|
+
expect(row[:action_id]).to eq(AuditAction.id_for!('user.account.create'))
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
it 'leaves a nil actor_label as nil (nothing to redact)' do
|
|
161
|
+
empty_account_id = 5151
|
|
162
|
+
described_class.record(
|
|
163
|
+
action: 'user.account.create', actor_type: :user, actor_id: empty_account_id,
|
|
164
|
+
actor_label: nil,
|
|
165
|
+
metadata: { email: 'noemail@example.test' }
|
|
166
|
+
)
|
|
167
|
+
described_class.erase_for_account!(empty_account_id)
|
|
168
|
+
row = described_class.dataset.where(actor_id: empty_account_id).first
|
|
169
|
+
expect(row[:actor_label]).to be_nil
|
|
170
|
+
expect(row[:metadata]['email']).to eq('[redacted]')
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
describe '.redact_pii — recursion shape' do
|
|
175
|
+
it 'recurses into arrays of hashes (each element gets its PII keys masked)' do
|
|
176
|
+
input = [{ 'email' => 'a@b' }, { 'email' => 'c@d', 'gender' => 'female' }]
|
|
177
|
+
out = described_class.redact_pii(input)
|
|
178
|
+
expect(out).to eq([{ 'email' => '[redacted]' }, { 'email' => '[redacted]', 'gender' => 'female' }])
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
describe '.erase_for_account! — impersonator + empty cases' do
|
|
183
|
+
before do
|
|
184
|
+
AuditAction.dataset.insert_conflict.insert(code: 'user.profile.update', category: 'auth')
|
|
185
|
+
AuditAction.refresh_cache!
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
it 'also redacts rows where the account was the impersonator (metadata.impersonator_id)' do
|
|
189
|
+
target_id = 5051
|
|
190
|
+
admin_id = 9090
|
|
191
|
+
described_class.record(
|
|
192
|
+
action: 'user.profile.update', actor_type: :user, actor_id: target_id,
|
|
193
|
+
actor_label: 'target@example.test',
|
|
194
|
+
metadata: { email: 'target@example.test', impersonator_id: admin_id }
|
|
195
|
+
)
|
|
196
|
+
described_class.erase_for_account!(admin_id)
|
|
197
|
+
|
|
198
|
+
row = described_class.dataset.where(actor_id: target_id).first
|
|
199
|
+
expect(row[:metadata]['email']).to eq('[redacted]')
|
|
200
|
+
expect(row[:metadata]['impersonator_id']).to eq(admin_id)
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
it 'returns 0 and updates nothing for an account with no audit rows' do
|
|
204
|
+
expect(described_class.erase_for_account!(999_999_999)).to eq(0)
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
describe 'current-period partition routing' do
|
|
209
|
+
it "routes today's writes to the concrete current-period partition (not default)" do
|
|
210
|
+
described_class.record(
|
|
211
|
+
action: 'user.login', actor_type: :user, actor_id: 12_345,
|
|
212
|
+
actor_label: '<spec: tableoid probe>'
|
|
213
|
+
)
|
|
214
|
+
landed_in = DB.fetch(<<~SQL, '<spec: tableoid probe>').get(:partition)
|
|
215
|
+
SELECT tableoid::regclass::text AS partition
|
|
216
|
+
FROM audit_log.audit_log
|
|
217
|
+
WHERE actor_label = ?
|
|
218
|
+
LIMIT 1
|
|
219
|
+
SQL
|
|
220
|
+
expected_name, = described_class.partition_for(Date.today, 0, AuditLog::PARTITION_CADENCE)
|
|
221
|
+
expect(landed_in).to eq("audit_log.#{expected_name}")
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
describe '.partition_for and .partition_for_period' do
|
|
226
|
+
let(:today) { Date.new(2026, 6, 19) }
|
|
227
|
+
|
|
228
|
+
it 'returns the current-month partition for offset 0' do
|
|
229
|
+
expect(described_class.partition_for(today, 0, :monthly))
|
|
230
|
+
.to eq(['audit_log_2026_06', Date.new(2026, 6, 1), Date.new(2026, 7, 1)])
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
it 'returns the next-month partition for offset 1' do
|
|
234
|
+
expect(described_class.partition_for(today, 1, :monthly))
|
|
235
|
+
.to eq(['audit_log_2026_07', Date.new(2026, 7, 1), Date.new(2026, 8, 1)])
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
it 'returns the current-quarter partition for cadence :quarterly' do
|
|
239
|
+
expect(described_class.partition_for(today, 0, :quarterly))
|
|
240
|
+
.to eq(['audit_log_2026_q2', Date.new(2026, 4, 1), Date.new(2026, 7, 1)])
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
it 'returns the next-quarter partition crossing year boundary' do
|
|
244
|
+
year_end = Date.new(2026, 11, 15)
|
|
245
|
+
expect(described_class.partition_for(year_end, 1, :quarterly))
|
|
246
|
+
.to eq(['audit_log_2027_q1', Date.new(2027, 1, 1), Date.new(2027, 4, 1)])
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
it 'returns the current-year partition for cadence :yearly' do
|
|
250
|
+
expect(described_class.partition_for(today, 0, :yearly))
|
|
251
|
+
.to eq(['audit_log_2026', Date.new(2026, 1, 1), Date.new(2027, 1, 1)])
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
it 'parses YYYY-MM period strings' do
|
|
255
|
+
expect(described_class.partition_for_period('2025-12'))
|
|
256
|
+
.to eq(['audit_log_2025_12', Date.new(2025, 12, 1), Date.new(2026, 1, 1)])
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
it 'parses YYYY-Qn period strings' do
|
|
260
|
+
expect(described_class.partition_for_period('2025-Q4'))
|
|
261
|
+
.to eq(['audit_log_2025_q4', Date.new(2025, 10, 1), Date.new(2026, 1, 1)])
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
it 'parses YYYY period strings' do
|
|
265
|
+
expect(described_class.partition_for_period('2024'))
|
|
266
|
+
.to eq(['audit_log_2024', Date.new(2024, 1, 1), Date.new(2025, 1, 1)])
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
# Unreachable in practice, the rake task validates cadence up front
|
|
270
|
+
it 'raises ArgumentError for an unknown cadence symbol' do
|
|
271
|
+
expect { described_class.partition_for(today, 0, :weekly) }
|
|
272
|
+
.to raise_error(ArgumentError, /unknown cadence/)
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
it 'raises ArgumentError for unrecognised period strings' do
|
|
276
|
+
expect { described_class.partition_for_period('not-a-period') }
|
|
277
|
+
.to raise_error(ArgumentError, /Unrecognised period/)
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
describe '.drop_partitions_before — retention' do
|
|
282
|
+
# Only drop partitions created here, dropping test:db's bootstrapped ones would push later suites
|
|
283
|
+
# into audit_log_default and mask routing and permission bugs
|
|
284
|
+
after do
|
|
285
|
+
DB.run 'DROP TABLE IF EXISTS audit_log.audit_log_test_2019_01'
|
|
286
|
+
DB.run 'DROP TABLE IF EXISTS audit_log.audit_log_test_2020_01'
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
it 'drops partitions whose range_end is at or before the cutoff and returns their names' do
|
|
290
|
+
DB.run "SELECT audit_log.create_partition('audit_log_test_2019_01', '2019-01-01', '2019-02-01')"
|
|
291
|
+
dropped = described_class.drop_partitions_before(Date.new(2019, 2, 1))
|
|
292
|
+
expect(dropped).to include('audit_log_test_2019_01')
|
|
293
|
+
expect(DB[Sequel[:pg_class]].where(relname: 'audit_log_test_2019_01').count).to eq(0)
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
it 'leaves the default partition alone when dropping a concrete past partition' do
|
|
297
|
+
DB.run "SELECT audit_log.create_partition('audit_log_test_2020_01', '2020-01-01', '2020-02-01')"
|
|
298
|
+
described_class.drop_partitions_before(Date.new(2020, 2, 1))
|
|
299
|
+
expect(DB[Sequel[:pg_class]].where(relname: 'audit_log_test_2020_01').count).to eq(0)
|
|
300
|
+
expect(DB[Sequel[:pg_class]].where(relname: 'audit_log_default').count).to eq(1)
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
it 'accepts a YYYY-MM-DD String cutoff' do
|
|
304
|
+
DB.run "SELECT audit_log.create_partition('audit_log_test_2019_01', '2019-01-01', '2019-02-01')"
|
|
305
|
+
expect(described_class.drop_partitions_before('2019-02-01')).to include('audit_log_test_2019_01')
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
# A LIST or HASH bound never parses as FOR VALUES FROM ... TO ..., so never droppable whatever the
|
|
309
|
+
# cutoff. send since the method is private
|
|
310
|
+
it 'returns false from partition_droppable? when the bound is not a parseable range' do
|
|
311
|
+
bogus = { name: 'audit_log_weird', bound: "FOR VALUES IN ('a', 'b')" }
|
|
312
|
+
expect(described_class.send(:partition_droppable?, bogus, Date.new(2999, 12, 31))).to be false
|
|
313
|
+
end
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
describe '.evacuate_default_partition — retro-partitioning' do
|
|
317
|
+
# 2018-03 is far enough back not to collide with the bootstrapped partitions, cleanup runs on failure too
|
|
318
|
+
after do
|
|
319
|
+
DB.run 'DROP TABLE IF EXISTS audit_log.audit_log_2018_03'
|
|
320
|
+
DB[Sequel[:audit_log][:audit_log_default]]
|
|
321
|
+
.where(Sequel.lit("occurred_at >= '2018-03-01' AND occurred_at < '2018-04-01'"))
|
|
322
|
+
.delete
|
|
323
|
+
end
|
|
324
|
+
|
|
325
|
+
# rubocop:disable-next RSpec/ExampleLength -- end-to-end retro-partitioning check needs the full insert+evacuate+verify chain
|
|
326
|
+
it 'moves rows from audit_log_default into a new partition and attaches it' do
|
|
327
|
+
described_class.record(
|
|
328
|
+
action: 'user.login', actor_type: :user, actor_id: 1234,
|
|
329
|
+
actor_label: '<spec: evacuate_default 2018-03 row 1>'
|
|
330
|
+
)
|
|
331
|
+
# record() lands in today's partition, UPDATE through the parent so PG re-routes the row to audit_log_default
|
|
332
|
+
DB.run "UPDATE audit_log.audit_log SET occurred_at = '2018-03-15' " \
|
|
333
|
+
"WHERE actor_label = '<spec: evacuate_default 2018-03 row 1>'"
|
|
334
|
+
|
|
335
|
+
result = described_class.evacuate_default_partition('2018-03')
|
|
336
|
+
|
|
337
|
+
expect(result).to include(name: 'audit_log_2018_03', moved: 1, status: :evacuated)
|
|
338
|
+
|
|
339
|
+
in_new = DB['SELECT count(*) FROM audit_log.audit_log_2018_03'].single_value
|
|
340
|
+
in_def = DB[Sequel[:audit_log][:audit_log_default]]
|
|
341
|
+
.where(Sequel.lit("occurred_at >= '2018-03-01' AND occurred_at < '2018-04-01'"))
|
|
342
|
+
.count
|
|
343
|
+
expect(in_new).to eq(1)
|
|
344
|
+
expect(in_def).to eq(0)
|
|
345
|
+
|
|
346
|
+
attached = DB.fetch(<<~SQL).all
|
|
347
|
+
SELECT child.relname AS name FROM pg_inherits
|
|
348
|
+
JOIN pg_class child ON child.oid = pg_inherits.inhrelid
|
|
349
|
+
JOIN pg_class parent ON parent.oid = pg_inherits.inhparent
|
|
350
|
+
WHERE parent.relname = 'audit_log'
|
|
351
|
+
SQL
|
|
352
|
+
expect(attached.map { |r| r[:name] }).to include('audit_log_2018_03')
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
it 'returns :already_partitioned when the partition already exists' do
|
|
356
|
+
DB.run "SELECT audit_log.create_partition('audit_log_2018_03', '2018-03-01', '2018-04-01')"
|
|
357
|
+
expect(described_class.evacuate_default_partition('2018-03'))
|
|
358
|
+
.to include(status: :already_partitioned, name: 'audit_log_2018_03', moved: 0)
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
it 'returns :nothing_in_default when default has no rows for the period' do
|
|
362
|
+
result = described_class.evacuate_default_partition('2018-03')
|
|
363
|
+
expect(result).to include(status: :nothing_in_default, moved: 0)
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
it 'raises ArgumentError for an unrecognised period string' do
|
|
367
|
+
expect { described_class.evacuate_default_partition('not-a-period') }
|
|
368
|
+
.to raise_error(ArgumentError, /Unrecognised period/)
|
|
369
|
+
end
|
|
370
|
+
|
|
371
|
+
# Both exit at :nothing_in_default, so no partition is created and nothing to clean up
|
|
372
|
+
it 'parses quarterly periods (YYYY-Q1..Q4)' do
|
|
373
|
+
expect(described_class.evacuate_default_partition('2017-Q2'))
|
|
374
|
+
.to include(name: 'audit_log_2017_q2', status: :nothing_in_default)
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
it 'parses yearly periods (YYYY)' do
|
|
378
|
+
expect(described_class.evacuate_default_partition('2016'))
|
|
379
|
+
.to include(name: 'audit_log_2016', status: :nothing_in_default)
|
|
380
|
+
end
|
|
381
|
+
|
|
382
|
+
it 'ignores a same-named table in another schema (does not short-circuit to :already_partitioned)' do
|
|
383
|
+
DB.run 'CREATE TABLE public.audit_log_2018_03 (probe int)'
|
|
384
|
+
|
|
385
|
+
described_class.record(
|
|
386
|
+
action: 'user.login', actor_type: :user, actor_id: 9876,
|
|
387
|
+
actor_label: '<spec: cross-schema name collision>'
|
|
388
|
+
)
|
|
389
|
+
DB.run "UPDATE audit_log.audit_log SET occurred_at = '2018-03-15' " \
|
|
390
|
+
"WHERE actor_label = '<spec: cross-schema name collision>'"
|
|
391
|
+
|
|
392
|
+
expect(described_class.evacuate_default_partition('2018-03'))
|
|
393
|
+
.to include(name: 'audit_log_2018_03', moved: 1, status: :evacuated)
|
|
394
|
+
ensure
|
|
395
|
+
DB.run 'DROP TABLE IF EXISTS public.audit_log_2018_03'
|
|
396
|
+
end
|
|
397
|
+
end
|
|
398
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe 'RBAC tables' do
|
|
6
|
+
let(:account) { Account.create(email: Faker::Internet.email(name: "rbac-#{SecureRandom.hex(4)}")) }
|
|
7
|
+
|
|
8
|
+
describe 'seeded data (db/migrate/create_authorization.rb)' do
|
|
9
|
+
it 'has admin + user roles' do
|
|
10
|
+
expect(Role.select_map(:role)).to contain_exactly('admin', 'user')
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'has the accounts.* privileges' do
|
|
14
|
+
expect(Privilege.select_map(:privilege)).to include(
|
|
15
|
+
'accounts.read', 'accounts.update', 'accounts.delete', 'accounts.impersonate', 'accounts.unlock'
|
|
16
|
+
)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'grants admin every seeded privilege' do
|
|
20
|
+
admin = Role['admin']
|
|
21
|
+
# privileges and role_privileges both carry a privilege column, bare :privilege raises PG::AmbiguousColumn
|
|
22
|
+
expect(admin.privileges_dataset.select_map(Sequel[:privileges][:privilege]))
|
|
23
|
+
.to contain_exactly(
|
|
24
|
+
'accounts.read', 'accounts.update', 'accounts.delete', 'accounts.impersonate', 'accounts.unlock',
|
|
25
|
+
'flags.read', 'flags.manage'
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe 'AccountRole' do
|
|
31
|
+
it 'composite PK rejects duplicate (account_id, role) pairs' do
|
|
32
|
+
AccountRole.create(account_id: account.id, role_id: 'admin')
|
|
33
|
+
expect { AccountRole.create(account_id: account.id, role_id: 'admin') }
|
|
34
|
+
.to raise_error(Sequel::UniqueConstraintViolation)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'allows the same role for different accounts' do
|
|
38
|
+
AccountRole.create(account_id: account.id, role_id: 'user')
|
|
39
|
+
other = Account.create(email: Faker::Internet.email(name: "rbac2-#{SecureRandom.hex(4)}"))
|
|
40
|
+
expect { AccountRole.create(account_id: other.id, role_id: 'user') }.not_to raise_error
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'rejects an unknown role via FK constraint' do
|
|
44
|
+
expect { AccountRole.create(account_id: account.id, role_id: 'no-such-role') }
|
|
45
|
+
.to raise_error(Sequel::ForeignKeyConstraintViolation)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
describe 'AccountPrivilege' do
|
|
50
|
+
it 'composite PK rejects duplicate (account_id, privilege) pairs' do
|
|
51
|
+
AccountPrivilege.create(account_id: account.id, privilege_id: 'accounts.read')
|
|
52
|
+
expect { AccountPrivilege.create(account_id: account.id, privilege_id: 'accounts.read') }
|
|
53
|
+
.to raise_error(Sequel::UniqueConstraintViolation)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'rejects an unknown privilege via FK constraint' do
|
|
57
|
+
expect { AccountPrivilege.create(account_id: account.id, privilege_id: 'made.up') }
|
|
58
|
+
.to raise_error(Sequel::ForeignKeyConstraintViolation)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
describe 'RolePrivilege' do
|
|
63
|
+
it 'rejects an unknown role or privilege via FK constraint' do
|
|
64
|
+
expect { RolePrivilege.create(role_id: 'admin', privilege_id: 'made.up') }
|
|
65
|
+
.to raise_error(Sequel::ForeignKeyConstraintViolation)
|
|
66
|
+
expect { RolePrivilege.create(role_id: 'no-such', privilege_id: 'accounts.read') }
|
|
67
|
+
.to raise_error(Sequel::ForeignKeyConstraintViolation)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
describe 'Role#accounts / Privilege#accounts' do
|
|
72
|
+
it 'reaches accounts through account_roles' do
|
|
73
|
+
AccountRole.create(account_id: account.id, role_id: 'admin')
|
|
74
|
+
expect(Role['admin'].accounts_dataset.select_map(:id)).to include(account.id)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it 'reaches accounts through account_privileges (direct grants)' do
|
|
78
|
+
AccountPrivilege.create(account_id: account.id, privilege_id: 'accounts.read')
|
|
79
|
+
expect(Privilege['accounts.read'].accounts_dataset.select_map(:id)).to include(account.id)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe CountryCallingCode do
|
|
6
|
+
it 'persists one row per country and reads back the calling code + trunk' do
|
|
7
|
+
row = described_class['SE']
|
|
8
|
+
expect(row.calling_code).to eq('46')
|
|
9
|
+
expect(row.trunc_code).to eq('0')
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
# FI ships four seeded exit codes, the most diverse set in the seed file
|
|
6
|
+
RSpec.describe CountryExitCode do
|
|
7
|
+
it 'allows multiple exit codes per country (composite PK)' do
|
|
8
|
+
expect(described_class.where(country: 'FI').count).to be > 1
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe CountryLanguage do
|
|
6
|
+
it 'allows multiple non-preferred languages per country' do
|
|
7
|
+
expect(described_class.where(country: 'CH', preferred: false).count).to be >= 2
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it 'allows exactly one preferred language per country' do
|
|
11
|
+
expect(described_class.where(country: 'CH', preferred: true).count).to eq(1)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'rejects a second preferred row for the same country' do
|
|
15
|
+
# SE already has sv preferred, so this trips the WHERE preferred = true partial unique index. Raises
|
|
16
|
+
# before COMMIT, so no row persists across runs
|
|
17
|
+
expect do
|
|
18
|
+
described_class.create(country: 'SE', language: 'en', preferred: true)
|
|
19
|
+
end.to raise_error(Sequel::UniqueConstraintViolation)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Country do
|
|
6
|
+
let(:country) { described_class['SE'] }
|
|
7
|
+
|
|
8
|
+
it 'persists and looks up by alpha-2 iso_code' do
|
|
9
|
+
expect(country.name).to eq('Sweden')
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe 'associations' do
|
|
13
|
+
it 'reaches languages via country_languages' do
|
|
14
|
+
expect(country.languages.map(&:iso_code)).to include('sv', 'tru')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'reaches its country_time_zones' do
|
|
18
|
+
expect(country.country_time_zones.map(&:time_zone)).to include('Europe/Stockholm')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'reaches its calling code (one_to_one)' do
|
|
22
|
+
expect(country.country_calling_code.calling_code).to eq('46')
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'reaches its exit codes' do
|
|
26
|
+
expect(country.country_exit_codes.map(&:exit_code)).to include('00')
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|