opensrs 0.3.8 → 0.4.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
- SHA1:
3
- metadata.gz: ab4edecdc574d1a43b6363a82ee08aafec9009c4
4
- data.tar.gz: 2573a679c20e68b6620480f8b6098344a8b96741
2
+ SHA256:
3
+ metadata.gz: 71d1e83d17bb3fbcf14fe9da34120322c4411bfeb37b9f6023806467025e5d5f
4
+ data.tar.gz: 941f1cc4275cf0f64635d6ed5e326a7ebdb9bc6ee98230c495de7e809637d661
5
5
  SHA512:
6
- metadata.gz: 66a37ff3deabef598de0110754b6ccc56d03b86abe14c40ed35f273145eec35e414aaa5788a63904086cf91027dbae1d7d1c786d82320b0976dcdc0e01dd5026
7
- data.tar.gz: 3bd39902a5ba5e08bf23f04c1e3f201e4e9e57e07af3b168c06e0dd42098031c9f5ebcdf151dadadb18729f63b7391d7a0234a2aec469851415c44b2ccfcd476
6
+ metadata.gz: df149b8fcd50164c419c51aa789d4dab1e8409952ec0b4b1f2fcd202948111512931d82a5169635b8690feec9f01d82fba0548b5952691dcf2d3323081b25210
7
+ data.tar.gz: 54e8f4bcbb4538d6215d94dd3bcd797f59dffa7e120a181b2af62d4f38c1cf8fb737d8298e516feda9f7bfc7b100b894714ea33cab4f8fc00458ab95b4b5c330
@@ -0,0 +1,43 @@
1
+ # pulled from repo
2
+ name: "Rubocop"
3
+
4
+ on:
5
+ push:
6
+ branches: [ master, rubocop ]
7
+ pull_request:
8
+ # The branches below must be a subset of the branches above
9
+ branches: [ master, rubocop ]
10
+ schedule:
11
+ - cron: '37 10 * * 2'
12
+
13
+ jobs:
14
+ rubocop:
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ fail-fast: false
18
+
19
+ steps:
20
+ - name: Checkout repository
21
+ uses: actions/checkout@v2
22
+
23
+ # If running on a self-hosted runner, check it meets the requirements
24
+ # listed at https://github.com/ruby/setup-ruby#using-self-hosted-runners
25
+ - name: Set up Ruby
26
+ uses: ruby/setup-ruby@v1
27
+ with:
28
+ ruby-version: 2.6
29
+
30
+ - name: Install dependencies
31
+ run: bundle install
32
+
33
+ - name: Rubocop run
34
+ run: |
35
+ bash -c "
36
+ bundle exec rubocop --require code_scanning --format CodeScanning::SarifFormatter -o rubocop.sarif
37
+ [[ $? -ne 2 ]]
38
+ "
39
+
40
+ - name: Upload Sarif output
41
+ uses: github/codeql-action/upload-sarif@v1
42
+ with:
43
+ sarif_file: rubocop.sarif
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  /.bundle/
2
+ /.vscode
2
3
  /.yardoc
3
4
  /Gemfile.lock
4
5
  /_yardoc/
@@ -13,3 +14,4 @@
13
14
  *.a
14
15
  *.gem
15
16
  mkmf.log
