Commit 3646782

mo <mo@mokhan.ca>
2019-04-30 21:00:09
add support for parsing ForceAuthn attribute
1 parent f6f0c74
Changed files (2)
lib/saml/kit/authentication_request.rb
@@ -47,6 +47,11 @@ module Saml
         at_xpath('./*/@AssertionConsumerServiceURL').try(:value)
       end
 
+      # Returns the ForceAuthn attribute as a boolean.
+      def force_authn
+        at_xpath('./*/@ForceAuthn').try(:value) == 'true'
+      end
+
       def name_id_format
         name_id_policy
       end
spec/saml/kit/authentication_request_spec.rb
@@ -30,6 +30,7 @@ RSpec.describe Saml::Kit::AuthenticationRequest do
   specify { expect(subject.assertion_consumer_service_url).to eql(assertion_consumer_service_url) }
   specify { expect(subject.name_id_format).to eql(name_id_format) }
   specify { expect(subject.destination).to eql(destination) }
+  specify { expect(subject.force_authn).to be(false) }
 
   describe '#valid?' do
     let(:registry) { instance_double(Saml::Kit::DefaultRegistry) }
@@ -186,6 +187,26 @@ RSpec.describe Saml::Kit::AuthenticationRequest do
     end
   end
 
+  describe "#force_authn" do
+    context "when set to true" do
+      subject { described_class.build { |x| x.force_authn = true } }
+
+      specify { expect(subject.force_authn).to be(true) }
+    end
+
+    context "when set to false" do
+      subject { described_class.build { |x| x.force_authn = false } }
+
+      specify { expect(subject.force_authn).to be(false) }
+    end
+
+    context "when not specified" do
+      subject { described_class.build { |x| x.force_authn = nil } }
+
+      specify { expect(subject.force_authn).to be(false) }
+    end
+  end
+
   describe '.build' do
     let(:url) { FFaker::Internet.uri('https') }
     let(:entity_id) { FFaker::Internet.uri('https') }