mirror of
https://github.com/mCaptcha/cache.git
synced 2024-12-04 04:39:01 +03:00
add spellcheck workflow and fix typos
This commit is contained in:
parent
efb67a4a85
commit
99e95b70b5
11 changed files with 193 additions and 52 deletions
37
.github/workflows/linux.yml
vendored
37
.github/workflows/linux.yml
vendored
|
@ -37,6 +37,9 @@ jobs:
|
||||||
profile: minimal
|
profile: minimal
|
||||||
override: false
|
override: false
|
||||||
|
|
||||||
|
- name: install virtualenv
|
||||||
|
run: pip install virtualenv
|
||||||
|
|
||||||
- name: install dependencies
|
- name: install dependencies
|
||||||
run: make env
|
run: make env
|
||||||
|
|
||||||
|
@ -52,19 +55,6 @@ jobs:
|
||||||
- name: stop docker container
|
- name: stop docker container
|
||||||
run: make docker-stop
|
run: make docker-stop
|
||||||
|
|
||||||
# - name: build
|
|
||||||
# uses: actions-rs/cargo@v1
|
|
||||||
# with:
|
|
||||||
# command: build
|
|
||||||
# args: --all --bins --examples --tests
|
|
||||||
#
|
|
||||||
# - name: tests
|
|
||||||
# uses: actions-rs/cargo@v1
|
|
||||||
# timeout-minutes: 40
|
|
||||||
# with:
|
|
||||||
# command: test
|
|
||||||
# args: --all --all-features --no-fail-fast
|
|
||||||
#
|
|
||||||
- name: Generate coverage file
|
- name: Generate coverage file
|
||||||
if: matrix.version == 'stable' && (github.ref == 'refs/heads/master' || github.event_name == 'pull_request')
|
if: matrix.version == 'stable' && (github.ref == 'refs/heads/master' || github.event_name == 'pull_request')
|
||||||
uses: actions-rs/tarpaulin@v0.1
|
uses: actions-rs/tarpaulin@v0.1
|
||||||
|
@ -74,25 +64,6 @@ jobs:
|
||||||
|
|
||||||
- name: Upload to Codecov
|
- name: Upload to Codecov
|
||||||
if: matrix.version == 'stable' && (github.ref == 'refs/heads/master' || github.event_name == 'pull_request')
|
if: matrix.version == 'stable' && (github.ref == 'refs/heads/master' || github.event_name == 'pull_request')
|
||||||
uses: codecov/codecov-action@v1
|
uses: codecov/codecov-action@v2
|
||||||
with:
|
with:
|
||||||
file: cobertura.xml
|
file: cobertura.xml
|
||||||
|
|
||||||
# - name: generate documentation
|
|
||||||
# if: matrix.version == 'stable' && (github.repository == 'mcaptcha/cache')
|
|
||||||
# run: make doc
|
|
||||||
#
|
|
||||||
# # - name: generate documentation
|
|
||||||
# # if: matrix.version == 'stable' && (github.repository == 'realaravinth/damn-vuln-blockchain')
|
|
||||||
# # uses: actions-rs/cargo@v1
|
|
||||||
# # with:
|
|
||||||
# # command: doc
|
|
||||||
# # args: --no-deps --workspace --all-features
|
|
||||||
#
|
|
||||||
# - name: Deploy to GitHub Pages
|
|
||||||
# if: matrix.version == 'stable' && (github.repository == 'mcaptcha/cache')
|
|
||||||
# uses: JamesIves/github-pages-deploy-action@3.7.1
|
|
||||||
# with:
|
|
||||||
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
# BRANCH: gh-pages
|
|
||||||
# FOLDER: target/doc
|
|
||||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@
|
||||||
*.rdb
|
*.rdb
|
||||||
tmp/
|
tmp/
|
||||||
tarpaulin-report.html
|
tarpaulin-report.html
|
||||||
|
*.profraw
|
||||||
|
|
8
Makefile
8
Makefile
|
@ -38,6 +38,8 @@ docker-stop:
|
||||||
docker rm $(DOCKER_CONTAINER)
|
docker rm $(DOCKER_CONTAINER)
|
||||||
env:
|
env:
|
||||||
./scripts/setup.sh
|
./scripts/setup.sh
|
||||||
|
@-virtualenv venv || true
|
||||||
|
@-pip install codespell
|
||||||
|
|
||||||
test:
|
test:
|
||||||
cargo test --all --all-features --no-fail-fast
|
cargo test --all --all-features --no-fail-fast
|
||||||
|
@ -52,8 +54,12 @@ run-redis:
|
||||||
stop-redis:
|
stop-redis:
|
||||||
killall redis-server
|
killall redis-server
|
||||||
|
|
||||||
help:
|
lint: ## Lint codebase
|
||||||
|
@ . venv/bin/activate && ./scripts/spellcheck.sh -w
|
||||||
|
cargo fmt -v --all -- --emit files
|
||||||
|
cargo clippy --workspace --tests --all-features
|
||||||
|
|
||||||
|
help:
|
||||||
@echo ' bench - run benchmarks'
|
@echo ' bench - run benchmarks'
|
||||||
@echo ' clean - drop builds and environments'
|
@echo ' clean - drop builds and environments'
|
||||||
@echo ' coverage - build test coverage in HTML format'
|
@echo ' coverage - build test coverage in HTML format'
|
||||||
|
|
72
scripts/coverage.sh
Executable file
72
scripts/coverage.sh
Executable file
|
@ -0,0 +1,72 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -Eeuo pipefail
|
||||||
|
|
||||||
|
readonly GRCOV_DOWNLOAD="https://github.com/mozilla/grcov/releases/download/v0.8.2/grcov-linux-x86_64.tar.bz2"
|
||||||
|
readonly PROJECT_ROOT=$(pwd)
|
||||||
|
readonly TMP_DIR=$PROJECT_ROOT/tmp
|
||||||
|
readonly GRCOV_TARBAL="$TMP_DIR/grcov.tar.bz2"
|
||||||
|
readonly GRCOV="$TMP_DIR/grcov"
|
||||||
|
|
||||||
|
source $(pwd)/scripts/lib.sh
|
||||||
|
|
||||||
|
|
||||||
|
clean_up() {
|
||||||
|
trap - SIGINT SIGTERM ERR EXIT
|
||||||
|
cd $PROJECT_ROOT
|
||||||
|
/bin/rm default.profraw lcov.info *.profraw || true
|
||||||
|
cd target
|
||||||
|
/bin/rm default.profraw lcov.info *.profraw || true
|
||||||
|
}
|
||||||
|
|
||||||
|
trap cleanup SIGINT SIGTERM ERR EXIT
|
||||||
|
setup_colors
|
||||||
|
|
||||||
|
download() {
|
||||||
|
if [ ! -e $GRCOV ];
|
||||||
|
then
|
||||||
|
msg "${GREEN}- Downloading grcov"
|
||||||
|
wget --quiet --output-doc=$GRCOV_TARBAL $GRCOV_DOWNLOAD;
|
||||||
|
cd $TMP_DIR
|
||||||
|
tar -xf $GRCOV_TARBAL;
|
||||||
|
cd $PROJECT_ROOT
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
build_and_test() {
|
||||||
|
export RUSTFLAGS="-Zinstrument-coverage"
|
||||||
|
cd $PROJECT_ROOT
|
||||||
|
|
||||||
|
msg "${GREEN}- Building project"
|
||||||
|
cargo build
|
||||||
|
|
||||||
|
export LLVM_PROFILE_FILE="target/mcatpcha-cache-%p-%m.profraw"
|
||||||
|
|
||||||
|
msg "${GREEN}- Running tests"
|
||||||
|
cargo test --lib
|
||||||
|
|
||||||
|
msg "${GREEN}- Generating coverage"
|
||||||
|
$GRCOV target/ --binary-path \
|
||||||
|
./target/debug/ \
|
||||||
|
-s . -t lcov --branch \
|
||||||
|
--ignore-not-existing \
|
||||||
|
--ignore "../*" -o target/lcov.info
|
||||||
|
}
|
||||||
|
|
||||||
|
run_coverage() {
|
||||||
|
cd $PROJECT_ROOT
|
||||||
|
mkdir $TMP_DIR || true
|
||||||
|
clean_up
|
||||||
|
download
|
||||||
|
build_and_test
|
||||||
|
}
|
||||||
|
|
||||||
|
check_arg $1
|
||||||
|
|
||||||
|
if match_arg $1 '-c' '--coverage'
|
||||||
|
then
|
||||||
|
run_coverage
|
||||||
|
else
|
||||||
|
msg "${RED}[!] Undefined option"
|
||||||
|
exit 1
|
||||||
|
fi
|
34
scripts/lib.sh
Executable file
34
scripts/lib.sh
Executable file
|
@ -0,0 +1,34 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
setup_colors() {
|
||||||
|
if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then
|
||||||
|
NOCOLOR='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' ORANGE='\033[0;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' CYAN='\033[0;36m' YELLOW='\033[1;33m'
|
||||||
|
else
|
||||||
|
NOCOLOR='' RED='' GREEN='' ORANGE='' BLUE='' PURPLE='' CYAN='' YELLOW=''
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
msg() {
|
||||||
|
echo >&2 -e "${1-}"
|
||||||
|
}
|
||||||
|
|
||||||
|
get_file_name() {
|
||||||
|
basename -- $1
|
||||||
|
}
|
||||||
|
|
||||||
|
check_arg(){
|
||||||
|
if [ -z $1 ]
|
||||||
|
then
|
||||||
|
help
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
match_arg() {
|
||||||
|
if [ $1 == $2 ] || [ $1 == $3 ]
|
||||||
|
then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
67
scripts/spellcheck.sh
Executable file
67
scripts/spellcheck.sh
Executable file
|
@ -0,0 +1,67 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -Eeuo pipefail
|
||||||
|
trap cleanup SIGINT SIGTERM ERR EXIT
|
||||||
|
|
||||||
|
|
||||||
|
readonly MISSPELL_DOWNLOAD="https://github.com/client9/misspell/releases/download/v0.3.4/misspell_0.3.4_linux_64bit.tar.gz"
|
||||||
|
readonly PROJECT_ROOT=$(pwd)
|
||||||
|
readonly TMP_DIR=$PROJECT_ROOT/tmp
|
||||||
|
readonly MISSPELL_TARBALL="$TMP_DIR/misspell.tar.bz2"
|
||||||
|
readonly MISSPELL="$TMP_DIR/misspell"
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
trap - SIGINT SIGTERM ERR EXIT
|
||||||
|
# script cleanup here
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
source $PROJECT_ROOT/scripts/lib.sh
|
||||||
|
setup_colors
|
||||||
|
|
||||||
|
FLAGS=""
|
||||||
|
|
||||||
|
download() {
|
||||||
|
if [ ! -e $MISSPELL ];
|
||||||
|
then
|
||||||
|
msg "${GREEN}- Downloading misspell"
|
||||||
|
wget --quiet --output-doc=$MISSPELL_TARBALL $MISSPELL_DOWNLOAD;
|
||||||
|
cd $TMP_DIR
|
||||||
|
tar -xf $MISSPELL_TARBALL;
|
||||||
|
cd $PROJECT_ROOT
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
spell_check_codespell() {
|
||||||
|
codespell $FLAGS $PROJECT_ROOT/tests
|
||||||
|
codespell $FLAGS $PROJECT_ROOT/docs/
|
||||||
|
codespell $FLAGS --ignore-words-list crate .$PROJECT_ROOT/src
|
||||||
|
codespell $FLAGS --ignore-words-list crate .$PROJECT_ROOT/README.md
|
||||||
|
}
|
||||||
|
|
||||||
|
spell_check_misspell() {
|
||||||
|
mkdir $TMP_DIR || true
|
||||||
|
download
|
||||||
|
$MISSPELL $FLAGS $PROJECT_ROOT/docs
|
||||||
|
$MISSPELL $FLAGS $PROJECT_ROOT/tests
|
||||||
|
$MISSPELL $FLAGS -i crate $PROJECT_ROOT/src
|
||||||
|
$MISSPELL $FLAGS -i crate $PROJECT_ROOT/README.md
|
||||||
|
}
|
||||||
|
|
||||||
|
check_arg $1
|
||||||
|
|
||||||
|
if match_arg $1 '-w' '--write'
|
||||||
|
then
|
||||||
|
msg "${GREEN}- Checking and correcting typos"
|
||||||
|
FLAGS="-w"
|
||||||
|
spell_check_misspell
|
||||||
|
spell_check_codespell
|
||||||
|
elif match_arg $1 '-c' '--check'
|
||||||
|
then
|
||||||
|
msg "${GREEN}- Scaning for typos"
|
||||||
|
spell_check_misspell
|
||||||
|
spell_check_codespell
|
||||||
|
else
|
||||||
|
msg "${RED}[!] Undefined option"
|
||||||
|
exit 1
|
||||||
|
fi
|
|
@ -14,7 +14,7 @@
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
//! Leaky bucket algorithim is implemantation for mcatpcha using batch processing Everytime count
|
//! Leaky bucket algorithm is implemantation for mcatpcha using batch processing Everytime count
|
||||||
//! is increased for an mcaptcha object, a decrement job is added to a batch that is scheduled to
|
//! is increased for an mcaptcha object, a decrement job is added to a batch that is scheduled to
|
||||||
//! be executed at that mcaptcha object's expiry rate(MCaptcha.get_duration())
|
//! be executed at that mcaptcha object's expiry rate(MCaptcha.get_duration())
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
|
@ -33,7 +33,7 @@ use challenge::MCAPTCHA_CHALLENGE_TYPE;
|
||||||
use mcaptcha::MCAPTCHA_MCAPTCHA_TYPE;
|
use mcaptcha::MCAPTCHA_MCAPTCHA_TYPE;
|
||||||
use safety::MCAPTCHA_SAFETY_TYPE;
|
use safety::MCAPTCHA_SAFETY_TYPE;
|
||||||
|
|
||||||
/// Initial allocation ammount of bucket[bucket::Bucket]
|
/// Initial allocation amount of bucket[bucket::Bucket]
|
||||||
pub const HIT_PER_SECOND: usize = 100;
|
pub const HIT_PER_SECOND: usize = 100;
|
||||||
pub const PKG_NAME: &str = "mcap";
|
pub const PKG_NAME: &str = "mcap";
|
||||||
pub const PKG_VERSION: usize = 0;
|
pub const PKG_VERSION: usize = 0;
|
||||||
|
|
|
@ -289,48 +289,38 @@ mod tests {
|
||||||
use libmcaptcha::defense::LevelBuilder;
|
use libmcaptcha::defense::LevelBuilder;
|
||||||
|
|
||||||
fn get_levels() -> Vec<Level> {
|
fn get_levels() -> Vec<Level> {
|
||||||
let mut levels = Vec::default();
|
vec![
|
||||||
levels.push(
|
|
||||||
LevelBuilder::default()
|
LevelBuilder::default()
|
||||||
.visitor_threshold(50)
|
.visitor_threshold(50)
|
||||||
.difficulty_factor(50)
|
.difficulty_factor(50)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.build()
|
.build()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
);
|
|
||||||
levels.push(
|
|
||||||
LevelBuilder::default()
|
LevelBuilder::default()
|
||||||
.visitor_threshold(500)
|
.visitor_threshold(500)
|
||||||
.difficulty_factor(5000)
|
.difficulty_factor(5000)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.build()
|
.build()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
);
|
|
||||||
levels.push(
|
|
||||||
LevelBuilder::default()
|
LevelBuilder::default()
|
||||||
.visitor_threshold(5000)
|
.visitor_threshold(5000)
|
||||||
.difficulty_factor(50000)
|
.difficulty_factor(50000)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.build()
|
.build()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
);
|
|
||||||
levels.push(
|
|
||||||
LevelBuilder::default()
|
LevelBuilder::default()
|
||||||
.visitor_threshold(50000)
|
.visitor_threshold(50000)
|
||||||
.difficulty_factor(500000)
|
.difficulty_factor(500000)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.build()
|
.build()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
);
|
|
||||||
levels.push(
|
|
||||||
LevelBuilder::default()
|
LevelBuilder::default()
|
||||||
.visitor_threshold(500000)
|
.visitor_threshold(500000)
|
||||||
.difficulty_factor(5000000)
|
.difficulty_factor(5000000)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.build()
|
.build()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
);
|
]
|
||||||
levels
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -57,7 +57,7 @@ impl MCaptchaSafety {
|
||||||
let mcaptcha_val = MCaptcha::get_mcaptcha(&mcaptcha);
|
let mcaptcha_val = MCaptcha::get_mcaptcha(&mcaptcha);
|
||||||
if mcaptcha_val.is_err() {
|
if mcaptcha_val.is_err() {
|
||||||
ctx.log_warning(&format!(
|
ctx.log_warning(&format!(
|
||||||
"error occured while trying to access mcaptcha {}. error {} is empty",
|
"error occurred while trying to access mcaptcha {}. error {} is empty",
|
||||||
mcaptcha_name,
|
mcaptcha_name,
|
||||||
mcaptcha_val.err().unwrap()
|
mcaptcha_val.err().unwrap()
|
||||||
));
|
));
|
||||||
|
@ -66,7 +66,7 @@ impl MCaptchaSafety {
|
||||||
let mcaptcha_val = mcaptcha_val.unwrap();
|
let mcaptcha_val = mcaptcha_val.unwrap();
|
||||||
if mcaptcha_val.is_none() {
|
if mcaptcha_val.is_none() {
|
||||||
ctx.log_warning(&format!(
|
ctx.log_warning(&format!(
|
||||||
"error occured while trying to access mcaptcha {}. is none",
|
"error occurred while trying to access mcaptcha {}. is none",
|
||||||
mcaptcha_name,
|
mcaptcha_name,
|
||||||
));
|
));
|
||||||
return;
|
return;
|
||||||
|
@ -77,7 +77,7 @@ impl MCaptchaSafety {
|
||||||
|
|
||||||
if Self::new(ctx, duration, mcaptcha_name).is_err() {
|
if Self::new(ctx, duration, mcaptcha_name).is_err() {
|
||||||
ctx.log_warning(&format!(
|
ctx.log_warning(&format!(
|
||||||
"error occured while creating safety for mcaptcha {}.",
|
"error occurred while creating safety for mcaptcha {}.",
|
||||||
mcaptcha_name,
|
mcaptcha_name,
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|
|
@ -51,6 +51,6 @@ class Runner(object):
|
||||||
for task in self.__tasks:
|
for task in self.__tasks:
|
||||||
await task
|
await task
|
||||||
|
|
||||||
"""Runs in seperate threads"""
|
"""Runs in separate threads"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(Runner, self).__init__()
|
super(Runner, self).__init__()
|
||||||
|
|
Loading…
Reference in a new issue