tshield 0.14.0.0 → 0.15.0.0

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
  SHA256:
3
- metadata.gz: 83eb12f572bdfd5f6fade21d83ee7d4883253aa9e42cad7fe0e9feac380d7ae6
4
- data.tar.gz: c1718a13671ee6899321dcda86c6d6dbaad23c1389cc24c0b6ea3b684024c725
3
+ metadata.gz: 3675ad22a08350950eadbc2000d89be8dbcf44acc9a4487d1b8c3a59bae3dcd1
4
+ data.tar.gz: c15c0f0d52cf43de37744efcc418932c83db271ba38a50b4ce72df7cd708e65b
5
5
  SHA512:
6
- metadata.gz: 003b70dbe21e80655ebfe6eae9e0260137a3f6e3e478200c04eefbc238ae72d8d172b62c4d980a934fd56a08eb7d2ad59d93b4d762a3c019e88d3e2e6cc39d46
7
- data.tar.gz: 6c4ada87361e89edff1b8fe7353389861c3748986631ad9693d01f148c71fb2dbe06547b318d94c3247dc584081c047fc915f5d1d014d6026172b8cf406b5753
6
+ metadata.gz: 0b9b08892d5f9843a5cc2fd2db34a0d160126104a83a83ad1d9f4b041b83d9acd5d773ea8645539f16dbf046d85fb54ee2a0a92b963f87f954b88a3ca9656f39
7
+ data.tar.gz: 6300ebfca1c90b7e11a19d2facc3e5cc855db320ffe352b49326a6e20d9f73f401d3e6c4a1f6f3f2c6ba5a01a7c8a2426c1108ce20a2009d6be05c8c484ae9be
data/README.md CHANGED
@@ -3,8 +3,6 @@ TShield
3
3
 
