Commit 1a56b61

mo <mo.khan@gmail.com>
2017-10-22 22:17:24
parse id and acs_url.
1 parent 0658a93
app/models/authentication_request.rb
@@ -8,11 +8,11 @@ class AuthenticationRequest
   end
 
   def id
-    raise NotImplementedError.new
+    @hash['AuthnRequest']['ID']
   end
 
   def acs_url
-    raise NotImplementedError.new
+    @hash['AuthnRequest']['AssertionConsumerServiceURL']
   end
 
   def issuer
spec/models/authentication_request_spec.rb
@@ -0,0 +1,33 @@
+require 'rails_helper'
+
+describe AuthenticationRequest do
+  subject { described_class.new(raw_xml, registry) }
+  let(:registry) { double }
+  let(:id) { SecureRandom.uuid }
+  let(:acs_url) { "https://#{FFaker::Internet.domain_name}/acs" }
+  let(:issuer) { FFaker::Movie.title }
+  let(:raw_xml) do
+    builder = AuthenticationRequest::Builder.new
+    builder.id = id
+    builder.issued_at = Time.now.utc
+    builder.issuer = issuer
+    builder.acs_url = acs_url
+    builder.to_xml
+  end
+
+  it { expect(subject.issuer).to eql(issuer) }
+  it { expect(subject.id).to eql(id) }
+  it { expect(subject.acs_url).to eql(acs_url) }
+
+  describe "#valid?" do
+    it 'returns false when the service provider is not known' do
+      allow(registry).to receive(:registered?).with(issuer).and_return(false)
+      expect(subject).to_not be_valid
+    end
+
+    it 'returns true when the service provider is registered' do
+      allow(registry).to receive(:registered?).with(issuer).and_return(true)
+      expect(subject).to be_valid
+    end
+  end
+end
spec/models/saml_request_spec.rb
@@ -1,28 +0,0 @@
-require 'rails_helper'
-
-describe AuthenticationRequest do
-  subject { described_class.new(raw_xml, registry) }
-  let(:registry) { double }
-  let(:acs_url) { "https://blah.dev/acs" }
-
-  describe "#valid?" do
-    let(:raw_xml) do
-      builder = AuthenticationRequest::Builder.new
-      builder.id = SecureRandom.uuid
-      builder.issued_at = Time.now.utc
-      builder.issuer = "my-issuer"
-      builder.acs_url = acs_url
-      builder.to_xml
-    end
-
-    it 'returns false when the service provider is not known' do
-      allow(registry).to receive(:registered?).with("my-issuer").and_return(false)
-      expect(subject).to_not be_valid
-    end
-
-    it 'returns true when the service provider is registered' do
-      allow(registry).to receive(:registered?).with("my-issuer").and_return(true)
-      expect(subject).to be_valid
-    end
-  end
-end