smart_proxy_abrt 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df8fa42c5653d24dc901ba4fb3f0ed7825dc7360
4
- data.tar.gz: 8c90a1213d9731990e7fe4b35eab8e6b199ea7a8
3
+ metadata.gz: 6ee13f97ca61bfe1beb9600243860112720ab77e
4
+ data.tar.gz: f7ac725e23e1043c4fee869faa2c17b2200fdb67
5
5
  SHA512:
6
- metadata.gz: 78d8ea31d80fe41f6cc79a1de8f06a1f87bd650d5e692487f57c8df927d3b00cfe65a6e974c0ffb9a88637882cf3728ce424f5a0a81912d13a6b596095f51ebb
7
- data.tar.gz: 58648ba8d92b9dce46e95a91ec8ddafb3e9e98f86f0cf94dedfae8e9c16a6edeebf1c7df8f1458d3133b8884e15459aef805c115d43d6486edf107359cf5b4be
6
+ metadata.gz: 9049b481899587f4bc23a12967df0563e984e4ee5bb76c1cb10e649d2dca1fae9b9774a82c5e042aad13cae8d2f4dd51fa6189418c59e6c68a3e283189fe45d7
7
+ data.tar.gz: 351de1e2a5545fb1f42684b48af2cc222671d65aabce30f4f40f7b72da48ab72cc0d4e7e54825166d70df10f66fa10e2cdbbbfa9fc16cf1bd474d14362691aae
@@ -12,7 +12,7 @@ module AbrtProxy
12
12
 
13
13
  post '/reports/new/' do
14
14
  begin
15
- cn = AbrtProxy::common_name request
15
+ names = AbrtProxy::cert_names request
16
16
  rescue AbrtProxy::Error::Unauthorized => e
17
17
  log_halt 403, "Client authentication required: #{e.message}"
18
18
  rescue AbrtProxy::Error::CertificateError => e
@@ -48,7 +48,7 @@ module AbrtProxy
48
48
  if Proxy::SETTINGS.foreman_url
49
49
  foreman_url = Proxy::SETTINGS.foreman_url
50
50
  foreman_url += "/" if foreman_url[-1] != "/"
51
- foreman_url += "hosts/#{cn}/abrt_reports"
51
+ foreman_url += "hosts/#{names[-1]}/abrt_reports"
52
52
  response["reported_to"] = [{ "reporter" => "Foreman",
53
53
  "type" => "url",
54
54
  "value" => foreman_url }]
@@ -58,7 +58,7 @@ module AbrtProxy
58
58
 
59
59
  #save report to disk
60
60
  begin
61
- AbrtProxy::HostReport.save cn, ureport
61
+ AbrtProxy::HostReport.save names, ureport
62
62
  rescue => e
63
63
  log_halt 500, "Failed to save the report: #{e}"
64
64
  end
@@ -74,7 +74,7 @@ module AbrtProxy
74
74
  response
75
75
  end
76
76
 
77
- def self.common_name(request)
77
+ def self.cert_names(request)
78
78
  client_cert = request.env['SSL_CLIENT_CERT']
79
79
  raise AbrtProxy::Error::Unauthorized, "Client certificate required" if client_cert.to_s.empty?
80
80
 
@@ -84,11 +84,28 @@ module AbrtProxy
84
84
  raise AbrtProxy::Error::CertificateError, e.message
85
85
  end
86
86
 
87
- cn = client_cert.subject.to_a.detect { |name, value| name == 'CN' }
88
- cn = cn[1] unless cn.nil?
89
- raise AbrtProxy::Error::CertificateError, "Common Name not found in the certificate" unless cn
87
+ begin
88
+ cn = client_cert.subject.to_a.find { |name, value| name == 'CN' }
89
+ names = [cn[1]]
90
+ rescue NoMethodError
91
+ raise AbrtProxy::Error::CertificateError, "Common Name not found in the certificate"
92
+ end
93
+
94
+ alt_name_ext = client_cert.extensions.find { |ext| ext.oid == 'subjectAltName' }
95
+ if alt_name_ext
96
+ names += alt_name_ext.value.
97
+ split(/, ?/).
98
+ select { |s| s.start_with? 'URI:CN=' }.
99
+ map { |s| s.sub(/^URI:CN=/, '') }
100
+ end
90
101
 
