foreman_rh_cloud 3.0.32 → 3.0.33

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a204ec60257c1312f0a0bb12676f7c835ca999818df927b29cb00bb2f44eb020
4
- data.tar.gz: 416c5b4fac2965ca6c282a9c640632806f27a7a7e3a50b239c72b404ad4fce40
3
+ metadata.gz: 1f5ec744a85ab1dc41ab93fc5949cd4f86df921c6141848fd4a1f2de7d26e0f6
4
+ data.tar.gz: a9754dcaa8eb46f7260bccd6ba6e4fb730793df4caf2dff18370e19f7a8a62cf
5
5
  SHA512:
6
- metadata.gz: '03680cfc35ac8dd829cd495427e45afabf64eab7864b5db6b03ab998528d4b390fc7f5723bee2b358a3075ce9ce7d9317e4d408d8c7645fa9fca1c06e94c89d2'
7
- data.tar.gz: e068877556691bb53eed6b720b87e595d6e467346dcf30923f9cd3c6e84674f81e27dd655532668963654e38117fa61039d8af75cfeb8443e921bcbfc7de3b47
6
+ metadata.gz: a22b012bf970556113871948f939b034ca9a2487bd2bbb23118cbdfa475d46a4481a3f7b5934a49d2ca6871fb8fa3bd3d4ab2dd692f35024c7623f85491fa259
7
+ data.tar.gz: 1153735dba9d5f08046e331e4b560620a9d463270942e919c32d5f1d1b36f2fe674d25b605af9681eeecb06deacbc9a3c04dcf6fe4a998bf3d23b53bb92ecfa5
@@ -25,14 +25,33 @@ module InsightsCloud::Api
25
25
  }, status: :bad_gateway
26
26
  end
27
27
 
28
- if @cloud_response.headers[:content_disposition]
29
- return send_data @cloud_response, disposition: @cloud_response.headers[:content_disposition], type: @cloud_response.headers[:content_type]
28
+ if @cloud_response.code >= 300
29
+ return render json: {
30
+ :message => 'Cloud request failed',
31
+ :headers => {},
32
+ :response => @cloud_response,
33
+ }, status: @cloud_response.code
30
34
  end
31
35
 
36
+ # Append redhat-specific headers
37
+ @cloud_response.headers.each do |key, value|
38
+ assign_header(response, @cloud_response, key, false) if key.to_s.start_with?('x_rh_')
39
+ end
40
+ # Append general headers
32
41
  assign_header(response, @cloud_response, :x_resource_count, true)
33
- assign_header(response, @cloud_response, :x_rh_insights_request_id, false)
42
+ headers[Rack::ETAG] = @cloud_response.headers[:etag]
34
43
 
35
- render json: @cloud_response, status: @cloud_response.code
44
+ if @cloud_response.headers[:content_disposition]
45
+ # If there is a Content-Disposition header, it means we are forwarding binary data, send the raw data with proper
46
+ # content type
47
+ send_data @cloud_response, disposition: @cloud_response.headers[:content_disposition], type: @cloud_response.headers[:content_type]
48
+ elsif @cloud_response.headers[:content_type] =~ /zip/
49
+ # if there is no Content-Disposition, but the content type is binary according the content type,
50
+ # forward the request as binry too
51
+ send_data @cloud_response, type: @cloud_response.headers[:content_type]
52
+ else
53
+ render json: @cloud_response, status: @cloud_response.code
54
+ end
36
55
  end
37
56
 
38
57
  def branch_info
@@ -17,17 +17,20 @@ module ForemanRhCloud
17
17
  logger.debug("Sending request to: #{request_opts[:url]}")
18
18
 
19
19
  execute_cloud_request(request_opts)
20
+ rescue RestClient::Exception => error_response
21
+ error_response.response
20
22
  end
21
23
 
22
24
  def prepare_request_opts(original_request, forward_payload, forward_params, certs)
23
25
  base_params = {
24
26
  method: original_request.method,
25
27
  payload: forward_payload,
26
- headers: {
27
- params: forward_params,
28
- user_agent: http_user_agent(original_request),
29
- content_type: original_request.media_type.presence || original_request.format.to_s,
30
- },
28
+ headers: original_headers(original_request).merge(
29
+ {
30
+ params: forward_params,
31
+ user_agent: http_user_agent(original_request),
32
+ content_type: original_request.media_type.presence || original_request.format.to_s,
33
+ }),
31
34
  }