4
4
  [![Build Status](https://travis-ci.org/diegorubin/tshield.svg)](https://travis-ci.org/diegorubin/tshield)
5
5
  [![Coverage Status](https://coveralls.io/repos/github/diegorubin/tshield/badge.svg?branch=master)](https://coveralls.io/github/diegorubin/tshield?branch=master)
6
- [![SourceLevel](https://app.sourcelevel.io/github/diegorubin/-/tshield.svg)](https://app.sourcelevel.io/github/diegorubin/-/tshield)
7
- [![Join the chat at https://gitter.im/diegorubin/tshield](https://badges.gitter.im/diegorubin/tshield.svg)](https://gitter.im/diegorubin/tshield?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
8
6
  [![Gem Version](https://badge.fury.io/rb/tshield.svg)](https://badge.fury.io/rb/tshield)
9
7
  ![TShield Publish](https://github.com/diegorubin/tshield/workflows/TShield%20Publish/badge.svg)
10
8
 
data/config/tshield.yml CHANGED
@@ -1,16 +1,16 @@
1
1
  ---
2
2
  grpc:
3
3
  port: 5678
4
- proto_dir: 'proto'
4
+ proto_dir: "proto"
5
5
  services:
6
- 'helloworld_services_pb':
7
- module: 'Helloworld::Greeter'
8
- hostname: '0.0.0.0:50051'
6
+ "helloworld_services_pb":
7
+ module: "Helloworld::Greeter"
8
+ hostname: "0.0.0.0:50051"
9
9
  request:
10
10
  timeout: 10
11
11
  domains:
12
- 'http://localhost:9090':
13
- name: 'components'
12
+ "http://localhost:9090":
13
+ name: "components"
14
14
  skip_query_params:
15
15
  - b
16
16
  paths:
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'yaml'
4
4
 
5
+ require 'tshield/errors'
5
6
  require 'tshield/after_filter'
6
7
  require 'tshield/before_filter'
7
8
  require 'tshield/options'
@@ -59,7 +60,7 @@ module TShield
59
60
  result = self.class.get_url_for_domain_by_path(path, config)
60
61
  return url if result
61
62
  end
62
- nil
63
+ raise ConfigurationNotFoundError.new("Domain not found for path #{path}")
63
64
  end
64
65
 
65
66
  def windows_compatibility?
@@ -89,8 +90,12 @@ module TShield
89
90
  end
90
91
 
91
92
  def get_filters(domain)
92
- (domains[domain]['filters'] || [])
93
- .collect { |filter| Class.const_get(filter) }
93
+ begin
94
+ (domains[domain]['filters'] || [])
95
+ .collect { |filter| Class.const_get(filter) }
96
+ rescue
97
+ puts "Error loading filters for domain #{domain}"
98
+ end
94
99
  end
95
100
 
96
101
  def get_excluded_headers(domain)
@@ -57,8 +57,6 @@ module TShield
57
57
  ip: request.ip
58
58
  }
59
59
 
60
- treat_headers_by_domain(options, path)
61
-
62
60
  if %w[POST PUT PATCH].include? method
63
61
  result = request.body.read.encode('UTF-8',
64
62
  invalid: :replace,
@@ -67,13 +65,21 @@ module TShield
67
65
  options[:body] = result
68
66
  end
69
67
  api_response = TShield::RequestMatching.new(path, options.clone).match_request
70
-
71
68
  unless api_response
72
- add_headers(options, path)
73
-
74
- api_response ||= TShield::RequestVCR.new(path, options.clone).vcr_response
75
- api_response.headers.reject! do |key, _v|
76
- configuration.get_excluded_headers(domain(path)).include?(key)
69
+ begin
70
+ treat_headers_by_domain(options, path)
71
+ add_headers(options, path)
72
+
73
+ api_response ||= TShield::RequestVCR.new(path, options.clone).vcr_response
74
+ api_response.headers.reject! do |key, _v|
75
+ configuration.get_excluded_headers(domain(path)).include?(key)
76
+ end
77
+ rescue ConfigurationNotFoundError => e
78
+ logger.error("Error on recover configuration for #{path}")
79
+
80
+ status 500
81
+ body({tshield: e }.to_json)
82
+ return
77
83
  end
78
84
  end
79
85
 
@@ -110,9 +116,13 @@ module TShield
110
116
  end
111
117
 
112
118
  def delay(path)
113
- delay_in_seconds = configuration.get_delay(domain(path), path) || 0
114
- logger.info("Response with delay of #{delay_in_seconds} seconds")
115
- sleep delay_in_seconds
119
+ begin
120
+ delay_in_seconds = configuration.get_delay(domain(path), path) || 0
121
+ logger.info("Response with delay of #{delay_in_seconds} seconds")
122
+ sleep delay_in_seconds
123
+ rescue ConfigurationNotFoundError
124
+ logger.debug('No delay configured')
125
+ end
116
126
  end
117
127
  end
118
128
  end
@@ -2,3 +2,7 @@
2
2
 
3
3
  class AppendSessionWithoutMainSessionError < RuntimeError
4
4
  end
5
+
6
+ class ConfigurationNotFoundError < RuntimeError
7
+ end
8
+
@@ -4,7 +4,7 @@ module TShield
4
4
  # Control version of gem
5
5
  class Version
6
6
  MAJOR = 0
7
- MINOR = 14
7
+ MINOR = 15
8
8
  PATCH = 0
9
9
  PRE = 0
10
10
 
@@ -61,7 +61,7 @@ describe TShield::Configuration do
61
61
  end
62
62
 
63
63
  it 'return nil if domain not found' do
64
- expect(@configuration.get_domain_for('/api/four')).to be_nil
64
+ expect{@configuration.get_domain_for('/api/four')}.to raise_error(ConfigurationNotFoundError)
65
65
  end
66
66
  end
67
67
 
@@ -47,6 +47,7 @@ describe TShield::Controllers::Requests do
47
47
  allow(matched_response).to receive(:headers).and_return({})
48
48
  allow(matched_response).to receive(:body).and_return('')
49
49
  allow(@mock_logger).to receive(:info)
50
+ allow(@mock_logger).to receive(:debug)
50
51
 
51
52
  expect(TShield::Controllers::Helpers::SessionHelpers)
52
53
  .to receive(:current_session_call).with(request, '/?a=b', 'GET')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tshield
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0.0
4
+ version: 0.15.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego Rubin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-10-18 00:00:00.000000000 Z
12
+ date: 2023-10-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: grpc
@@ -469,18 +469,18 @@ specification_version: 4
469
469
  summary: Proxy for mocks API responses
470
470
  test_files:
471
471
  - spec/spec_helper.rb
472
+ - spec/tshield/configuration_spec.rb
472
473
  - spec/tshield/request_matching_spec.rb
473
474
  - spec/tshield/sessions_spec.rb
475
+ - spec/tshield/controllers/requests_spec.rb
474
476
  - spec/tshield/request_vcr_spec.rb
475
- - spec/tshield/after_filter_spec.rb
476
477
  - spec/tshield/grpc_spec.rb
477
478
  - spec/tshield/options_spec.rb
479
+ - spec/tshield/after_filter_spec.rb
478
480
  - spec/tshield/fixtures/config/tshield-without-grpc.yml
481
+ - spec/tshield/fixtures/config/tshield.yml
479
482
  - spec/tshield/fixtures/config/tshield-with-send-content-type-header_as_false.yml
480
483
  - spec/tshield/fixtures/config/tshield-with-send-content-type-header.yml
481
- - spec/tshield/fixtures/config/tshield.yml
482
- - spec/tshield/fixtures/proto/test_services_pb.rb
483
484
  - spec/tshield/fixtures/matching/example.json
485
+ - spec/tshield/fixtures/proto/test_services_pb.rb
484
486
  - spec/tshield/fixtures/filters/example_filter.rb
485
- - spec/tshield/controllers/requests_spec.rb
486
- - spec/tshield/configuration_spec.rb