Skip to content

Commit 3b0a71b

Browse files
[READY] V2.x - Nokogiri Upgrade Part 3 - Shim XMLSecurity so it raises deprecation warnings and errors (#748)
1 parent a058598 commit 3b0a71b

27 files changed

+253
-299
lines changed

.rubocop.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,27 @@ AllCops:
1616
- 'tmp/**/*'
1717
- 'vendor/**/*'
1818

19+
Metrics/AbcSize:
20+
Max: 200
21+
22+
Metrics/BlockLength:
23+
Max: 100
24+
25+
Metrics/ClassLength:
26+
Max: 1000
27+
28+
Metrics/CyclomaticComplexity:
29+
Max: 30
30+
31+
Metrics/MethodLength:
32+
Max: 100
33+
34+
Metrics/ModuleLength:
35+
Max: 1000
36+
37+
Metrics/PerceivedComplexity:
38+
Max: 30
39+
1940
Style/Alias:
2041
EnforcedStyle: prefer_alias_method
2142

.rubocop_todo.yml

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -178,47 +178,11 @@ Lint/UselessAssignment:
178178
Exclude:
179179
- 'lib/ruby_saml/slo_logoutrequest.rb'
180180

181-
# Offense count: 42
182-
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
183-
Metrics/AbcSize:
184-
Max: 200
185-
186-
# Offense count: 1
187-
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
188-
# AllowedMethods: refine
189-
Metrics/BlockLength:
190-
Max: 27
191-
192-
# Offense count: 8
193-
# Configuration parameters: CountComments, CountAsOne.
194-
Metrics/ClassLength:
195-
Max: 1000
196-
197-
# Offense count: 29
198-
# Configuration parameters: AllowedMethods, AllowedPatterns.
199-
Metrics/CyclomaticComplexity:
200-
Max: 21
201-
202-
# Offense count: 60
203-
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
204-
Metrics/MethodLength:
205-
Max: 77
206-
207-
# Offense count: 1
208-
# Configuration parameters: CountComments, CountAsOne.
209-
Metrics/ModuleLength:
210-
Max: 261
211-
212181
# Offense count: 2
213182
# Configuration parameters: Max, CountKeywordArgs.
214183
Metrics/ParameterLists:
215184
MaxOptionalParameters: 4
216185

217-
# Offense count: 25
218-
# Configuration parameters: AllowedMethods, AllowedPatterns.
219-
Metrics/PerceivedComplexity:
220-
Max: 22
221-
222186
# Offense count: 15
223187
Naming/AccessorMethodName:
224188
Exclude:
@@ -359,7 +323,6 @@ Style/Documentation:
359323
- 'lib/ruby_saml/error_handling.rb'
360324
- 'lib/ruby_saml/idp_metadata_parser.rb'
361325
- 'lib/ruby_saml/logging.rb'
362-
- 'lib/ruby_saml/xml/base_document.rb'
363326
- 'lib/ruby_saml/xml/document.rb'
364327
- 'lib/ruby_saml/xml/signed_document.rb'
365328

UPGRADING.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,21 @@ Note that the project folder structure has also been updated accordingly. Notabl
3030
For backward compatibility, the alias `OneLogin = Object` has been set, so `OneLogin::RubySaml::` will still work
3131
as before. This alias will be removed in RubySaml version `2.1.0`.
3232

33-
### Root "XMLSecurity" namespace changed to "RubySaml::XML"
33+
### Deprecation and removal of "XMLSecurity" namespace
3434

35-
RubySaml version `2.0.0` changes the namespace `::XMLSecurity` to `::RubySaml::XML`. Please search your
36-
codebase for `XMLSecurity` and replace it as appropriate. In addition, you must replace direct usage of
37-
`require 'xml_security'` with `require 'ruby_saml/xml'`.
35+
RubySaml version `2.0.0` deprecates the `::XMLSecurity` namespace and the following classes:
3836

39-
For backward compatibility, if the constant `XMLSecurity` is not already defined by another gem, it will
40-
be aliased to `RubySaml::XML`. In addition, a shim file has been added so that `require 'xml_security'`
41-
continues to work. These aliases will be removed in RubySaml version `2.1.0`.
37+
| Removed Class | Replacement Module & Method |
38+
|-------------------------------|----------------------------------------------------------------------------------|
39+
| `XMLSecurity::BaseDocument` | (none) |
40+
| `XMLSecurity::Document` | Will be replaced with `RubySaml::XML::DocumentSigner.sign_document` |
41+
| `XMLSecurity::SignedDocument` | Will be replaced with `RubySaml::XML::SignedDocumentValidator.validate_document` |
42+
43+
If your application does not already define the `XMLSecurity` namespace (e.g. from another gem),
44+
these old classes will be shimmed to raise a deprecation warning or `NoMethodError` when used.
45+
46+
The new modules in the `RubySaml::XML` namespace provide similar functionality as the
47+
deprecated classes, but are based on Nokogiri instead of REXML.
4248

4349
### Security: Change default hashing algorithm to SHA-256 (was SHA-1)
4450

lib/ruby_saml/utils.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
require 'ruby_saml/pem_formatter'
66

77
module RubySaml
8-
98
# SAML2 Auxiliary class
10-
#
11-
module Utils # rubocop:disable Metrics/ModuleLength
9+
module Utils
1210
extend self
1311

1412
BINDINGS = { post: "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST",

lib/ruby_saml/xml.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,4 @@ def get_algorithm_attr(element)
132132
require 'ruby_saml/xml/base_document'
133133
require 'ruby_saml/xml/document'
134134
require 'ruby_saml/xml/signed_document'
135-
136-
# @deprecated This alias adds compatibility with v1.x and will be removed in v2.1.0
137-
XMLSecurity = RubySaml::XML unless defined?(XMLSecurity)
135+
require 'ruby_saml/xml/deprecated'

lib/ruby_saml/xml/base_document.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@
1010

1111
module RubySaml
1212
module XML
13+
# @deprecated Will be removed soon.
1314
class BaseDocument < REXML::Document
1415
# TODO: This affects the global state
1516
REXML::Security.entity_expansion_limit = 0
1617

17-
# @deprecated Constants moved to RubySaml::XML module
18-
C14N = RubySaml::XML::C14N
19-
DSIG = RubySaml::XML::DSIG
20-
NOKOGIRI_OPTIONS = RubySaml::XML::NOKOGIRI_OPTIONS
21-
2218
# @deprecated Remove in v2.1.0
2319
def canon_algorithm(algorithm)
2420
RubySaml::XML.canon_algorithm(algorithm)

lib/ruby_saml/xml/deprecated.rb

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# frozen_string_literal: true
2+
3+
unless defined?(XMLSecurity)
4+
require 'ruby_saml/logging'
5+
6+
module XMLSecurity
7+
# @deprecated Will be removed in v2.1.0.
8+
# @api private
9+
class BaseDocument < REXML::Document
10+
# @deprecated Constants
11+
C14N = RubySaml::XML::C14N
12+
DSIG = RubySaml::XML::DSIG
13+
NOKOGIRI_OPTIONS = RubySaml::XML::NOKOGIRI_OPTIONS
14+
15+
# @deprecated Will be removed in v2.1.0.
16+
def canon_algorithm(algorithm)
17+
RubySaml::Logging.deprecate 'XMLSecurity::BaseDocument#canon_algorithm is deprecated and will be removed in v2.1.0. ' \
18+
'Use RubySaml::XML.canon_algorithm instead.'
19+
RubySaml::XML.canon_algorithm(algorithm)
20+
end
21+
22+
# @deprecated Will be removed in v2.1.0.
23+
def algorithm(algorithm)
24+
RubySaml::Logging.deprecate 'XMLSecurity::BaseDocument#algorithm is deprecated and will be removed in v2.1.0. ' \
25+
'Use RubySaml::XML.hash_algorithm instead.'
26+
RubySaml::XML.hash_algorithm(algorithm)
27+
end
28+
end
29+
30+
# @deprecated Will be removed in v2.1.0.
31+
# @api private
32+
class Document < BaseDocument
33+
# @deprecated Constants
34+
INC_PREFIX_LIST = RubySaml::XML::Document::INC_PREFIX_LIST
35+
RSA_SHA1 = RubySaml::XML::RSA_SHA1
36+
RSA_SHA224 = RubySaml::XML::RSA_SHA224
37+
RSA_SHA256 = RubySaml::XML::RSA_SHA256
38+
RSA_SHA384 = RubySaml::XML::RSA_SHA384
39+
RSA_SHA512 = RubySaml::XML::RSA_SHA512
40+
DSA_SHA1 = RubySaml::XML::DSA_SHA1
41+
DSA_SHA256 = RubySaml::XML::DSA_SHA256
42+
ECDSA_SHA1 = RubySaml::XML::ECDSA_SHA1
43+
ECDSA_SHA224 = RubySaml::XML::ECDSA_SHA224
44+
ECDSA_SHA256 = RubySaml::XML::ECDSA_SHA256
45+
ECDSA_SHA384 = RubySaml::XML::ECDSA_SHA384
46+
ECDSA_SHA512 = RubySaml::XML::ECDSA_SHA512
47+
SHA1 = RubySaml::XML::SHA1
48+
SHA224 = RubySaml::XML::SHA224
49+
SHA256 = RubySaml::XML::SHA256
50+
SHA384 = RubySaml::XML::SHA384
51+
SHA512 = RubySaml::XML::SHA512
52+
ENVELOPED_SIG = RubySaml::XML::ENVELOPED_SIG
53+
54+
# @deprecated Will be removed in v2.1.0.
55+
def initialize(*args, **_kwargs)
56+
RubySaml::Logging.deprecate 'XMLSecurity::Document is deprecated and will be removed in v2.1.0. ' \
57+
'Use RubySaml::XML::DocumentSigner.sign_document instead.'
58+
super(args[0])
59+
end
60+
61+
# @deprecated Will be removed in v2.1.0.
62+
def sign_document(*_args, **_kwargs)
63+
msg = 'XMLSecurity::Document#sign_document has been removed. ' \
64+
'Use RubySaml::XML::DocumentSigner.sign_document instead.'
65+
raise ::NoMethodError.new(msg)
66+
end
67+
end
68+
69+
# @deprecated Will be removed in v2.1.0.
70+
# @api private
71+
class SignedDocument < BaseDocument
72+
# @deprecated Will be removed in v2.1.0.
73+
def initialize(*args, **_kwargs)
74+
RubySaml::Logging.deprecate 'XMLSecurity::SignedDocument is deprecated and will be removed in v2.1.0.' \
75+
'Use RubySaml::XML::SignedDocumentValidator.validate_document instead.'
76+
super(args[0])
77+
end
78+
79+
# @deprecated Will be removed in v2.1.0.
80+
def validate_document(*_args, **_kwargs)
81+
msg = 'XMLSecurity::SignedDocument#validate_document has been removed. ' \
82+
'Use RubySaml::XML::SignedDocumentValidator.validate_document instead.'
83+
raise ::NoMethodError.new(msg)
84+
end
85+
86+
# @deprecated Will be removed in v2.1.0.
87+
def extract_inclusive_namespaces
88+
msg = 'XMLSecurity::SignedDocument#extract_inclusive_namespaces has been removed.'
89+
raise ::NoMethodError.new(msg)
90+
end
91+
end
92+
end
93+
end

lib/ruby_saml/xml/document.rb

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,6 @@ module XML
77
class Document < BaseDocument
88
INC_PREFIX_LIST = '#default samlp saml ds xs xsi md'
99

10-
# @deprecated Constants moved to RubySaml::XML module
11-
RSA_SHA1 = RubySaml::XML::RSA_SHA1
12-
RSA_SHA224 = RubySaml::XML::RSA_SHA224
13-
RSA_SHA256 = RubySaml::XML::RSA_SHA256
14-
RSA_SHA384 = RubySaml::XML::RSA_SHA384
15-
RSA_SHA512 = RubySaml::XML::RSA_SHA512
16-
DSA_SHA1 = RubySaml::XML::DSA_SHA1
17-
DSA_SHA256 = RubySaml::XML::DSA_SHA256
18-
ECDSA_SHA1 = RubySaml::XML::ECDSA_SHA1
19-
ECDSA_SHA224 = RubySaml::XML::ECDSA_SHA224
20-
ECDSA_SHA256 = RubySaml::XML::ECDSA_SHA256
21-
ECDSA_SHA384 = RubySaml::XML::ECDSA_SHA384
22-
ECDSA_SHA512 = RubySaml::XML::ECDSA_SHA512
23-
SHA1 = RubySaml::XML::SHA1
24-
SHA224 = RubySaml::XML::SHA224
25-
SHA256 = RubySaml::XML::SHA256
26-
SHA384 = RubySaml::XML::SHA384
27-
SHA512 = RubySaml::XML::SHA512
28-
ENVELOPED_SIG = RubySaml::XML::ENVELOPED_SIG
29-
3010
# <Signature>
3111
# <SignedInfo>
3212
# <CanonicalizationMethod />

lib/xml_security.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
require 'ruby_saml/logging'
44
RubySaml::Logging.deprecate 'Using `require "xml_security"` is deprecated and will be removed ' \
5-
'in RubySaml 2.1.0. Please use `require "ruby_saml/xml"` instead.'
5+
'in RubySaml 2.1.0. Instead, please `require "ruby-saml"` and use ' \
6+
'the modules in RubySaml::XML instead.'
67

78
# @deprecated This file adds compatibility with v1.x and will be removed in v2.1.0
89
require 'ruby_saml/xml'

test/attributes_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
require_relative 'test_helper'
1+
# frozen_string_literal: true
22

3+
require_relative 'test_helper'
34
require 'ruby_saml/attributes'
45

56
class AttributesTest < Minitest::Test

0 commit comments

Comments
 (0)