32
35
  base_params.merge(path_params(original_request.path, certs))
33
36
  end
@@ -78,6 +81,16 @@ module ForemanRhCloud
78
81
  end
79
82
  end
80
83
 
84
+ def original_headers(original_request)
85
+ headers = {
86
+ if_none_match: original_request.if_none_match,
87
+ if_modified_since: original_request.if_modified_since,
88
+ }.compact
89
+
90
+ logger.debug("Sending headers: #{headers}")
91
+ headers
92
+ end
93
+
81
94
  def platform_request?
82
95
  ->(request_path) { request_path.include? '/platform' }
83
96
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '3.0.32'.freeze
2
+ VERSION = '3.0.33'.freeze
3
3
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foreman_rh_cloud",
3
- "version": "3.0.32",
3
+ "version": "3.0.33",
4
4
  "description": "Inventory Upload =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -3,6 +3,8 @@ require 'test_plugin_helper'
3
3
  module InsightsCloud::Api
4
4
  class MachineTelemetriesControllerTest < ActionController::TestCase
5
5
  context '#forward_request' do
6
+ include MockCerts
7
+
6
8
  setup do
7
9
  @body = 'Cloud response body'
8
10
  @http_req = RestClient::Request.new(:method => 'GET', :url => 'http://test.theforeman.org')
@@ -12,38 +14,9 @@ module InsightsCloud::Api
12
14
  User.current = ::Katello::CpConsumerUser.new(:uuid => host.subscription_facet.uuid, :login => host.subscription_facet.uuid)
13
15
  InsightsCloud::Api::MachineTelemetriesController.any_instance.stubs(:upstream_owner).returns({ 'uuid' => 'abcdefg' })
14
16
 
15
- @cert1 = "-----BEGIN CERTIFICATE-----\r\n" +
16
- "MIIFdDCCA1ygAwIBAgIJAM5Uqykb3EAtMA0GCSqGSIb3DQEBCwUAME8xCzAJBgNV\r\n" +
17
- "BAYTAklMMREwDwYDVQQIDAhUZWwgQXZpdjEUMBIGA1UECgwLVGhlIEZvcmVtYW4x\r\n" +
18
- "FzAVBgNVBAMMDnRoZWZvcmVtYW4ub3JnMB4XDTE4MDMyNDEyMzYyOFoXDTI4MDMy\r\n" +
19
- "MTEyMzYyOFowTzELMAkGA1UEBhMCSUwxETAPBgNVBAgMCFRlbCBBdml2MRQwEgYD\r\n" +
20
- "VQQKDAtUaGUgRm9yZW1hbjEXMBUGA1UEAwwOdGhlZm9yZW1hbi5vcmcwggIiMA0G\r\n" +
21
- "CSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDF04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ppQuRod72H39B\r\n" +
36
- "vxMlG5zxDss0WMo3vZeKZbTY6QhXi/lY2IZ6OGV4feSvCsYxn27GTjjrRUSLFeHH\r\n" +
37
- "JVemCwCDMavaE3+OIY4v2P4FcG+MjUvfOB9ahI24TWL7YgrsNVmJjCILq+EeUj0t\r\n" +
38
- "Gde1SXVyLkqt7PoxHRJAE0BCEMJSnjxaVB329acJgeehBUxjj4CCPqtDxtbz9HEH\r\n" +
39
- "mOKfNdaKpFor+DUeEKUWVGnr9U9xOaC+Ws+oX7MIEUCDM7p2ob4JwcjnFs1jZgHh\r\n" +
40
- "Hwig+i7doTlc701PvKWO96fuNHK3B3/jTb1fVvSZ49O/RvY1VWODdUdxWmXGHNh3\r\n" +
41
- "LoR8tSPEb46lC2DXGaIQumqQt8PnBG+vL1qkQa1SGTV7dJ8TTbxbv0S+sS+igkk9\r\n" +
42
- "zsIEK8Ea3Ep935cXximz0faAAKHSA+It+xHLAyDtqy2KaAEBgGsBuuWlUfK6TaP3\r\n" +
43
- "Gwdjct3y4yYUO45lUsUfHqX8vk/4ttW5zYeDiW+HArJz+9VUXNbEdury4kGuHgBj\r\n" +
44
- "xHD4Bsul65+hHZ9QywKU26F1A6TLkYpQ2rk/Dx9LGICM4m4IlHjWJPFsQdtkyOor\r\n" +
45
- "osxMtcaZZ1E=\r\n" +
46
- "-----END CERTIFICATE-----"
17
+ setup_certs_expectation do
18
+ InsightsCloud::Api::MachineTelemetriesController.any_instance.stubs(:candlepin_id_cert)
19
+ end
47
20
  end
