Skip to content
This repository has been archived by the owner on Nov 19, 2018. It is now read-only.

Commit

Permalink
fixes issue #45 - passing a CSR from a file as a String
Browse files Browse the repository at this point in the history
  • Loading branch information
snatchev committed Jun 23, 2015
1 parent f7ed498 commit 4fcf860
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/spaceship/certificate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ def create!(csr: nil, bundle_id: nil)
app_id = app.app_id
end

# ensure csr is a OpenSSL::X509::Request
csr = OpenSSL::X509::Request.new(csr) if csr.is_a?(String)

# if this succeeds, we need to save the .cer and the private key in keychain access or wherever they go in linux
response = client.create_certificate!(type, csr.to_pem, app_id)
# munge the response to make it work for the factory
Expand Down
19 changes: 17 additions & 2 deletions spec/certificate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,28 @@
expect(client).to receive(:create_certificate!).with('3BQKVH9I2X', /BEGIN CERTIFICATE REQUEST/, 'B7JBD8LHAA') {
JSON.parse(read_fixture_file('certificateCreate.certRequest.json'))
}
certificate = Spaceship::Certificate::ProductionPush.create!(csr: Spaceship::Certificate.create_certificate_signing_request.first, bundle_id: 'net.sunapps.151')
csr, pkey = Spaceship::Certificate.create_certificate_signing_request
certificate = Spaceship::Certificate::ProductionPush.create!(csr: csr, bundle_id: 'net.sunapps.151')
expect(certificate).to be_instance_of(Spaceship::Certificate::ProductionPush)
end

it 'should create a new certificate using a CSR from a file' do
expect(client).to receive(:create_certificate!).with('3BQKVH9I2X', /BEGIN CERTIFICATE REQUEST/, 'B7JBD8LHAA') {
JSON.parse(read_fixture_file('certificateCreate.certRequest.json'))
}
csr, pkey = Spaceship::Certificate.create_certificate_signing_request
Tempfile.open('csr') do |f|
f.write(csr.to_pem)
f.rewind
pem = f.read
Spaceship::Certificate::ProductionPush.create!(csr: pem, bundle_id: 'net.sunapps.151')
end
end

it 'raises an error if the user wants to create a certificate for a non-existing app' do
expect {
Spaceship::Certificate::ProductionPush.create!(csr: Spaceship::Certificate.create_certificate_signing_request.first, bundle_id: 'notExisting')
csr, pkey = Spaceship::Certificate.create_certificate_signing_request
Spaceship::Certificate::ProductionPush.create!(csr: csr, bundle_id: 'notExisting')
}.to raise_error "Could not find app with bundle id 'notExisting'"
end
end
Expand Down

0 comments on commit 4fcf860

Please sign in to comment.