Skip to content

Commit

Permalink
Disallow pushing of gems with unresolved dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuanchiliao1 committed Dec 20, 2024
1 parent c31f920 commit 8efa0a9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/models/pusher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def process
authorize &&
verify_gem_scope &&
verify_mfa_requirement &&
verify_dependencies_resolvable &&
validate &&
save
end
Expand All @@ -46,6 +47,20 @@ def verify_mfa_requirement
notify("Rubygem requires owners to enable MFA. You must enable MFA before pushing new version.", 403)
end

def verify_dependencies_resolvable
return true if spec.dependencies.empty?

dependency_names = spec.dependencies.map(&:name)
existing_gems = Rubygem.where(name: dependency_names).pluck(:name)
missing_gems = dependency_names - existing_gems

if missing_gems.any?
return notify("There was a problem saving your gem: \nThe following dependencies don't exist: #{missing_gems.join(', ')}", 422)
end

true
end

def validate
unless validate_signature_exists?
return notify("There was a problem saving your gem: \nYou have added cert_chain in gemspec but signature was empty", 403)
Expand Down

0 comments on commit 8efa0a9

Please sign in to comment.