diff --git a/lib/omniauth/strategies/latvija.rb b/lib/omniauth/strategies/latvija.rb index 3ec1dfe..f5ffcd0 100644 --- a/lib/omniauth/strategies/latvija.rb +++ b/lib/omniauth/strategies/latvija.rb @@ -88,7 +88,7 @@ def raw_info end def uid - @response.name_identifier + "PK:#{raw_info['privatepersonalidentifier']}" end def full_name @@ -99,7 +99,8 @@ def legacy_uids # UIDs that could have been assigned to this identity by previous versions of the gem, or due to peronal identifier change legacy_uids = [ - "#{full_name}, #{raw_info["privatepersonalidentifier"]}" # generated by gem version <= 4.0 + "#{full_name}, #{raw_info["privatepersonalidentifier"]}", # generated by gem version <= 4.0 + @response.name_identifier # VPM internal UID fallback, generated by gem version <= 6.3.0 ] raw_info.fetch('historical_privatepersonalidentifier', []).each do |historical_identifier| diff --git a/spec/fixtures/wresult_single_personal_code_nameidentifier_mismatch_decrypted.xml b/spec/fixtures/wresult_single_personal_code_nameidentifier_mismatch_decrypted.xml new file mode 100644 index 0000000..8fe80ab --- /dev/null +++ b/spec/fixtures/wresult_single_personal_code_nameidentifier_mismatch_decrypted.xml @@ -0,0 +1,63 @@ + + + + + 2019-11-05T13:57:02.777Z + 2019-11-05T17:57:02.777Z + + + + https://example.com + + + + + + + https://ivis.eps.gov.lv/LVP.Sitecore + + + + + PK:32345678901 + + urn:oasis:names:tc:SAML:1.0:cm:bearer + + + + ODS + + + KNISLIS + + + 01018012345 + + + 4 + + + https://epakvisstv.vraa.gov.lv/STS/VISS.LVP.STS/Image.ashx?id=am-test + + + + + PK:32345678901 + + urn:oasis:names:tc:SAML:1.0:cm:bearer + + + + + + + urn:oasis:names:tc:SAML:1.0:assertion + http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue + http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer + + diff --git a/spec/omniauth/strategies/latvija_spec.rb b/spec/omniauth/strategies/latvija_spec.rb index b888cc9..450a009 100644 --- a/spec/omniauth/strategies/latvija_spec.rb +++ b/spec/omniauth/strategies/latvija_spec.rb @@ -198,7 +198,7 @@ def strategy expect(response.dig('extra', 'raw_info', 'historical_privatepersonalidentifier')).to match_array(['12345678901']) end - it 'should return NameIdentifier property as the auth UID' do + it 'should return PK:privatepersonalidentifier as the auth UID' do expect(response.dig('uid')).to eq('PK:32345678901') end @@ -237,9 +237,39 @@ def strategy expect(response.dig('extra', 'raw_info', 'historical_privatepersonalidentifier')).to be_empty end - it 'should return NameIdentifier property as the auth UID' do + it 'should return PK:privatepersonalidentifier as the auth UID' do expect(response.dig('uid')).to eq('PK:32345678901') end end + + context 'when response NameIdentifier code does not match real private personal identifier' do + let(:wresult_decrypted) { File.read('spec/fixtures/wresult_single_personal_code_nameidentifier_mismatch_decrypted.xml') } + + before(:each) do + allow_any_instance_of(OmniAuth::Strategies::Latvija::SignedDocument).to receive(:validate!).and_return(true) + end + + let(:response) do + post '/auth/latvija/callback', { + :wa => "wsignin1.0", + :wctx => "http://example.org/auth/latvija/callback", + :wresult => wresult_decrypted + } + + last_request.env['omniauth.auth'] + end + + it 'should return primary personal code' do + expect(response.dig('info', 'private_personal_identifier')).to eq('01018012345') + end + + it 'should not return historical personal codes in extra info' do + expect(response.dig('extra', 'raw_info', 'historical_privatepersonalidentifier')).to be_empty + end + + it 'should return PK:privatepersonalidentifier as the auth UID' do + expect(response.dig('uid')).to eq('PK:01018012345') + end + end end end