Skip to content

Commit ecb6a85

Browse files
committed
Build trusted publisher filter
1 parent a86b845 commit ecb6a85

17 files changed

+78
-2
lines changed

app/models/concerns/rubygem_searchable.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ module RubygemSearchable
2525
suggest: { type: "completion", contexts: { name: "yanked", type: "category" } },
2626
yanked: { type: "boolean" },
2727
downloads: { type: "long" },
28-
updated: { type: "date" }
28+
updated: { type: "date" },
29+
trusted_publisher: { type: "boolean" }
2930
}
3031
}
3132
scope :search_import, -> { includes(:linkset, :gem_download, :most_recent_version, :versions, :latest_version) }
@@ -43,6 +44,7 @@ def search_data # rubocop:disable Metrics/MethodLength
4344
version_downloads: latest_version&.downloads_count,
4445
platform: latest_version&.platform,
4546
authors: latest_version&.authors,
47+
trusted_publisher: latest_version&.pushed_by_trusted_publisher?,
4648
info: latest_version&.info,
4749
licenses: latest_version&.licenses,
4850
metadata: latest_version&.metadata,

app/models/version.rb

+4
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,10 @@ def gem_file_name
411411
"#{full_name}.gem"
412412
end
413413

414+
def pushed_by_trusted_publisher?
415+
pusher_api_key&.trusted_publisher? ? true : false
416+
end
417+
414418
private
415419

416420
def update_prerelease

app/views/searches/advanced.html.erb

+3
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,8 @@
3232

3333
<dt><%= label_tag :updated, t(".updated"), class: "form__label" %></dt>
3434
<dd><%= text_field_tag :updated, "", placeholder: ">#{1.week.ago.strftime('%F')}", class: "form__input", pattern: "\\s*(<=?|>=?)?[\\d-]+\\s*", data: { search_target: "attribute", action: "input->search#input keydown.enter->search#submit" } %></dd>
35+
36+
<dt><%= label_tag :trusted_publisher, t(".trusted_publisher"), class: "form__label" %></dt>
37+
<dd><%= text_field_tag :trusted_publisher, "", placeholder: "true", class: "form__input", pattern: "true|false", data: { search_target: "attribute", action: "input->search#input keydown.enter->search#submit" } %></dd>
3538
</dl>
3639
</div>

config/locales/de.yml

+1
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,7 @@ de:
844844
summary:
845845
description:
846846
downloads:
847+
trusted_publisher:
847848
updated:
848849
yanked:
849850
show:

config/locales/en.yml

+1
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,7 @@ en:
757757
summary: Summary
758758
description: Description
759759
downloads: Downloads
760+
trusted_publisher: Trusted Publisher
760761
updated: Updated
761762
yanked: Yanked
762763
show:

config/locales/es.yml

+1
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,7 @@ es:
870870
summary: Resumen
871871
description: Descripción
872872
downloads: Descargas
873+
trusted_publisher:
873874
updated: Actualizada
874875
yanked: Borrada
875876
show:

config/locales/fr.yml

+1
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ fr:
794794
summary: Sommaire
795795
description: Description
796796
downloads: Téléchargements
797+
trusted_publisher:
797798
updated: Mis à jour
798799
yanked:
799800
show:

config/locales/ja.yml

+1
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ ja:
755755
summary: 概要
756756
description: 説明
757757
downloads: ダウンロード数
758+
trusted_publisher:
758759
updated: 更新日
759760
yanked: ヤンク済み
760761
show:

config/locales/nl.yml

+1
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ nl:
748748
summary:
749749
description:
750750
downloads:
751+
trusted_publisher:
751752
updated:
752753
yanked:
753754
show:

config/locales/pt-BR.yml

+1
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@ pt-BR:
772772
summary:
773773
description:
774774
downloads:
775+
trusted_publisher:
775776
updated:
776777
yanked:
777778
show:

config/locales/zh-CN.yml

+1
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ zh-CN:
760760
summary: 概要
761761
description: 描述
762762
downloads: 下载数
763+
trusted_publisher:
763764
updated: 更新
764765
yanked: 撤回
765766
show:

