Merge pull request #17366 from Aaron-212/disable-osdn-url

Audit: disable OSDN urls
This commit is contained in:
Mike McQuaid 2024-05-27 08:19:57 +01:00 committed by GitHub
commit 91affd113e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 21 deletions

View File

@ -324,13 +324,18 @@ module Cask
return if block_url_offline?
odebug "Auditing URL format"
if bad_sourceforge_url?
add_error "SourceForge URL format incorrect. See #{Formatter.url(SOURCEFORGE_OSDN_REFERENCE_URL)}",
location: cask.url.location
elsif bad_osdn_url?
add_error "OSDN URL format incorrect. See #{Formatter.url(SOURCEFORGE_OSDN_REFERENCE_URL)}",
location: cask.url.location
end
return unless bad_sourceforge_url?
add_error "SourceForge URL format incorrect. See #{Formatter.url(SOURCEFORGE_OSDN_REFERENCE_URL)}",
location: cask.url.location
end
def audit_download_url_is_osdn
return unless cask.url
return if block_url_offline?
return unless bad_osdn_url?
add_error "OSDN download urls are disabled.", location: cask.url.location, strict_only: true
end
VERIFIED_URL_REFERENCE_URL = "https://docs.brew.sh/Cask-Cookbook#when-url-and-homepage-domains-differ-add-verified"
@ -895,7 +900,7 @@ module Cask
sig { returns(T::Boolean) }
def bad_osdn_url?
bad_url_format?(/osd/, [%r{\Ahttps?://([^/]+.)?dl\.osdn\.jp/}])
domain.match?(%r{^(?:\w+\.)*osdn\.jp(?=/|$)})
end
# sig { returns(String) }

View File

@ -932,17 +932,21 @@ RSpec.describe Cask::Audit, :cask do
it { is_expected.not_to error_with(message) }
end
end
context "with incorrect OSDN URL format" do
let(:cask_token) { "osdn-incorrect-url-format" }
describe "disable OSDN download url" do
let(:only) { ["download_url_is_osdn"] }
let(:message) { /OSDN download urls are disabled./ }
let(:cask_token) { "osdn-urls" }
it { is_expected.to error_with(message) }
context "when --strict is not passed" do
it { is_expected.not_to error_with(message) }
end
context "with correct OSDN URL format" do
let(:cask_token) { "osdn-correct-url-format" }
context "when --strict is passed" do
let(:strict) { true }
it { is_expected.not_to error_with(message) }
it { is_expected.to error_with(message) }
end
end

View File

@ -1,6 +0,0 @@
cask "osdn-incorrect-url-format" do
version "1.2.3"
url "https://osdn.jp/projects/something/files/Something-1.2.3.dmg/download"
homepage "https://osdn.jp/projects/something/"
end

View File

@ -1,4 +1,4 @@
cask "osdn-correct-url-format" do
cask "osdn-urls" do
version "1.2.3"
url "https://user.dl.osdn.jp/something/id/Something-1.2.3.dmg"