Skip to content

Commit fd41c69

Browse files
committed
Fix tests
1 parent ada54de commit fd41c69

6 files changed

Lines changed: 80 additions & 55 deletions

File tree

lib/ruby_saml/authrequest.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module RubySaml
1515
class Authrequest < SamlMessage
1616

1717
# AuthNRequest ID
18-
attr_reader :uuid
18+
attr_accessor :uuid
1919
alias_method :request_id, :uuid
2020

2121
# Creates the AuthNRequest string.

lib/ruby_saml/logoutrequest.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module RubySaml
1313
class Logoutrequest < SamlMessage
1414

1515
# Logout Request ID
16-
attr_reader :uuid
16+
attr_accessor :uuid
1717
alias_method :request_id, :uuid
1818

1919
# Creates the Logout Request string.

lib/ruby_saml/slo_logoutresponse.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22

33
require "ruby_saml/logging"
4-
54
require "ruby_saml/saml_message"
65
require "ruby_saml/utils"
76
require "ruby_saml/setting_error"
@@ -14,8 +13,8 @@ module RubySaml
1413
class SloLogoutresponse < SamlMessage
1514

1615
# Logout Response ID
17-
attr_reader :uuid
18-
alias_method :request_id, :uuid
16+
attr_accessor :uuid
17+
alias_method :response_id, :uuid
1918

2019
# Creates the Logout Response string.
2120
# @param settings [RubySaml::Settings|nil] Toolkit settings

test/authrequest_test.rb

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,39 @@ class AuthrequestTest < Minitest::Test
161161
assert auth_url.include?('&RelayState=http%3A%2F%2Fexample.com')
162162
end
163163

164-
it "creates request with ID prefixed with default '_'" do
165-
request = RubySaml::Authrequest.new
164+
describe "uuid" do
165+
it "uuid is initialized to nil" do
166+
request = RubySaml::Authrequest.new
166167

167-
assert_match(/^_/, request.uuid)
168-
end
168+
assert_nil(request.uuid)
169+
assert_equal request.request_id, request.uuid
170+
end
171+
172+
it "creates request with ID prefixed with default '_'" do
173+
request = RubySaml::Authrequest.new
174+
request.create(settings)
175+
176+
assert_match(/^_/, request.uuid)
177+
assert_equal request.request_id, request.uuid
178+
end
179+
180+
it "creates request with ID prefixed by Settings#sp_uuid_prefix" do
181+
settings.sp_uuid_prefix = 'test'
182+
request = RubySaml::Authrequest.new
183+
request.create(settings)
169184

170-
it "creates request with ID is prefixed, when :id_prefix is passed" do
171-
RubySaml::Utils::set_prefix("test")
172-
request = RubySaml::Authrequest.new
173-
assert_match(/^test/, request.uuid)
174-
RubySaml::Utils::set_prefix("_")
185+
assert_match(/^test/, request.uuid)
186+
assert_equal request.request_id, request.uuid
187+
end
188+
189+
it "can mutate the uuid" do
190+
request = RubySaml::Authrequest.new
191+
request_id = request.request_id
192+
assert_equal request_id, request.uuid
193+
request.uuid = "new_uuid"
194+
assert_equal "new_uuid", request.uuid
195+
assert_equal request.request_id, request.uuid
196+
end
175197
end
176198

177199
describe "when the target url is not set" do
@@ -272,17 +294,6 @@ class AuthrequestTest < Minitest::Test
272294
assert auth_doc.to_s =~ /<saml:AuthnContextDeclRef>example\/decl\/ref<\/saml:AuthnContextDeclRef>/
273295
end
274296

275-
describe "#manipulate request_id" do
276-
it "be able to modify the request id" do
277-
authnrequest = RubySaml::Authrequest.new
278-
request_id = authnrequest.request_id
279-
assert_equal request_id, authnrequest.uuid
280-
authnrequest.uuid = "new_uuid"
281-
assert_equal authnrequest.request_id, authnrequest.uuid
282-
assert_equal "new_uuid", authnrequest.request_id
283-
end
284-
end
285-
286297
each_signature_algorithm do |sp_key_algo, sp_hash_algo|
287298
describe "#create_params signing with HTTP-POST binding" do
288299
before do

