diff --git a/app/models/one_login/core_identity_validator.rb b/app/models/one_login/core_identity_validator.rb index 4fbec78fbf..5bbaa5aab5 100644 --- a/app/models/one_login/core_identity_validator.rb +++ b/app/models/one_login/core_identity_validator.rb @@ -22,7 +22,15 @@ def date_of_birth end def full_name - name_parts.map { |hash| hash["value"] }.join(" ") + given_names = name_parts + .select { |hash| hash["type"] == "GivenName" } + .map { |hash| hash["value"] } + + family_names = name_parts + .select { |hash| hash["type"] == "FamilyName" } + .map { |hash| hash["value"] } + + (given_names + family_names).join(" ") end private diff --git a/spec/models/one_login/core_identity_validator_spec.rb b/spec/models/one_login/core_identity_validator_spec.rb index c6ba813db4..44eaa9d086 100644 --- a/spec/models/one_login/core_identity_validator_spec.rb +++ b/spec/models/one_login/core_identity_validator_spec.rb @@ -91,6 +91,19 @@ it "returns whole name" do expect(subject.full_name).to eql("KENNETH DECERQUEIRA") end + + context "if name parts is out of order" do + it "ensures family name is used as last name" do + out_of_order = [ + {"value" => "DECERQUEIRA", "type" => "FamilyName"}, + {"value" => "KENNETH", "type" => "GivenName"} + ] + + allow(subject).to receive(:name_parts).and_return(out_of_order) + + expect(subject.full_name).to eql("KENNETH DECERQUEIRA") + end + end end let(:stub_normal_did) do