discourse/spec/models/sidebar_url_spec.rb
Krzysztof Kotlarek c86d772277
FIX: Drop internal URL validation for paths in sidebar (#20891)
`Rails.application.routes.recognize_path(value)` was not working for /admin paths because StaffConstraint.new requires user to check permission.

This validation is not bringing much value, and the easiest way is to drop it. In the worse case scenario, a user will have an incorrect link in their sidebar.

Bug reported: https://meta.discourse.org/t/custom-sidebar-sections-being-tested-on-meta/255303/66
2023-03-31 13:26:56 +08:00

41 lines
989 B
Ruby

# frozen_string_literal: true
RSpec.describe SidebarUrl do
it "validates external URLs" do
expect(
SidebarUrl.new(
icon: "link",
name: "external",
value: "https://www.test.com/discourse-test",
).valid?,
).to eq(true)
end
it "sets external flag" do
expect(
SidebarUrl.create!(icon: "link", name: "categories", value: "/categories").external,
).to be false
expect(
SidebarUrl.create!(
icon: "link",
name: "categories",
value: "http://#{Discourse.current_hostname}/categories",
).external,
).to be false
expect(
SidebarUrl.create!(
icon: "link",
name: "categories",
value: "https://#{Discourse.current_hostname}/categories",
).external,
).to be false
expect(
SidebarUrl.create!(
icon: "link",
name: "categories",
value: "https://www.test.com/discourse-test",
).external,
).to be true
end
end