48
21
 
49
22
  test "should respond with response from cloud" do
@@ -63,13 +36,6 @@ module InsightsCloud::Api
63
36
  ::ForemanRhCloud::CloudRequestForwarder.any_instance.expects(:execute_cloud_request).with do |opts|
64
37
  opts[:headers][:content_type] == 'application/json'
65
38
  end.returns(res)
66
- InsightsCloud::Api::MachineTelemetriesController.any_instance.expects(:candlepin_id_cert)
67
- .returns(
68
- {
69
- cert: @cert1,
70
- key: OpenSSL::PKey::RSA.new(1024).to_pem,
71
- }
72
- )
73
39
  InsightsCloud::Api::MachineTelemetriesController.any_instance.expects(:cp_owner_id).returns('123')
74
40
 
75
41
  post :forward_request, as: :json, params: { "path" => "static/v1/test", "machine_telemetry" => {"foo" => "bar"} }
@@ -90,6 +56,29 @@ module InsightsCloud::Api
90
56
  assert_equal x_rh_insights_request_id, @response.headers['x_rh_insights_request_id']
91
57
  end
92
58
 
59
+ test "should set etag header to response from cloud" do
60
+ etag = '12345'
61
+ req = RestClient::Request.new(:method => 'GET', :url => 'http://test.theforeman.org', :headers => { "If-None-Match": etag})
62
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, "OK")
63
+ net_http_resp[Rack::ETAG] = etag
64
+ res = RestClient::Response.create(@body, net_http_resp, req)
65
+ ::ForemanRhCloud::CloudRequestForwarder.any_instance.stubs(:forward_request).returns(res)
66
+
67
+ get :forward_request, params: { "path" => "static/v1/release/insights-core.egg" }
68
+ assert_equal etag, @response.headers[Rack::ETAG]
69
+ end
70
+
71
+ test "should set content type header to response from cloud" do
72
+ req = RestClient::Request.new(:method => 'GET', :url => 'http://test.theforeman.org')
73
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, "OK")
74
+ net_http_resp['Content-Type'] = 'application/zip'
75
+ res = RestClient::Response.create(@body, net_http_resp, req)
76
+ ::ForemanRhCloud::CloudRequestForwarder.any_instance.stubs(:forward_request).returns(res)
77
+
78
+ get :forward_request, params: { "path" => "static/v1/release/insights-core.egg" }
79
+ assert_equal net_http_resp['Content-Type'], @response.headers['Content-Type']
80
+ end
81
+
93
82
  test "should handle failed authentication to cloud" do
94
83
  net_http_resp = Net::HTTPResponse.new(1.0, 401, "Unauthorized")
95
84
  res = RestClient::Response.create(@body, net_http_resp, @http_req)
@@ -99,6 +88,17 @@ module InsightsCloud::Api
99
88
  assert_equal 502, @response.status
100
89
  assert_equal 'Authentication to the Insights Service failed.', JSON.parse(@response.body)['message']
101
90
  end
91
+
92
+ test "should forward errors to the client" do
93
+ net_http_resp = Net::HTTPResponse.new(1.0, 500, "TEST_RESPONSE")
94
+ res = RestClient::Response.create(@body, net_http_resp, @http_req)
95
+ ::ForemanRhCloud::CloudRequestForwarder.any_instance.stubs(:execute_cloud_request).raises(RestClient::InternalServerError.new(res))
96
+
97
+ get :forward_request, params: { "path" => "platform/module-update-router/v1/channel" }
98
+ assert_equal 500, @response.status
99
+ assert_equal 'Cloud request failed', JSON.parse(@response.body)['message']
100
+ assert_match /#{@body}/, JSON.parse(@response.body)['response']
101
+ end
102
102
  end
103
103
 
104
104
  context '#branch_info' do
@@ -39,3 +39,56 @@ module KatelloLocationFix
39
39
  end
40
40
  end
