Skip to content
代码片段 群组 项目
提交 91ae4a4c 编辑于 作者: charlie ablett's avatar charlie ablett
浏览文件

Merge branch 'pass-similar-cc-count-to-pvs' into 'master'

Add similar credit card counts to external pipeline validation service payload

See merge request gitlab-org/gitlab!96264
No related branches found
No related tags found
无相关合并请求
...@@ -21,5 +21,9 @@ def similar_records ...@@ -21,5 +21,9 @@ def similar_records
network: network network: network
).order(credit_card_validated_at: :desc).includes(:user) ).order(credit_card_validated_at: :desc).includes(:user)
end end
def similar_holder_names_count
self.class.where('lower(holder_name) = :value', value: holder_name.downcase).count
end
end end
end end
# frozen_string_literal: true
class ReplaceIndexOnCreditCardValidations < Gitlab::Database::Migration[2.0]
disable_ddl_transaction!
OLD_INDEX_NAME = 'index_user_credit_card_validations_meta_data_full_match'
NEW_INDEX_NAME = 'index_user_credit_card_validations_meta_data_full_match_lower'
OLD_FIELDS = [:holder_name, :expiration_date, :last_digits, :credit_card_validated_at]
NEW_FIELDS = 'lower(holder_name), expiration_date, last_digits, credit_card_validated_at'
def up
add_concurrent_index :user_credit_card_validations, NEW_FIELDS, name: NEW_INDEX_NAME
remove_concurrent_index :user_credit_card_validations, OLD_FIELDS, name: OLD_INDEX_NAME
end
def down
add_concurrent_index :user_credit_card_validations, OLD_FIELDS, name: OLD_INDEX_NAME
remove_concurrent_index :user_credit_card_validations, NEW_FIELDS, name: NEW_INDEX_NAME
end
end
4d8be5080046eff9c3736cd2494c02b2d2cb1eeea2753479617cb344bc5b1cbb
\ No newline at end of file
...@@ -30341,7 +30341,7 @@ CREATE UNIQUE INDEX index_user_canonical_emails_on_user_id ON user_canonical_ema ...@@ -30341,7 +30341,7 @@ CREATE UNIQUE INDEX index_user_canonical_emails_on_user_id ON user_canonical_ema
   
CREATE UNIQUE INDEX index_user_canonical_emails_on_user_id_and_canonical_email ON user_canonical_emails USING btree (user_id, canonical_email); CREATE UNIQUE INDEX index_user_canonical_emails_on_user_id_and_canonical_email ON user_canonical_emails USING btree (user_id, canonical_email);
   
CREATE INDEX index_user_credit_card_validations_meta_data_full_match ON user_credit_card_validations USING btree (holder_name, expiration_date, last_digits, credit_card_validated_at); CREATE INDEX index_user_credit_card_validations_meta_data_full_match_lower ON user_credit_card_validations USING btree (lower(holder_name), expiration_date, last_digits, credit_card_validated_at);
   
CREATE INDEX index_user_credit_card_validations_meta_data_partial_match ON user_credit_card_validations USING btree (expiration_date, last_digits, network, credit_card_validated_at); CREATE INDEX index_user_credit_card_validations_meta_data_partial_match ON user_credit_card_validations USING btree (expiration_date, last_digits, network, credit_card_validated_at);
   
