From 9f283eb8363594d2f925b5c3a44793325a9d6979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Guitaut?= Date: Mon, 15 May 2023 06:12:25 +0200 Subject: [PATCH] DEV: Set a limit for ApiKey#description (#21502) --- app/models/api_key.rb | 2 ++ spec/models/api_key_spec.rb | 1 + 2 files changed, 3 insertions(+) diff --git a/app/models/api_key.rb b/app/models/api_key.rb index dc66d2fb40e..5c53ea52912 100644 --- a/app/models/api_key.rb +++ b/app/models/api_key.rb @@ -17,6 +17,8 @@ class ApiKey < ActiveRecord::Base where(key_hash: hashed) } + validates :description, length: { maximum: 255 } + after_initialize :generate_key def generate_key diff --git a/spec/models/api_key_spec.rb b/spec/models/api_key_spec.rb index 330b4b103cb..caf5c16e9dc 100644 --- a/spec/models/api_key_spec.rb +++ b/spec/models/api_key_spec.rb @@ -6,6 +6,7 @@ RSpec.describe ApiKey do it { is_expected.to belong_to :user } it { is_expected.to belong_to :created_by } + it { is_expected.to validate_length_of(:description).is_at_most(255) } it "generates a key when saving" do api_key = ApiKey.new