17
+ *.sarif
data/.rubocop.yml ADDED
@@ -0,0 +1,131 @@
1
+ require: rubocop-rspec
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.5
5
+ SuggestExtensions: false
6
+
7
+ Style/FrozenStringLiteralComment:
8
+ Enabled: false
9
+
10
+ RSpec/InstanceVariable:
11
+ Enabled: false
12
+
13
+ Metrics/BlockLength:
14
+ Enabled: false
15
+
16
+ RSpec/FilePath:
17
+ Enabled: false
18
+
19
+ Layout/LineLength:
20
+ Enabled: false
21
+
22
+ RSpec/MultipleExpectations:
23
+ Enabled: false
24
+
25
+ RSpec/ExampleLength:
26
+ Enabled: false
27
+
28
+ RSpec/NestedGroups:
29
+ Enabled: false
30
+
31
+ RSpec/MultipleMemoizedHelpers:
32
+ Enabled: false
33
+
34
+ RSpec/MessageSpies:
35
+ Enabled: false
36
+
37
+ RSpec/StubbedMock:
38
+ Enabled: false
39
+
40
+ RSpec/VerifiedDoubles:
41
+ Enabled: false
42
+
43
+ Metrics/MethodLength:
44
+ Enabled: false
45
+
46
+ Metrics/AbcSize:
47
+ Enabled: false
48
+
49
+ Style/ClassVars:
50
+ Enabled: false
51
+
52
+ Gemspec/DateAssignment: # (new in 1.10)
53
+ Enabled: true
54
+ Layout/LineEndStringConcatenationIndentation: # (new in 1.18)
55
+ Enabled: true
56
+ Layout/SpaceBeforeBrackets: # (new in 1.7)
57
+ Enabled: true
58
+ Lint/AmbiguousAssignment: # (new in 1.7)
59
+ Enabled: true
60
+ Lint/AmbiguousRange: # (new in 1.19)
61
+ Enabled: true
62
+ Lint/DeprecatedConstants: # (new in 1.8)
63
+ Enabled: true
64
+ Lint/DuplicateBranch: # (new in 1.3)
65
+ Enabled: true
66
+ Lint/DuplicateRegexpCharacterClassElement: # (new in 1.1)
67
+ Enabled: true
68
+ Lint/EmptyBlock: # (new in 1.1)
69
+ Enabled: true
70
+ Lint/EmptyClass: # (new in 1.3)
71
+ Enabled: true
72
+ Lint/EmptyInPattern: # (new in 1.16)
73
+ Enabled: true
74
+ Lint/LambdaWithoutLiteralBlock: # (new in 1.8)
75
+ Enabled: true
76
+ Lint/NoReturnInBeginEndBlocks: # (new in 1.2)
77
+ Enabled: true
78
+ Lint/NumberedParameterAssignment: # (new in 1.9)
79
+ Enabled: true
80
+ Lint/OrAssignmentToConstant: # (new in 1.9)
81
+ Enabled: true
82
+ Lint/RedundantDirGlobSort: # (new in 1.8)
83
+ Enabled: true
84
+ Lint/SymbolConversion: # (new in 1.9)
85
+ Enabled: true
86
+ Lint/ToEnumArguments: # (new in 1.1)
87
+ Enabled: true
88
+ Lint/TripleQuotes: # (new in 1.9)
89
+ Enabled: true
90
+ Lint/UnexpectedBlockArity: # (new in 1.5)
91
+ Enabled: true
92
+ Lint/UnmodifiedReduceAccumulator: # (new in 1.1)
93
+ Enabled: true
94
+ Naming/InclusiveLanguage: # (new in 1.18)
95
+ Enabled: true
96
+ Style/ArgumentsForwarding: # (new in 1.1)
97
+ Enabled: true
98
+ Style/CollectionCompact: # (new in 1.2)
99
+ Enabled: true
100
+ Style/DocumentDynamicEvalDefinition: # (new in 1.1)
101
+ Enabled: true
102
+ Style/EndlessMethod: # (new in 1.8)
103
+ Enabled: true
104
+ Style/HashConversion: # (new in 1.10)
105
+ Enabled: true
106
+ Style/HashExcept: # (new in 1.7)
107
+ Enabled: true
108
+ Style/IfWithBooleanLiteralBranches: # (new in 1.9)
109
+ Enabled: true
110
+ Style/InPatternThen: # (new in 1.16)
111
+ Enabled: true
112
+ Style/MultilineInPatternThen: # (new in 1.16)
113
+ Enabled: true
114
+ Style/NegatedIfElseCondition: # (new in 1.2)
115
+ Enabled: true
116
+ Style/NilLambda: # (new in 1.3)
117
+ Enabled: true
118
+ Style/QuotedSymbols: # (new in 1.16)
119
+ Enabled: true
120
+ Style/RedundantArgument: # (new in 1.4)
121
+ Enabled: true
122
+ Style/RedundantSelfAssignmentBranch: # (new in 1.19)
123
+ Enabled: true
124
+ Style/StringChars: # (new in 1.12)
125
+ Enabled: true
126
+ Style/SwapValues: # (new in 1.1)
127
+ Enabled: true
128
+ RSpec/IdenticalEqualityAssertion: # (new in 2.4)
129
+ Enabled: true
130
+ RSpec/Rails/AvoidSetupHook: # (new in 2.4)
131
+ Enabled: true
data/Gemfile.lock CHANGED
@@ -1,32 +1,43 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- opensrs (0.3.6)
4
+ opensrs (0.3.8)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- activesupport (4.2.1)
9
+ activesupport (4.2.10)
10
10
  i18n (~> 0.7)
11
- json (~> 1.7, >= 1.7.7)
12
11
  minitest (~> 5.1)
13
12
  thread_safe (~> 0.3, >= 0.3.4)
14
13
  tzinfo (~> 1.1)
14
+ ast (2.4.2)
15
+ code-scanning-rubocop (0.5.0)
16
+ rubocop (~> 1.0)
15
17
  coderay (1.1.0)
18
+ concurrent-ruby (1.0.5)
16
19
  diff-lcs (1.2.5)
17
- i18n (0.7.0)
18
- json (1.8.2)
19
- libxml-ruby (2.8.0)
20
+ i18n (0.9.3)
21
+ concurrent-ruby (~> 1.0)
22
+ libxml-ruby (3.2.1)
20
23
  method_source (0.8.2)
21
- mini_portile (0.6.2)
22
- minitest (5.6.1)
23
- nokogiri (1.6.6.2)
24
- mini_portile (~> 0.6.0)
24
+ mini_portile2 (2.5.1)
25
+ minitest (5.11.3)
26
+ nokogiri (1.11.4)
27
+ mini_portile2 (~> 2.5.0)
28
+ racc (~> 1.4)
29
+ parallel (1.20.1)
30
+ parser (3.0.2.0)
31
+ ast (~> 2.4.1)
25
32
  pry (0.10.1)
