mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 08:33:58 +02:00
[rubygems/rubygems] Add --attestation option to gem push
Signed-off-by: Samuel Giddins <segiddins@segiddins.me>
a5412d9a0e
This commit is contained in:
parent
b4969348bf
commit
b70c1bb150
3 changed files with 81 additions and 5 deletions
|
@ -102,6 +102,47 @@ class TestGemCommandsPushCommand < Gem::TestCase
|
|||
@fetcher.last_request["Content-Type"]
|
||||
end
|
||||
|
||||
def test_execute_attestation
|
||||
@response = "Successfully registered gem: freewill (1.0.0)"
|
||||
@fetcher.data["#{Gem.host}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK")
|
||||
|
||||
File.write("#{@path}.sigstore.json", "attestation")
|
||||
@cmd.options[:args] = [@path]
|
||||
@cmd.options[:attestations] = ["#{@path}.sigstore.json"]
|
||||
|
||||
@cmd.execute
|
||||
|
||||
assert_equal Gem::Net::HTTP::Post, @fetcher.last_request.class
|
||||
content_length = @fetcher.last_request["Content-Length"].to_i
|
||||
assert_equal content_length, @fetcher.last_request.body.length
|
||||
assert_equal "multipart", @fetcher.last_request.main_type, @fetcher.last_request.content_type
|
||||
assert_equal "form-data", @fetcher.last_request.sub_type
|
||||
assert_include @fetcher.last_request.type_params, "boundary"
|
||||
boundary = @fetcher.last_request.type_params["boundary"]
|
||||
|
||||
parts = @fetcher.last_request.body.split(/(?:\r\n|\A)--#{Regexp.quote(boundary)}(?:\r\n|--)/m)
|
||||
refute_empty parts
|
||||
assert_empty parts[0]
|
||||
parts.shift # remove the first empty part
|
||||
|
||||
p1 = parts.shift
|
||||
p2 = parts.shift
|
||||
assert_equal "\r\n", parts.shift
|
||||
assert_empty parts
|
||||
|
||||
assert_equal [
|
||||
"Content-Disposition: form-data; name=\"gem\"; filename=\"#{@path}\"",
|
||||
"Content-Type: application/octet-stream",
|
||||
nil,
|
||||
Gem.read_binary(@path),
|
||||
].join("\r\n").b, p1
|
||||
assert_equal [
|
||||
"Content-Disposition: form-data; name=\"attestations\"",
|
||||
nil,
|
||||
"[#{Gem.read_binary("#{@path}.sigstore.json")}]",
|
||||
].join("\r\n").b, p2
|
||||
end
|
||||
|
||||
def test_execute_allowed_push_host
|
||||
@spec, @path = util_gem "freebird", "1.0.1" do |spec|
|
||||
spec.metadata["allowed_push_host"] = "https://privategemserver.example"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue