Merge pull request #9880 from demarches-simplifiees/api_token_store_last_used_ips

API: stocke les ips utilisées pour accéder à l'API
This commit is contained in:
Colin Darie 2023-12-21 16:18:00 +00:00 committed by GitHub
commit 6f7d786783
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 1 deletions

View file

@ -157,4 +157,24 @@ describe APIToken, type: :model do
it { is_expected.to be_nil }
end
end
describe '#store_new_ip' do
let(:api_token) { APIToken.generate(administrateur).first }
let(:ip) { '192.168.0.1' }
subject do
api_token.store_new_ip(ip)
api_token.stored_ips
end
context 'when none ip is stored' do
it { is_expected.to eq([IPAddr.new(ip)]) }
end
context 'when the ip is already stored' do
before { api_token.update!(stored_ips: [ip]) }
it { is_expected.to eq([IPAddr.new(ip)]) }
end
end
end