Skip to content

Commit

Permalink
Fix creating rubygem trusted publisher when gh action exists (#4282)
Browse files Browse the repository at this point in the history
Fix is removing repository_owner_id from search params
  • Loading branch information
segiddins authored Dec 11, 2023
1 parent 2cf9d88 commit fdbbcb5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/models/oidc/trusted_publisher/github_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ def self.permitted_attributes
end

def self.build_trusted_publisher(params)
params.delete(:environment) if params[:environment].blank?
params = params.reverse_merge(repository_owner_id: nil, repository_name: nil, workflow_filename: nil, environment: nil)
params.delete(:environment) if params[:environment].blank?
params.delete(:repository_owner_id)
find_or_initialize_by(params)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,25 @@ class OIDC::RubygemTrustedPublishersControllerTest < ActionDispatch::Integration
assert_redirected_to rubygem_trusted_publishers_url(@rubygem.slug)
end

should "create rubygem trusted publisher when trusted publisher already exists" do
stub_request(:get, "https://api.github.com/users/example")
.to_return(status: 200, body: { id: "123456" }.to_json, headers: { "Content-Type" => "application/json" })

github_action_trusted_publisher = create(:oidc_trusted_publisher_github_action)

assert_difference("OIDC::RubygemTrustedPublisher.count") do
post rubygem_trusted_publishers_url(@rubygem.slug), params: {
oidc_rubygem_trusted_publisher: {
trusted_publisher_type: github_action_trusted_publisher.class.polymorphic_name,
trusted_publisher_attributes: github_action_trusted_publisher.as_json
.slice("workflow_filename", "repository_owner", "repository_name").merge("environment" => "")
}
}
end

assert_redirected_to rubygem_trusted_publishers_url(@rubygem.slug)
end

should "error creating trusted publisher with type" do
assert_no_difference("OIDC::RubygemTrustedPublisher.count") do
post rubygem_trusted_publishers_url(@rubygem.slug), params: {
Expand Down

0 comments on commit fdbbcb5

Please sign in to comment.