41
41
  end
42
+
43
+ module MockCerts
44
+ extend ActiveSupport::Concern
45
+
46
+ def test_certificate
47
+ @test_certificate ||= "-----BEGIN CERTIFICATE-----\r\n" +
48
+ "MIIFdDCCA1ygAwIBAgIJAM5Uqykb3EAtMA0GCSqGSIb3DQEBCwUAME8xCzAJBgNV\r\n" +
49
+ "BAYTAklMMREwDwYDVQQIDAhUZWwgQXZpdjEUMBIGA1UECgwLVGhlIEZvcmVtYW4x\r\n" +
50
+ "FzAVBgNVBAMMDnRoZWZvcmVtYW4ub3JnMB4XDTE4MDMyNDEyMzYyOFoXDTI4MDMy\r\n" +
51
+ "MTEyMzYyOFowTzELMAkGA1UEBhMCSUwxETAPBgNVBAgMCFRlbCBBdml2MRQwEgYD\r\n" +
52
+ "VQQKDAtUaGUgRm9yZW1hbjEXMBUGA1UEAwwOdGhlZm9yZW1hbi5vcmcwggIiMA0G\r\n" +
53
+ "CSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDF04/s4h+BgHPG1HDZ/sDlYq925pkc\r\n" +
54
+ "RTVAfnE2EXDAmZ6W4Q9ueDY65MHe3ZWO5Dg72kNSP2sK9kRI7Dk5CAFOgyw1rH8t\r\n" +
55
+ "Hd1+0xp/lv6e4SvSYghxIL68vFe0ftKkm1usqejBM5ZTgKr7JCI+XSIN36F65Kde\r\n" +
56
+ "c+vxwB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PoxHRJAE0BCEMJSnjxaVB329acJgeehBUxjj4CCPqtDxtbz9HEH\r\n" +
71
+ "mOKfNdaKpFor+DUeEKUWVGnr9U9xOaC+Ws+oX7MIEUCDM7p2ob4JwcjnFs1jZgHh\r\n" +
72
+ "Hwig+i7doTlc701PvKWO96fuNHK3B3/jTb1fVvSZ49O/RvY1VWODdUdxWmXGHNh3\r\n" +
73
+ "LoR8tSPEb46lC2DXGaIQumqQt8PnBG+vL1qkQa1SGTV7dJ8TTbxbv0S+sS+igkk9\r\n" +
74
+ "zsIEK8Ea3Ep935cXximz0faAAKHSA+It+xHLAyDtqy2KaAEBgGsBuuWlUfK6TaP3\r\n" +
75
+ "Gwdjct3y4yYUO45lUsUfHqX8vk/4ttW5zYeDiW+HArJz+9VUXNbEdury4kGuHgBj\r\n" +
76
+ "xHD4Bsul65+hHZ9QywKU26F1A6TLkYpQ2rk/Dx9LGICM4m4IlHjWJPFsQdtkyOor\r\n" +
77
+ "osxMtcaZZ1E=\r\n" +
78
+ "-----END CERTIFICATE-----"
79
+ end
80
+
81
+ def generate_certs_hash
82
+ {
83
+ cert: test_certificate,
84
+ key: OpenSSL::PKey::RSA.new(1024).to_pem,
85
+ }
86
+ end
87
+
88
+ def setup_certs_expectation
89
+ expectation = yield
90
+ expectation.returns(
91
+ generate_certs_hash
92
+ )
93
+ end
94
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_rh_cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.32
4
+ version: 3.0.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - Foreman Red Hat Cloud team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-10 00:00:00.000000000 Z
11
+ date: 2022-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: katello
@@ -188,7 +188,6 @@ files:
188
188
  - app/views/layouts/foreman_rh_cloud/application.html.erb
189
189
  - config/Gemfile.lock.gh_test
190
190
  - config/database.yml.example
191
- - config/package-lock.json
192
191
  - config/package-lock.json.gh_test
193
192
  - config/package-lock.json.plugin
194
193
  - config/routes.rb
@@ -673,7 +672,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
673
672
  - !ruby/object:Gem::Version
674
673
  version: '0'
675
674
  requirements: []
676
- rubygems_version: 3.2.22
675
+ rubygems_version: 3.3.7
677
676
  signing_key:
678
677
  specification_version: 4
679
678
  summary: Summary of ForemanRhCloud.