26
33
  coderay (~> 1.1.0)
27
34
  method_source (~> 0.8.1)
28
35
  slop (~> 3.4)
29
- rake (10.4.2)
36
+ racc (1.5.2)
37
+ rainbow (3.0.0)
38
+ rake (13.0.6)
39
+ regexp_parser (2.1.1)
40
+ rexml (3.2.5)
30
41
  rspec (3.2.0)
31
42
  rspec-core (~> 3.2.0)
32
43
  rspec-expectations (~> 3.2.0)
@@ -40,6 +51,21 @@ GEM
40
51
  diff-lcs (>= 1.2.0, < 2.0)
41
52
  rspec-support (~> 3.2.0)
42
53
  rspec-support (3.2.2)
54
+ rubocop (1.19.0)
55
+ parallel (~> 1.10)
56
+ parser (>= 3.0.0.0)
57
+ rainbow (>= 2.2.2, < 4.0)
58
+ regexp_parser (>= 1.8, < 3.0)
59
+ rexml
60
+ rubocop-ast (>= 1.9.1, < 2.0)
61
+ ruby-progressbar (~> 1.7)
62
+ unicode-display_width (>= 1.4.0, < 3.0)
63
+ rubocop-ast (1.10.0)
64
+ parser (>= 3.0.1.1)
65
+ rubocop-rspec (2.4.0)
66
+ rubocop (~> 1.0)
67
+ rubocop-ast (>= 1.1.0)
68
+ ruby-progressbar (1.11.0)
43
69
  shoulda (3.5.0)
44
70
  shoulda-context (~> 1.0, >= 1.0.1)
45
71
  shoulda-matchers (>= 1.4.1, < 3.0)
@@ -47,19 +73,27 @@ GEM
47
73
  shoulda-matchers (2.8.0)
48
74
  activesupport (>= 3.0.0)
49
75
  slop (3.6.0)
50
- thread_safe (0.3.5)
51
- tzinfo (1.2.2)
76
+ thread_safe (0.3.6)
77
+ tzinfo (1.2.4)
52
78
  thread_safe (~> 0.1)
79
+ unicode-display_width (2.0.0)
53
80
 
54
81
  PLATFORMS
55
82
  ruby
56
83
 
57
84
  DEPENDENCIES
85
+ activesupport (~> 4.2.2)
58
86
  bundler
59
- libxml-ruby (~> 2)
60
- nokogiri
87
+ code-scanning-rubocop (~> 0.5)
88
+ libxml-ruby (~> 3)
89
+ nokogiri (~> 1.11.4)
61
90
  opensrs!
62
91
  pry
63
92
  rake
64
93
  rspec
94
+ rubocop (~> 1)
95
+ rubocop-rspec
65
96
  shoulda
97
+
98
+ BUNDLED WITH
99
+ 1.17.2
data/README.md CHANGED
@@ -1,17 +1,13 @@
1
1
  # OpenSRS
2
2
 
