|
56 | 56 |
|
57 | 57 | context 'when there is an HTTP error fetching the certificate' do |
58 | 58 | it 'returns nil and logs the error' do |
59 | | - stub_request(:get, 'http://example.com').to_return(status: [500, 'Internal Server Error']) |
| 59 | + stub_request(:get, 'http://example.com/').to_return( |
| 60 | + status: [500, 'Internal Server Error'], |
| 61 | + body: 'Internal Server Error', |
| 62 | + ) |
60 | 63 |
|
61 | 64 | certificate = certificates_in_collection(certificate_set, :type, :leaf).first |
62 | 65 | expect(NewRelic::Agent).to receive(:notice_error).with( |
63 | | - IssuingCaService::UnexpectedPKCS7Response |
| 66 | + IssuingCaService::UnexpectedPKCS7Response.new('Internal Server Error'), |
| 67 | + custom_params: { issuer_uri: 'http://example.com/' }, |
| 68 | + ) |
| 69 | + fetched_cert = described_class.fetch_signing_key_for_cert(certificate) |
| 70 | + expect(fetched_cert).to eq nil |
| 71 | + end |
| 72 | + end |
| 73 | + |
| 74 | + context 'when there is an HTTP timeout fetching the certificate' do |
| 75 | + it 'returns nil and logs the error' do |
| 76 | + stub_request(:get, 'http://example.com/').to_timeout |
| 77 | + |
| 78 | + certificate = certificates_in_collection(certificate_set, :type, :leaf).first |
| 79 | + expect(NewRelic::Agent).to receive(:notice_error).with( |
| 80 | + Net::OpenTimeout, |
| 81 | + custom_params: { |
| 82 | + issuer_uri: 'http://example.com/', |
| 83 | + response_body: nil, |
| 84 | + }, |
64 | 85 | ) |
65 | 86 | fetched_cert = described_class.fetch_signing_key_for_cert(certificate) |
66 | 87 | expect(fetched_cert).to eq nil |
|
69 | 90 |
|
70 | 91 | context 'when the PKCS7 response is invalid' do |
71 | 92 | it 'returns nil and logs the error' do |
72 | | - stub_request(:get, 'http://example.com').to_return(body: 'bad pkcs7 response') |
| 93 | + stub_request(:get, 'http://example.com/').to_return(body: 'bad pkcs7 response') |
73 | 94 |
|
74 | 95 | certificate = certificates_in_collection(certificate_set, :type, :leaf).first |
75 | | - expect(NewRelic::Agent).to receive(:notice_error).with(ArgumentError) |
| 96 | + expect(NewRelic::Agent).to receive(:notice_error).with( |
| 97 | + ArgumentError, |
| 98 | + custom_params: { |
| 99 | + issuer_uri: 'http://example.com/', |
| 100 | + response_body: 'bad pkcs7 response', |
| 101 | + }, |
| 102 | + ) |
76 | 103 | fetched_cert = described_class.fetch_signing_key_for_cert(certificate) |
77 | 104 | expect(fetched_cert).to eq nil |
78 | 105 | end |
|
0 commit comments