2023-03-04 22:23:32 +00:00
|
|
|
# typed: false
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "rubocops/rubocop-cask"
|
|
|
|
require "test/rubocops/cask/shared_examples/cask_cop"
|
|
|
|
|
|
|
|
describe RuboCop::Cop::Cask::Url do
|
|
|
|
include CaskCop
|
|
|
|
|
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
|
|
|
context "when url 'verified' value does not start with a protocol" do
|
|
|
|
let(:source) do
|
|
|
|
<<~CASK
|
|
|
|
cask "foo" do
|
|
|
|
url "https://example.com/download/foo-v1.2.0.dmg",
|
2023-04-02 19:39:23 +01:00
|
|
|
verified: "example.com/download/"
|
2023-03-04 22:23:32 +00:00
|
|
|
end
|
|
|
|
CASK
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples "does not report any offenses"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when url 'verified' value starts with a protocol" do
|
|
|
|
let(:source) do
|
|
|
|
<<~CASK
|
|
|
|
cask "foo" do
|
|
|
|
url "https://example.com/download/foo-v1.2.0.dmg",
|
2023-04-02 19:39:23 +01:00
|
|
|
verified: "https://example.com/download/"
|
2023-03-04 22:23:32 +00:00
|
|
|
end
|
|
|
|
CASK
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:expected_offenses) do
|
|
|
|
[{
|
|
|
|
message: "Verified URL parameter value should not start with https:// or http://.",
|
|
|
|
severity: :convention,
|
|
|
|
line: 3,
|
2023-04-02 16:38:33 +01:00
|
|
|
column: 16,
|
2023-04-02 19:39:23 +01:00
|
|
|
source: "\"https://example.com/download/\"",
|
2023-03-04 22:23:32 +00:00
|
|
|
}]
|
|
|
|
end
|
|
|
|
|
2023-03-05 17:08:43 +00:00
|
|
|
let(:correct_source) do
|
|
|
|
<<~CASK
|
|
|
|
cask "foo" do
|
|
|
|
url "https://example.com/download/foo-v1.2.0.dmg",
|
2023-04-02 19:39:23 +01:00
|
|
|
verified: "example.com/download/"
|
|
|
|
end
|
|
|
|
CASK
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples "reports offenses"
|
|
|
|
include_examples "autocorrects source"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when url 'verified' value does not have a path component" do
|
|
|
|
context "when the URL ends with a slash" do
|
|
|
|
let(:source) do
|
|
|
|
<<~CASK
|
|
|
|
cask "foo" do
|
|
|
|
url "https://example.org/",
|
|
|
|
verified: "example.org/"
|
|
|
|
end
|
|
|
|
CASK
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples "does not report any offenses"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the URL does not end with a slash" do
|
|
|
|
let(:source) do
|
|
|
|
<<~CASK
|
|
|
|
cask "foo" do
|
|
|
|
url "https://example.org/",
|
|
|
|
verified: "example.org"
|
|
|
|
end
|
|
|
|
CASK
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:expected_offenses) do
|
|
|
|
[{
|
|
|
|
message: "Verified URL parameter value should end with a /.",
|
|
|
|
severity: :convention,
|
|
|
|
line: 3,
|
|
|
|
column: 16,
|
|
|
|
source: "\"example.org\"",
|
|
|
|
}]
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:correct_source) do
|
|
|
|
<<~CASK
|
|
|
|
cask "foo" do
|
|
|
|
url "https://example.org/",
|
|
|
|
verified: "example.org/"
|
|
|
|
end
|
|
|
|
CASK
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples "reports offenses"
|
|
|
|
include_examples "autocorrects source"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the URL does not end with a slash" do
|
|
|
|
let(:source) do
|
|
|
|
<<~CASK
|
|
|
|
cask "foo" do
|
|
|
|
url "https://github.com/Foo",
|
|
|
|
verified: "github.com/Foo"
|
|
|
|
end
|
|
|
|
CASK
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples "does not report any offenses"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the url ends with a / and the verified value does too" do
|
|
|
|
let(:source) do
|
|
|
|
<<~CASK
|
|
|
|
cask "foo" do
|
|
|
|
url "https://github.com/",
|
|
|
|
verified: "github.com/"
|
|
|
|
end
|
|
|
|
CASK
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples "does not report any offenses"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the url ends with a / and the verified value does not" do
|
|
|
|
let(:source) do
|
|
|
|
<<~CASK
|
|
|
|
cask "foo" do
|
|
|
|
url "https://github.com/",
|
|
|
|
verified: "github.com"
|
|
|
|
end
|
|
|
|
CASK
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:expected_offenses) do
|
|
|
|
[{
|
|
|
|
message: "Verified URL parameter value should end with a /.",
|
|
|
|
severity: :convention,
|
|
|
|
line: 3,
|
|
|
|
column: 16,
|
|
|
|
source: "\"github.com\"",
|
|
|
|
}]
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:correct_source) do
|
|
|
|
<<~CASK
|
|
|
|
cask "foo" do
|
|
|
|
url "https://github.com/",
|
|
|
|
verified: "github.com/"
|
2023-03-05 17:08:43 +00:00
|
|
|
end
|
|
|
|
CASK
|
|
|
|
end
|
|
|
|
|
2023-03-04 22:23:32 +00:00
|
|
|
include_examples "reports offenses"
|
2023-03-05 17:08:43 +00:00
|
|
|
include_examples "autocorrects source"
|
2023-03-04 22:23:32 +00:00
|
|
|
end
|
2023-04-02 15:29:17 +01:00
|
|
|
|
|
|
|
context "when url 'verified' value has a path component that ends with a /" do
|
|
|
|
let(:source) do
|
|
|
|
<<~CASK
|
|
|
|
cask "foo" do
|
2023-04-02 19:39:23 +01:00
|
|
|
url "https://github.com/Foo/foo/releases/download/v1.2.0/foo-v1.2.0.dmg",
|
|
|
|
verified: "github.com/Foo/foo/"
|
2023-04-02 15:29:17 +01:00
|
|
|
end
|
|
|
|
CASK
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples "does not report any offenses"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the url 'verified' value has a path component that doesn't end with a /" do
|
|
|
|
let(:source) do
|
|
|
|
<<~CASK
|
|
|
|
cask "foo" do
|
2023-04-02 19:39:23 +01:00
|
|
|
url "https://github.com/Foo/foo/releases/download/v1.2.0/foo-v1.2.0.dmg",
|
|
|
|
verified: "github.com/Foo/foo"
|
2023-04-02 15:29:17 +01:00
|
|
|
end
|
|
|
|
CASK
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:expected_offenses) do
|
|
|
|
[{
|
|
|
|
message: "Verified URL parameter value should end with a /.",
|
|
|
|
severity: :convention,
|
|
|
|
line: 3,
|
2023-04-02 16:38:33 +01:00
|
|
|
column: 16,
|
2023-04-02 19:39:23 +01:00
|
|
|
source: "\"github.com/Foo/foo\"",
|
2023-04-02 15:29:17 +01:00
|
|
|
}]
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:correct_source) do
|
|
|
|
<<~CASK
|
|
|
|
cask "foo" do
|
2023-04-02 19:39:23 +01:00
|
|
|
url "https://github.com/Foo/foo/releases/download/v1.2.0/foo-v1.2.0.dmg",
|
|
|
|
verified: "github.com/Foo/foo/"
|
2023-04-02 15:29:17 +01:00
|
|
|
end
|
|
|
|
CASK
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples "reports offenses"
|
|
|
|
include_examples "autocorrects source"
|
|
|
|
end
|
2023-03-04 22:23:32 +00:00
|
|
|
end
|