et_fake_acas_server 0.1.12 → 0.2.0

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: d5c5cd02d12ff822ddc8f3c5c68a3ea23c1964e346b4310536126a8a20e5d626
4
+ data.tar.gz: c0ad55f520e6d25efd85d3e8f0ce4d829762f5b31cfbfe9f8494d4c0ee3d1b7c
5
5
  SHA512:
6
- metadata.gz: 1a625215b357753a371c30b9de3c388814aa52f2bddbff3f2e3be680e4a1766c2dba1c7d78c23165fede3cd0a714150306145a85c55a637326f5d71ed525c064
7
- data.tar.gz: e5e07fa8518656f770efd226165554a27076cc36a218728da06d9d9242bc035ad4c1076cc4cd3f6078fd04342e87e443dd2043eb14af8ca1f0ec36cb4acf0a82
6
+ metadata.gz: ae3a4aa4a8767939fd52db6a6d833abf8fa9152102ad08797d4d960932eb36997dc8adf568fb050681f534a1af146da737224b858c69563766538dd9ddb10df6
7
+ data.tar.gz: 2fbcd8f0a30b21d89afa47bd504084ff6ebe712a5f91dd43c1f3b1a0259c18050c5dcdf7c96e783f2a7e8276cce0c0148ea51a90ace609cf4129afd6107d1e1a
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.0)
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
26
  minitest (5.15.0)
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)
@@ -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,62 @@
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
+ configure :development, :production do
18
+ logger = Logger.new(STDOUT)
19
+ logger.level = Logger::DEBUG
20
+ set :logger, logger
21
+ end
22
+
23
+ post '/ECCLJson' do
24
+ form = CertificatesLookupForm.new(request.body.read)
25
+ request.body.rewind
26
+ form.validate
27
+ json = form.certificate_numbers.map do |certificate_number|
28
+ case certificate_number
29
+ when /\A(R|NE|MU)000200/ then
30
+ json_builder_for_no_match(certificate_number)
31
+ else
32
+ json_builder_for_found(certificate_number)
33
+ end
34
+ end
35
+ JSON.pretty_generate(json)
36
+ end
37
+
38
+ private
39
+
40
+ attr_accessor :subscription_key
41
+
42
+ def json_builder_for_no_match(certificate_number)
43
+ {
44
+ CertificateNumber: certificate_number,
45
+ CertificateDocument: 'not found'
46
+ }
47
+ end
48
+
49
+ def json_builder_for_found(certificate_number)
50
+ {
51
+ CertificateNumber: certificate_number,
52
+ CertificateDocument: dummy_certificate_as_base_64
53
+ }
54
+ end
55
+
56
+ def dummy_certificate_as_base_64
57
+ filename = File.absolute_path(File.join('..', 'pdfs', '76 EC (C) Certificate R000080.pdf'), __dir__)
58
+ Base64.encode64(File.read(filename))
59
+ end
60
+ end
61
+ end
62
+
@@ -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.0"
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.0
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-10 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