* Drop proprietary CI stuff
* Setup workspace and CI through GH Actions
* Bump to valitydev/damsel@4e82c24
This commit is contained in:
Andrew Mayorov 2022-09-21 16:12:42 +03:00 committed by GitHub
parent 5d26beb1a9
commit d9c82e9fa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 244 additions and 217 deletions

3
.env Normal file
View File

@ -0,0 +1,3 @@
OTP_VERSION=24.3.4
REBAR_VERSION=3.18
THRIFT_VERSION=0.14.2.3

38
.github/workflows/erlang-checks.yml vendored Normal file
View File

@ -0,0 +1,38 @@
name: Erlang CI Checks
on:
push:
branches:
- 'master'
- 'epic/**'
pull_request:
branches: ['**']
jobs:
setup:
name: Load .env
runs-on: ubuntu-latest
outputs:
otp-version: ${{ steps.otp-version.outputs.version }}
rebar-version: ${{ steps.rebar-version.outputs.version }}
thrift-version: ${{ steps.thrift-version.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- run: grep -v '^#' .env >> $GITHUB_ENV
- id: otp-version
run: echo "::set-output name=version::$OTP_VERSION"
- id: rebar-version
run: echo "::set-output name=version::$REBAR_VERSION"
- id: thrift-version
run: echo "::set-output name=version::$THRIFT_VERSION"
run:
name: Run checks
needs: setup
uses: valitydev/erlang-workflows/.github/workflows/erlang-parallel-build.yml@v1.0.1
with:
otp-version: ${{ needs.setup.outputs.otp-version }}
rebar-version: ${{ needs.setup.outputs.rebar-version }}
use-thrift: true
thrift-version: ${{ needs.setup.outputs.thrift-version }}

24
.gitignore vendored
View File

@ -1,19 +1,13 @@
.rebar3
_*
.eunit
# Build artifacts
/_build/
*.o
*.beam
*.plt
*.swp
*.swo
.erlang.cookie
ebin
log
# Run artifacts
erl_crash.dump
.rebar
logs
_build
.idea
*.iml
rebar3.crashdump
*~
log
# make stuff
/.image.*
Makefile.env

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "build_utils"]
path = build_utils
url = https://github.com/rbkmoney/build_utils.git

10
Dockerfile.dev Normal file
View File

@ -0,0 +1,10 @@
ARG OTP_VERSION
FROM docker.io/library/erlang:${OTP_VERSION}
# Set env
ENV CHARSET=UTF-8
ENV LANG=C.UTF-8
# Set runtime
CMD ["/bin/bash"]

42
Jenkinsfile vendored
View File

@ -1,42 +0,0 @@
#!groovy
// -*- mode: groovy -*-
//
// Copyright 2017 RBKmoney
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
def finalHook = {
runStage('store CT logs') {
archive '_build/test/logs/'
}
}
build('bankcard_validator', 'docker-host', finalHook) {
checkoutRepo()
loadBuildUtils()
def pipeErlangLib
runStage('load pipeline') {
env.JENKINS_LIB = "build_utils/jenkins_lib"
env.SH_TOOLS = "build_utils/sh"
pipeErlangLib = load("${env.JENKINS_LIB}/pipeErlangLib.groovy")
}
// NOTE: Parallel pipeline almost always fails because of
// rebar3's design (it uses link for libraries, so
// parallel runs with different profiles brake each other)
// To prevent this use sequential pipleine here
pipeErlangLib.runPipe(false, false, 'test')
}

111
Makefile
View File

@ -1,71 +1,94 @@
REBAR := $(shell which rebar3 2>/dev/null || which ./rebar3)
SUBMODULES = build_utils
SUBTARGETS = $(patsubst %,%/.git,$(SUBMODULES))
# HINT
# Use this file to override variables here.
# For example, to run with podman put `DOCKER=podman` there.
-include Makefile.env
UTILS_PATH := build_utils
TEMPLATES_PATH := .
# NOTE
# Variables specified in `.env` file are used to pick and setup specific
# component versions, both when building a development image and when running
# CI workflows on GH Actions. This ensures that tasks run with `wc-` prefix
# (like `wc-dialyze`) are reproducible between local machine and CI runners.
DOTENV := $(shell grep -v '^\#' .env)
# Name of the service
SERVICE_NAME := bankcard_validate
# Service image default tag
SERVICE_IMAGE_TAG ?= $(shell git rev-parse HEAD)
# The tag for service image to be pushed with
SERVICE_IMAGE_PUSH_TAG ?= $(SERVICE_IMAGE_TAG)
# Base image for the service
BASE_IMAGE_NAME := service-erlang
BASE_IMAGE_TAG := c0aee9a464ee26b8887dd9660dca69d4c3444179
# Build image tag to be used
BUILD_IMAGE_NAME := build-erlang
BUILD_IMAGE_TAG := cc2d319150ec0b9cd23ad9347692a8066616b0f4
CALL_ANYWHERE := all submodules rebar-update compile xref lint dialyze plt_update \
clean distclean format check_format
CALL_W_CONTAINER := $(CALL_ANYWHERE) test
DOCKER ?= docker
REBAR ?= rebar3
TEST_CONTAINER_NAME ?= bankcard-validator
all: compile
-include $(UTILS_PATH)/make_lib/utils_container.mk
-include $(UTILS_PATH)/make_lib/utils_image.mk
# Development images
.PHONY: $(CALL_W_CONTAINER)
DEV_IMAGE_TAG = $(TEST_CONTAINER_NAME)-dev
DEV_IMAGE_ID = $(file < .image.dev)
# CALL_ANYWHERE
$(SUBTARGETS): %/.git: %
git submodule update --init $<
touch $@
.PHONY: dev-image clean-dev-image wc-shell test
submodules: $(SUBTARGETS)
dev-image: .image.dev
rebar-update:
$(REBAR) update
.image.dev: Dockerfile.dev .env
$(DOCKER) build . -f Dockerfile.dev --tag $(DEV_IMAGE_TAG) $(DOTENV:%=--build-arg %)
$(DOCKER) image ls -q -f "reference=$(DEV_IMAGE_TAG)" | head -n1 > $@
compile: submodules rebar-update
clean-dev-image:
ifneq ($(DEV_IMAGE_ID),)
$(DOCKER) image rm -f $(DEV_IMAGE_TAG)
rm .image.dev
endif
DOCKER_WC_OPTIONS := -v $(PWD):$(PWD) --workdir $(PWD)
DOCKER_WC_EXTRA_OPTIONS ?= --rm
DOCKER_RUN = $(DOCKER) run -t $(DOCKER_WC_OPTIONS) $(DOCKER_WC_EXTRA_OPTIONS)
# Utility tasks
wc-shell: dev-image
$(DOCKER_RUN) --interactive --tty $(DEV_IMAGE_TAG)
wc-%: dev-image
$(DOCKER_RUN) $(DEV_IMAGE_TAG) make $*
# Rebar tasks
rebar-shell:
$(REBAR) shell
compile:
$(REBAR) compile
xref: submodules
xref:
$(REBAR) xref
lint:
$(REBAR) lint
check_format:
check-format:
$(REBAR) fmt -c
dialyze:
$(REBAR) as test dialyzer
release:
$(REBAR) as prod release
eunit:
$(REBAR) eunit --cover
common-test:
$(REBAR) ct --cover
cover:
$(REBAR) covertool generate
format:
$(REBAR) fmt -w
dialyze: submodules
$(REBAR) as test dialyzer
clean:
$(REBAR) clean
distclean:
distclean: clean-build-image
rm -rf _build
# CALL_W_CONTAINER
test: submodules
$(REBAR) as test proper,ct
test: eunit common-test
cover-report:
$(REBAR) cover

@ -1 +0,0 @@
Subproject commit 24aa772730be966667adb285a09fcb494d4f218e

View File

@ -1,14 +0,0 @@
#!/bin/bash
cat <<EOF
version: '2.1'
services:
${SERVICE_NAME}:
image: ${BUILD_IMAGE}
restart: always
volumes:
- .:/$PWD
- $HOME/.cache:/home/$UNAME/.cache
working_dir: /$PWD
command: /sbin/init
EOF

View File

@ -1,5 +1,6 @@
[
{elvis, [
{verbose, true},
{config, [
#{
dirs => ["src", "include", "test"],
@ -7,14 +8,9 @@
ruleset => erl_files,
rules => [
{elvis_text_style, line_length, #{limit => 120}},
{elvis_text_style, no_trailing_whitespace, #{ignore_empty_lines => true}},
{elvis_style, nesting_level, #{level => 3}},
{elvis_style, function_naming_convention, #{regex => "^([a-z][a-z0-9]*_?)*$"}},
{elvis_style, no_if_expression, disable},
{elvis_style, dont_repeat_yourself, #{min_complexity => 15}},
{elvis_style, no_debug_call, #{
ignore => [bankcard_validation_invalid_carddata, bankcard_validation_valid_carddata]
}}
{elvis_style, no_if_expression, disable}
]
},
#{
@ -32,7 +28,7 @@
filter => "rebar.config",
ruleset => rebar_config,
rules => [
{elvis_text_style, line_length, #{limit => 120, skip_comments => false}},
{elvis_text_style, line_length, #{limit => 120}},
{elvis_text_style, no_tabs},
{elvis_text_style, no_trailing_whitespace},
%% Temporarily disabled till regex pattern is available
@ -43,7 +39,7 @@
dirs => ["src"],
filter => "*.app.src",
rules => [
{elvis_text_style, line_length, #{limit => 120, skip_comments => false}},
{elvis_text_style, line_length, #{limit => 120}},
{elvis_text_style, no_tabs},
{elvis_text_style, no_trailing_whitespace}
]

View File

@ -26,9 +26,9 @@
%% Common project dependencies.
{deps, [
{genlib, {git, "https://github.com/rbkmoney/genlib.git", {branch, "master"}}},
{damsel, {git, "https://github.com/rbkmoney/damsel.git", {branch, "release/erlang/master"}}},
{dmt_client, {git, "https://github.com/rbkmoney/dmt_client.git", {branch, "master"}}}
{genlib, {git, "https://github.com/valitydev/genlib.git", {branch, "master"}}},
{damsel, {git, "https://github.com/valitydev/damsel.git", {branch, "master"}}},
{dmt_client, {git, "https://github.com/valitydev/dmt_client.git", {branch, "master"}}}
]}.
%% XRef checks
@ -38,13 +38,9 @@
deprecated_functions_calls,
deprecated_functions
]}.
% at will
% {xref_warnings, true}.
%% Tests
{cover_enabled, true}.
%% Dialyzer static analyzing
{dialyzer, [
{warnings, [
@ -59,26 +55,36 @@
{profiles, [
{test, [
{cover_enabled, true},
{deps, [
{proper, "1.4.0"},
{meck, "0.9.2"}
]},
{cover_enabled, true},
{dialyzer, [{plt_extra_apps, [proper, eunit, common_test, meck]}]}
{dialyzer, [
{plt_extra_apps, [proper, eunit, common_test, meck]}
]}
]}
]}.
{plugins, [
{erlfmt, "0.12.0"},
{rebar3_lint, "1.0.1"},
{erlfmt, "1.0.0"},
rebar3_proper,
{rebar3_lint, "0.4.0"}
{covertool, "2.0.4"}
]}.
%% Linter config.
{elvis_output_format, colors}.
{erlfmt, [
{print_width, 120},
{files, ["{src,include,test}/*.{hrl,erl}", "rebar.config", "elvis.config"]}
]}.
{pre_hooks, [
{thrift, "git submodule update --init"}
{covertool, [
{coverdata_files, [
"eunit.coverdata",
"ct.coverdata"
]}
]}.

View File

@ -1,67 +1,53 @@
{"1.2.0",
[{<<"bear">>,{pkg,<<"bear">>,<<"0.8.7">>},4},
{<<"cache">>,{pkg,<<"cache">>,<<"2.3.3">>},2},
{<<"certifi">>,{pkg,<<"certifi">>,<<"2.6.1">>},3},
{<<"cg_mon">>,
{git,"https://github.com/rbkmoney/cg_mon.git",
{ref,"5a87a37694e42b6592d3b4164ae54e0e87e24e18"}},
3},
[{<<"cache">>,{pkg,<<"cache">>,<<"2.3.3">>},2},
{<<"certifi">>,{pkg,<<"certifi">>,<<"2.8.0">>},3},
{<<"cowboy">>,{pkg,<<"cowboy">>,<<"2.9.0">>},2},
{<<"cowlib">>,{pkg,<<"cowlib">>,<<"2.11.0">>},3},
{<<"damsel">>,
{git,"https://github.com/rbkmoney/damsel.git",
{ref,"647430ddbec581844e17f6615b64f9a3e814ac3d"}},
{git,"https://github.com/valitydev/damsel.git",
{ref,"4e82c2431ae5d0045c7e21a29ed27f01f5b0f6d5"}},
0},
{<<"dmt_client">>,
{git,"https://github.com/rbkmoney/dmt_client.git",
{ref,"b04dcb651db4e85e3e84c187a023c223fcb02a3e"}},
{git,"https://github.com/valitydev/dmt_client.git",
{ref,"ce6678af1499230fe13f8b34258aabe8b92ac722"}},
0},
{<<"dmt_core">>,
{git,"https://github.com/rbkmoney/dmt_core.git",
{ref,"5a0ff399dee3fd606bb864dd0e27ddde539345e2"}},
{git,"https://github.com/valitydev/dmt-core.git",
{ref,"75841332fe0b40a77da0c12ea8d5dbb994da8e82"}},
1},
{<<"folsom">>,
{git,"https://github.com/folsom-project/folsom.git",
{ref,"eeb1cc467eb64bd94075b95b8963e80d8b4df3df"}},
3},
{<<"genlib">>,
{git,"https://github.com/rbkmoney/genlib.git",
{ref,"c9ba550925b9a4431a92b928e69da01331fd3253"}},
{git,"https://github.com/valitydev/genlib.git",
{ref,"82c5ff3866e3019eb347c7f1d8f1f847bed28c10"}},
0},
{<<"gproc">>,{pkg,<<"gproc">>,<<"0.9.0">>},2},
{<<"hackney">>,{pkg,<<"hackney">>,<<"1.17.4">>},2},
{<<"how_are_you">>,
{git,"https://github.com/rbkmoney/how_are_you.git",
{ref,"8f11d17eeb6eb74096da7363a9df272fd3099718"}},
2},
{<<"hackney">>,{pkg,<<"hackney">>,<<"1.18.0">>},2},
{<<"idna">>,{pkg,<<"idna">>,<<"6.1.1">>},3},
{<<"metrics">>,{pkg,<<"metrics">>,<<"1.0.1">>},3},
{<<"mimerl">>,{pkg,<<"mimerl">>,<<"1.2.0">>},3},
{<<"parse_trans">>,{pkg,<<"parse_trans">>,<<"3.3.1">>},3},
{<<"ranch">>,{pkg,<<"ranch">>,<<"1.8.0">>},3},
{<<"snowflake">>,
{git,"https://github.com/rbkmoney/snowflake.git",
{git,"https://github.com/valitydev/snowflake.git",
{ref,"de159486ef40cec67074afe71882bdc7f7deab72"}},
2},
{<<"ssl_verify_fun">>,{pkg,<<"ssl_verify_fun">>,<<"1.1.6">>},3},
{<<"thrift">>,
{git,"https://github.com/rbkmoney/thrift_erlang.git",
{ref,"846a0819d9b6d09d0c31f160e33a78dbad2067b4"}},
{git,"https://github.com/valitydev/thrift_erlang.git",
{ref,"c280ff266ae1c1906fb0dcee8320bb8d8a4a3c75"}},
2},
{<<"unicode_util_compat">>,{pkg,<<"unicode_util_compat">>,<<"0.7.0">>},3},
{<<"woody">>,
{git,"https://github.com/rbkmoney/woody_erlang.git",
{ref,"d9fca6da55a46e39bdb7ad2c0dba0b7205a7e70b"}},
{git,"https://github.com/valitydev/woody_erlang.git",
{ref,"0c2e16dfc8a51f6f63fcd74df982178a9aeab322"}},
1}]}.
[
{pkg_hash,[
{<<"bear">>, <<"16264309AE5D005D03718A5C82641FCC259C9E8F09ADEB6FD79CA4271168656F">>},
{<<"cache">>, <<"B23A5FE7095445A88412A6E614C933377E0137B44FFED77C9B3FEF1A731A20B2">>},
{<<"certifi">>, <<"DBAB8E5E155A0763EEA978C913CA280A6B544BFA115633FA20249C3D396D9493">>},
{<<"certifi">>, <<"D4FB0A6BB20B7C9C3643E22507E42F356AC090A1DCEA9AB99E27E0376D695EBA">>},
{<<"cowboy">>, <<"865DD8B6607E14CF03282E10E934023A1BD8BE6F6BACF921A7E2A96D800CD452">>},
{<<"cowlib">>, <<"0B9FF9C346629256C42EBE1EEB769A83C6CB771A6EE5960BD110AB0B9B872063">>},
{<<"gproc">>, <<"853CCB7805E9ADA25D227A157BA966F7B34508F386A3E7E21992B1B484230699">>},
{<<"hackney">>, <<"99DA4674592504D3FB0CFEF0DB84C3BA02B4508BAE2DFF8C0108BAA0D6E0977C">>},
{<<"hackney">>, <<"C4443D960BB9FBA6D01161D01CD81173089686717D9490E5D3606644C48D121F">>},
{<<"idna">>, <<"8A63070E9F7D0C62EB9D9FCB360A7DE382448200FBBD1B106CC96D3D8099DF8D">>},
{<<"metrics">>, <<"25F094DEA2CDA98213CECC3AEFF09E940299D950904393B2A29D191C346A8486">>},
{<<"mimerl">>, <<"67E2D3F571088D5CFD3E550C383094B47159F3EEE8FFA08E64106CDF5E981BE3">>},
@ -70,13 +56,12 @@
{<<"ssl_verify_fun">>, <<"CF344F5692C82D2CD7554F5EC8FD961548D4FD09E7D22F5B62482E5AEAEBD4B0">>},
{<<"unicode_util_compat">>, <<"BC84380C9AB48177092F43AC89E4DFA2C6D62B40B8BD132B1059ECC7232F9A78">>}]},
{pkg_hash_ext,[
{<<"bear">>, <<"534217DCE6A719D59E54FB0EB7A367900DBFC5F85757E8C1F94269DF383F6D9B">>},
{<<"cache">>, <<"44516CE6FA03594D3A2AF025DD3A87BFE711000EB730219E1DDEFC816E0AA2F4">>},
{<<"certifi">>, <<"524C97B4991B3849DD5C17A631223896272C6B0AF446778BA4675A1DFF53BB7E">>},
{<<"certifi">>, <<"6AC7EFC1C6F8600B08D625292D4BBF584E14847CE1B6B5C44D983D273E1097EA">>},
{<<"cowboy">>, <<"2C729F934B4E1AA149AFF882F57C6372C15399A20D54F65C8D67BEF583021BDE">>},
{<<"cowlib">>, <<"2B3E9DA0B21C4565751A6D4901C20D1B4CC25CBB7FD50D91D2AB6DD287BC86A9">>},
{<<"gproc">>, <<"587E8AF698CCD3504CF4BA8D90F893EDE2B0F58CABB8A916E2BF9321DE3CF10B">>},
{<<"hackney">>, <<"DE16FF4996556C8548D512F4DBE22DD58A587BF3332E7FD362430A7EF3986B16">>},
{<<"hackney">>, <<"9AFCDA620704D720DB8C6A3123E9848D09C87586DC1C10479C42627B905B5C5E">>},
{<<"idna">>, <<"92376EB7894412ED19AC475E4A86F7B413C1B9FBB5BD16DCCD57934157944CEA">>},
{<<"metrics">>, <<"69B09ADDDC4F74A40716AE54D140F93BEB0FB8978D8636EADED0C31B6F099F16">>},
{<<"mimerl">>, <<"F278585650AA581986264638EBF698F8BB19DF297F66AD91B18910DFC6E19323">>},

View File

@ -1,5 +1,6 @@
%%%
%%% Copyright 2021 RBKmoney
%%% Copyright 2022 Vality.dev
%%%
%%% Licensed under the Apache License, Version 2.0 (the "License");
%%% you may not use this file except in compliance with the License.
@ -64,17 +65,17 @@ run_assertions(CardData, Assertions, Env) ->
fun
({K, Checks}) when is_list(Checks) ->
V = maps:get(K, CardData, undefined),
lists:foreach(
fun(C) -> check_value(V, C, Env) orelse erlang:throw({invalid, K, convert(C)}) end,
Checks
);
lists:foreach(fun(C) -> assert_value(K, V, C, Env) end, Checks);
({K, Check}) ->
V = maps:get(K, CardData, undefined),
check_value(V, Check, Env) orelse erlang:throw({invalid, K, convert(Check)})
assert_value(K, V, Check, Env)
end,
Assertions
).
assert_value(K, V, Check, Env) ->
check_value(V, Check, Env) orelse erlang:throw({invalid, K, convert(Check)}).
check_value(undefined, _, _) ->
true;
check_value(V, {ranges, Ranges}, _) ->
@ -90,7 +91,7 @@ check_value({M, Y}, {exact_exp_date, #domain_PaymentCardExactExpirationDate{}},
M =< 12 andalso
{Y, M} >= {Y0, M0}.
check_range(V, #'IntegerRange'{lower = L, upper = U}) ->
check_range(V, #base_IntegerRange{lower = L, upper = U}) ->
L =< byte_size(V) andalso byte_size(V) =< U.
check_luhn(<<CheckSum>>, Sum) ->
@ -122,6 +123,6 @@ get_ruleset(PaymentSystem, Context) ->
end.
convert({checksum, {luhn, _}}) -> luhn;
convert({ranges, Ranges}) -> {ranges, [{range, L, U} || #'IntegerRange'{upper = U, lower = L} <- Ranges]};
convert({length, #'IntegerRange'{upper = U, lower = L}}) -> {length, L, U};
convert({ranges, Ranges}) -> {ranges, [{range, L, U} || #base_IntegerRange{upper = U, lower = L} <- Ranges]};
convert({length, #base_IntegerRange{upper = U, lower = L}}) -> {length, L, U};
convert({exact_exp_date, _}) -> expiration.

View File

@ -1,5 +1,6 @@
%%%
%%% Copyright 2021 RBKmoney
%%% Copyright 2022 Vality.dev
%%%
%%% Licensed under the Apache License, Version 2.0 (the "License");
%%% you may not use this file except in compliance with the License.
@ -17,7 +18,7 @@
-module(bankcard_validator_domain).
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
-include_lib("damsel/include/dmsl_domain_config_thrift.hrl").
-include_lib("damsel/include/dmsl_domain_conf_thrift.hrl").
-export([get_payment_system_ruleset/2]).
@ -36,6 +37,6 @@ get_payment_system_ruleset(PaymentSystemID, Context) ->
{payment_system, #domain_PaymentSystemObject{data = #domain_PaymentSystem{validation_rules = Ruleset}}} ->
{ok, Ruleset}
catch
throw:#'ObjectNotFound'{} ->
throw:#domain_conf_ObjectNotFound{} ->
{error, not_found}
end.

View File

@ -1,5 +1,6 @@
%%%
%%% Copyright 2021 RBKmoney
%%% Copyright 2022 Vality.dev
%%%
%%% Licensed under the Apache License, Version 2.0 (the "License");
%%% you may not use this file except in compliance with the License.
@ -16,6 +17,7 @@
-module(bankcard_validator_legacy).
-include_lib("damsel/include/dmsl_base_thrift.hrl").
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
-export([get_payment_system_ruleset/1]).
@ -28,50 +30,58 @@
-define(KNOWN_RULES, #{
<<"AMERICAN EXPRESS">> => [
{card_number, {checksum, {luhn, #'domain_PaymentCardNumberChecksumLuhn'{}}}},
{card_number, {ranges, [#'IntegerRange'{lower = 15, upper = 15}]}},
{cvc, {length, #'IntegerRange'{lower = 3, upper = 4}}},
{card_number, {ranges, [#base_IntegerRange{lower = 15, upper = 15}]}},
{cvc, {length, #base_IntegerRange{lower = 3, upper = 4}}},
{exp_date, {exact_exp_date, #'domain_PaymentCardExactExpirationDate'{}}}
],
%% TODO Remove in favor of <<"AMERICAN EXPRESS">>
<<"AMERICAN EXPRESS COMPANY">> => [
{card_number, {checksum, {luhn, #'domain_PaymentCardNumberChecksumLuhn'{}}}},
{card_number, {ranges, [#'IntegerRange'{lower = 15, upper = 15}]}},
{cvc, {length, #'IntegerRange'{lower = 3, upper = 4}}},
{card_number, {ranges, [#base_IntegerRange{lower = 15, upper = 15}]}},
{cvc, {length, #base_IntegerRange{lower = 3, upper = 4}}},
{exp_date, {exact_exp_date, #'domain_PaymentCardExactExpirationDate'{}}}
],
<<"CHINA UNION PAY">> => [
{card_number, {checksum, {luhn, #'domain_PaymentCardNumberChecksumLuhn'{}}}},
{card_number, {ranges, [#'IntegerRange'{lower = 16, upper = 16}, #'IntegerRange'{lower = 19, upper = 19}]}},
{cvc, {length, #'IntegerRange'{lower = 3, upper = 3}}},
{card_number,
{ranges, [
#base_IntegerRange{lower = 16, upper = 16},
#base_IntegerRange{lower = 19, upper = 19}
]}},
{cvc, {length, #base_IntegerRange{lower = 3, upper = 3}}},
{exp_date, {exact_exp_date, #'domain_PaymentCardExactExpirationDate'{}}}
],
<<"DANKORT">> => [
{card_number, {checksum, {luhn, #'domain_PaymentCardNumberChecksumLuhn'{}}}},
{card_number, {ranges, [#'IntegerRange'{lower = 16, upper = 16}]}},
{cvc, {length, #'IntegerRange'{lower = 3, upper = 3}}},
{card_number, {ranges, [#base_IntegerRange{lower = 16, upper = 16}]}},
{cvc, {length, #base_IntegerRange{lower = 3, upper = 3}}},
{exp_date, {exact_exp_date, #'domain_PaymentCardExactExpirationDate'{}}}
],
<<"DINERS CLUB INTERNATIONAL">> => [
{card_number, {checksum, {luhn, #'domain_PaymentCardNumberChecksumLuhn'{}}}},
{card_number, {ranges, [#'IntegerRange'{lower = 14, upper = 14}, #'IntegerRange'{lower = 19, upper = 19}]}},
{cvc, {length, #'IntegerRange'{lower = 3, upper = 3}}},
{card_number,
{ranges, [
#base_IntegerRange{lower = 14, upper = 14},
#base_IntegerRange{lower = 19, upper = 19}
]}},
{cvc, {length, #base_IntegerRange{lower = 3, upper = 3}}},
{exp_date, {exact_exp_date, #'domain_PaymentCardExactExpirationDate'{}}}
],
<<"DISCOVER">> => [
{card_number, {checksum, {luhn, #'domain_PaymentCardNumberChecksumLuhn'{}}}},
{card_number, {ranges, [#'IntegerRange'{lower = 16, upper = 16}]}},
{cvc, {length, #'IntegerRange'{lower = 3, upper = 3}}},
{card_number, {ranges, [#base_IntegerRange{lower = 16, upper = 16}]}},
{cvc, {length, #base_IntegerRange{lower = 3, upper = 3}}},
{exp_date, {exact_exp_date, #'domain_PaymentCardExactExpirationDate'{}}}
],
<<"JCB">> => [
{card_number, {checksum, {luhn, #'domain_PaymentCardNumberChecksumLuhn'{}}}},
{card_number, {ranges, [#'IntegerRange'{lower = 16, upper = 16}]}},
{cvc, {length, #'IntegerRange'{lower = 3, upper = 3}}},
{card_number, {ranges, [#base_IntegerRange{lower = 16, upper = 16}]}},
{cvc, {length, #base_IntegerRange{lower = 3, upper = 3}}},
{exp_date, {exact_exp_date, #'domain_PaymentCardExactExpirationDate'{}}}
],
@ -88,36 +98,52 @@
%% by the ISO Registration Authority, and must be unique.
<<"MAESTRO">> => [
{card_number, {checksum, {luhn, #'domain_PaymentCardNumberChecksumLuhn'{}}}},
{card_number, {ranges, [#'IntegerRange'{lower = 12, upper = 12}, #'IntegerRange'{lower = 19, upper = 19}]}},
{cvc, {length, #'IntegerRange'{lower = 3, upper = 3}}},
{card_number,
{ranges, [
#base_IntegerRange{lower = 12, upper = 12},
#base_IntegerRange{lower = 19, upper = 19}
]}},
{cvc, {length, #base_IntegerRange{lower = 3, upper = 3}}},
{exp_date, {exact_exp_date, #'domain_PaymentCardExactExpirationDate'{}}}
],
<<"MASTERCARD">> => [
{card_number, {checksum, {luhn, #'domain_PaymentCardNumberChecksumLuhn'{}}}},
{card_number, {ranges, [#'IntegerRange'{lower = 16, upper = 16}]}},
{cvc, {length, #'IntegerRange'{lower = 3, upper = 3}}},
{card_number, {ranges, [#base_IntegerRange{lower = 16, upper = 16}]}},
{cvc, {length, #base_IntegerRange{lower = 3, upper = 3}}},
{exp_date, {exact_exp_date, #'domain_PaymentCardExactExpirationDate'{}}}
],
<<"NSPK MIR">> => [
{card_number, {checksum, {luhn, #'domain_PaymentCardNumberChecksumLuhn'{}}}},
{card_number, {ranges, [#'IntegerRange'{lower = 16, upper = 16}, #'IntegerRange'{lower = 19, upper = 20}]}},
{cvc, {length, #'IntegerRange'{lower = 3, upper = 3}}},
{card_number,
{ranges, [
#base_IntegerRange{lower = 16, upper = 16},
#base_IntegerRange{lower = 19, upper = 20}
]}},
{cvc, {length, #base_IntegerRange{lower = 3, upper = 3}}},
{exp_date, {exact_exp_date, #'domain_PaymentCardExactExpirationDate'{}}}
],
<<"VISA">> => [
{card_number, {checksum, {luhn, #'domain_PaymentCardNumberChecksumLuhn'{}}}},
{card_number, {ranges, [#'IntegerRange'{lower = 13, upper = 13}, #'IntegerRange'{lower = 16, upper = 16}]}},
{cvc, {length, #'IntegerRange'{lower = 3, upper = 3}}},
{card_number,
{ranges, [
#base_IntegerRange{lower = 13, upper = 13},
#base_IntegerRange{lower = 16, upper = 16}
]}},
{cvc, {length, #base_IntegerRange{lower = 3, upper = 3}}},
{exp_date, {exact_exp_date, #'domain_PaymentCardExactExpirationDate'{}}}
],
<<"VISA/DANKORT">> => [
{card_number, {checksum, {luhn, #'domain_PaymentCardNumberChecksumLuhn'{}}}},
{card_number, {ranges, [#'IntegerRange'{lower = 13, upper = 13}, #'IntegerRange'{lower = 16, upper = 16}]}},
{cvc, {length, #'IntegerRange'{lower = 3, upper = 3}}},
{card_number,
{ranges, [
#base_IntegerRange{lower = 13, upper = 13},
#base_IntegerRange{lower = 16, upper = 16}
]}},
{cvc, {length, #base_IntegerRange{lower = 3, upper = 3}}},
{exp_date, {exact_exp_date, #'domain_PaymentCardExactExpirationDate'{}}}
],

View File

@ -1,5 +1,6 @@
%%%
%%% Copyright 2021 RBKmoney
%%% Copyright 2022 Vality.dev
%%%
%%% Licensed under the Apache License, Version 2.0 (the "License");
%%% you may not use this file except in compliance with the License.
@ -17,7 +18,8 @@
-module(bankcard_validator_ct_helper).
-include_lib("common_test/include/ct.hrl").
-include_lib("damsel/include/dmsl_domain_config_thrift.hrl").
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
-include_lib("damsel/include/dmsl_domain_conf_thrift.hrl").
%% API
-export([init_suite/2]).
@ -47,9 +49,9 @@ init_suite(Module, Config) ->
[
{
'Repository',
{dmsl_domain_config_thrift, 'Repository'},
{dmsl_domain_conf_thrift, 'Repository'},
fun('Checkout', _) ->
{ok, #'Snapshot'{
{ok, #domain_conf_Snapshot{
version = 1,
domain = #{
?PAYMENT_SYSTEM_REF(<<"VISA">>) =>

View File

@ -1,5 +1,6 @@
%%%
%%% Copyright 2021 RBKmoney
%%% Copyright 2022 Vality.dev
%%%
%%% Licensed under the Apache License, Version 2.0 (the "License");
%%% you may not use this file except in compliance with the License.

View File

@ -1,5 +1,6 @@
%%%
%%% Copyright 2021 RBKmoney
%%% Copyright 2022 Vality.dev
%%%
%%% Licensed under the Apache License, Version 2.0 (the "License");
%%% you may not use this file except in compliance with the License.

View File

@ -102,11 +102,11 @@ add_luhn_checksum(<<N, Rest/binary>>, Sum) ->
get_cvc(PaymentSystem) ->
Rules = bankcard_validator_legacy:get_payment_system_ruleset(PaymentSystem),
case proplists:get_value(cvc, Rules) of
{length, #'IntegerRange'{lower = L, upper = undefined}} ->
{length, #base_IntegerRange{lower = L, upper = undefined}} ->
vector(L, choose($0, $9));
{length, #'IntegerRange'{lower = undefined, upper = U}} ->
{length, #base_IntegerRange{lower = undefined, upper = U}} ->
vector(U, choose($0, $9));
{length, #'IntegerRange'{lower = L, upper = U}} ->
{length, #base_IntegerRange{lower = L, upper = U}} ->
?LET(
CvcLength,
choose(L, U),
@ -128,9 +128,9 @@ get_card_number_length(PaymentSystem) ->
get_possible_lengths([], Acc) ->
ordsets:to_list(Acc);
get_possible_lengths([#'IntegerRange'{lower = L, upper = undefined} | Rest], Acc) ->
get_possible_lengths([#base_IntegerRange{lower = L, upper = undefined} | Rest], Acc) ->
get_possible_lengths(Rest, ordsets:add_element(L - 1, Acc));
get_possible_lengths([#'IntegerRange'{lower = undefined, upper = U} | Rest], Acc) ->
get_possible_lengths([#base_IntegerRange{lower = undefined, upper = U} | Rest], Acc) ->
get_possible_lengths(Rest, ordsets:add_element(U - 1, Acc));
get_possible_lengths([#'IntegerRange'{lower = L, upper = U} | Rest], Acc) ->
get_possible_lengths([#base_IntegerRange{lower = L, upper = U} | Rest], Acc) ->
get_possible_lengths(Rest, ordsets:add_element(choose(L - 1, U - 1), Acc)).