...@@ -44,6 +44,7 @@ required number of seconds. ...@@ -44,6 +44,7 @@ required number of seconds.
"required" : [ "required" : [
"project", "project",
"user", "user",
"credit_card",
"pipeline", "pipeline",
"builds", "builds",
"total_builds_count", "total_builds_count",
...@@ -85,6 +86,17 @@ required number of seconds. ...@@ -85,6 +86,17 @@ required number of seconds.
"sign_in_count": { "type": "integer" } "sign_in_count": { "type": "integer" }
} }
}, },
"credit_card": {
"type": "object",
"required": [
"similar_cards_count",
"similar_holder_names_count"
],
"properties": {
"similar_cards_count": { "type": "integer" },
"similar_holder_names_count": { "type": "integer" }
}
},
"pipeline": { "pipeline": {
"type": "object", "type": "object",
"required": [ "required": [
......
...@@ -97,6 +97,10 @@ def validation_service_payload ...@@ -97,6 +97,10 @@ def validation_service_payload
last_sign_in_ip: current_user.last_sign_in_ip, last_sign_in_ip: current_user.last_sign_in_ip,
sign_in_count: current_user.sign_in_count sign_in_count: current_user.sign_in_count
}, },
credit_card: {
similar_cards_count: current_user.credit_card_validation&.similar_records&.count.to_i,
similar_holder_names_count: current_user.credit_card_validation&.similar_holder_names_count.to_i
},
pipeline: { pipeline: {
sha: pipeline.sha, sha: pipeline.sha,
ref: pipeline.ref, ref: pipeline.ref,
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
"required" : [ "required" : [
"project", "project",
"user", "user",
"credit_card",
"pipeline", "pipeline",
"builds", "builds",
"total_builds_count" "total_builds_count"
...@@ -43,6 +44,17 @@ ...@@ -43,6 +44,17 @@
"sign_in_count": { "type": "integer" } "sign_in_count": { "type": "integer" }
} }
}, },
"credit_card": {
"type": "object",
"required": [
"similar_cards_count",
"similar_holder_names_count"
],
"properties": {
"similar_cards_count": { "type": "integer" },
"similar_holder_names_count": { "type": "integer" }
}
},
"pipeline": { "pipeline": {
"type": "object", "type": "object",
"required": [ "required": [
......
...@@ -179,6 +179,70 @@ ...@@ -179,6 +179,70 @@
perform! perform!
end end
end end
describe 'credit_card' do
context 'with no registered credit_card' do
it 'returns the expected credit card counts' do
expect(::Gitlab::HTTP).to receive(:post) do |_url, params|
payload = Gitlab::Json.parse(params[:body])
expect(payload['credit_card']['similar_cards_count']).to eq(0)
expect(payload['credit_card']['similar_holder_names_count']).to eq(0)
end
perform!
end
end
context 'with a registered credit card' do
let!(:credit_card) { create(:credit_card_validation, last_digits: 10, holder_name: 'Alice', user: user) }
it 'returns the expected credit card counts' do
expect(::Gitlab::HTTP).to receive(:post) do |_url, params|
payload = Gitlab::Json.parse(params[:body])
expect(payload['credit_card']['similar_cards_count']).to eq(1)
expect(payload['credit_card']['similar_holder_names_count']).to eq(1)
end
perform!
end
context 'with similar credit cards registered by other users' do
before do
create(:credit_card_validation, last_digits: 10, holder_name: 'Bob')
end
it 'returns the expected credit card counts' do
expect(::Gitlab::HTTP).to receive(:post) do |_url, params|
payload = Gitlab::Json.parse(params[:body])
expect(payload['credit_card']['similar_cards_count']).to eq(2)
expect(payload['credit_card']['similar_holder_names_count']).to eq(1)
end
perform!
end
end
context 'with similar holder names registered by other users' do
before do
create(:credit_card_validation, last_digits: 11, holder_name: 'Alice')
end
it 'returns the expected credit card counts' do
expect(::Gitlab::HTTP).to receive(:post) do |_url, params|
payload = Gitlab::Json.parse(params[:body])
expect(payload['credit_card']['similar_cards_count']).to eq(1)
expect(payload['credit_card']['similar_holder_names_count']).to eq(2)
end
perform!
end
end
end
end
end end
context 'when EXTERNAL_VALIDATION_SERVICE_TOKEN is set' do context 'when EXTERNAL_VALIDATION_SERVICE_TOKEN is set' do
......
...@@ -28,4 +28,15 @@ ...@@ -28,4 +28,15 @@
expect(subject.similar_records).to eq([match2, match1, subject]) expect(subject.similar_records).to eq([match2, match1, subject])
end end
end end
describe '.similar_holder_names_count' do
subject!(:credit_card_validation) { create(:credit_card_validation, holder_name: 'ALICE M SMITH') }
let!(:match) { create(:credit_card_validation, holder_name: 'Alice M Smith') }
let!(:non_match) { create(:credit_card_validation, holder_name: 'Bob B Brown') }
it 'returns the count of cards with similar case insensitive holder names' do
expect(subject.similar_holder_names_count).to eq(2)
end
end
end end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册