trek 2.3.2 → 2.5.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 +4 -4
- data/.node-version +1 -1
- data/.yarn/releases/yarn-4.18.1.cjs +1000 -0
- data/.yarnrc.yml +3 -5
- data/AGENTS.md +12 -8
- data/CHANGELOG.md +73 -0
- data/Gemfile.lock +226 -171
- data/Makefile +38 -1
- data/README.md +2 -2
- data/app/assets/icons/trek/passkey.svg +5 -0
- data/app/assets/stylesheets/trek/base.css +6 -0
- data/app/components/trek/entries/item_component/item_component.css +6 -0
- data/app/components/trek/form/image_field_component/image_field_component.html.slim +9 -0
- data/app/components/trek/form/image_field_component.rb +1 -5
- data/app/components/trek/form/password_strength_component/password_strength_component.css +56 -0
- data/app/components/trek/form/password_strength_component/password_strength_component.html.slim +8 -0
- data/app/components/trek/form/password_strength_component/password_strength_component.js +74 -0
- data/app/components/trek/form/password_strength_component.rb +29 -0
- data/app/components/trek/gate_component/gate_component.css +7 -0
- data/app/components/trek/icon/sprite_component.rb +3 -2
- data/app/components/trek/list/item_component.rb +1 -1
- data/app/components/trek/list/tree/item_component.rb +2 -2
- data/app/components/trek/search_component/search_component.html.slim +2 -1
- data/app/components/trek/search_component.rb +9 -1
- data/app/components/trek/section_component/section_component.css +22 -0
- data/app/components/trek/section_component/section_component.html.slim +5 -0
- data/app/components/trek/section_component/section_component.js +1 -0
- data/app/components/trek/section_component.rb +14 -0
- data/app/content/trek/content/bullet_list.rb +10 -0
- data/app/content/trek/content/document.rb +33 -0
- data/app/content/trek/content/image_block.rb +52 -0
- data/app/content/trek/content/link_resolver.rb +33 -0
- data/app/content/trek/content/list_item.rb +19 -0
- data/app/content/trek/content/ordered_list.rb +10 -0
- data/app/content/trek/content/paragraph.rb +10 -0
- data/app/content/trek/content/prompts_block.rb +22 -0
- data/app/content/trek/content.rb +32 -0
- data/app/controllers/concerns/trek/auditable.rb +103 -0
- data/app/controllers/concerns/trek/filters.rb +2 -0
- data/app/controllers/concerns/trek/passkeys.rb +37 -0
- data/app/controllers/concerns/trek/reorderable.rb +14 -3
- data/app/controllers/trek/csp_reports_controller.rb +59 -0
- data/app/controllers/trek/panels/base_controller.rb +3 -0
- data/app/controllers/trek/panels/links_controller.rb +1 -1
- data/app/controllers/trek/panels/prompts_controller.rb +1 -1
- data/app/controllers/trek/resource_controller.rb +7 -1
- data/app/helpers/trek/audit_logs_helper.rb +21 -0
- data/app/helpers/trek/thumbnail_helper.rb +11 -0
- data/app/helpers/trek/user_agents_helper.rb +36 -0
- data/app/javascript/controllers/index.js +3 -0
- data/app/javascript/controllers/passkey_controller.js +118 -0
- data/app/javascript/trek.js +4 -0
- data/app/jobs/trek/audit_log/purge_job.rb +18 -0
- data/app/jobs/trek/purge_expired_sessions_job.rb +14 -0
- data/app/jobs/trek/resolve_session_hostname_job.rb +17 -0
- data/app/models/concerns/trek/audit_log.rb +30 -0
- data/app/models/concerns/trek/contentable.rb +9 -14
- data/app/models/concerns/trek/pageable.rb +10 -1
- data/app/models/concerns/trek/users/passkeys.rb +75 -0
- data/app/models/concerns/trek/users/password_history.rb +51 -0
- data/app/models/concerns/trek/users/password_policy.rb +85 -0
- data/app/models/concerns/trek/users/password_renewal.rb +51 -0
- data/app/models/concerns/trek/users/session_lifetime.rb +39 -0
- data/app/models/concerns/trek/users/sign_in_lockout.rb +67 -0
- data/app/models/concerns/trek/users/sign_ins.rb +31 -0
- data/app/models/concerns/trek/users/validations.rb +3 -2
- data/app/models/trek/feature.rb +6 -0
- data/app/models/trek/pwned_passwords.rb +40 -0
- data/app/models/trek/user_session.rb +10 -0
- data/app/policies/trek/audit_log_policy.rb +34 -0
- data/app/policies/trek/user_policy.rb +5 -0
- data/app/validators/not_disposable_validator.rb +18 -0
- data/app/views/trek/panels/images/_form.html.slim +1 -1
- data/app/views/trek/panels/images/create.turbo_stream.slim +1 -1
- data/app/views/trek/panels/links/_form.html.slim +1 -1
- data/app/views/trek/panels/prompts/_form.html.slim +1 -1
- data/config/brakeman.ignore +22 -0
- data/config/i18n-tasks.yml +7 -0
- data/config/locales/trek.en.yml +167 -39
- data/config/locales/trek.fr.yml +168 -40
- data/docs/.vitepress/config.mjs +8 -3
- data/docs/deploy.md +2 -0
- data/docs/getting-started.md +3 -3
- data/docs/proxies.md +53 -0
- data/docs/reference/components.md +1 -0
- data/docs/reference/concerns/contentable.md +2 -1
- data/docs/reference/controllers.md +1 -1
- data/docs/reference/environment-variables.md +2 -0
- data/docs/reference/formatters.md +31 -8
- data/docs/reference/generators/admin-user.md +1 -1
- data/docs/reference/generators/audit-log.md +113 -0
- data/docs/reference/generators/install.md +12 -3
- data/docs/reference/generators/security-headers.md +109 -0
- data/docs/reference/index.md +3 -0
- data/docs/reference/models/fragment.md +1 -0
- data/docs/reference/models/tag.md +4 -2
- data/docs/reference/models/user.md +123 -3
- data/docs/reference/validators.md +94 -0
- data/docs/security.md +90 -0
- data/docs/what-is-trek.md +4 -4
- data/lefthook.yml +8 -0
- data/lib/generators/trek/helpers.rb +13 -5
- data/lib/generators/trek/install/admin/user_password_resets_generator.rb +5 -0
- data/lib/generators/trek/install/admin/user_sessions_generator.rb +5 -0
- data/lib/generators/trek/install/admin/users_generator.rb +23 -0
- data/lib/generators/trek/install/admin_generator.rb +8 -0
- data/lib/generators/trek/install/appsignal_generator.rb +1 -1
- data/lib/generators/trek/install/audit_log_generator.rb +56 -0
- data/lib/generators/trek/install/authentication_generator.rb +78 -4
- data/lib/generators/trek/install/authorization_generator.rb +1 -1
- data/lib/generators/trek/install/esbuild_generator.rb +1 -2
- data/lib/generators/trek/install/mailer_generator.rb +18 -0
- data/lib/generators/trek/install/model_specs_generator.rb +6 -4
- data/lib/generators/trek/install/postcss_generator.rb +1 -4
- data/lib/generators/trek/install/postmark_generator.rb +2 -2
- data/lib/generators/trek/install/security_headers_generator.rb +49 -0
- data/lib/generators/trek/install/specs_generator.rb +11 -0
- data/lib/generators/trek/install/user_generator.rb +1 -1
- data/lib/generators/trek/install/yarn_generator.rb +1 -1
- data/lib/generators/trek/install_generator.rb +62 -54
- data/lib/generators/trek/scaffold_generator.rb +13 -5
- data/lib/generators/trek/taxonomies_generator.rb +5 -0
- data/lib/generators/trek/templates/.gitlab-ci.yml +18 -2
- data/lib/generators/trek/templates/Makefile +1 -1
- data/lib/generators/trek/templates/controllers/admin/active_sessions_controller.rb +21 -0
- data/lib/generators/trek/templates/controllers/admin/audit_logs_controller.rb +30 -0
- data/lib/generators/trek/templates/controllers/admin/fragments_controller.rb +7 -0
- data/lib/generators/trek/templates/controllers/admin/panels/images_controller.rb +8 -0
- data/lib/generators/trek/templates/controllers/admin/panels/links_controller.rb +8 -0
- data/lib/generators/trek/templates/controllers/admin/panels/prompts_controller.rb +8 -0
- data/lib/generators/trek/templates/controllers/admin/passkey_sessions_controller.rb +41 -0
- data/lib/generators/trek/templates/controllers/admin/passkeys_controller.rb +37 -0
- data/lib/generators/trek/templates/controllers/admin/user_password_resets_controller.rb +4 -4
- data/lib/generators/trek/templates/controllers/admin/user_sessions_controller.rb +53 -4
- data/lib/generators/trek/templates/controllers/admin/users_controller.rb +20 -0
- data/lib/generators/trek/templates/controllers/concerns/trek/authentication.rb +58 -7
- data/lib/generators/trek/templates/helpers/application_helper.rb +0 -4
- data/lib/generators/trek/templates/initializers/audit_log.rb +11 -0
- data/lib/generators/trek/templates/initializers/content_security_policy.rb +49 -0
- data/lib/generators/trek/templates/initializers/permissions_policy.rb +19 -0
- data/lib/generators/trek/templates/jobs/admin/password_reset_job.rb +9 -0
- data/lib/generators/trek/templates/layouts/admin/auth.html.slim +0 -5
- data/lib/generators/trek/templates/layouts/admin.html.slim +0 -3
- data/lib/generators/trek/templates/mailers/admin/passwords_mailer.rb +1 -1
- data/lib/generators/trek/templates/mailers/admin_mailer.rb +28 -1
- data/lib/generators/trek/templates/migrations/audit_logs.rb.erb +27 -0
- data/lib/generators/trek/templates/migrations/tags.rb.erb +6 -1
- data/lib/generators/trek/templates/migrations/user_passkeys.rb.erb +24 -0
- data/lib/generators/trek/templates/migrations/user_password_renewal.rb.erb +8 -0
- data/lib/generators/trek/templates/migrations/user_previous_passwords.rb.erb +10 -0
- data/lib/generators/trek/templates/migrations/user_session_tracking.rb.erb +11 -0
- data/lib/generators/trek/templates/migrations/user_sign_in_lockout.rb.erb +7 -0
- data/lib/generators/trek/templates/migrations/user_sign_ins.rb.erb +13 -0
- data/lib/generators/trek/templates/models/audit_log.rb +3 -0
- data/lib/generators/trek/templates/models/fragment.rb +14 -0
- data/lib/generators/trek/templates/models/tag_category.rb +2 -1
- data/lib/generators/trek/templates/models/user/passkey.rb +17 -0
- data/lib/generators/trek/templates/models/user/previous_password.rb +4 -0
- data/lib/generators/trek/templates/models/user/session.rb +8 -0
- data/lib/generators/trek/templates/policies/audit_log.rb +4 -0
- data/lib/generators/trek/templates/spec/mailers/admin/passwords_mailer_spec.rb +16 -0
- data/lib/generators/trek/templates/spec/mailers/admin_mailer_spec.rb +51 -0
- data/lib/generators/trek/templates/spec/models/audit_log_spec.rb +43 -0
- data/lib/generators/trek/templates/spec/models/tag_spec.rb +52 -0
- data/lib/generators/trek/templates/spec/models/user/session_spec.rb +68 -0
- data/lib/generators/trek/templates/spec/models/user_spec.rb +142 -4
- data/lib/generators/trek/templates/spec/requests/admin/active_sessions_spec.rb +120 -0
- data/lib/generators/trek/templates/spec/requests/admin/audit_logs_spec.rb +149 -0
- data/lib/generators/trek/templates/spec/requests/admin/fragments_spec.rb +26 -2
- data/lib/generators/trek/templates/spec/requests/admin/pages_spec.rb +8 -0
- data/lib/generators/trek/templates/spec/requests/admin/panels_spec.rb +54 -0
- data/lib/generators/trek/templates/spec/requests/admin/passkey_sessions_spec.rb +103 -0
- data/lib/generators/trek/templates/spec/requests/admin/passkeys_spec.rb +104 -0
- data/lib/generators/trek/templates/spec/requests/admin/password_renewal_spec.rb +83 -0
- data/lib/generators/trek/templates/spec/requests/admin/sign_in_lockout_spec.rb +95 -0
- data/lib/generators/trek/templates/spec/requests/admin/sign_in_notices_spec.rb +95 -0
- data/lib/generators/trek/templates/spec/requests/admin/user_password_resets_spec.rb +43 -6
- data/lib/generators/trek/templates/spec/requests/admin/user_sessions_spec.rb +25 -2
- data/lib/generators/trek/templates/views/admin/audit_logs/index.html.slim +35 -0
- data/lib/generators/trek/templates/views/admin/audit_logs/show.html.slim +50 -0
- data/lib/generators/trek/templates/views/admin/fragments/index.html.slim +14 -3
- data/lib/generators/trek/templates/views/admin/user_password_resets/edit.html.slim +16 -6
- data/lib/generators/trek/templates/views/admin/user_password_resets/new.html.slim +2 -1
- data/lib/generators/trek/templates/views/admin/user_sessions/new.html.slim +27 -1
- data/lib/generators/trek/templates/views/admin/users/_passkeys.html.slim +67 -0
- data/lib/generators/trek/templates/views/admin/users/_properties.html.slim +21 -0
- data/lib/generators/trek/templates/views/admin/users/_sessions.html.slim +70 -0
- data/lib/generators/trek/templates/views/admin/users/index.html.slim +13 -0
- data/lib/generators/trek/templates/views/admin/users/show.html.slim +10 -21
- data/lib/generators/trek/templates/views/admin_mailer/new_sign_in.en.html.slim +22 -0
- data/lib/generators/trek/templates/views/admin_mailer/new_sign_in.en.text.erb +16 -0
- data/lib/generators/trek/templates/views/admin_mailer/new_sign_in.fr.html.slim +22 -0
- data/lib/generators/trek/templates/views/admin_mailer/new_sign_in.fr.text.erb +16 -0
- data/lib/generators/trek/templates/views/admin_mailer/sign_in_locked.en.html.slim +17 -0
- data/lib/generators/trek/templates/views/admin_mailer/sign_in_locked.en.text.erb +10 -0
- data/lib/generators/trek/templates/views/admin_mailer/sign_in_locked.fr.html.slim +18 -0
- data/lib/generators/trek/templates/views/admin_mailer/sign_in_locked.fr.text.erb +10 -0
- data/lib/trek/admin_ip_allowlist.rb +52 -0
- data/lib/trek/csp_reports.rb +99 -0
- data/lib/trek/data/common_passwords.txt +857 -0
- data/lib/trek/data/passkey_providers.json +404 -0
- data/lib/trek/disposable_email_domains.rb +53 -0
- data/lib/trek/engine.rb +18 -1
- data/lib/trek/passkey_providers.rb +19 -0
- data/lib/trek/reverse_dns.rb +27 -0
- data/lib/trek/saved_attachments_reload.rb +2 -1
- data/lib/trek/version.rb +1 -1
- data/lib/trek.rb +14 -1
- data/package.json +3 -5
- data/renovate.json +12 -1
- data/trek.gemspec +6 -3
- data/yarn.lock +2273 -2573
- metadata +160 -17
- data/.yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs +0 -541
- data/.yarn/releases/yarn-3.8.0.cjs +0 -875
- data/app/formatters/prosemirror_to_html/global_id_to_links_formatter.rb +0 -19
- data/app/formatters/prosemirror_to_html/nodes/image_block.rb +0 -44
- data/app/formatters/prosemirror_to_html/nodes/prompts_block.rb +0 -28
- data/app/formatters/prosemirror_to_html/remove_empty_paragraphs_formatter.rb +0 -11
- data/app/models/prosemirror.rb +0 -23
- data/lib/generators/trek/templates/models/user_session.rb +0 -3
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require "rails_helper"
|
|
2
|
+
|
|
3
|
+
RSpec.describe AdminMailer do
|
|
4
|
+
include ActionView::Helpers::DateHelper
|
|
5
|
+
|
|
6
|
+
# Not the app's default locale, so the email can't be right by chance
|
|
7
|
+
let(:locale) { (I18n.available_locales - [I18n.default_locale]).first }
|
|
8
|
+
|
|
9
|
+
it "formats the invite link's expiry in the recipient's locale" do
|
|
10
|
+
skip "the app has a single locale" unless locale
|
|
11
|
+
user = users.create(role: :editor, locale: locale)
|
|
12
|
+
expiry = I18n.with_locale(locale) { distance_of_time_in_words(0, User.token_definitions[:invite].expires_in) }
|
|
13
|
+
|
|
14
|
+
expect(described_class.invite(user).text_part.body.to_s).to include(expiry)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe "the new sign-in email" do
|
|
18
|
+
# In English whatever the app's default locale: the examples read English words
|
|
19
|
+
let(:user) { users.create(role: :editor, locale: "en") }
|
|
20
|
+
let(:mail) do
|
|
21
|
+
described_class.new_sign_in(
|
|
22
|
+
user,
|
|
23
|
+
at: Time.zone.parse("2026-10-13 08:30"),
|
|
24
|
+
ip: "203.0.113.7",
|
|
25
|
+
user_agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0"
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "tells the user which browser and address signed in" do
|
|
30
|
+
expect(mail.text_part.body.to_s).to include("Firefox on Windows").and include("203.0.113.7")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "links to the active sessions and to a password reset" do
|
|
34
|
+
expect(mail.html_part.body.to_s).to include("#sessions").and include("user_password_resets/new")
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "tells about a sign-in lock in the recipient's locale" do
|
|
39
|
+
skip "the app has a single locale" unless locale
|
|
40
|
+
user = users.create(role: :editor, locale: locale)
|
|
41
|
+
subject = I18n.with_locale(locale) { I18n.t("admin_mailer.sign_in_locked.subject") }
|
|
42
|
+
|
|
43
|
+
expect(described_class.sign_in_locked(user).subject).to eq(subject)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "links a sign-in lock to a password reset" do
|
|
47
|
+
user = users.create(role: :editor)
|
|
48
|
+
|
|
49
|
+
expect(described_class.sign_in_locked(user).text_part.body.to_s).to include("/admin/user_password_resets/new")
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require "rails_helper"
|
|
2
|
+
|
|
3
|
+
RSpec.describe AuditLog, type: :model do
|
|
4
|
+
it "lists the failures: an error status or a raised error" do
|
|
5
|
+
server_error = create_log(http_status: 500)
|
|
6
|
+
raised = create_log(error_class: "ActiveRecord::RecordNotFound")
|
|
7
|
+
create_log(http_status: 302)
|
|
8
|
+
|
|
9
|
+
expect(described_class.failures).to contain_exactly(server_error, raised)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "orders the most recent rows first" do
|
|
13
|
+
old = create_log(created_at: 2.days.ago)
|
|
14
|
+
recent = create_log(created_at: 1.day.ago)
|
|
15
|
+
|
|
16
|
+
expect(described_class.ordered).to eq([recent, old])
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "can't be changed once written" do
|
|
20
|
+
log = create_log
|
|
21
|
+
|
|
22
|
+
expect { log.update!(http_status: 200) }.to raise_error(ActiveRecord::ReadOnlyRecord)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "reads as its date, action and status" do
|
|
26
|
+
log = create_log(created_at: Time.zone.parse("2026-10-12 10:00"), http_status: 302)
|
|
27
|
+
|
|
28
|
+
expect(log.to_s).to eq("#{log.created_at.iso8601} – admin/pages#update – 302")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "purges the rows older than the retention window" do
|
|
32
|
+
create_log(created_at: (Trek::AuditLog::PurgeJob.retention + 1.day).ago)
|
|
33
|
+
recent = create_log(created_at: (Trek::AuditLog::PurgeJob.retention - 1.day).ago)
|
|
34
|
+
|
|
35
|
+
Trek::AuditLog::PurgeJob.perform_now
|
|
36
|
+
|
|
37
|
+
expect(described_class.all).to contain_exactly(recent)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def create_log(**attributes)
|
|
41
|
+
described_class.create!(action: "admin/pages#update", http_method: "PATCH", path: "/admin/pages/1", **attributes)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
require "rails_helper"
|
|
2
|
+
|
|
3
|
+
RSpec.describe Tag do
|
|
4
|
+
let(:colors) { TagCategory.create!(name: "Colors", key: "colors") }
|
|
5
|
+
let(:fruits) { TagCategory.create!(name: "Fruits", key: "fruits") }
|
|
6
|
+
|
|
7
|
+
describe "key" do
|
|
8
|
+
it "may be the same in two categories" do
|
|
9
|
+
described_class.create!(name: "Orange", key: "orange", category: colors)
|
|
10
|
+
|
|
11
|
+
expect(described_class.create(name: "Orange", key: "orange", category: fruits)).to be_persisted
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "is unique within a category" do
|
|
15
|
+
described_class.create!(name: "Orange", key: "orange", category: colors)
|
|
16
|
+
|
|
17
|
+
expect(described_class.new(name: "Orange", key: "orange", category: colors).tap(&:validate).errors.details[:key]).to include(error: :taken, value: "orange")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "is unique among the tags without a category" do
|
|
21
|
+
described_class.create!(name: "Orange", key: "orange")
|
|
22
|
+
|
|
23
|
+
expect(described_class.new(name: "Orange", key: "orange").tap(&:validate).errors.details[:key]).to include(error: :taken, value: "orange")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# The database holds the rule too, against two saves at once
|
|
27
|
+
it "is unique within a category in the database" do
|
|
28
|
+
described_class.create!(name: "Orange", key: "orange", category: colors)
|
|
29
|
+
|
|
30
|
+
expect { described_class.new(name: "Orange", key: "orange", category: colors).save!(validate: false) }.to raise_error(ActiveRecord::RecordNotUnique)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "is unique among the tags without a category in the database" do
|
|
34
|
+
described_class.create!(name: "Orange", key: "orange")
|
|
35
|
+
|
|
36
|
+
expect { described_class.new(name: "Orange", key: "orange").save!(validate: false) }.to raise_error(ActiveRecord::RecordNotUnique)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe "category" do
|
|
41
|
+
# Its tags would be left without a category, where their keys could collide
|
|
42
|
+
it "can't be deleted while it has tags" do
|
|
43
|
+
described_class.create!(name: "Orange", key: "orange", category: colors)
|
|
44
|
+
|
|
45
|
+
expect(colors.destroy).to be(false)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "can be deleted once empty" do
|
|
49
|
+
expect(colors.destroy).to be_destroyed
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require "rails_helper"
|
|
2
|
+
|
|
3
|
+
RSpec.describe User::Session do
|
|
4
|
+
include ActiveSupport::Testing::TimeHelpers
|
|
5
|
+
|
|
6
|
+
let(:user) { users.create }
|
|
7
|
+
let(:session) { user.sessions.create! }
|
|
8
|
+
|
|
9
|
+
def come_back_after(duration)
|
|
10
|
+
travel duration
|
|
11
|
+
session.record_activity
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "is active right after signing in" do
|
|
15
|
+
expect(described_class.active).to include(session)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "expires after idle_timeout without a request" do
|
|
19
|
+
session
|
|
20
|
+
travel described_class.idle_timeout + 1.minute
|
|
21
|
+
|
|
22
|
+
expect(session.reload).to be_expired
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "stays active while requests come in, until its lifetime" do
|
|
26
|
+
session
|
|
27
|
+
5.times { come_back_after(described_class.idle_timeout - 1.hour) }
|
|
28
|
+
|
|
29
|
+
expect(session.reload).not_to be_expired
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "expires after its lifetime, even when in use" do
|
|
33
|
+
session
|
|
34
|
+
travel_to (described_class.lifetime + 1.day).from_now do
|
|
35
|
+
session.record_activity
|
|
36
|
+
|
|
37
|
+
expect(session).to be_expired
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "records a request without touching updated_at" do
|
|
42
|
+
session
|
|
43
|
+
travel 1.hour
|
|
44
|
+
|
|
45
|
+
expect { session.record_activity }.not_to(change { session.reload.updated_at })
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "records a request at most once every activity_interval" do
|
|
49
|
+
session
|
|
50
|
+
travel 1.minute
|
|
51
|
+
|
|
52
|
+
expect { session.record_activity }.not_to(change { session.reload.last_activity_at })
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "purges the expired sessions" do
|
|
56
|
+
old = user.sessions.create!(created_at: 1.year.ago, last_activity_at: 1.year.ago)
|
|
57
|
+
|
|
58
|
+
Trek::PurgeExpiredSessionsJob.perform_now
|
|
59
|
+
|
|
60
|
+
expect(described_class.where(id: [old.id, session.id]).pluck(:id)).to eq([session.id])
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "lists the expired sessions, for the purge" do
|
|
64
|
+
old = user.sessions.create!(created_at: 1.year.ago, last_activity_at: 1.year.ago)
|
|
65
|
+
|
|
66
|
+
expect(described_class.expired).to contain_exactly(old)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -47,15 +47,15 @@ RSpec.describe User do
|
|
|
47
47
|
expect(user).to be_invalid
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
-
it "requires a password of at least
|
|
51
|
-
user.password = "
|
|
50
|
+
it "requires a password of at least 12 characters on creation" do
|
|
51
|
+
user.password = "Sh0rt-but-1"
|
|
52
52
|
|
|
53
53
|
expect(user).to be_invalid
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
-
it "requires a password of at least
|
|
56
|
+
it "requires a password of at least 12 characters when changing it" do
|
|
57
57
|
user = users.create
|
|
58
|
-
user.password = "
|
|
58
|
+
user.password = "Sh0rt-but-1"
|
|
59
59
|
|
|
60
60
|
expect(user).to be_invalid
|
|
61
61
|
end
|
|
@@ -68,6 +68,144 @@ RSpec.describe User do
|
|
|
68
68
|
end
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
+
describe "previous passwords" do
|
|
72
|
+
let(:user) { users.create }
|
|
73
|
+
|
|
74
|
+
it "refuses the current password" do
|
|
75
|
+
user.password = users.password
|
|
76
|
+
|
|
77
|
+
expect(user).to be_invalid
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "refuses one of the last passwords" do
|
|
81
|
+
%w[second-password-2! third-password-3! fourth-password-4! fifth-password-5!].each { |password| user.update!(password:) }
|
|
82
|
+
user.password = users.password
|
|
83
|
+
|
|
84
|
+
expect(user).to be_invalid
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "accepts a password older than the last ones" do
|
|
88
|
+
%w[second-password-2! third-password-3! fourth-password-4! fifth-password-5! sixth-password-6!].each { |password| user.update!(password:) }
|
|
89
|
+
user.password = users.password
|
|
90
|
+
|
|
91
|
+
expect(user).to be_valid
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "keeps no more digests than needed" do
|
|
95
|
+
%w[second-password-2! third-password-3! fourth-password-4! fifth-password-5! sixth-password-6!].each { |password| user.update!(password:) }
|
|
96
|
+
|
|
97
|
+
expect(user.previous_passwords.count).to eq(described_class.password_history_size - 1)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it "deletes the digests with the user" do
|
|
101
|
+
user.update!(password: "second-password-2!")
|
|
102
|
+
|
|
103
|
+
expect { user.destroy }.to change(User::PreviousPassword, :count).by(-1)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
describe "sign-in lockout" do
|
|
108
|
+
include ActiveSupport::Testing::TimeHelpers
|
|
109
|
+
|
|
110
|
+
let(:user) { users.create }
|
|
111
|
+
|
|
112
|
+
def fail_sign_ins(count)
|
|
113
|
+
count.times { user.record_failed_sign_in! }
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Each failure once the previous lock is over, as while locked they don't count
|
|
117
|
+
def fail_sign_ins_after_locks(count)
|
|
118
|
+
count.times do
|
|
119
|
+
travel_to(user.sign_in_locked_until + 1.second) if user.sign_in_locked?
|
|
120
|
+
user.record_failed_sign_in!
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
it "locks signing in after the failures allowed" do
|
|
125
|
+
fail_sign_ins(described_class.sign_in_lockout_after)
|
|
126
|
+
|
|
127
|
+
expect(user.sign_in_locked_until).to be_within(1.second).of(described_class.sign_in_lockout_duration.from_now)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
it "doesn't lock before" do
|
|
131
|
+
fail_sign_ins(described_class.sign_in_lockout_after - 1)
|
|
132
|
+
|
|
133
|
+
expect(user.sign_in_locked?).to be(false)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it "doubles the lock on each further failure" do
|
|
137
|
+
fail_sign_ins_after_locks(described_class.sign_in_lockout_after + 2)
|
|
138
|
+
|
|
139
|
+
expect(user.sign_in_locked_until).to be_within(1.second).of((described_class.sign_in_lockout_duration * 4).from_now)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
it "never locks for longer than the maximum" do
|
|
143
|
+
fail_sign_ins_after_locks(described_class.sign_in_lockout_after + 30)
|
|
144
|
+
|
|
145
|
+
expect(user.sign_in_locked_until).to be_within(1.second).of(described_class.sign_in_lockout_max.from_now)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
it "doesn't count failures while locked" do
|
|
149
|
+
fail_sign_ins(described_class.sign_in_lockout_after + 3)
|
|
150
|
+
|
|
151
|
+
expect(user.failed_sign_in_count).to eq(described_class.sign_in_lockout_after)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
it "unlocks with a new password" do
|
|
155
|
+
fail_sign_ins(described_class.sign_in_lockout_after)
|
|
156
|
+
|
|
157
|
+
user.update!(password: "second-password-2!")
|
|
158
|
+
|
|
159
|
+
expect([user.sign_in_locked?, user.failed_sign_in_count]).to eq([false, 0])
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it "starts the count over after a successful sign-in" do
|
|
163
|
+
fail_sign_ins(described_class.sign_in_lockout_after - 1)
|
|
164
|
+
|
|
165
|
+
user.record_successful_sign_in!
|
|
166
|
+
|
|
167
|
+
expect(user.reload.failed_sign_in_count).to eq(0)
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
describe "password policy" do
|
|
172
|
+
def password_errors(password, **attributes)
|
|
173
|
+
users.new(password:, **attributes).tap(&:validate).errors.details[:password].pluck(:error)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
it "accepts a short password with a digit and a symbol" do
|
|
177
|
+
expect(password_errors("Brume-de-l1n")).to be_empty
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
it "requires a digit and a symbol in a password shorter than a passphrase" do
|
|
181
|
+
expect(password_errors("brumedelinxyz")).to include(:digit_and_symbol)
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
it "accepts a long passphrase made of letters only" do
|
|
185
|
+
expect(password_errors("velo orange sous la pluie")).to be_empty
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
it "refuses a common password, whatever its case and punctuation" do
|
|
189
|
+
expect(password_errors("Password123!")).to include(:common)
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
it "refuses a password built on a keyboard or number sequence" do
|
|
193
|
+
expect(password_errors("Azerty-2026!x")).to include(:sequence)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
it "refuses a password repeating a character" do
|
|
197
|
+
expect(password_errors("Gaaaaa-2026!x")).to include(:sequence)
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
it "refuses a password containing the user's email" do
|
|
201
|
+
expect(password_errors("Lovelace-1815!", email: "ada.lovelace@example.com")).to include(:personal)
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
it "refuses a password containing the user's name" do
|
|
205
|
+
expect(password_errors("Byron-1815!xyz", name: "Ada Byron")).to include(:personal)
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
|
|
71
209
|
describe "email" do
|
|
72
210
|
it "is stored in lower case, without surrounding spaces" do
|
|
73
211
|
expect(users.create(email: " Ada@Example.com ").email).to eq("ada@example.com")
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
require "rails_helper"
|
|
2
|
+
|
|
3
|
+
RSpec.describe "Admin active sessions", type: :request do
|
|
4
|
+
include ActiveSupport::Testing::TimeHelpers
|
|
5
|
+
|
|
6
|
+
let(:editor) { users.create(role: :editor) }
|
|
7
|
+
let(:safari) { "Mozilla/5.0 (Macintosh; Intel Mac OS X 14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Safari/605.1.15" }
|
|
8
|
+
let(:firefox) { "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0" }
|
|
9
|
+
|
|
10
|
+
def sign_in(user)
|
|
11
|
+
post admin_user_session_path, params: { email: user.email, password: users.password }, headers: { "User-Agent" => safari }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def come_back_after(duration)
|
|
15
|
+
travel duration
|
|
16
|
+
get admin_root_path
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "looks the host name of the address up after signing in, not during it" do
|
|
20
|
+
expect { sign_in(editor) }.to have_enqueued_job(Trek::ResolveSessionHostnameJob)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "records the host name of the address signing in" do
|
|
24
|
+
allow(Trek::ReverseDns).to receive(:hostname).and_return("host.example.net")
|
|
25
|
+
|
|
26
|
+
perform_enqueued_jobs { sign_in(editor) }
|
|
27
|
+
|
|
28
|
+
expect(editor.sessions.last.ip_hostname).to eq("host.example.net")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe "expiry" do
|
|
32
|
+
it "signs the user out after idle_timeout without a request" do
|
|
33
|
+
sign_in(editor)
|
|
34
|
+
travel User::Session.idle_timeout + 1.minute
|
|
35
|
+
|
|
36
|
+
get admin_root_path
|
|
37
|
+
|
|
38
|
+
expect(response).to redirect_to(new_admin_user_session_path)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "keeps the user signed in while requests come in" do
|
|
42
|
+
sign_in(editor)
|
|
43
|
+
come_back_after(User::Session.idle_timeout - 1.hour)
|
|
44
|
+
|
|
45
|
+
come_back_after(User::Session.idle_timeout - 1.hour)
|
|
46
|
+
|
|
47
|
+
expect(response).to have_http_status(:ok)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "records the activity at most once every activity_interval" do
|
|
51
|
+
sign_in(editor)
|
|
52
|
+
get admin_root_path
|
|
53
|
+
travel 1.minute
|
|
54
|
+
|
|
55
|
+
expect { get admin_root_path }.not_to(change { editor.reload.last_activity_at })
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe "the sessions tab of the user's profile" do
|
|
60
|
+
let!(:other_session) { editor.sessions.create!(user_agent: firefox, ip_address: "203.0.113.7") }
|
|
61
|
+
|
|
62
|
+
before { sign_in(editor) }
|
|
63
|
+
|
|
64
|
+
it "lists the user's sessions with their browser and IP address" do
|
|
65
|
+
editor.update!(locale: "en") # the browsers' descriptions are in English
|
|
66
|
+
get admin_user_path(editor)
|
|
67
|
+
|
|
68
|
+
expect(response.body).to include("Safari on macOS").and include("Firefox on Windows").and include("203.0.113.7")
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "shows an IP address's host name on hover" do
|
|
72
|
+
other_session.update!(ip_hostname: "host.example.net")
|
|
73
|
+
|
|
74
|
+
get admin_user_path(editor)
|
|
75
|
+
|
|
76
|
+
expect(response.body).to include('<abbr title="host.example.net">203.0.113.7</abbr>')
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "leaves out other users' sessions" do
|
|
80
|
+
users.create(role: :editor).sessions.create!(user_agent: firefox, ip_address: "198.51.100.9")
|
|
81
|
+
|
|
82
|
+
get admin_user_path(editor)
|
|
83
|
+
|
|
84
|
+
expect(response.body).not_to include("198.51.100.9")
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "signs another session out" do
|
|
88
|
+
expect { delete admin_active_session_path(other_session) }.to change(User::Session, :count).by(-1)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "goes back to the sessions tab" do
|
|
92
|
+
delete admin_active_session_path(other_session)
|
|
93
|
+
|
|
94
|
+
expect(response).to redirect_to(admin_user_path(editor, anchor: "sessions"))
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "doesn't sign out another user's session" do
|
|
98
|
+
stranger = users.create(role: :editor).sessions.create!
|
|
99
|
+
|
|
100
|
+
delete admin_active_session_path(stranger)
|
|
101
|
+
|
|
102
|
+
expect(User::Session.exists?(stranger.id)).to be(true)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "signs out every other session, and keeps this one" do
|
|
106
|
+
delete others_admin_active_sessions_path
|
|
107
|
+
get admin_root_path
|
|
108
|
+
|
|
109
|
+
expect([editor.sessions.count, response.status]).to eq([1, 200])
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "shows no sessions tab on another user's profile" do
|
|
114
|
+
sign_in(users.create(role: :admin))
|
|
115
|
+
|
|
116
|
+
get admin_user_path(editor)
|
|
117
|
+
|
|
118
|
+
expect(response.body).not_to include('href="#sessions"')
|
|
119
|
+
end
|
|
120
|
+
end
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
require "rails_helper"
|
|
2
|
+
|
|
3
|
+
RSpec.describe "Admin audit log", type: :request do
|
|
4
|
+
let(:admin) { users.create(role: :admin) }
|
|
5
|
+
|
|
6
|
+
before { seed "cases/page_tree" }
|
|
7
|
+
|
|
8
|
+
def sign_in(user)
|
|
9
|
+
post admin_user_session_path, params: { email: user.email, password: users.password }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe "recording" do
|
|
13
|
+
before { sign_in(admin) }
|
|
14
|
+
|
|
15
|
+
it "records a change with its author, request, target and status" do
|
|
16
|
+
patch admin_page_path(pages.team), params: { page: { title: "The team" } }
|
|
17
|
+
|
|
18
|
+
expect(AuditLog.recent.first).to have_attributes(
|
|
19
|
+
actor: admin, action: "admin/pages#update", http_method: "PATCH", path: admin_page_path(pages.team),
|
|
20
|
+
auditable: pages.team, http_status: 302, error_class: nil
|
|
21
|
+
)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "records the parameters by name, without the values the form sent" do
|
|
25
|
+
patch admin_page_path(pages.team), params: { page: { title: "The team" } }
|
|
26
|
+
|
|
27
|
+
expect(AuditLog.recent.first.params).to include("id" => pages.team.id.to_s, "page" => { "title" => "[FILTERED]" })
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "records the value of a role change" do
|
|
31
|
+
editor = users.create(role: :editor)
|
|
32
|
+
|
|
33
|
+
patch admin_user_path(editor), params: { user: { role: "admin" } }
|
|
34
|
+
|
|
35
|
+
expect(AuditLog.recent.first.params).to include("user" => { "role" => "admin" })
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "records a deleted record as the target" do
|
|
39
|
+
page = pages.team
|
|
40
|
+
|
|
41
|
+
delete admin_page_path(page)
|
|
42
|
+
|
|
43
|
+
expect(AuditLog.recent.first).to have_attributes(auditable_type: "Page", auditable_id: page.id)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "records the error a failed request raised" do
|
|
47
|
+
patch admin_page_path(id: 0), params: { page: { title: "Missing" } }
|
|
48
|
+
|
|
49
|
+
expect(AuditLog.recent.first).to have_attributes(error_class: "ActiveRecord::RecordNotFound", http_status: nil)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "records nothing for a read" do
|
|
53
|
+
expect { get admin_pages_path }.not_to change(AuditLog, :count)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "records nothing for a HEAD request either" do
|
|
57
|
+
expect { head admin_pages_path }.not_to change(AuditLog, :count)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "records nothing when switched off with FEATURE_AUDIT_LOG=false" do
|
|
61
|
+
allow(ENV).to receive(:fetch).and_call_original
|
|
62
|
+
allow(ENV).to receive(:fetch).with("FEATURE_AUDIT_LOG", "true").and_return("false")
|
|
63
|
+
|
|
64
|
+
expect { patch admin_page_path(pages.team), params: { page: { title: "The team" } } }
|
|
65
|
+
.not_to change(AuditLog, :count)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
context "when the row can't be written" do
|
|
69
|
+
before do
|
|
70
|
+
allow(AuditLog).to receive(:create!).and_raise(ActiveRecord::StatementInvalid)
|
|
71
|
+
allow(Rails.error).to receive(:report)
|
|
72
|
+
patch admin_page_path(pages.team), params: { page: { title: "The team" } }
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "still completes the request" do
|
|
76
|
+
expect(pages.team.reload.title).to eq("The team")
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "reports the failure" do
|
|
80
|
+
expect(Rails.error).to have_received(:report).with(an_instance_of(ActiveRecord::StatementInvalid), anything)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
describe "recording sign-ins" do
|
|
86
|
+
it "records a failed sign-in, without its password" do
|
|
87
|
+
post admin_user_session_path, params: { email: admin.email, password: "wrong" }
|
|
88
|
+
|
|
89
|
+
expect(AuditLog.recent.first).to have_attributes(
|
|
90
|
+
actor: nil, action: "admin/user_sessions#create", params: hash_including("password" => "[FILTERED]")
|
|
91
|
+
)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "records a failed sign-in as a failure, on the account tried" do
|
|
95
|
+
post admin_user_session_path, params: { email: admin.email, password: "wrong" }
|
|
96
|
+
|
|
97
|
+
expect(AuditLog.failures.for_auditable(admin)).to exist
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it "records a change attempted without signing in" do
|
|
101
|
+
patch admin_page_path(pages.team), params: { page: { title: "Hacked" } }
|
|
102
|
+
|
|
103
|
+
expect(AuditLog.recent.first).to have_attributes(actor: nil, action: "admin/pages#update", http_status: 302)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
describe "listing" do
|
|
108
|
+
before { sign_in(admin) }
|
|
109
|
+
|
|
110
|
+
it "lists the rows" do
|
|
111
|
+
get admin_audit_logs_path
|
|
112
|
+
|
|
113
|
+
expect(response.body).to include("admin/user_sessions#create")
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it "filters the rows on a record", :aggregate_failures do
|
|
117
|
+
AuditLog.create!(action: "admin/pages#update", http_method: "PATCH", path: "/", auditable: pages.team)
|
|
118
|
+
AuditLog.create!(action: "admin/pages#destroy", http_method: "DELETE", path: "/", auditable: pages.company)
|
|
119
|
+
|
|
120
|
+
get admin_audit_logs_path(filters: { auditable_type: "Page", auditable_id: pages.team.id })
|
|
121
|
+
|
|
122
|
+
expect(response.body).to include("admin/pages#update")
|
|
123
|
+
expect(response.body).not_to include("admin/pages#destroy")
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it "lists the failures only", :aggregate_failures do
|
|
127
|
+
AuditLog.create!(action: "admin/pages#update", http_method: "PATCH", path: "/", http_status: 422)
|
|
128
|
+
|
|
129
|
+
get admin_audit_logs_path(scopes: { failures: 1 })
|
|
130
|
+
|
|
131
|
+
expect(response.body).to include("admin/pages#update")
|
|
132
|
+
expect(response.body).not_to include("admin/user_sessions#create")
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it "shows a row" do
|
|
136
|
+
get admin_audit_log_path(AuditLog.recent.first)
|
|
137
|
+
|
|
138
|
+
expect(response.body).to include("admin/user_sessions#create")
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
it "is closed to an editor" do
|
|
143
|
+
sign_in(users.create(role: :editor))
|
|
144
|
+
|
|
145
|
+
get admin_audit_logs_path
|
|
146
|
+
|
|
147
|
+
expect(response).to redirect_to(admin_root_path)
|
|
148
|
+
end
|
|
149
|
+
end
|
|
@@ -8,10 +8,34 @@ RSpec.describe "Admin fragments", type: :request do
|
|
|
8
8
|
post admin_user_session_path, params: { email: editor.email, password: users.password }
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
it "lists the fragments" do
|
|
11
|
+
it "lists the fragments with their key and an excerpt of their content" do
|
|
12
|
+
footer.update!(content: { type: "doc", content: [{ type: "paragraph", content: [{ type: "text", text: "All rights reserved" }] }] })
|
|
13
|
+
|
|
12
14
|
get admin_fragments_path
|
|
13
15
|
|
|
14
|
-
expect(response.body).to include("footer")
|
|
16
|
+
expect(response.body).to include("Footer", "<code>layout.footer</code>", "All rights reserved")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe "searching" do
|
|
20
|
+
before do
|
|
21
|
+
footer.update!(content: { type: "doc", content: [{ type: "paragraph", content: [{ type: "text", text: "All rights reserved" }] }] })
|
|
22
|
+
fragments.create(key: "tagline", namespace: "home", title: "Tagline")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "finds fragments by key, title or content text", :aggregate_failures do
|
|
26
|
+
["layout.foot", "FOOTER", "rights"].each do |search|
|
|
27
|
+
get admin_fragments_path(search:)
|
|
28
|
+
|
|
29
|
+
expect(response.body).to include("layout.footer")
|
|
30
|
+
expect(response.body).not_to include("home.tagline")
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "ignores the content's structure" do
|
|
35
|
+
get admin_fragments_path(search: "paragraph")
|
|
36
|
+
|
|
37
|
+
expect(response.body).not_to include("layout.footer")
|
|
38
|
+
end
|
|
15
39
|
end
|
|
16
40
|
|
|
17
41
|
it "renders the new fragment form" do
|