Initial commit
This commit is contained in:
49
scripts/benchmark/phones.rb
Normal file
49
scripts/benchmark/phones.rb
Normal file
@@ -0,0 +1,49 @@
|
||||
require 'benchmark'
|
||||
require_relative "../../config/environment"
|
||||
|
||||
# Check only Error logs
|
||||
ActiveRecord::Base.logger.level = 3
|
||||
|
||||
## Before benchmark
|
||||
user = User.find_or_create_by(uid: "UIDExample", email: 'test_example@gmail.com') do |u|
|
||||
u.password = "PasswordExample12"
|
||||
end
|
||||
|
||||
# Benchmark
|
||||
puts '---------------------------'
|
||||
puts 'Phone creating'
|
||||
puts '---------------------------'
|
||||
Benchmark.bm do |x|
|
||||
# Creates 1 phone
|
||||
x.report(:p_1) {
|
||||
phone = Phone.new(user_id: user.id, country: 'UA', number: '123123123')
|
||||
phone.save(validate: false)
|
||||
}
|
||||
# Creates 1000 phones
|
||||
x.report(:p_1000) {
|
||||
1_000.times do
|
||||
phone = Phone.new(user_id: user.id, country: 'UA', number: '123123123')
|
||||
phone.save(validate: false)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
puts '---------------------------'
|
||||
puts 'Descrypts data from phone'
|
||||
puts '---------------------------'
|
||||
Benchmark.bm do |x|
|
||||
# Descrypts 1 phone
|
||||
x.report(:p_1) {
|
||||
Phone.last.number
|
||||
}
|
||||
# Descrypts 1000 phones
|
||||
x.report(:p_1000) {
|
||||
Phone.where(user_id: user.id).limit(1000).each do |phone|
|
||||
phone.number
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
## After benchmark
|
||||
Phone.where(user_id: user.id).delete_all
|
||||
user.destroy
|
||||
55
scripts/benchmark/profiles.rb
Normal file
55
scripts/benchmark/profiles.rb
Normal file
@@ -0,0 +1,55 @@
|
||||
require 'benchmark'
|
||||
require_relative "../../config/environment"
|
||||
|
||||
# Check only Error logs
|
||||
ActiveRecord::Base.logger.level = 3
|
||||
|
||||
## Before benchmark
|
||||
user = User.find_or_create_by(uid: "UIDExample", email: 'test_example@gmail.com') do |u|
|
||||
u.password = "PasswordExample12"
|
||||
end
|
||||
|
||||
# Benchmark
|
||||
puts '---------------------------'
|
||||
puts 'Profile creating'
|
||||
puts '---------------------------'
|
||||
Benchmark.bm do |x|
|
||||
# Creates 1 profile
|
||||
x.report(:p_1) {
|
||||
Profile.create!(user_id: user.id, first_name: 'first_name', last_name: 'last_name',
|
||||
address: 'address', dob: Time.now.to_date, state: 'verified')
|
||||
}
|
||||
# Creates 1000 profiles
|
||||
x.report(:p_1000) {
|
||||
1_000.times do
|
||||
Profile.create!(user_id: user.id, first_name: 'first_name', last_name: 'last_name',
|
||||
address: 'address', dob: Time.now.to_date, state: 'verified')
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
puts '---------------------------'
|
||||
puts 'Descrypts data from profile'
|
||||
puts '---------------------------'
|
||||
Benchmark.bm do |x|
|
||||
# Descrypts 1 profile
|
||||
x.report(:p_1) {
|
||||
Profile.last.first_name
|
||||
Profile.last.last_name
|
||||
Profile.last.address
|
||||
Profile.last.dob
|
||||
}
|
||||
# Descrypts 1000 profiles
|
||||
x.report(:p_1000) {
|
||||
Profile.where(user_id: user.id).limit(1000).each do |profile|
|
||||
profile.first_name
|
||||
profile.last_name
|
||||
profile.address
|
||||
profile.dob
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
## After benchmark
|
||||
Profile.where(user_id: user.id).delete_all
|
||||
user.destroy
|
||||
74
scripts/verify-security-pins.sh
Normal file
74
scripts/verify-security-pins.sh
Normal file
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env bash
|
||||
# Verify phase-1/2 minimum security gem/package versions in lockfiles.
|
||||
set -euo pipefail
|
||||
|
||||
semver_ge() {
|
||||
printf '%s\n%s\n' "$2" "$1" | sort -V | head -1 | grep -qx "$2"
|
||||
}
|
||||
|
||||
check_gemfile_lock() {
|
||||
local file=$1 name min
|
||||
echo "Checking ${file}..."
|
||||
while read -r name min; do
|
||||
[[ -z "$name" ]] && continue
|
||||
local ver
|
||||
ver=$(grep -E "^ ${name} \(" "$file" | head -1 | sed -E 's/.*\(([0-9][0-9.a-z-]*).*/\1/' || true)
|
||||
if [[ -z "$ver" ]]; then
|
||||
echo "FAIL: ${name} not found in ${file}"
|
||||
exit 1
|
||||
fi
|
||||
if ! semver_ge "$ver" "$min"; then
|
||||
echo "FAIL: ${name} ${ver} < required ${min} in ${file}"
|
||||
exit 1
|
||||
fi
|
||||
echo " OK ${name} ${ver} (>= ${min})"
|
||||
done <<'GEMS'
|
||||
rack 2.2.13
|
||||
nokogiri 1.15.5
|
||||
rexml 3.3.9
|
||||
tzinfo 1.2.10
|
||||
rails-html-sanitizer 1.4.4
|
||||
GEMS
|
||||
if grep -qE '^ sidekiq \(' "$file"; then
|
||||
local sidekiq_ver
|
||||
sidekiq_ver=$(grep -E '^ sidekiq \(' "$file" | head -1 | sed -E 's/.*\(([0-9][0-9.a-z-]*).*/\1/')
|
||||
if ! semver_ge "$sidekiq_ver" "6.4.0"; then
|
||||
echo "FAIL: sidekiq ${sidekiq_ver} < required 6.4.0 in ${file}"
|
||||
exit 1
|
||||
fi
|
||||
echo " OK sidekiq ${sidekiq_ver} (>= 6.4.0)"
|
||||
fi
|
||||
}
|
||||
|
||||
check_yarn_lock() {
|
||||
local file=$1
|
||||
echo "Checking ${file}..."
|
||||
local axios ws
|
||||
axios=$(grep -A1 '^axios@\^0\.32' "$file" | grep 'version "' | head -1 | sed -E 's/.*version "([^"]+)".*/\1/')
|
||||
ws=$(grep -A1 '^ws@\^7\.5' "$file" | grep 'version "' | head -1 | sed -E 's/.*version "([^"]+)".*/\1/')
|
||||
if [[ -z "$axios" ]] || ! semver_ge "$axios" "0.32.0"; then
|
||||
echo "FAIL: axios ${axios:-missing} < 0.32.0"
|
||||
exit 1
|
||||
fi
|
||||
echo " OK axios ${axios} (>= 0.32.0)"
|
||||
if [[ -z "$ws" ]] || ! semver_ge "$ws" "7.5.10"; then
|
||||
echo "FAIL: ws ${ws:-missing} < 7.5.10"
|
||||
exit 1
|
||||
fi
|
||||
echo " OK ws ${ws} (>= 7.5.10)"
|
||||
}
|
||||
|
||||
case "${1:-}" in
|
||||
ruby)
|
||||
check_gemfile_lock "${2:-Gemfile.lock}"
|
||||
;;
|
||||
yarn)
|
||||
check_yarn_lock "${2:-yarn.lock}"
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 ruby [Gemfile.lock] | yarn [yarn.lock]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "Security pin verification passed."
|
||||
Reference in New Issue
Block a user