From 466ed0e1ace6ebf069d444d666f0db3f9224a4b9 Mon Sep 17 00:00:00 2001
From: Samuel Giddins <segiddins@segiddins.me>
Date: Sat, 10 Feb 2024 19:52:13 -0800
Subject: [PATCH] [rubygems/rubygems] Add a test for safe yaml

https://github.com/rubygems/rubygems/commit/148deade0a

Reference:https://github.com/ruby/ruby/commit/466ed0e1ace6ebf069d444d666f0db3f9224a4b9
Conflict:use assert_raises not assert_raise and requires diffs.
---
 test/rubygems/test_gem_safe_yaml.rb | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644 test/rubygems/test_gem_safe_yaml.rb

diff --git a/test/rubygems/test_gem_safe_yaml.rb b/test/rubygems/test_gem_safe_yaml.rb
new file mode 100644
index 0000000..cfe1342
--- /dev/null
+++ b/test/rubygems/test_gem_safe_yaml.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+require 'yaml'
+require 'rubygems/test_case'
+require 'rubygems/safe_yaml'
+require 'test/unit'
+
+Gem.load_yaml
+
+class TestGemSafeYAML < Gem::TestCase
+  def test_aliases_enabled_by_default
+    assert_predicate Gem::SafeYAML, :aliases_enabled?
+    assert_equal({ "a" => "a", "b" => "a" }, Gem::SafeYAML.safe_load("a: &a a\nb: *a\n"))
+  end
+
+  def test_aliases_disabled
+    aliases_enabled = Gem::SafeYAML.aliases_enabled?
+    Gem::SafeYAML.aliases_enabled = false
+    refute_predicate Gem::SafeYAML, :aliases_enabled?
+    assert_raises Psych::AliasesNotEnabled do
+      Gem::SafeYAML.safe_load("a: &a\nb: *a\n")
+    end
+  ensure
+    Gem::SafeYAML.aliases_enabled = aliases_enabled
+  end
+end
-- 
2.33.0


