acquiring-sdk-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +2 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +140 -0
  5. data/Rakefile +34 -0
  6. data/acquiring-sdk-ruby.gemspec +30 -0
  7. data/lib/worldline/acquiring/sdk/api_resource.rb +53 -0
  8. data/lib/worldline/acquiring/sdk/authentication/authenticator.rb +21 -0
  9. data/lib/worldline/acquiring/sdk/authentication/authorization_type.rb +17 -0
  10. data/lib/worldline/acquiring/sdk/authentication/oauth2_authenticator.rb +142 -0
  11. data/lib/worldline/acquiring/sdk/authentication/oauth2_exception.rb +15 -0
  12. data/lib/worldline/acquiring/sdk/authentication.rb +1 -0
  13. data/lib/worldline/acquiring/sdk/call_context.rb +9 -0
  14. data/lib/worldline/acquiring/sdk/client.rb +69 -0
  15. data/lib/worldline/acquiring/sdk/communication/communication_exception.rb +21 -0
  16. data/lib/worldline/acquiring/sdk/communication/connection.rb +50 -0
  17. data/lib/worldline/acquiring/sdk/communication/default_connection.rb +429 -0
  18. data/lib/worldline/acquiring/sdk/communication/metadata_provider.rb +162 -0
  19. data/lib/worldline/acquiring/sdk/communication/multipart_form_data_object.rb +54 -0
  20. data/lib/worldline/acquiring/sdk/communication/multipart_form_data_request.rb +15 -0
  21. data/lib/worldline/acquiring/sdk/communication/not_found_exception.rb +21 -0
  22. data/lib/worldline/acquiring/sdk/communication/param_request.rb +16 -0
  23. data/lib/worldline/acquiring/sdk/communication/pooled_connection.rb +28 -0
  24. data/lib/worldline/acquiring/sdk/communication/request_header.rb +64 -0
  25. data/lib/worldline/acquiring/sdk/communication/request_param.rb +30 -0
  26. data/lib/worldline/acquiring/sdk/communication/response_exception.rb +58 -0
  27. data/lib/worldline/acquiring/sdk/communication/response_header.rb +80 -0
  28. data/lib/worldline/acquiring/sdk/communication.rb +1 -0
  29. data/lib/worldline/acquiring/sdk/communicator.rb +506 -0
  30. data/lib/worldline/acquiring/sdk/communicator_configuration.rb +197 -0
  31. data/lib/worldline/acquiring/sdk/domain/data_object.rb +34 -0
  32. data/lib/worldline/acquiring/sdk/domain/shopping_cart_extension.rb +62 -0
  33. data/lib/worldline/acquiring/sdk/domain/uploadable_file.rb +35 -0
  34. data/lib/worldline/acquiring/sdk/domain.rb +1 -0
  35. data/lib/worldline/acquiring/sdk/factory.rb +183 -0
  36. data/lib/worldline/acquiring/sdk/json/default_marshaller.rb +36 -0
  37. data/lib/worldline/acquiring/sdk/json/marshaller.rb +29 -0
  38. data/lib/worldline/acquiring/sdk/json/marshaller_syntax_exception.rb +11 -0
  39. data/lib/worldline/acquiring/sdk/json.rb +1 -0
  40. data/lib/worldline/acquiring/sdk/logging/communicator_logger.rb +26 -0
  41. data/lib/worldline/acquiring/sdk/logging/log_message_builder.rb +91 -0
  42. data/lib/worldline/acquiring/sdk/logging/logging_capable.rb +19 -0
  43. data/lib/worldline/acquiring/sdk/logging/obfuscation/body_obfuscator.rb +101 -0
  44. data/lib/worldline/acquiring/sdk/logging/obfuscation/header_obfuscator.rb +54 -0
  45. data/lib/worldline/acquiring/sdk/logging/obfuscation/obfuscation_capable.rb +23 -0
  46. data/lib/worldline/acquiring/sdk/logging/obfuscation/obfuscation_rule.rb +49 -0
  47. data/lib/worldline/acquiring/sdk/logging/obfuscation.rb +1 -0
  48. data/lib/worldline/acquiring/sdk/logging/request_log_message_builder.rb +52 -0
  49. data/lib/worldline/acquiring/sdk/logging/response_log_message_builder.rb +43 -0
  50. data/lib/worldline/acquiring/sdk/logging/ruby_communicator_logger.rb +63 -0
  51. data/lib/worldline/acquiring/sdk/logging/stdout_communicator_logger.rb +33 -0
  52. data/lib/worldline/acquiring/sdk/logging.rb +1 -0
  53. data/lib/worldline/acquiring/sdk/proxy_configuration.rb +76 -0
  54. data/lib/worldline/acquiring/sdk/v1/acquirer/acquirer_client.rb +35 -0
  55. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/accountverifications/account_verifications_client.rb +60 -0
  56. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/accountverifications.rb +4 -0
  57. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/dynamiccurrencyconversion/dynamic_currency_conversion_client.rb +60 -0
  58. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/dynamiccurrencyconversion.rb +4 -0
  59. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/merchant_client.rb +66 -0
  60. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/payments/get_payment_status_params.rb +34 -0
  61. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/payments/payments_client.rb +224 -0
  62. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/payments.rb +4 -0
  63. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/refunds/get_refund_params.rb +34 -0
  64. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/refunds/refunds_client.rb +157 -0
  65. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/refunds.rb +4 -0
  66. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/technicalreversals/technical_reversals_client.rb +64 -0
  67. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/technicalreversals.rb +4 -0
  68. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant.rb +4 -0
  69. data/lib/worldline/acquiring/sdk/v1/acquirer.rb +4 -0
  70. data/lib/worldline/acquiring/sdk/v1/api_exception.rb +63 -0
  71. data/lib/worldline/acquiring/sdk/v1/authorization_exception.rb +23 -0
  72. data/lib/worldline/acquiring/sdk/v1/domain/address_verification_data.rb +41 -0
  73. data/lib/worldline/acquiring/sdk/v1/domain/amount_data.rb +48 -0
  74. data/lib/worldline/acquiring/sdk/v1/domain/api_account_verification_request.rb +70 -0
  75. data/lib/worldline/acquiring/sdk/v1/domain/api_account_verification_response.rb +87 -0
  76. data/lib/worldline/acquiring/sdk/v1/domain/api_action_response.rb +71 -0
  77. data/lib/worldline/acquiring/sdk/v1/domain/api_action_response_for_refund.rb +71 -0
  78. data/lib/worldline/acquiring/sdk/v1/domain/api_capture_request.rb +75 -0
  79. data/lib/worldline/acquiring/sdk/v1/domain/api_capture_request_for_refund.rb +43 -0
  80. data/lib/worldline/acquiring/sdk/v1/domain/api_increment_request.rb +61 -0
  81. data/lib/worldline/acquiring/sdk/v1/domain/api_increment_response.rb +43 -0
  82. data/lib/worldline/acquiring/sdk/v1/domain/api_payment_error_response.rb +62 -0
  83. data/lib/worldline/acquiring/sdk/v1/domain/api_payment_refund_request.rb +77 -0
  84. data/lib/worldline/acquiring/sdk/v1/domain/api_payment_request.rb +95 -0
  85. data/lib/worldline/acquiring/sdk/v1/domain/api_payment_resource.rb +103 -0
  86. data/lib/worldline/acquiring/sdk/v1/domain/api_payment_response.rb +126 -0
  87. data/lib/worldline/acquiring/sdk/v1/domain/api_payment_reversal_request.rb +61 -0
  88. data/lib/worldline/acquiring/sdk/v1/domain/api_payment_summary_for_response.rb +66 -0
  89. data/lib/worldline/acquiring/sdk/v1/domain/api_references_for_responses.rb +48 -0
  90. data/lib/worldline/acquiring/sdk/v1/domain/api_refund_request.rb +88 -0
  91. data/lib/worldline/acquiring/sdk/v1/domain/api_refund_resource.rb +110 -0
  92. data/lib/worldline/acquiring/sdk/v1/domain/api_refund_response.rb +133 -0
  93. data/lib/worldline/acquiring/sdk/v1/domain/api_refund_summary_for_response.rb +66 -0
  94. data/lib/worldline/acquiring/sdk/v1/domain/api_reversal_response.rb +36 -0
  95. data/lib/worldline/acquiring/sdk/v1/domain/api_technical_reversal_request.rb +50 -0
  96. data/lib/worldline/acquiring/sdk/v1/domain/api_technical_reversal_response.rb +62 -0
  97. data/lib/worldline/acquiring/sdk/v1/domain/card_data_for_dcc.rb +48 -0
  98. data/lib/worldline/acquiring/sdk/v1/domain/card_on_file_data.rb +52 -0
  99. data/lib/worldline/acquiring/sdk/v1/domain/card_payment_data.rb +114 -0
  100. data/lib/worldline/acquiring/sdk/v1/domain/card_payment_data_for_refund.rb +82 -0
  101. data/lib/worldline/acquiring/sdk/v1/domain/card_payment_data_for_resource.rb +43 -0
  102. data/lib/worldline/acquiring/sdk/v1/domain/card_payment_data_for_response.rb +52 -0
  103. data/lib/worldline/acquiring/sdk/v1/domain/card_payment_data_for_verification.rb +91 -0
  104. data/lib/worldline/acquiring/sdk/v1/domain/dcc_data.rb +55 -0
  105. data/lib/worldline/acquiring/sdk/v1/domain/dcc_proposal.rb +60 -0
  106. data/lib/worldline/acquiring/sdk/v1/domain/e_commerce_data.rb +52 -0
  107. data/lib/worldline/acquiring/sdk/v1/domain/e_commerce_data_for_account_verification.rb +45 -0
  108. data/lib/worldline/acquiring/sdk/v1/domain/e_commerce_data_for_response.rb +41 -0
  109. data/lib/worldline/acquiring/sdk/v1/domain/get_dcc_rate_request.rb +75 -0
  110. data/lib/worldline/acquiring/sdk/v1/domain/get_dcc_rate_response.rb +57 -0
  111. data/lib/worldline/acquiring/sdk/v1/domain/initial_card_on_file_data.rb +41 -0
  112. data/lib/worldline/acquiring/sdk/v1/domain/merchant_data.rb +76 -0
  113. data/lib/worldline/acquiring/sdk/v1/domain/network_token_data.rb +41 -0
  114. data/lib/worldline/acquiring/sdk/v1/domain/payment_references.rb +48 -0
  115. data/lib/worldline/acquiring/sdk/v1/domain/plain_card_data.rb +48 -0
  116. data/lib/worldline/acquiring/sdk/v1/domain/point_of_sale_data.rb +34 -0
  117. data/lib/worldline/acquiring/sdk/v1/domain/point_of_sale_data_for_dcc.rb +41 -0
  118. data/lib/worldline/acquiring/sdk/v1/domain/rate_data.rb +64 -0
  119. data/lib/worldline/acquiring/sdk/v1/domain/sub_operation.rb +94 -0
  120. data/lib/worldline/acquiring/sdk/v1/domain/sub_operation_for_refund.rb +87 -0
  121. data/lib/worldline/acquiring/sdk/v1/domain/subsequent_card_on_file_data.rb +48 -0
  122. data/lib/worldline/acquiring/sdk/v1/domain/three_d_secure.rb +62 -0
  123. data/lib/worldline/acquiring/sdk/v1/domain/transaction_data_for_dcc.rb +52 -0
  124. data/lib/worldline/acquiring/sdk/v1/domain.rb +4 -0
  125. data/lib/worldline/acquiring/sdk/v1/exception_factory.rb +48 -0
  126. data/lib/worldline/acquiring/sdk/v1/ping/ping_client.rb +52 -0
  127. data/lib/worldline/acquiring/sdk/v1/ping.rb +4 -0
  128. data/lib/worldline/acquiring/sdk/v1/platform_exception.rb +23 -0
  129. data/lib/worldline/acquiring/sdk/v1/reference_exception.rb +23 -0
  130. data/lib/worldline/acquiring/sdk/v1/v1_client.rb +43 -0
  131. data/lib/worldline/acquiring/sdk/v1/validation_exception.rb +23 -0
  132. data/lib/worldline/acquiring/sdk/v1.rb +4 -0
  133. data/lib/worldline/acquiring/sdk.rb +1 -0
  134. data/spec/comparable_extension.rb +29 -0
  135. data/spec/fixtures/resources/authentication/oauth2AccessToken.expired.json +4 -0
  136. data/spec/fixtures/resources/authentication/oauth2AccessToken.invalidClient.json +4 -0
  137. data/spec/fixtures/resources/authentication/oauth2AccessToken.json +4 -0
  138. data/spec/fixtures/resources/communication/getWithQueryParams.json +3 -0
  139. data/spec/fixtures/resources/communication/getWithoutQueryParams.json +3 -0
  140. data/spec/fixtures/resources/communication/notFound.html +1 -0
  141. data/spec/fixtures/resources/communication/postWithBadRequestResponse.json +11 -0
  142. data/spec/fixtures/resources/communication/postWithCreatedResponse.json +6 -0
  143. data/spec/fixtures/resources/communication/unknownServerError.json +10 -0
  144. data/spec/fixtures/resources/logging/bodyNoObfuscation.json +7 -0
  145. data/spec/fixtures/resources/logging/bodyWithBinObfuscated.json +3 -0
  146. data/spec/fixtures/resources/logging/bodyWithBinOriginal.json +3 -0
  147. data/spec/fixtures/resources/logging/bodyWithCardCustomObfuscated.json +13 -0
  148. data/spec/fixtures/resources/logging/bodyWithCardObfuscated.json +13 -0
  149. data/spec/fixtures/resources/logging/bodyWithCardOriginal.json +13 -0
  150. data/spec/fixtures/resources/logging/bodyWithObjectObfuscated.json +5 -0
  151. data/spec/fixtures/resources/logging/bodyWithObjectOriginal.json +5 -0
  152. data/spec/fixtures/resources/properties.oauth2.yml +8 -0
  153. data/spec/fixtures/resources/properties.proxy.yml +14 -0
  154. data/spec/integration/connection_pooling_spec.rb +74 -0
  155. data/spec/integration/multipart_form_data_spec.rb +216 -0
  156. data/spec/integration/process_payment_spec.rb +43 -0
  157. data/spec/integration/request_dcc_rate_spec.rb +24 -0
  158. data/spec/integration/sdk_proxy_spec.rb +70 -0
  159. data/spec/integration_setup.rb +111 -0
  160. data/spec/lib/authentication/oauth2_authenticator_spec.rb +68 -0
  161. data/spec/lib/client_spec.rb +47 -0
  162. data/spec/lib/communication/default_connection_logger_spec.rb +484 -0
  163. data/spec/lib/communication/default_connection_spec.rb +352 -0
  164. data/spec/lib/communication/metadata_provider_spec.rb +93 -0
  165. data/spec/lib/communicator_configuration_spec.rb +181 -0
  166. data/spec/lib/communicator_spec.rb +34 -0
  167. data/spec/lib/factory_spec.rb +38 -0
  168. data/spec/lib/json/default_marshaller_spec.rb +39 -0
  169. data/spec/lib/logging/obfuscation/body_obfuscator_spec.rb +86 -0
  170. data/spec/lib/logging/obfuscation/header_obfuscator_spec.rb +100 -0
  171. data/spec/lib/logging/ruby_communicator_logger_spec.rb +92 -0
  172. data/spec/lib/logging/stdout_communicator_logger_spec.rb +64 -0
  173. data/spec/spec_helper.rb +32 -0
  174. metadata +375 -0
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+ require 'uri'
3
+
4
+ Factory ||= Worldline::Acquiring::SDK::Factory
5
+
6
+ describe 'Factory' do
7
+ it 'can initialize configurations' do
8
+ configuration = Factory.create_configuration(PROPERTIES_URI_OAUTH2, OAUTH2_CLIENT_ID, OAUTH2_CLIENT_SECRET)
9
+
10
+ expect(configuration.api_endpoint).to eq('https://api.preprod.acquiring.worldline-solutions.com')
11
+ expect(configuration.authorization_type).to eq('OAuth2')
12
+ expect(configuration.connect_timeout).to eq(1000)
13
+ expect(configuration.socket_timeout).to eq(1000)
14
+ expect(configuration.max_connections).to eq(100)
15
+ expect(configuration.oauth2_client_id).to eq(OAUTH2_CLIENT_ID)
16
+ expect(configuration.oauth2_client_secret).to eq(OAUTH2_CLIENT_SECRET)
17
+ expect(configuration.proxy_configuration).to be_nil
18
+ end
19
+
20
+ it 'can initialize communicators' do
21
+ communicator = Factory.create_communicator_from_file(PROPERTIES_URI_OAUTH2, OAUTH2_CLIENT_ID, OAUTH2_CLIENT_SECRET)
22
+ connection = communicator.instance_variable_get(:@connection)
23
+ authenticator = communicator.instance_variable_get(:@authenticator)
24
+ metadata_provider = communicator.instance_variable_get(:@metadata_provider)
25
+ request_headers = metadata_provider.metadata_headers
26
+
27
+ expect(communicator.marshaller).to be(Worldline::Acquiring::SDK::JSON::DefaultMarshaller.instance)
28
+ expect(connection).to be_an_instance_of(Worldline::Acquiring::SDK::Communication::DefaultConnection)
29
+ expect(authenticator).to be_an_instance_of(Worldline::Acquiring::SDK::Authentication::OAuth2Authenticator)
30
+ expect(metadata_provider).to be_an_instance_of(Worldline::Acquiring::SDK::Communication::MetadataProvider)
31
+
32
+ expect(authenticator.instance_variable_get(:@client_id)).to eq(OAUTH2_CLIENT_ID)
33
+ expect(authenticator.instance_variable_get(:@client_secret)).to eq(OAUTH2_CLIENT_SECRET)
34
+
35
+ expect(request_headers.length).to eq(1)
36
+ expect(request_headers[0].name).to eq('X-WL-ServerMetaInfo')
37
+ end
38
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ DataObject ||= Worldline::Acquiring::SDK::Domain::DataObject
4
+ DefaultMarshaller ||= Worldline::Acquiring::SDK::JSON::DefaultMarshaller
5
+
6
+ class BaseObject < DataObject
7
+ attr_accessor :id
8
+
9
+ def to_h
10
+ hash = super
11
+ hash['id'] = @id unless @id.nil?
12
+ hash
13
+ end
14
+
15
+ def from_hash(hash)
16
+ super
17
+ if hash.has_key? 'id'
18
+ @id = hash['id']
19
+ end
20
+ end
21
+ end
22
+
23
+ class ObjectWithExtraField < BaseObject
24
+ attr_accessor :dummy
25
+ end
26
+
27
+ describe DefaultMarshaller do
28
+ context 'unmarshal()' do
29
+ it 'should unmarshal extra fields' do
30
+ object = ObjectWithExtraField.new
31
+ object.id = '1234'
32
+ object.dummy = 'foobar'
33
+ # marshal the extended object and unmarshal it as a regular object
34
+ unmarshalled = DefaultMarshaller.instance.unmarshal(DefaultMarshaller.instance.marshal(object), BaseObject)
35
+
36
+ expect(unmarshalled.id).to eq('1234')
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ BodyObfuscator = Worldline::Acquiring::SDK::Logging::Obfuscation::BodyObfuscator
4
+
5
+ def test_obfuscate_body_with_matches(original_resource, obfuscated_resource,
6
+ body_obfuscator=BodyObfuscator.default_obfuscator)
7
+ prefix = 'spec/fixtures/resources/logging/'
8
+ body = IO.read(prefix + original_resource)
9
+ expected = IO.read(prefix + obfuscated_resource)
10
+ expected == body_obfuscator.obfuscate_body(body)
11
+ end
12
+
13
+ def test_obfuscate_body_with_no_matches(resource)
14
+ prefix = 'spec/fixtures/resources/logging/'
15
+ body = IO.read(prefix + resource)
16
+ body == BodyObfuscator.default_obfuscator.obfuscate_body(body)
17
+ end
18
+
19
+ describe BodyObfuscator do
20
+ context '.obfuscate_body()' do
21
+
22
+ context 'with null body' do
23
+ let(:body) { nil }
24
+ it 'returns null body' do
25
+ expect(
26
+ BodyObfuscator.default_obfuscator.obfuscate_body(body)
27
+ ).to be_nil
28
+ end
29
+ end
30
+
31
+ context 'with empty body' do
32
+ let(:body) { '' }
33
+ it 'returns empty body' do
34
+ expect(
35
+ BodyObfuscator.default_obfuscator.obfuscate_body(body)
36
+ ).to eq(body)
37
+ end
38
+ end
39
+
40
+ it 'works with card' do
41
+ expect(
42
+ test_obfuscate_body_with_matches("bodyWithCardOriginal.json",
43
+ "bodyWithCardObfuscated.json")
44
+ ).to be(true)
45
+ end
46
+
47
+ it 'works with custom card rule' do
48
+ def obfuscate_custom(value)
49
+ # range describes the range of characters to replace with asterisks
50
+ range = 6...(value.length - 4)
51
+ value[range] = '*' * range.size
52
+ value
53
+ end
54
+
55
+ body_obfuscator = BodyObfuscator.new(additional_rules={
56
+ 'cardNumber' => method(:obfuscate_custom)
57
+ })
58
+
59
+ expect(
60
+ test_obfuscate_body_with_matches("bodyWithCardOriginal.json",
61
+ "bodyWithCardCustomObfuscated.json",
62
+ body_obfuscator=body_obfuscator)
63
+ ).to be(true)
64
+ end
65
+
66
+ it 'works with bin' do
67
+ expect(
68
+ test_obfuscate_body_with_matches("bodyWithBinOriginal.json",
69
+ "bodyWithBinObfuscated.json")
70
+ ).to be(true)
71
+ end
72
+
73
+ it 'works when there is no match' do
74
+ expect(
75
+ test_obfuscate_body_with_no_matches("bodyNoObfuscation.json")
76
+ ).to be(true)
77
+ end
78
+
79
+ it 'works with object' do
80
+ expect(
81
+ test_obfuscate_body_with_matches("bodyWithObjectOriginal.json",
82
+ "bodyWithObjectObfuscated.json")
83
+ ).to be(true)
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,100 @@
1
+ require 'spec_helper'
2
+
3
+ HeaderObfuscator = Worldline::Acquiring::SDK::Logging::Obfuscation::HeaderObfuscator
4
+ Obfuscation = Worldline::Acquiring::SDK::Logging::Obfuscation
5
+
6
+ def test_obfuscate_header_with_match(name, original_value, expected_value,
7
+ header_obfuscator=HeaderObfuscator.default_obfuscator)
8
+ expected_value == header_obfuscator.obfuscate_header(name, original_value)
9
+ end
10
+
11
+ def test_obfuscate_header_with_no_match(name, original_value)
12
+ original_value == HeaderObfuscator.default_obfuscator.obfuscate_header(name, original_value)
13
+ end
14
+
15
+ describe HeaderObfuscator do
16
+ context '.obfuscate_header()' do
17
+ it 'works when there is a match' do
18
+ expect(
19
+ test_obfuscate_header_with_match("Authorization",
20
+ "Basic QWxhZGRpbjpPcGVuU2VzYW1l",
21
+ "********")
22
+ ).to be(true)
23
+
24
+ expect(
25
+ test_obfuscate_header_with_match("authorization",
26
+ "Basic QWxhZGRpbjpPcGVuU2VzYW1l",
27
+ "********")
28
+ ).to be(true)
29
+
30
+ expect(
31
+ test_obfuscate_header_with_match("AUTHORIZATION",
32
+ "Basic QWxhZGRpbjpPcGVuU2VzYW1l",
33
+ "********")
34
+ ).to be(true)
35
+ end
36
+
37
+ it 'works when there is no match' do
38
+ expect(
39
+ test_obfuscate_header_with_no_match("Content-Type",
40
+ "application/json")
41
+ ).to be(true)
42
+
43
+ expect(
44
+ test_obfuscate_header_with_no_match("content-type",
45
+ "application/json")
46
+ ).to be(true)
47
+
48
+ expect(
49
+ test_obfuscate_header_with_no_match("CONTENT-TYPE",
50
+ "application/json")
51
+ ).to be(true)
52
+ end
53
+
54
+ it 'works with a custom rule' do
55
+ header_obfuscator = HeaderObfuscator.new(additional_rules={
56
+ 'content-type' => Obfuscation.obfuscate_all
57
+ })
58
+
59
+ expect(
60
+ test_obfuscate_header_with_match("Authorization",
61
+ "Basic QWxhZGRpbjpPcGVuU2VzYW1l",
62
+ "********",
63
+ header_obfuscator=header_obfuscator)
64
+ ).to be(true)
65
+
66
+ expect(
67
+ test_obfuscate_header_with_match("authorization",
68
+ "Basic QWxhZGRpbjpPcGVuU2VzYW1l",
69
+ "********",
70
+ header_obfuscator=header_obfuscator)
71
+ ).to be(true)
72
+
73
+ expect(
74
+ test_obfuscate_header_with_match("AUTHORIZATION",
75
+ "Basic QWxhZGRpbjpPcGVuU2VzYW1l",
76
+ "********",
77
+ header_obfuscator=header_obfuscator)
78
+ ).to be(true)
79
+
80
+ expect(
81
+ test_obfuscate_header_with_match("Content-Type", "application/json",
82
+ "****************",
83
+ header_obfuscator=header_obfuscator)
84
+ ).to be(true)
85
+
86
+ expect(
87
+ test_obfuscate_header_with_match("content-type", "application/json",
88
+ "****************",
89
+ header_obfuscator=header_obfuscator)
90
+ ).to be(true)
91
+
92
+ expect(
93
+ test_obfuscate_header_with_match("CONTENT-TYPE", "application/json",
94
+ "****************",
95
+ header_obfuscator=header_obfuscator)
96
+ ).to be(true)
97
+ end
98
+
99
+ end
100
+ end
@@ -0,0 +1,92 @@
1
+ require 'spec_helper'
2
+ require 'logger'
3
+ require 'English'
4
+
5
+ RubyCommunicatorLogger = Worldline::Acquiring::SDK::Logging::RubyCommunicatorLogger
6
+
7
+ describe RubyCommunicatorLogger do
8
+
9
+ # TODO: is it possbile that we run into a filename collision here?
10
+ let(:filename) { "testing-#{(0...8).map { (65 + rand(26)).chr }.join}.log" }
11
+ let(:logger) { Logger.new(RubyCommunicatorLogger.create_logfile(filename)) }
12
+ let(:regex) { Regexp.new("#{tag}, .* -- : (.*)#{$RS}", Regexp::MULTILINE) }
13
+ subject(:sample) { RubyCommunicatorLogger.new(logger, log_level, error_level) }
14
+
15
+ def expected_msg(msg, thrown=false)
16
+ return msg unless thrown
17
+ msg + $RS + thrown.to_s + $RS + thrown.backtrace.join($RS)
18
+ end
19
+
20
+ after do
21
+ # delete the log files
22
+ logger.close
23
+ File.delete(filename)
24
+ end
25
+
26
+
27
+ context 'logging without error' do
28
+
29
+ let(:error_level) { Logger::WARN }
30
+ let(:msg) { 'Hello World' }
31
+
32
+ context "with level 'INFO'" do
33
+ let(:log_level) { Logger::INFO }
34
+ let(:tag) { 'I' }
35
+
36
+ it 'should not throw an exception when logging unicode strings' do
37
+ message = Worldline::Acquiring::SDK::Logging::ResponseLogMessageBuilder.new("aaa", 2345, 45.32)
38
+ body = "Schröder"
39
+ content = "JSON"
40
+ message.set_body(body, content)
41
+ sample.log(message.get_message)
42
+ end
43
+ it 'logs with the correct logLevel and message' do
44
+ sample.log(msg)
45
+ line = IO.readlines(filename).last
46
+
47
+ expect(line).to match(regex)
48
+ expect(
49
+ line.match(regex)[1] # first capture
50
+ ).to eq(expected_msg(msg))
51
+ end
52
+ end
53
+
54
+ context "with level 'WARN'" do
55
+ let(:log_level) { Logger::WARN }
56
+ let(:tag) { 'W' }
57
+
58
+ it 'logs with the correct logLevel and message' do
59
+ sample.log(msg)
60
+ line = IO.readlines(filename).last
61
+
62
+ expect(line).to match(regex)
63
+ expect(
64
+ line.match(regex)[1] # idem
65
+ ).to eq(expected_msg(msg))
66
+ end
67
+ end
68
+ end
69
+
70
+ context 'logging with error' do
71
+ let(:error_level) { Logger::WARN }
72
+ let(:log_level) { Logger::INFO }
73
+ let(:msg) { 'Some error message' }
74
+ let(:tag) { 'W' }
75
+
76
+ it 'logs with the errorLevel and message with backtrace' do
77
+ def dummy_method
78
+ raise 'Boom!'
79
+ end
80
+
81
+ begin
82
+ dummy_method
83
+ rescue => exception
84
+ sample.log(msg, exception)
85
+ end
86
+
87
+ line = IO.read(filename)
88
+ expect(line).to match(regex)
89
+ expect(line.match(regex)[1]).to eq(expected_msg(msg, exception))
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+ require 'English'
3
+
4
+ StdoutCommunicatorLogger ||= Worldline::Acquiring::SDK::Logging::StdoutCommunicatorLogger
5
+
6
+ describe StdoutCommunicatorLogger do
7
+ before do
8
+ $stdout = StringIO.new
9
+ end
10
+
11
+ after do
12
+ $stdout.close
13
+ $stdout = STDOUT
14
+ end
15
+
16
+ subject(:sample) { StdoutCommunicatorLogger.instance }
17
+ let(:regex) do
18
+ Regexp.new("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2} (.*)#{$RS}",
19
+ Regexp::MULTILINE)
20
+ end
21
+
22
+ def expected_msg(msg, thrown=false)
23
+ return msg unless thrown
24
+ msg + $RS + thrown.to_s + $RS + thrown.backtrace.join($RS)
25
+ end
26
+
27
+ context 'test log' do
28
+ let(:msg) { 'Hello World' }
29
+
30
+ it 'should log the exact message' do
31
+ sample.log(msg)
32
+
33
+ expect(
34
+ $stdout.string
35
+ ).to match(regex)
36
+
37
+ expect(
38
+ regex.match($stdout.string)[1] # first capture
39
+ ).to eq(expected_msg(msg))
40
+ end
41
+
42
+ it 'should log the backtrace of the exception' do
43
+
44
+ def dummy_method
45
+ raise 'Boom!'
46
+ end
47
+
48
+ begin
49
+ dummy_method
50
+ rescue => exception
51
+ sample.log(msg, exception)
52
+ end
53
+
54
+ expect(
55
+ $stdout.string
56
+ ).to match(regex)
57
+
58
+ expect(
59
+ regex.match($stdout.string)[1] # first capture
60
+ ).to eq(expected_msg(msg, exception))
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,32 @@
1
+ require 'rspec'
2
+ require 'webmock/rspec'
3
+
4
+ require 'worldline/acquiring/sdk'
5
+ require 'comparable_extension'
6
+
7
+ RSpec.configure do |config|
8
+
9
+ WebMock.disable_net_connect! # make it explicit
10
+
11
+ config.order = 'random'
12
+ config.profile_examples = 5 # show the slowest tests
13
+
14
+ # declaration of constants to use throughout the tests
15
+ config.before(:suite) do
16
+ class MockAuthenticator < Worldline::Acquiring::SDK::Authentication::Authenticator
17
+ def get_authorization(http_method, resource_uri, request_headers)
18
+ 'ignored'
19
+ end
20
+ end
21
+
22
+ PROPERTIES_URI_OAUTH2 = File.expand_path('../../spec/fixtures/resources/properties.oauth2.yml', __FILE__)
23
+ OAUTH2_CLIENT_ID = 'someId'
24
+ OAUTH2_CLIENT_SECRET = 'someSecret'
25
+ authenticator = MockAuthenticator.new
26
+ COMMUNICATOR = Worldline::Acquiring::SDK::Factory.create_communicator_from_file(PROPERTIES_URI_OAUTH2, OAUTH2_CLIENT_ID, OAUTH2_CLIENT_SECRET,
27
+ authenticator: authenticator)
28
+ CLIENT = Worldline::Acquiring::SDK::Factory.create_client_from_communicator(COMMUNICATOR)
29
+ end
30
+
31
+ config.after(:suite) { CLIENT.close }
32
+ end