3
- [![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/voxxit/opensrs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
-
5
- [![Build Status](https://travis-ci.org/voxxit/opensrs.svg?branch=master)](https://travis-ci.org/voxxit/opensrs)
6
- [![Code Climate](https://codeclimate.com/github/voxxit/opensrs/badges/gpa.svg)](https://codeclimate.com/github/voxxit/opensrs)
7
3
  [![Coverage Status](https://img.shields.io/coveralls/voxxit/opensrs.svg)](https://coveralls.io/r/voxxit/opensrs)
8
4
 
9
- This (unofficial) OpenSRS gem provides basic support to connect to, and utilize the [OpenSRS API.](http://www.opensrs.com/site/resources/documentation/api) This library has been well-tested in high-performance production
5
+ This unofficial OpenSRS gem provides basic support to connect to and utilize the [OpenSRS API.](http://www.opensrs.com/site/resources/documentation/api) This library has been well-tested in high-performance production
10
6
  environments.
11
7
 
12
8
  ### Requirements
13
9
 
14
- * Ruby **>= 1.9.2** or **>= 2.0.0** or **>= 2.1.2**
10
+ * Ruby **>= 2.5**
15
11
 
16
12
  ### Installation
17
13
 
@@ -101,7 +97,6 @@ Responses from OpenSRS are returned in an OpenSRS::Response object, which gives
101
97
  Method | Description
102
98
  ---|---
103
99
  `response.response` | This gives you the response in a Hash form, which is highly accessible to most other actions in your application.
104
- `response.response` | This gives you the response in a Hash form, which is highly accessible to most other actions in your application.
105
100
  `response.errors` | If there are errors which come back from OpenSRS, they are returned here. If not, it returns nil.
106
101
  `response.success?` | Returns true if the response was labeled as successful. If not, it returns false.
107
102
  `response.request_xml` | Returns raw request XML.
@@ -126,9 +121,6 @@ If you have any bugs or feature requests for this gem, feel free to [open an iss
126
121
 
127
122
  ### Copyright
128
123
 
129
- Copyright (c) 2010-2016 Joshua Delsman.
124
+ Copyright (c) 2010-2021 Joshua Delsman.
130
125
 
131
126
  Distributed under the MIT license. See `LICENSE` for details.
132
-
133
-
134
- [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/voxxit/opensrs/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
data/SECURITY.md ADDED
@@ -0,0 +1,12 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ | Version | Supported |
6
+ | ------- | ------------------ |
7
+ | 0.4.x | :white_check_mark: |
8
+ | < 0.4.x | :x: |
9
+
10
+ ## Reporting a Vulnerability
11
+
12
+ Please encyrpt your message to me at https://keybase.io/encrypt#jdelsman, then send to j@srv.im. Since this is an unsupported open-source project, I will get to it as quickly as I can.
data/bin/console CHANGED
@@ -1,10 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'bundler/setup'
3
+ require 'opensrs'
2
4
 
3
- require "bundler/setup"
4
- require "opensrs"
5
-
6
- require "pry"
5
+ require 'pry'
7
6
  Pry.start
8
7
 
9
- require "irb"
8
+ require 'irb'
10
9
  IRB.start
data/lib/opensrs.rb CHANGED
@@ -1,7 +1,9 @@
1
- require "opensrs/xml_processor"
2
- require "opensrs/server"
3
- require "opensrs/response"
4
- require "opensrs/version"
1
+ require 'opensrs/xml_processor'
2
+ require 'opensrs/server'
3
+ require 'opensrs/response'
4
+ require 'opensrs/sanitizable_string'
5
+ require 'opensrs/version'
5
6
 
7
+ # OpenSRS
6
8
  module OpenSRS
7
9
  end
@@ -1,4 +1,5 @@
1
1
  module OpenSRS
2
+ # Response
2
3
  class Response
3
4
  attr_reader :request_xml, :response_xml
4
5
  attr_accessor :response, :success
@@ -13,19 +14,22 @@ module OpenSRS
13
14
  # We need to return the error message unless the
14
15
  # response is successful.
15
16
  def errors
16
- unless success?
17
- msg = @response["response_text"]
18
- code = @response["response_code"]
17
+ return if success?
19
18
 
20
- return msg && code ? "#{msg} (Code #{code})" : "Unknown error"
21
- end
19
+ msg = @response['response_text']
20
+ code = @response['response_code']
21
+
22
+ msg && code ? "#{msg} (Code #{code})" : 'Unknown error'
22
23
  end
23
24
 
24
25
  # If 'is_success' is returned, the API is letting us know that they
25
26
  # will explicitly tell us whether something has succeeded or not.
26
- # Otherwise, just assume it is successful.
27
+ #
28
+ # Otherwise, just assume it failed.
27
29
  def success?
28
- @response["is_success"] && @response["is_success"] == "1" ? true : false
30
+ return false unless @response['is_success']
31
+
32
+ @response['is_success'] == '1'
29
33
  end
30
34
  end
31
35
  end
@@ -0,0 +1,21 @@
1
+ require 'delegate'
2
+
3
+ module OpenSRS
4
+ # SanitizableString
5
+ class SanitizableString < SimpleDelegator
6
+ @enable_sanitization = false
7
+
8
+ class << self
9
+ attr_accessor :enable_sanitization
10
+ end
11
+
12
+ def initialize(original_string, sanitized_string)
13
+ super(original_string)
14
+ @sanitized_string = sanitized_string
15
+ end
16
+
17
+ def sanitized
18
+ self.class.enable_sanitization ? @sanitized_string : self
19
+ end
20
+ end
21
+ end
@@ -1,45 +1,53 @@
1
- require "uri"
2
- require "net/https"
3
- require "digest/md5"
4
- require "openssl"
1
+ require 'uri'
2
+ require 'net/https'
3
+ require 'digest/md5'
4
+ require 'openssl'
5
5
 
6
6
  module OpenSRS
7
7
  class OpenSRSError < StandardError; end
8
8
 
9
9
  class BadResponse < OpenSRSError; end
10
+
10
11
  class ConnectionError < OpenSRSError; end
12
+
11
13
  class TimeoutError < ConnectionError; end
12
14
 
15
+ # Server
13
16
  class Server
14
- attr_accessor :server, :username, :password, :key, :timeout, :open_timeout, :logger
17
+ attr_accessor :server, :username, :password, :key, :timeout, :open_timeout, :logger, :proxy
15
18
 
16
19
  def initialize(options = {})
17
- @server = URI.parse(options[:server] || "https://rr-n1-tor.opensrs.net:55443/")
20
+ @server = URI.parse(options[:server] || 'https://rr-n1-tor.opensrs.net:55443/')
18
21
  @username = options[:username]
19
22
  @password = options[:password]
20
23
  @key = options[:key]
21
24
  @timeout = options[:timeout]
22
25
  @open_timeout = options[:open_timeout]
23
26
  @logger = options[:logger]
27
+ @proxy = URI.parse(options[:proxy]) if options[:proxy]
28
+ @sanitize_request = options[:sanitize_request]
29
+
30
+ OpenSRS::SanitizableString.enable_sanitization = @sanitize_request
24
31
  end
25
32
 
26
33
  def call(data = {})
27
- xml = xml_processor.build({ :protocol => "XCP" }.merge!(data))
28
- log('Request', xml, data)
34
+ xml = xml_processor.build({ protocol: 'XCP' }.merge!(data))
35
+ log('Request', xml.sanitized, data)
29
36
 
30
37
  begin
31
38
  response = http.post(server_path, xml, headers(xml))
32
39
  log('Response', response.body, data)
33
40
  rescue Net::HTTPBadResponse
34
- raise OpenSRS::BadResponse, "Received a bad response from OpenSRS. Please check that your IP address is added to the whitelist, and try again."
41
+ raise OpenSRS::BadResponse,
42
+ 'Received a bad response from OpenSRS. Please check that your IP address is added to the whitelist, and try again.'
35
43
  end
36
44
 
37
45
  parsed_response = xml_processor.parse(response.body)
38
- return OpenSRS::Response.new(parsed_response, xml, response.body)
39
- rescue Timeout::Error => err
40
- raise OpenSRS::TimeoutError, err
41
- rescue Errno::ECONNRESET, Errno::ECONNREFUSED => err
42
- raise OpenSRS::ConnectionError, err
46
+ OpenSRS::Response.new(parsed_response, xml.sanitized, response.body)
47
+ rescue Timeout::Error => e
48
+ raise OpenSRS::TimeoutError, e
49
+ rescue Errno::ECONNRESET, Errno::ECONNREFUSED => e
50
+ raise OpenSRS::ConnectionError, e
43
51
  end
44
52
 
45
53
  def xml_processor
@@ -48,17 +56,17 @@ module OpenSRS
48
56
 
49
57
  def self.xml_processor=(name)
50
58
  require "opensrs/xml_processor/#{name.to_s.downcase}"
51
- @@xml_processor = OpenSRS::XmlProcessor.const_get("#{name.to_s.capitalize}")
59
+ @@xml_processor = OpenSRS::XmlProcessor.const_get(name.to_s.capitalize.to_s)
52
60
  end
53
61
 
54
62
  private
55
63
 
56
64
  def headers(request)
57
65
  {
58
- "Content-Length" => request.length.to_s,
59
- "Content-Type" => "text/xml",
60
- "X-Username" => username,
61
- "X-Signature" => signature(request)
66
+ 'Content-Length' => request.length.to_s,
67
+ 'Content-Type' => 'text/xml',
68
+ 'X-Username' => username,
69
+ 'X-Signature' => signature(request)
62
70
  }
63
71
  end
64
72
 
@@ -67,8 +75,13 @@ module OpenSRS
67
75
  end
68
76
 
69
77
  def http
70
- http = Net::HTTP.new(server.host, server.port)
71
- http.use_ssl = (server.scheme == "https")
78
+ http = if @proxy
79
+ Net::HTTP.new(server.host, server.port, @proxy.host, @proxy.port, @proxy.user, @proxy.password)
80
+ else
81
+ Net::HTTP.new(server.host, server.port)
82
+ end
83
+
84
+ http.use_ssl = (server.scheme == 'https')
72
85
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
73
86
  http.read_timeout = http.open_timeout = @timeout if @timeout
74
87
  http.open_timeout = @open_timeout if @open_timeout
@@ -1,3 +1,3 @@
1
1
  module OpenSRS
2
- VERSION = "0.3.8"
2
+ VERSION = '0.4.0'.freeze
3
3
  end
@@ -1,18 +1,16 @@
1
1
  module OpenSRS
2
+ # XmlProcessor
2
3
  class XmlProcessor
3
-
4
4
  # Parses the main data block from OpenSRS and discards
5
5
  # the rest of the response.
6
6
  def self.parse(response)
7
7
  data_block = data_block_element(response)
8
8
 
9
- raise ArgumentError.new("No data found in document") if !data_block
9
+ raise ArgumentError, 'No data found in document' unless data_block
10
10
 
11
- return decode_data(data_block)
11
+ decode_data(data_block)
12
12
  end
13
13
 
14
- protected
15
-
16
14
  # Encodes individual elements, and their child elements, for the root XML document.
17
15
  def self.encode_data(data, container = nil)
18
16
  case data
@@ -42,11 +40,16 @@ module OpenSRS
42
40
  # if hash, item will be array of the key & value
43
41
  data.each_with_index do |item, index|
44
42
  item_node = new_element(:item, container)
45
- item_node["key"] = item.is_a?(Array) ? item[0].to_s : index.to_s
43
+ item_node['key'] = item.is_a?(Array) ? item[0].to_s : index.to_s
46
44
 
47
45
  value = item.is_a?(Array) ? item[1] : item
48
46
 
49
- item_node << encode_data(value, item_node)
47
+ encoded_data = encode_data(value, item_node)
48
+ if encoded_data.is_a?(String)
49
+ item_node.content = encoded_data
50
+ else
51
+ item_node << encoded_data
52
+ end
50
53
  element << item_node
51
54
  end
52
55
 
@@ -58,16 +61,16 @@ module OpenSRS
58
61
  def self.decode_data(data)
59
62
  data.each do |element|
60
63
  case element.name
61
- when "dt_array"
64
+ when 'dt_array'
62
65
  return decode_dt_array_data(element)
63
- when "dt_assoc"
66
+ when 'dt_assoc'
64
67
  return decode_dt_assoc_data(element)
65
- when "text", "item", "dt_scalar"
68
+ when 'text', 'item', 'dt_scalar'
66
69
  next if element.content.strip.empty?
70
+
67
71
  return element.content.strip
68
72
  end
69
73
  end
70
74
  end
71
-
72
75
  end
73
76
  end
@@ -1,12 +1,13 @@
1
1
  begin
2
2
  require 'libxml'
3
3
  rescue LoadError => e
4
- $stderr.puts "Cannot find `libxml` gem. Please install it before using it as the XML processor"
4
+ warn 'Cannot find `libxml` gem. Please install it before using it as the XML processor'
5
5
  raise e
6
6
  end
7
7
 
8
8
  module OpenSRS
9
9
  class XmlProcessor
10
+ # Libxml
10
11
  class Libxml < OpenSRS::XmlProcessor
11
12
  include ::LibXML::XML
12
13
 
@@ -14,23 +15,35 @@ module OpenSRS
14
15
  # go ahead and build the entire XML document to send to OpenSRS.
15
16
  def self.build(data)
16
17
  xml = Document.new
17
- xml.root = envelope = Node.new("OPS_envelope")
18
+ xml.root = envelope = Node.new('OPS_envelope')
18
19
 
19
- envelope << header = Node.new("header")
20
- envelope << body = Node.new("body")
21
- header << Node.new("version", "0.9")
22
- body << data_block = Node.new("data_block")
20
+ envelope << header = Node.new('header')
21
+ envelope << body = Node.new('body')
22
+ header << Node.new('version', '0.9')
23
+ body << data_block = Node.new('data_block')
23
24
 
24
25
  data_block << encode_data(data, data_block)
25
26
 
26
- return xml.to_s
27
+ OpenSRS::SanitizableString.new(xml.to_s, sanitize(xml).to_s)
27
28
  end
28
29
 
29
- protected
30
+ def self.sanitize(doc)
31
+ # Before changing the iteration through the nodes, read:
32
+ # https://www.rubydoc.info/gems/libxml-ruby/LibXML/XML/Document#find-instance_method
33
+
34
+ username_nodes = doc.find("//item[@key='reg_username']")
35
+ username_nodes.each { |node| node.content = 'FILTERED' }
36
+
37
+ password_nodes = doc.find("//item[@key='reg_password']")
38
+ password_nodes.each { |node| node.content = 'FILTERED' }
39
+
40
+ doc
41
+ end
42
+ private_class_method :sanitize
30
43
 
31
44
  def self.data_block_element(response)
32
45
  doc = Parser.string(response).parse
33
- return doc.find("//OPS_envelope/body/data_block/*")
46
+ doc.find('//OPS_envelope/body/data_block/*')
34
47
  end
35
48
 
36
49
  def self.decode_dt_array_data(element)
@@ -38,10 +51,11 @@ module OpenSRS
38
51
 
39
52
  element.children.each do |item|
40
53
  next if item.empty?
41
- dt_array[item.attributes["key"].to_i] = decode_data(item)
54
+
55
+ dt_array[item.attributes['key'].to_i] = decode_data(item)
42
56
  end
43
57
 
44
- return dt_array
58
+ dt_array
45
59
  end
46
60
 
47
61
  def self.decode_dt_assoc_data(element)
@@ -49,19 +63,19 @@ module OpenSRS
49
63
 
50
64
  element.children.each do |item|
51
65
  next if item.content.strip.empty?
52
- dt_assoc[item.attributes["key"]] = decode_data(item)
66
+
67
+ dt_assoc[item.attributes['key']] = decode_data(item)
53
68
  end
54
69
 
55
- return dt_assoc
70
+ dt_assoc
56
71
  end
57
72
 
58
73
  # Accepts two parameters but uses only one; to keep the interface same as other xml parser classes
59
74
  # Is that a side effect of Template pattern?
60
75
  #
61
- def self.new_element(element_name, container)
62
- return Node.new(element_name.to_s)
76
+ def self.new_element(element_name, _container)
77
+ Node.new(element_name.to_s)
63
78
  end
64
-
65
79
  end
66
80
  end
67
81
  end
@@ -1,22 +1,22 @@
1
1
  begin
2
2
  require 'nokogiri'
3
3
  rescue LoadError => e
4
- $stderr.puts "Cannot find `nokogiri` gem. Please install it before using it as the XML processor"
4
+ warn 'Cannot find `nokogiri` gem. Please install it before using it as the XML processor'
5
5
  raise e
6
6
  end
7
7
 
8
8
  module OpenSRS
9
9
  class XmlProcessor
10
+ # Nokogiri
10
11
  class Nokogiri < OpenSRS::XmlProcessor
11
-
12
12
  def self.build(data)
13
13
  builder = ::Nokogiri::XML::Builder.new
14
14
 
15
- envelope = ::Nokogiri::XML::Node.new("OPS_envelope", builder.doc)
16
- header = ::Nokogiri::XML::Node.new("header", builder.doc)
17
- version = ::Nokogiri::XML::Node.new("version", builder.doc)
18
- body = ::Nokogiri::XML::Node.new("body", builder.doc)
19
- data_block = ::Nokogiri::XML::Node.new("data_block", builder.doc)
15
+ envelope = ::Nokogiri::XML::Node.new('OPS_envelope', builder.doc)
16
+ header = ::Nokogiri::XML::Node.new('header', builder.doc)
17
+ version = ::Nokogiri::XML::Node.new('version', builder.doc)
18
+ body = ::Nokogiri::XML::Node.new('body', builder.doc)
19
+ data_block = ::Nokogiri::XML::Node.new('data_block', builder.doc)
20
20
  other_data = encode_data(data, builder.doc)
21
21
  version << '0.9'
22
22
  header << version
@@ -25,14 +25,25 @@ module OpenSRS
25
25
  data_block << other_data
26
26
  body << data_block
27
27
  envelope << body
28
- return builder.to_xml
28
+
29
+ OpenSRS::SanitizableString.new(builder.to_xml, sanitize(builder.to_xml))
29
30
  end
30
31
 
31
- protected
32
+ def self.sanitize(xml_string)
33
+ doc = ::Nokogiri::XML(xml_string)
34
+ doc.xpath("//item[@key='reg_username']").each do |node|
35
+ node.content = 'FILTERED'
36
+ end
37
+ doc.xpath("//item[@key='reg_password']").each do |node|
38
+ node.content = 'FILTERED'
39
+ end
40
+ doc.to_xml
41
+ end
42
+ private_class_method :sanitize
32
43
 
33
44
  def self.data_block_element(response)
34
45
  doc = ::Nokogiri::XML(response)
35
- return doc.xpath('//OPS_envelope/body/data_block/*')
46
+ doc.xpath('//OPS_envelope/body/data_block/*')
36
47
  end
37
48
 
38
49
  def self.decode_dt_array_data(element)
@@ -40,10 +51,11 @@ module OpenSRS
40
51
 
41
52
  element.children.each do |item|
42
53
  next if item.content.strip.empty?
43
- dt_array[item.attributes["key"].value.to_i] = decode_data(item.children)
54
+
55
+ dt_array[item.attributes['key'].value.to_i] = decode_data(item.children)
44
56
  end
45
57
 
46
- return dt_array
58
+ dt_array
47
59
  end
48
60
 
49
61
  def self.decode_dt_assoc_data(element)
@@ -51,16 +63,16 @@ module OpenSRS
51
63
 
52
64
  element.children.each do |item|
53
65
  next if item.content.strip.empty?
54
- dt_assoc[item.attributes["key"].value] = decode_data(item.children)
66
+
67
+ dt_assoc[item.attributes['key'].value] = decode_data(item.children)
55
68
  end
56
69
 
57
- return dt_assoc
70
+ dt_assoc
58
71
  end
59
72
 
60
73
  def self.new_element(element_name, container)
61
- return ::Nokogiri::XML::Node.new(element_name.to_s, container)
74
+ ::Nokogiri::XML::Node.new(element_name.to_s, container)
62
75
  end
63
-
64
76
  end
65
77
  end
66
78
  end
data/opensrs.gemspec CHANGED
@@ -1,29 +1,32 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "opensrs/version"
3
+ require 'opensrs/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
-
8
- spec.name = "opensrs"
6
+ spec.name = 'opensrs'
9
7
  spec.version = OpenSRS::VERSION
10
- spec.authors = [ "Joshua Delsman" ]
11
- spec.email = [ "j@srv.im" ]
12
- spec.summary = "OpenSRS API for Ruby"
13
- spec.description = "Provides support to utilize the OpenSRS API with Ruby."
14
- spec.homepage = "https://github.com/voxxit/opensrs"
15
- spec.license = "MIT"
8
+ spec.authors = ['Joshua Delsman']
9
+ spec.email = ['j@srv.im']
10
+ spec.summary = 'OpenSRS API for Ruby'
11
+ spec.description = 'Provides support to utilize the OpenSRS API with Ruby.'
12
+ spec.homepage = 'https://github.com/voxxit/opensrs'
13
+ spec.license = 'MIT'
14
+ spec.required_ruby_version = '~> 2.5'
16
15
 
17
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = "exe"
17
+ spec.bindir = 'exe'
19
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
21
20
 
22
- spec.add_development_dependency "libxml-ruby", "~> 2"
23
- spec.add_development_dependency "bundler"
24
- spec.add_development_dependency "rake"
25
- spec.add_development_dependency "rspec"
26
- spec.add_development_dependency "shoulda"
27
- spec.add_development_dependency "nokogiri"
28
- spec.add_development_dependency "pry"
21
+ spec.add_development_dependency 'activesupport', '~> 4.2.2'
22
+ spec.add_development_dependency 'bundler'
23
+ spec.add_development_dependency 'code-scanning-rubocop', '~> 0.5'
24
+ spec.add_development_dependency 'libxml-ruby', '~> 3'
25
+ spec.add_development_dependency 'nokogiri', '~> 1.11.4'
26
+ spec.add_development_dependency 'pry'
27
+ spec.add_development_dependency 'rake'
28
+ spec.add_development_dependency 'rspec'
29
+ spec.add_development_dependency 'rubocop', '~> 1'
30
+ spec.add_development_dependency 'rubocop-rspec'
31
+ spec.add_development_dependency 'shoulda'
29
32
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opensrs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Delsman
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-03 00:00:00.000000000 Z
11
+ date: 2021-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: libxml-ruby
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2'
19
+ version: 4.2.2
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2'
26
+ version: 4.2.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +39,49 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: code-scanning-rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: libxml-ruby
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.11.4
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.11.4
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
43
85
  requirement: !ruby/object:Gem::Requirement
44
86
  requirements:
45
87
  - - ">="
@@ -53,7 +95,7 @@ dependencies:
53
95
  - !ruby/object:Gem::Version
54
96
  version: '0'
55
97
  - !ruby/object:Gem::Dependency
56
- name: rspec
98
+ name: rake
57
99
  requirement: !ruby/object:Gem::Requirement
58
100
  requirements:
59
101
  - - ">="
@@ -67,7 +109,7 @@ dependencies:
67
109
  - !ruby/object:Gem::Version
68
110
  version: '0'
69
111
  - !ruby/object:Gem::Dependency
70
- name: shoulda
112
+ name: rspec
71
113
  requirement: !ruby/object:Gem::Requirement
72
114
  requirements:
73
115
  - - ">="
@@ -81,7 +123,21 @@ dependencies:
81
123
  - !ruby/object:Gem::Version
82
124
  version: '0'
83
125
  - !ruby/object:Gem::Dependency
84
- name: nokogiri
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-rspec
85
141
  requirement: !ruby/object:Gem::Requirement
86
142
  requirements:
87
143
  - - ">="
@@ -95,7 +151,7 @@ dependencies:
95
151
  - !ruby/object:Gem::Version
96
152
  version: '0'
97
153
  - !ruby/object:Gem::Dependency
98
- name: pry
154
+ name: shoulda
99
155
  requirement: !ruby/object:Gem::Requirement
100
156
  requirements:
101
157
  - - ">="
@@ -116,17 +172,21 @@ extensions: []
116
172
  extra_rdoc_files: []
117
173
  files:
118
174
  - ".document"
175
+ - ".github/workflows/rubocop-analysis.yml"
119
176
  - ".gitignore"
120
177
  - ".rspec"
178
+ - ".rubocop.yml"
121
179
  - Gemfile
122
180
  - Gemfile.lock
123
181
  - LICENSE.txt
124
182
  - README.md
125
183
  - Rakefile
184
+ - SECURITY.md
126
185
  - bin/console
127
186
  - bin/setup
128
187
  - lib/opensrs.rb
129
188
  - lib/opensrs/response.rb
189
+ - lib/opensrs/sanitizable_string.rb
130
190
  - lib/opensrs/server.rb
131
191
  - lib/opensrs/version.rb
132
192
  - lib/opensrs/xml_processor.rb
@@ -137,25 +197,23 @@ homepage: https://github.com/voxxit/opensrs
137
197
  licenses:
138
198
  - MIT
139
199
  metadata: {}
140
- post_install_message:
200
+ post_install_message:
141
201
  rdoc_options: []
142
202
  require_paths:
143
203
  - lib
144
204
  required_ruby_version: !ruby/object:Gem::Requirement
145
205
  requirements:
146
- - - ">="
206
+ - - "~>"
147
207
  - !ruby/object:Gem::Version
148
- version: '0'
208
+ version: '2.5'
149
209
  required_rubygems_version: !ruby/object:Gem::Requirement
150
210
  requirements:
151
211
  - - ">="
152
212
  - !ruby/object:Gem::Version
153
213
  version: '0'
154
214
  requirements: []
155
- rubyforge_project:
156
- rubygems_version: 2.5.1
157
- signing_key:
215
+ rubygems_version: 3.0.3.1
216
+ signing_key:
158
217
  specification_version: 4
159
218
  summary: OpenSRS API for Ruby
160
219
  test_files: []
161
- has_rdoc: