Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ea2213cc
Commit
ea2213cc
authored
Oct 15, 2020
by
Peter Leitzen
Committed by
Adam Hegyi
Oct 19, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't force encrypted database columns to have a text limit
parent
eff188a5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
0 deletions
+32
-0
rubocop/cop/migration/add_limit_to_text_columns.rb
rubocop/cop/migration/add_limit_to_text_columns.rb
+10
-0
spec/rubocop/cop/migration/add_limit_to_text_columns_spec.rb
spec/rubocop/cop/migration/add_limit_to_text_columns_spec.rb
+22
-0
No files found.
rubocop/cop/migration/add_limit_to_text_columns.rb
View file @
ea2213cc
...
...
@@ -6,6 +6,10 @@ module RuboCop
module
Cop
module
Migration
# Cop that enforces always adding a limit on text columns
#
# Text columns starting with `encrypted_` are very likely used
# by `attr_encrypted` which controls the text length. Those columns
# should not add a text limit.
class
AddLimitToTextColumns
<
RuboCop
::
Cop
::
Cop
include
MigrationHelpers
...
...
@@ -102,6 +106,8 @@ module RuboCop
# Check if there is an `add_text_limit` call for the provided
# table and attribute name
def
text_limit_missing?
(
node
,
table_name
,
attribute_name
)
return
false
if
encrypted_attribute_name?
(
attribute_name
)
limit_found
=
false
node
.
each_descendant
(
:send
)
do
|
send_node
|
...
...
@@ -118,6 +124,10 @@ module RuboCop
!
limit_found
end
def
encrypted_attribute_name?
(
attribute_name
)
attribute_name
.
to_s
.
start_with?
(
'encrypted_'
)
end
end
end
end
...
...
spec/rubocop/cop/migration/add_limit_to_text_columns_spec.rb
View file @
ea2213cc
...
...
@@ -129,6 +129,28 @@ RSpec.describe RuboCop::Cop::Migration::AddLimitToTextColumns, type: :rubocop do
end
end
context
'when text columns are used for encryption'
do
it
'registers no offenses'
do
expect_no_offenses
(
<<~
RUBY
)
class TestTextLimits < ActiveRecord::Migration[6.0]
DOWNTIME = false
disable_ddl_transaction!
def up
create_table :test_text_limits, id: false do |t|
t.integer :test_id, null: false
t.text :encrypted_name
end
add_column :encrypted_test_text_limits, :encrypted_email, :text
add_column_with_default :encrypted_test_text_limits, :encrypted_role, :text, default: 'default'
change_column_type_concurrently :encrypted_test_text_limits, :encrypted_test_id, :text
end
end
RUBY
end
end
context
'on down'
do
it
'registers no offense'
do
expect_no_offenses
(
<<~
RUBY
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment