et_fake_acas_server 0.1.12 → 0.2.2

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: 045b2fef35e0388e2b6e3ce79f3c56ea87f45331b9193443e305dbf8b5d4122e
4
- data.tar.gz: 593279ffe78f4d3ab2b15209347d44e4359cacd8f9cc4224ed47eaa4a7b6e306
3
+ metadata.gz: a62c46bbc2882af494e209a2d6df00a9460c421f4aa617701ac0279aeb3aa162
4
+ data.tar.gz: cb65365826e839e3eb7f3bf8c9f69e01310f10ccdc9d9c3b5859984e94751dd8
5
5
  SHA512:
6
- metadata.gz: 1a625215b357753a371c30b9de3c388814aa52f2bddbff3f2e3be680e4a1766c2dba1c7d78c23165fede3cd0a714150306145a85c55a637326f5d71ed525c064
7
- data.tar.gz: e5e07fa8518656f770efd226165554a27076cc36a218728da06d9d9242bc035ad4c1076cc4cd3f6078fd04342e87e443dd2043eb14af8ca1f0ec36cb4acf0a82
6
+ metadata.gz: d1cc21716f00c5c57c6b759b06e6fc97699b0f3976b13f474b1a82526ea76557f2a8eed7aa8f6d9c56937182c47b974d224212dc847114071120bc1f24e1e045
7
+ data.tar.gz: 27fc5722ce845e579054a7d6d72a8d561f823201af5c9842d8f6dd3743e401486a53647c31cb96d870fd3a217160fab43f22aeb5f85e952357659e1c00be3c68
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- et_fake_acas_server (0.1.12)
4
+ et_fake_acas_server (0.2.2)
5
5
  activesupport (~> 6.1)
6
6
  iodine (~> 0.7)
7
7
  nokogiri (~> 1.8, >= 1.8.2)
@@ -12,7 +12,7 @@ PATH
12
12
  GEM
13
13
  remote: https://rubygems.org/
14
14
  specs:
15
- activesupport (6.1.5)
15
+ activesupport (6.1.6)
16
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
17
  i18n (>= 1.6, < 2)
18
18
  minitest (>= 5.1)
@@ -21,17 +21,17 @@ GEM
21
21
  concurrent-ruby (1.1.10)
22
22
  i18n (1.10.0)
23
23
  concurrent-ruby (~> 1.0)
24
- iodine (0.7.45)
24
+ iodine (0.7.47)
25
25
  mini_portile2 (2.8.0)
26
- minitest (5.15.0)
26
+ minitest (5.16.1)
27
27
  multi_json (1.15.0)
28
28
  mustermann (1.1.1)
29
29
  ruby2_keywords (~> 0.0.1)
30
- nokogiri (1.13.4)
30
+ nokogiri (1.13.6)
31
31
  mini_portile2 (~> 2.8.0)
32
32
  racc (~> 1.4)
33
33
  racc (1.6.0)
34
- rack (2.2.3)
34
+ rack (2.2.3.1)
35
35
  rack-protection (2.2.0)
36
36
  rack
37
37
  rake (13.0.1)
@@ -51,7 +51,7 @@ GEM
51
51
  tilt (2.0.10)
52
52
  tzinfo (2.0.4)
53
53
  concurrent-ruby (~> 1.0)
54
- zeitwerk (2.5.4)
54
+ zeitwerk (2.6.0)
55
55
 
56
56
  PLATFORMS
57
57
  ruby
@@ -0,0 +1,22 @@
1
+ require 'base64'
2
+ require 'active_support'
3
+ require 'active_support/core_ext/string'
4
+ module EtFakeAcasServer
5
+ class CertificatesLookupForm
6
+ def initialize(payload)
7
+ self.payload = JSON.parse(payload)
8
+ end
9
+
10
+ def validate
11
+
12
+ end
13
+
14
+ def certificate_numbers
15
+ payload['CertificateNumbers']
16
+ end
17
+
18
+ private
19
+
20
+ attr_accessor :payload
21
+ end
22
+ end
@@ -0,0 +1,78 @@
1
+ require 'sinatra/base'
2
+ require 'sinatra/custom_logger'
3
+ require 'logger'
4
+ require 'et_fake_acas_server/forms/certificates_lookup_form'
5
+ require 'active_support'
6
+ require 'active_support/core_ext/numeric/time'
7
+ require 'base64'
8
+
9
+
10
+ module EtFakeAcasServer
11
+ class JsonServer < Sinatra::Base
12
+ def initialize(*)
13
+ super
14
+ self.subscription_key = ENV.fetch('ACAS_JSON_SUBSCRIPTION_KEY', 'fakesubscriptionkeyfortesting')
15
+ end
16
+
17
+ before do
18
+ content_type 'application/json'
19
+ end
20
+
21
+ configure :development, :production do
22
+ logger = Logger.new(STDOUT)
23
+ logger.level = Logger::DEBUG
24
+ set :logger, logger
25
+ end
26
+
27
+ post '/ECCLJson' do
28
+ form = CertificatesLookupForm.new(request.body.read)
29
+ request.body.rewind
30
+ form.validate
31
+ json = form.certificate_numbers.map do |certificate_number|
32
+ case certificate_number
33
+ when /\A(R|NE|MU)000200/ then
34
+ json_builder_for_no_match(certificate_number)
35
+ when /\A(R|NE|MU)000500/ then
36
+ json_builder_for_internal_error
37
+ else
38
+ json_builder_for_found(certificate_number)
39
+ end
40
+ end
41
+ JSON.pretty_generate(json)
42
+ end
43
+
44
+ private
45
+
46
+ attr_accessor :subscription_key
47
+
48
+ def json_builder_for_no_match(certificate_number)
49
+ {
50
+ CertificateNumber: certificate_number,
51
+ CertificateDocument: 'not found'
52
+ }
53
+ end
54
+
55
+ def json_builder_for_found(certificate_number)
56
+ {
57
+ CertificateNumber: certificate_number,
58
+ CertificateDocument: dummy_certificate_as_base_64
59
+ }
60
+ end
61
+
62
+ def json_builder_for_internal_error
63
+ {
64
+ error: {
65
+ code: 'NoResponse',
66
+ message: 'The server did not receive a response from an upstream server.'
67
+ }
68
+
69
+ }
70
+ end
71
+
72
+ def dummy_certificate_as_base_64
73
+ filename = File.absolute_path(File.join('..', 'pdfs', '76 EC (C) Certificate R000080.pdf'), __dir__)
74
+ Base64.encode64(File.read(filename))
75
+ end
76
+ end
77
+ end
78
+
@@ -1,72 +1,12 @@
1
1
  require 'sinatra/base'
2
2
  require 'sinatra/custom_logger'
3
3
  require 'logger'
4
- require 'et_fake_acas_server/forms/certificate_lookup_form'
5
- require 'et_fake_acas_server/xml_builders/found_xml_builder'
6
- require 'et_fake_acas_server/xml_builders/no_match_xml_builder'
7
- require 'et_fake_acas_server/xml_builders/internal_error_xml_builder'
8
- require 'et_fake_acas_server/xml_builders/invalid_certificate_format_xml_builder'
9
- require 'active_support'
10
- require 'active_support/core_ext/numeric/time'
11
-
4
+ require 'et_fake_acas_server/soap_server'
5
+ require 'et_fake_acas_server/json_server'
12
6
 
13
7
  module EtFakeAcasServer
14
8
  class Server < Sinatra::Base
15
- def initialize(*)
16
- super
17
- self.private_key_file = ENV.fetch('ACAS_PRIVATE_KEY_FILE', File.absolute_path(File.join('..', '..', 'temp_x509', 'acas', 'privatekey.pem'), __dir__))
18
- self.et_public_key_file = ENV.fetch('ET_PUBLIC_KEY_FILE', File.absolute_path(File.join('..', '..', 'temp_x509', 'et', 'publickey.cer'), __dir__))
19
- end
20
-
21
- configure :development, :production do
22
- logger = Logger.new(STDOUT)
23
- logger.level = Logger::DEBUG
24
- set :logger, logger
25
- end
26
-
27
- post '/Lookup/ECService.svc' do
28
- form = CertificateLookupForm.new(request.body.read, private_key_file: private_key_file)
29
- request.body.rewind
30
- form.validate
31
- case form.certificate_number
32
- when /\A(R|NE|MU)000200/ then
33
- xml_builder_for_no_match(form).to_xml
34
- when /\A(R|NE|MU)000201/ then
35
- xml_builder_for_invalid_certificate_format(form).to_xml
36
- when /\A(R|NE|MU)000500/ then
37
- xml_builder_for_internal_error(form).to_xml
38
- else
39
- xml_builder_for_found(form).to_xml
40
- end
41
- end
42
-
43
- private
44
-
45
- attr_accessor :private_key_file, :et_public_key_file
46
-
47
- def xml_builder_for_found(form)
48
- data = OpenStruct.new claimant_name: 'Claimant’s Name',
49
- respondent_name: 'Respondent’s Name',
50
- date_of_issue: Time.parse('1 December 2017 12:00:00'),
51
- date_of_receipt: Time.parse('1 January 2017 12:00:00'),
52
- certificate_number: form.certificate_number,
53
- message: 'CertificateFound',
54
- method_of_issue: 'Email',
55
- certificate_file: File.absolute_path(File.join('..', 'pdfs', '76 EC (C) Certificate R000080.pdf'), __dir__)
56
- FoundXmlBuilder.new(form, rsa_et_certificate_path: et_public_key_file).builder(data)
57
- end
58
-
59
- def xml_builder_for_no_match(form)
60
- NoMatchXmlBuilder.new(form, rsa_et_certificate_path: et_public_key_file).builder
61
- end
62
-
63
- def xml_builder_for_internal_error(form)
64
- InternalErrorXmlBuilder.new(form, rsa_et_certificate_path: et_public_key_file).builder
65
- end
66
-
67
- def xml_builder_for_invalid_certificate_format(form)
68
- InvalidCertificateFormatXmlBuilder.new(form, rsa_et_certificate_path: et_public_key_file).builder
69
- end
9
+ post(/\/Lookup\/.*/) { SoapServer.call(env) }
10
+ post(/\/ECCLJson/) { JsonServer.call(env) }
70
11
  end
