DEV: Drop 'key' column from user_api_keys (#9388)

This commit is contained in:
Dan Ungureanu 2020-04-22 12:13:19 +03:00 committed by GitHub
parent 5c45363e67
commit 4e5f9d4cd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 8 deletions

View File

@ -28,7 +28,6 @@ class UserApiKey < ActiveRecord::Base
def generate_key
if !self.key_hash
@key ||= SecureRandom.hex
self.key = @key
self.key_hash = ApiKey.hash_key(@key)
end
end
@ -102,7 +101,6 @@ end
# id :integer not null, primary key
# user_id :integer not null
# client_id :string not null
# key :string not null
# application_name :string not null
# push_url :string
# created_at :datetime not null
@ -115,7 +113,6 @@ end
# Indexes
#
# index_user_api_keys_on_client_id (client_id) UNIQUE
# index_user_api_keys_on_key (key) UNIQUE
# index_user_api_keys_on_key_hash (key_hash) UNIQUE
# index_user_api_keys_on_user_id (user_id)
#

View File

@ -0,0 +1,17 @@
# frozen_string_literal: true
class RemoveKeyFromUserApiKey < ActiveRecord::Migration[6.0]
DROPPED_COLUMNS ||= {
user_api_keys: %i{key}
}
def up
DROPPED_COLUMNS.each do |table, columns|
Migration::ColumnDropper.execute_drop(table, columns)
end
end
def down
raise ActiveRecord::IrreversibleMigration
end
end

View File

@ -769,7 +769,6 @@ describe Auth::DefaultCurrentUserProvider do
application_name: 'my app',
client_id: '1234',
scopes: ['read'],
key: SecureRandom.hex,
user_id: user.id
)
end
@ -779,7 +778,6 @@ describe Auth::DefaultCurrentUserProvider do
application_name: 'my app',
client_id: '12345',
scopes: ['read'],
key: SecureRandom.hex,
user_id: user.id
)

View File

@ -4,6 +4,5 @@ Fabricator(:readonly_user_api_key, from: :user_api_key) do
user
scopes ['read']
client_id { SecureRandom.hex }
key { SecureRandom.hex }
application_name 'some app'
end

View File

@ -681,7 +681,6 @@ describe PostAlerter do
2.times do |i|
UserApiKey.create!(user_id: evil_trout.id,
client_id: "xxx#{i}",
key: "yyy#{i}",
application_name: "iPhone#{i}",
scopes: ['notifications'],
push_url: "https://site2.com/push")
@ -697,7 +696,6 @@ describe PostAlerter do
2.times do |i|
UserApiKey.create!(user_id: evil_trout.id,
client_id: "xxx#{i}",
key: "yyy#{i}",
application_name: "iPhone#{i}",
scopes: ['notifications'],
push_url: "https://site2.com/push")