Skip to content

Commit ff1cf3f

Browse files
committed
Add alias file lib/xml_security.rb
1 parent 8565353 commit ff1cf3f

File tree

7 files changed

+40
-21
lines changed

7 files changed

+40
-21
lines changed

.rubocop_todo.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2024-07-09 07:40:52 UTC using RuboCop version 1.64.1.
3+
# on 2024-07-09 11:29:15 UTC using RuboCop version 1.64.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -170,12 +170,11 @@ Lint/UnreachableLoop:
170170
Exclude:
171171
- 'lib/ruby_saml/saml_message.rb'
172172

173-
# Offense count: 3
173+
# Offense count: 2
174174
# This cop supports unsafe autocorrection (--autocorrect-all).
175175
# Configuration parameters: AutoCorrect.
176176
Lint/UselessAssignment:
177177
Exclude:
178-
- 'lib/ruby_saml/logging.rb'
179178
- 'lib/ruby_saml/slo_logoutrequest.rb'
180179

181180
# Offense count: 42
@@ -407,6 +406,14 @@ Style/IfUnlessModifier:
407406
- 'lib/ruby_saml/xml/document.rb'
408407
- 'lib/ruby_saml/xml/signed_document.rb'
409408

409+
# Offense count: 1
410+
# This cop supports unsafe autocorrection (--autocorrect-all).
411+
# Configuration parameters: EnforcedStyle, Autocorrect.
412+
# SupportedStyles: module_function, extend_self, forbidden
413+
Style/ModuleFunction:
414+
Exclude:
415+
- 'lib/ruby_saml/logging.rb'
416+
410417
# Offense count: 15
411418
# Configuration parameters: AllowedMethods.
412419
# AllowedMethods: respond_to_missing?

UPGRADING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ codebase for `RubySaml::XML::` and replace it as appropriate. In addition, you m
2727
`require 'xml_security'` with `require 'ruby_saml/xml'`.
2828

2929
For backward compatibility, the alias `XMLSecurity = RubySaml::XML` has been set, so `RubySaml::XML::` will still work
30-
as before. This alias will be removed in RubySaml version `2.1.0`.
30+
as before. In addition, a shim file has been added so that `require 'xml_security'` continues to work.
31+
These aliases will be removed in RubySaml version `2.1.0`.
3132

3233
### Security: Change default hashing algorithm to SHA-256 (was SHA-1)
3334

lib/ruby_saml.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,5 @@
1919
require 'ruby_saml/utils'
2020
require 'ruby_saml/version'
2121

22-
# @deprecated These aliases add compatibility with v1.x and will be removed in v2.1.0
22+
# @deprecated This alias adds compatibility with v1.x and will be removed in v2.1.0
2323
OneLogin = Object
24-
XMLSecurity = RubySaml::XML

lib/ruby_saml/logging.rb

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,33 @@
22

33
require 'logger'
44

5-
# Simplistic log class when we're running in Rails
65
module RubySaml
7-
class Logging
6+
module Logging
7+
extend self
8+
89
DEFAULT_LOGGER = ::Logger.new($stdout)
910

10-
def self.logger
11+
attr_writer :logger
12+
13+
def logger
1114
@logger ||= begin
1215
logger = Rails.logger if defined?(::Rails) && Rails.respond_to?(:logger)
13-
logger ||= DEFAULT_LOGGER
16+
logger || DEFAULT_LOGGER
1417
end
1518
end
1619

17-
class << self
18-
attr_writer :logger
20+
%i[error warn debug info].each do |level|
21+
define_method(level) do |message|
22+
logger.send(level, message) if enabled?
23+
end
1924
end
2025

21-
def self.debug(message)
22-
return if ENV['ruby-saml/testing']
23-
24-
logger.debug(message)
26+
def deprecate(message)
27+
warn("[DEPRECATION] RubySaml: #{message}")
2528
end
2629

27-
def self.info(message)
28-
return if ENV['ruby-saml/testing']
29-
30-
logger.info(message)
30+
def enabled?
31+
!ENV['ruby-saml/testing']
3132
end
3233
end
3334
end

lib/ruby_saml/xml.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33
require 'ruby_saml/xml/base_document'
44
require 'ruby_saml/xml/document'
55
require 'ruby_saml/xml/signed_document'
6+
7+
# @deprecated This alias adds compatibility with v1.x and will be removed in v2.1.0
8+
XMLSecurity = RubySaml::XML

lib/xml_security.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
require 'ruby_saml/logging'
4+
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.'
6+
7+
# @deprecated This file adds compatibility with v1.x and will be removed in v2.1.0
8+
require 'ruby_saml/xml'

test/xml_security_alias_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require_relative 'test_helper'
2-
require 'ruby_saml/xml'
2+
require 'xml_security'
33

44
class XmlSecurityAliasTest < Minitest::Test
55

0 commit comments

Comments
 (0)