Skip to content

Commit

Permalink
Merge pull request #17366 from Aaron-212/disable-osdn-url
Browse files Browse the repository at this point in the history
Audit: disable OSDN urls
  • Loading branch information
MikeMcQuaid committed May 27, 2024
2 parents 9fdb0d5 + ed73551 commit 91affd1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
21 changes: 13 additions & 8 deletions Library/Homebrew/cask/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,18 @@ def audit_download_url_format
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"
Expand Down Expand Up @@ -895,7 +900,7 @@ def bad_sourceforge_url?

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) }
Expand Down
16 changes: 10 additions & 6 deletions Library/Homebrew/test/cask/audit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -932,17 +932,21 @@ def tmp_cask(name, text)

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

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 91affd1

Please sign in to comment.