91
- return cn
102
+ return names
103
+ end
104
+
105
+ class AbrtRequest < Proxy::HttpRequest::ForemanRequest
106
+ def post_report(report)
107
+ send_request(request_factory.create_post('/api/abrt_reports', report))
108
+ end
92
109
  end
93
110
 
94
111
  class HostReport
@@ -127,6 +144,7 @@ module AbrtProxy
127
144
  @by_hash[hash] = ar unless hash.nil?
128
145
  @files = [fname]
129
146
  @host = json["host"]
147
+ @althosts = json["althosts"]
130
148
  end
131
149
 
132
150
  def merge(other)
@@ -150,7 +168,7 @@ module AbrtProxy
150
168
  def send_to_foreman
151
169
  foreman_report = create_foreman_report
152
170
  logger.debug "Sending #{foreman_report}"
153
- Proxy::HttpRequest::ForemanRequest.new.send_request("/api/abrt_reports", foreman_report.to_json)
171
+ AbrtRequest.new.post_report(foreman_report.to_json)
154
172
  end
155
173
 
156
174
  def unlink
@@ -160,12 +178,12 @@ module AbrtProxy
160
178
  end
161
179
  end
162
180
 
163
- def self.save(host, report, reported_at=nil)
181
+ def self.save(hostnames, report, reported_at=nil)
164
182
  # create the spool dir if it does not exist
165
183
  FileUtils.mkdir_p HostReport.spooldir
166
184
 
167
185
  reported_at ||= Time.now.utc
168
- on_disk_report = { "host" => host, "report" => report , "reported_at" => reported_at.to_s }
186
+ on_disk_report = { "host" => hostnames[0], "report" => report , "reported_at" => reported_at.to_s, "althosts" => hostnames[1..-1] }
169
187
 
170
188
  # write report to temporary file
171
189
  temp_fname = unique_filename "new-"
@@ -209,6 +227,7 @@ module AbrtProxy
209
227
  def create_foreman_report
210
228
  { "abrt_report" => {
211
229
  "host" => @host,
230
+ "althosts" => @althosts,
212
231
  "reports" => format_reports
213
232
  }
214
233
  }
@@ -1,3 +1,3 @@
1
1
  module AbrtProxy
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -19,7 +19,7 @@ class AbrtApiTest < Test::Unit::TestCase
19
19
  @post_data = {
20
20
  "file" => Rack::Test::UploadedFile.new(ureport_file, "application/json")
21
21
  }
22
- AbrtProxy.stubs(:common_name).returns('localhost')
22
+ AbrtProxy.stubs(:cert_names).returns(['localhost'])
23
23
  end
24
24
 
25
25
  def assert_dir_contains_report(dir)
@@ -84,7 +84,7 @@ class AbrtTest < Test::Unit::TestCase
84
84
  end
85
85
 
86
86
  def test_hostreport_send_to_foreman
87
- Proxy::HttpRequest::ForemanRequest.any_instance.expects(:send_request).once
87
+ AbrtProxy::AbrtRequest.any_instance.expects(:post_report).once
88
88
 
89
89
  reports = []
90
90
  Dir[File.join(@tmpdir, "ureport-ondisk-host1-*")].each do |file|
@@ -117,7 +117,7 @@ class AbrtTest < Test::Unit::TestCase
117
117
  Dir[File.join(@tmpdir, "*")].each { |file| File.unlink file }
118
118
  ureport = IO.read "test/fixtures/ureport1.json"
119
119
  ureport = JSON.parse ureport
120
- AbrtProxy::HostReport.save "localhost", ureport
120
+ AbrtProxy::HostReport.save ["localhost"], ureport
121
121
 
122
122
  hr = AbrtProxy::HostReport.new Dir[File.join(@tmpdir, "*")][0]
123
123
  assert_equal "localhost", hr.host
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_abrt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Milata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-08 00:00:00.000000000 Z
11
+ date: 2014-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: satyr