Commit 51f4416
Changed files (6)
app
models
config
initializers
spec
models
app/models/saml_response.rb
@@ -34,7 +34,8 @@ class SamlResponse
Destination: request.acs_url,
InResponseTo: request.id,
}
- xml.tag! "samlp:Response", options do |response|
+ xml.tag!("samlp:Response", options) do
+ xml.tag!('saml:Issuer', configuration.issuer)
end
xml.target!
end
@@ -42,5 +43,11 @@ class SamlResponse
def build
SamlResponse.new(to_xml)
end
+
+ private
+
+ def configuration
+ Rails.configuration.x
+ end
end
end
config/initializers/configuration.rb
@@ -0,0 +1,1 @@
+Rails.application.config.x.issuer = ENV['ISSUER']
spec/models/saml_response_spec.rb
@@ -6,6 +6,7 @@ describe SamlResponse do
let(:user) { double(:user) }
let(:request) { double(id: SecureRandom.uuid, acs_url: acs_url) }
let(:acs_url) { "https://#{FFaker::Internet.domain_name}/acs" }
+ let(:issuer) { FFaker::Movie.title }
<<-XML
<samlp:Response
@@ -55,6 +56,7 @@ describe SamlResponse do
XML
it 'returns a proper response for the user' do
travel_to 1.second.from_now
+ allow(Rails.configuration.x).to receive(:issuer).and_return(issuer)
result = subject.for(user, request).to_xml
hash = Hash.from_xml(result)
@@ -63,6 +65,7 @@ describe SamlResponse do
expect(hash['Response']['IssueInstant']).to eql(Time.now.utc.iso8601)
expect(hash['Response']['Destination']).to eql(acs_url)
expect(hash['Response']['InResponseTo']).to eql(request.id)
+ expect(hash['Response']['Issuer']).to eql(issuer)
end
end
end
.env
@@ -0,0 +1,1 @@
+ISSUER=proof.dev
Gemfile
@@ -56,3 +56,4 @@ end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
+gem 'dotenv-rails'
Gemfile.lock
@@ -66,6 +66,10 @@ GEM
safe_yaml (~> 1.0.0)
crass (1.0.2)
diff-lcs (1.3)
+ dotenv (2.2.1)
+ dotenv-rails (2.2.1)
+ dotenv (= 2.2.1)
+ railties (>= 3.2, < 5.2)
erubi (1.7.0)
execjs (2.7.0)
ffaker (2.7.0)
@@ -214,6 +218,7 @@ DEPENDENCIES
byebug
capybara (~> 2.13)
coffee-rails (~> 4.2)
+ dotenv-rails
ffaker
jbuilder (~> 2.5)
listen (>= 3.0.5, < 3.2)