test/logoutrequest_test.rb

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,29 +94,35 @@ class RequestTest < Minitest::Test
9494
end
9595
end
9696

97-
describe "playgin with preix" do
97+
describe "uuid" do
98+
it "uuid is initialized to nil" do
99+
request = RubySaml::Logoutrequest.new
100+
101+
assert_nil(request.uuid)
102+
end
103+
98104
it "creates request with ID prefixed with default '_'" do
99105
request = RubySaml::Logoutrequest.new
106+
request.create(settings)
100107

101108
assert_match(/^_/, request.uuid)
102109
end
103110

104-
it "creates request with ID is prefixed, when :id_prefix is passed" do
105-
RubySaml::Utils::set_prefix("test")
111+
it "creates request with ID prefixed by Settings#sp_uuid_prefix" do
112+
settings.sp_uuid_prefix = 'test'
106113
request = RubySaml::Logoutrequest.new
114+
request.create(settings)
115+
107116
assert_match(/^test/, request.uuid)
108-
RubySaml::Utils::set_prefix("_")
109117
end
110-
end
111118

112-
describe "#manipulate request_id" do
113-
it "be able to modify the request id" do
114-
logoutrequest = RubySaml::Logoutrequest.new
115-
request_id = logoutrequest.request_id
116-
assert_equal request_id, logoutrequest.uuid
117-
logoutrequest.uuid = "new_uuid"
118-
assert_equal logoutrequest.request_id, logoutrequest.uuid
119-
assert_equal "new_uuid", logoutrequest.request_id
119+
it "can mutate the uuid" do
120+
request = RubySaml::Logoutrequest.new
121+
request_id = request.request_id
122+
assert_equal request_id, request.uuid
123+
request.uuid = "new_uuid"
124+
assert_equal "new_uuid", request.uuid
125+
assert_equal request.request_id, request.uuid
120126
end
121127
end
122128

test/slo_logoutresponse_test.rb

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,29 +82,38 @@ class SloLogoutresponseTest < Minitest::Test
8282
assert_match(/Destination='http:\/\/unauth.com\/logout\/return'/, inflated)
8383
end
8484

85-
describe "playgin with preix" do
86-
it "creates request with ID prefixed with default '_'" do
87-
request = RubySaml::SloLogoutresponse.new
85+
describe "uuid" do
86+
it "uuid is initialized to nil" do
87+
response = RubySaml::SloLogoutresponse.new
8888

89-
assert_match(/^_/, request.uuid)
89+
assert_nil(response.uuid)
90+
assert_equal response.response_id, response.uuid
9091
end
9192

92-
it "creates request with ID is prefixed, when :id_prefix is passed" do
93-
RubySaml::Utils::set_prefix("test")
94-
request = RubySaml::SloLogoutresponse.new
95-
assert_match(/^test/, request.uuid)
96-
RubySaml::Utils::set_prefix("_")
93+
it "creates response with ID prefixed with default '_'" do
94+
response = RubySaml::SloLogoutresponse.new
95+
response.create(settings)
96+
97+
assert_match(/^_/, response.uuid)
98+
assert_equal response.response_id, response.uuid
99+
end
100+
101+
it "creates response with ID prefixed by Settings#sp_uuid_prefix" do
102+
settings.sp_uuid_prefix = 'test'
103+
response = RubySaml::SloLogoutresponse.new
104+
response.create(settings)
105+
106+
assert_match(/^test/, response.uuid)
107+
assert_equal response.response_id, response.uuid
97108
end
98-
end
99109

100-
describe "#manipulate response_id" do
101110
it "be able to modify the response id" do
102-
logoutresponse = RubySaml::SloLogoutresponse.new
103-
response_id = logoutresponse.response_id
104-
assert_equal response_id, logoutresponse.uuid
105-
logoutresponse.uuid = "new_uuid"
106-
assert_equal logoutresponse.response_id, logoutresponse.uuid
107-
assert_equal "new_uuid", logoutresponse.response_id
111+
response = RubySaml::SloLogoutresponse.new
112+
response_id = response.response_id
113+
assert_equal response_id, response.uuid
114+
response.uuid = "new_uuid"
115+
assert_equal "new_uuid", response.uuid
116+
assert_equal response.response_id, response.uuid
108117
end
109118
end
110119

0 commit comments

Comments
 (0)