71
12
  end
72
-
@@ -0,0 +1,72 @@
1
+ require 'sinatra/base'
2
+ require 'sinatra/custom_logger'
3
+ require 'logger'
4
+ require 'et_fake_acas_server/forms/certificate_lookup_form'
5
+ require 'et_fake_acas_server/xml_builders/found_xml_builder'
6
+ require 'et_fake_acas_server/xml_builders/no_match_xml_builder'
7
+ require 'et_fake_acas_server/xml_builders/internal_error_xml_builder'
8
+ require 'et_fake_acas_server/xml_builders/invalid_certificate_format_xml_builder'
9
+ require 'active_support'
10
+ require 'active_support/core_ext/numeric/time'
11
+
12
+
13
+ module EtFakeAcasServer
14
+ class SoapServer < Sinatra::Base
15
+ def initialize(*)
16
+ super
17
+ self.private_key_file = ENV.fetch('ACAS_PRIVATE_KEY_FILE', File.absolute_path(File.join('..', '..', 'temp_x509', 'acas', 'privatekey.pem'), __dir__))
18
+ self.et_public_key_file = ENV.fetch('ET_PUBLIC_KEY_FILE', File.absolute_path(File.join('..', '..', 'temp_x509', 'et', 'publickey.cer'), __dir__))
19
+ end
20
+
21
+ configure :development, :production do
22
+ logger = Logger.new(STDOUT)
23
+ logger.level = Logger::DEBUG
24
+ set :logger, logger
25
+ end
26
+
27
+ post '/Lookup/ECService.svc' do
28
+ form = CertificateLookupForm.new(request.body.read, private_key_file: private_key_file)
29
+ request.body.rewind
30
+ form.validate
31
+ case form.certificate_number
32
+ when /\A(R|NE|MU)000200/ then
33
+ xml_builder_for_no_match(form).to_xml
34
+ when /\A(R|NE|MU)000201/ then
35
+ xml_builder_for_invalid_certificate_format(form).to_xml
36
+ when /\A(R|NE|MU)000500/ then
37
+ xml_builder_for_internal_error(form).to_xml
38
+ else
39
+ xml_builder_for_found(form).to_xml
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ attr_accessor :private_key_file, :et_public_key_file
46
+
47
+ def xml_builder_for_found(form)
48
+ data = OpenStruct.new claimant_name: 'Claimant’s Name',
49
+ respondent_name: 'Respondent’s Name',
50
+ date_of_issue: Time.parse('1 December 2017 12:00:00'),
51
+ date_of_receipt: Time.parse('1 January 2017 12:00:00'),
52
+ certificate_number: form.certificate_number,
53
+ message: 'CertificateFound',
54
+ method_of_issue: 'Email',
55
+ certificate_file: File.absolute_path(File.join('..', 'pdfs', '76 EC (C) Certificate R000080.pdf'), __dir__)
56
+ FoundXmlBuilder.new(form, rsa_et_certificate_path: et_public_key_file).builder(data)
57
+ end
58
+
59
+ def xml_builder_for_no_match(form)
60
+ NoMatchXmlBuilder.new(form, rsa_et_certificate_path: et_public_key_file).builder
61
+ end
62
+
63
+ def xml_builder_for_internal_error(form)
64
+ InternalErrorXmlBuilder.new(form, rsa_et_certificate_path: et_public_key_file).builder
65
+ end
66
+
67
+ def xml_builder_for_invalid_certificate_format(form)
68
+ InvalidCertificateFormatXmlBuilder.new(form, rsa_et_certificate_path: et_public_key_file).builder
69
+ end
70
+ end
71
+ end
72
+
@@ -1,3 +1,3 @@
1
1
  module EtFakeAcasServer
2
- VERSION = "0.1.12"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: et_fake_acas_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary Taylor
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-25 00:00:00.000000000 Z
11
+ date: 2022-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -159,7 +159,10 @@ files:
159
159
  - lib/config.ru
160
160
  - lib/et_fake_acas_server.rb
161
161
  - lib/et_fake_acas_server/forms/certificate_lookup_form.rb
162
+ - lib/et_fake_acas_server/forms/certificates_lookup_form.rb
163
+ - lib/et_fake_acas_server/json_server.rb
162
164
  - lib/et_fake_acas_server/server.rb
165
+ - lib/et_fake_acas_server/soap_server.rb
163
166
  - lib/et_fake_acas_server/version.rb
164
167
  - lib/et_fake_acas_server/xml_builders/found_xml_builder.rb
165
168
  - lib/et_fake_acas_server/xml_builders/internal_error_xml_builder.rb