Commit 94d1280

mo <mo.khan@gmail.com>
2017-10-22 22:31:12
parse the acs_url from the saml response.
1 parent c12a3ce
Changed files (3)
app/models/saml_response.rb
@@ -5,6 +5,10 @@ class SamlResponse
     @xml = xml
   end
 
+  def acs_url
+    Hash.from_xml(@xml)['Response']['Destination']
+  end
+
   def to_xml
     @xml
   end
app/views/sessions/saml_post.html.erb
@@ -38,7 +38,7 @@
   </head>
   <body onload="document.forms[0].submit();">
     <div class="spinner"><svg xmlns="http://www.w3.org/2000/svg" width="25" height="25" viewBox="0 0 25 25"><defs><style>line{fill:none;stroke:#1a1a1a;stroke-linecap:round;stroke-miterlimit:10;stroke-width:2px;}.o25{opacity:0.25;}.o85{opacity:0.85;}.o7{opacity:0.7;}.o55{opacity:0.55;}.o35{opacity:0.35;}</style></defs><line x1="12.5" y1="2" x2="12.5" y2="7.05463"/><line class="o25" x1="12.5" y1="23" x2="12.5" y2="17.94537"/><line class="o85" x1="7.25" y1="3.40674" x2="9.77942" y2="7.78778"/><line class="o25" x1="17.75" y1="21.59326" x2="15.22058" y2="17.21222"/><line class="o25" x1="17.21222" y1="15.22058" x2="21.59326" y2="17.75"/><line class="o7" x1="7.78778" y1="9.77942" x2="3.40674" y2="7.25"/><line class="o25" x1="23" y1="12.5" x2="17.94537" y2="12.5"/><line class="o55" x1="7.05463" y1="12.5" x2="2" y2="12.5"/><line class="o35" x1="7.78778" y1="15.22058" x2="3.40674" y2="17.75"/><line class="o25" x1="21.59326" y1="7.25" x2="17.21222" y2="9.77942"/><line class="o25" x1="9.77942" y1="17.21222" x2="7.25" y2="21.59326"/><line class="o25" x1="17.75" y1="3.40674" x2="15.22058" y2="7.78778"/></svg></div>
-    <%= form_tag(saml_acs_url, style: "position: absolute; left: -10000px; top: -10000px;") do %>
+    <%= form_tag(@saml_response.acs_url, style: "position: absolute; left: -10000px; top: -10000px;") do %>
       <%= hidden_field_tag("SAMLResponse", @saml_response) %>
       <%= hidden_field_tag("RelayState", @relay_state) %>
       <%= submit_tag "Submit" %>
spec/models/saml_response_spec.rb
@@ -1,7 +1,18 @@
 require 'rails_helper'
 
 describe SamlResponse do
-  describe "#build" do
+  describe "#acs_url" do
+    let(:acs_url) { "https://#{FFaker::Internet.domain_name}/acs" }
+    let(:user) { double(:user, uuid: SecureRandom.uuid, assertion_attributes: { }) }
+    let(:request) { double(id: SecureRandom.uuid, acs_url: acs_url, issuer: FFaker::Movie.title) }
+    subject { SamlResponse::Builder.new(user, request).build }
+
+    it 'returns the acs_url' do
+      expect(subject.acs_url).to eql(acs_url)
+    end
+  end
+
+  describe "#to_xml" do
     subject { SamlResponse::Builder.new(user, request) }
     let(:user) { double(:user, uuid: SecureRandom.uuid, assertion_attributes: { email: email, created_at: Time.now.utc.iso8601 }) }
     let(:request) { double(id: SecureRandom.uuid, acs_url: acs_url, issuer: FFaker::Movie.title) }