config/locales/zh-TW.yml

+1
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@ zh-TW:
750750
summary: 摘要
751751
description: 描述
752752
downloads: 下載數
753+
trusted_publisher:
753754
updated: 更新於
754755
yanked: 移除於
755756
show:

test/factories/version.rb

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
metadata { { "rubygems_mfa_required" => "true" } }
2929
end
3030

31+
trait :has_trusted_publisher do
32+
pusher_api_key { association(:api_key, :trusted_publisher, key: SecureRandom.hex(24)) }
33+
end
34+
35+
trait :has_untrusted_publisher do
36+
pusher_api_key { association(:api_key, key: SecureRandom.hex(24)) }
37+
end
38+
3139
after(:create) do |version|
3240
if version.info_checksum.blank?
3341
checksum = GemInfo.new(version.rubygem.name).info_checksum

test/integration/search_test.rb

+16
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,20 @@ class SearchTest < SystemTest
115115
refute page.has_content? "Search reverse dependencies Gems…"
116116
assert page.has_content? "This gem has no reverse dependencies"
117117
end
118+
119+
test "filtering by trusted publishers" do
120+
rubygem1 = create(:rubygem, name: "LDAP", number: "1.0.0")
121+
rubygem2 = create(:rubygem, name: "LDAP-Shady-Gem", number: "1.0.0")
122+
create(:version, :has_trusted_publisher, rubygem: rubygem1, indexed: false)
123+
create(:version, :has_untrusted_publisher, rubygem: rubygem2, indexed: false)
124+
import_and_refresh
125+
126+
visit search_path
127+
128+
fill_in "query", with: "LDAP&trusted_publisher=true"
129+
click_button "search_submit"
130+
131+
assert page.has_content? "LDAP"
132+
assert page.has_no_content? "LDAP-Shady-Gem"
133+
end
118134
end

test/models/pusher_test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ def two_cert_chain(signing_key:, root_not_before: Time.current, cert_not_before:
636636
"version_downloads" => 0,
637637
"platform" => "ruby",
638638
"authors" => "Joe User",
639+
"trusted_publisher" => false,
639640
"info" => "Some awesome gem",
640641
"licenses" => "MIT",
641642
"metadata" => { "foo" => "bar" },

test/models/version_test.rb

+32
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,38 @@ class VersionTest < ActiveSupport::TestCase
117117
end
118118
end
119119

120+
context "#pushed_by_trusted_publisher?" do
121+
context "with a trusted publisher api key association" do
122+
setup do
123+
@version = build(:version, :has_trusted_publisher)
124+
end
125+
126+
should "return true" do
127+
assert_predicate @version, :pushed_by_trusted_publisher?
128+
end
129+
end
130+
131+
context "with an untrusted publisher api key association" do
132+
setup do
133+
@version = build(:version, :has_untrusted_publisher)
134+
end
135+
136+
should "return false" do
137+
refute_predicate @version, :pushed_by_trusted_publisher?
138+
end
139+
end
140+
141+
context "with no api key association" do
142+
setup do
143+
@version = build(:version)
144+
end
145+
146+
should "return false" do
147+
refute_predicate @version, :pushed_by_trusted_publisher?
148+
end
149+
end
150+
end
151+
120152
context "updated gems" do
121153
setup do
122154
@existing_gem = create(:rubygem)

test/system/advanced_search_test.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class AdvancedSearchTest < ApplicationSystemTestCase
3939
fill_in "description", with: "foo"
4040
fill_in "downloads", with: ">69"
4141
fill_in "updated", with: ">2021-05-05"
42+
fill_in "trusted_publisher", with: "true"
4243

43-
assert has_field? "Search Gems…", with: "name: hello summary: world description: foo downloads: >69 updated: >2021-05-05"
44+
assert has_field? "Search Gems…", with: "name: hello summary: world description: foo downloads: >69 updated: >2021-05-05 trusted_publisher: true"
4445
end
4546
end

0 commit comments

Comments
 (0)