Compare commits
No commits in common. "master" and "feat-percentile" have entirely different histories.
master
...
feat-perce
25 changed files with 6949 additions and 7427 deletions
2
.github/workflows/linux.yml
vendored
2
.github/workflows/linux.yml
vendored
|
@ -84,7 +84,7 @@ jobs:
|
||||||
|
|
||||||
- name: Deploy to GitHub Pages
|
- name: Deploy to GitHub Pages
|
||||||
if: matrix.version == 'stable' && (github.repository == 'mcapthca/survey')
|
if: matrix.version == 'stable' && (github.repository == 'mcapthca/survey')
|
||||||
uses: JamesIves/github-pages-deploy-action@v4.6.4
|
uses: JamesIves/github-pages-deploy-action@3.7.1
|
||||||
with:
|
with:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
BRANCH: gh-pages
|
BRANCH: gh-pages
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT\n difficulty\n FROM\n survey_benches\n WHERE\n duration <= $1\n ORDER BY difficulty ASC LIMIT 1 OFFSET $2;",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "difficulty",
|
|
||||||
"type_info": "Int4"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Float4",
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "52c16c2c0759140af6348ef7de56b74151a20532ceebc8ee41d079decee3acb5"
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT COUNT(difficulty) FROM survey_benches WHERE duration <= $1;",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "count",
|
|
||||||
"type_info": "Int8"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Float4"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
null
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "63370a30a4ff6d31292a3cb632c66184ccff75583e21df5ddf5e8872f710d3d2"
|
|
||||||
}
|
|
1240
Cargo.lock
generated
1240
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
18
Cargo.toml
18
Cargo.toml
|
@ -24,10 +24,10 @@ path = "./src/tests-migrate.rs"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "4.3"
|
actix-web = "4.3"
|
||||||
actix-identity = "0.4.0"
|
actix-identity = "0.4.0"
|
||||||
actix-session = { version = "0.10.0", features = ["cookie-session"]}
|
actix-session = { version = "0.6.1", features = ["cookie-session"]}
|
||||||
actix-http = "3.0.4"
|
actix-http = "3.0.4"
|
||||||
actix-rt = "2"
|
actix-rt = "2"
|
||||||
actix-cors = "0.7.0"
|
actix-cors = "0.6.1"
|
||||||
actix-files = "0.6.0"
|
actix-files = "0.6.0"
|
||||||
actix-service = "2.0.0"
|
actix-service = "2.0.0"
|
||||||
#actix = "0.12"
|
#actix = "0.12"
|
||||||
|
@ -37,16 +37,16 @@ actix-web-codegen-const-routes = "0.2.0"
|
||||||
|
|
||||||
futures = "0.3.15"
|
futures = "0.3.15"
|
||||||
|
|
||||||
sqlx = { version = "0.8", features = [ "runtime-tokio-rustls", "postgres", "time", "uuid" ] }
|
sqlx = { version = "0.7", features = [ "runtime-tokio-rustls", "postgres", "time", "uuid" ] }
|
||||||
|
|
||||||
#argon2-creds = "0.2.3"
|
#argon2-creds = "0.2.3"
|
||||||
argon2-creds = { branch = "master", git = "https://github.com/realaravinth/argon2-creds"}
|
argon2-creds = { branch = "master", git = "https://github.com/realaravinth/argon2-creds"}
|
||||||
|
|
||||||
derive_builder = "0.20"
|
derive_builder = "0.11"
|
||||||
validator = { version = "0.18", features = ["derive"]}
|
validator = { version = "0.14", features = ["derive"]}
|
||||||
derive_more = "0.99"
|
derive_more = "0.99"
|
||||||
|
|
||||||
config = "0.14"
|
config = "0.13"
|
||||||
|
|
||||||
serde = "1"
|
serde = "1"
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
|
@ -62,7 +62,7 @@ rand = "0.8"
|
||||||
uuid = { version = "1.4.1", features = ["v4", "serde"] }
|
uuid = { version = "1.4.1", features = ["v4", "serde"] }
|
||||||
|
|
||||||
mime_guess = "2.0.3"
|
mime_guess = "2.0.3"
|
||||||
rust-embed = "8.0.0"
|
rust-embed = "6.0.0"
|
||||||
#libcachebust = "0.3.0"
|
#libcachebust = "0.3.0"
|
||||||
cache-buster = { git = "https://github.com/realaravinth/cache-buster" }
|
cache-buster = { git = "https://github.com/realaravinth/cache-buster" }
|
||||||
mime = "0.3.16"
|
mime = "0.3.16"
|
||||||
|
@ -73,7 +73,7 @@ tera = { version="1.17.1", features=["builtins"]}
|
||||||
tokio = { version = "1.25.0", features = ["fs", "macros"] }
|
tokio = { version = "1.25.0", features = ["fs", "macros"] }
|
||||||
csv-async = { version = "1.2.5", features = ["serde", "tokio"] }
|
csv-async = { version = "1.2.5", features = ["serde", "tokio"] }
|
||||||
async-trait = "0.1.68"
|
async-trait = "0.1.68"
|
||||||
reqwest = { version = "0.12.0", features = ["json", "gzip", "native-tls-vendored"] }
|
reqwest = { version = "0.11.18", features = ["json", "gzip", "native-tls-vendored"] }
|
||||||
|
|
||||||
#tokio = "1.11.0"
|
#tokio = "1.11.0"
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ version = "0.2"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
#serde_yaml = "0.8.17"
|
#serde_yaml = "0.8.17"
|
||||||
sqlx = { version = "0.8", features = [ "runtime-tokio-rustls", "uuid", "postgres", "time"] }
|
sqlx = { version = "0.7", features = [ "runtime-tokio-rustls", "uuid", "postgres", "time"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
cache-buster = { version = "0.2.0", git = "https://github.com/realaravinth/cache-buster" }
|
cache-buster = { version = "0.2.0", git = "https://github.com/realaravinth/cache-buster" }
|
||||||
mime = "0.3.16"
|
mime = "0.3.16"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FROM node:20-bookworm-slim as frontend
|
FROM node:18-bookworm-slim as frontend
|
||||||
LABEL org.opencontainers.image.source https://github.com/mCaptcha/survey
|
LABEL org.opencontainers.image.source https://github.com/mCaptcha/survey
|
||||||
RUN apt-get update && apt-get install -y make
|
RUN apt-get update && apt-get install -y make
|
||||||
COPY package.json yarn.lock /src/
|
COPY package.json yarn.lock /src/
|
||||||
|
@ -8,14 +8,14 @@ RUN yarn install
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN make frontend
|
RUN make frontend
|
||||||
|
|
||||||
FROM rust:latest as rust
|
FROM rust:1-slim-bookworm as rust
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
RUN apt-get update && apt-get install -y git libssl-dev
|
RUN apt-get update && apt-get install -y git
|
||||||
COPY . /src
|
COPY . /src
|
||||||
COPY --from=frontend /src/static/cache/bundle /src/static/cache/bundle
|
COPY --from=frontend /src/static/cache/bundle /src/static/cache/bundle
|
||||||
RUN cargo build --release
|
RUN cargo build --release
|
||||||
|
|
||||||
FROM debian:bookworm
|
FROM debian:bookworm-slim
|
||||||
RUN useradd -ms /bin/bash -u 1001 mcaptcha-survey
|
RUN useradd -ms /bin/bash -u 1001 mcaptcha-survey
|
||||||
WORKDIR /home/mcaptcha-survey
|
WORKDIR /home/mcaptcha-survey
|
||||||
COPY --from=rust /src/target/release/survey /usr/local/bin/
|
COPY --from=rust /src/target/release/survey /usr/local/bin/
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -49,7 +49,7 @@ doc: ## Prepare documentation
|
||||||
cargo doc --no-deps --workspace --all-features
|
cargo doc --no-deps --workspace --all-features
|
||||||
|
|
||||||
docker: ## Build docker images
|
docker: ## Build docker images
|
||||||
docker buildx build -t mcaptcha/survey:master -t mcaptcha/survey:latest . --load
|
docker build -t mcaptcha/survey:master -t mcaptcha/survey:latest .
|
||||||
|
|
||||||
docker-publish: docker ## Build and publish docker images
|
docker-publish: docker ## Build and publish docker images
|
||||||
docker push mcaptcha/survey:master
|
docker push mcaptcha/survey:master
|
||||||
|
|
|
@ -10,7 +10,7 @@ services:
|
||||||
RUST_LOG: debug
|
RUST_LOG: debug
|
||||||
|
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:16.4
|
image: postgres:13.2
|
||||||
volumes:
|
volumes:
|
||||||
- mcaptcha-survey-data:/var/lib/postgresql/
|
- mcaptcha-survey-data:/var/lib/postgresql/
|
||||||
environment:
|
environment:
|
||||||
|
|
8946
package-lock.json
generated
8946
package-lock.json
generated
File diff suppressed because it is too large
Load diff
28
package.json
28
package.json
|
@ -10,26 +10,26 @@
|
||||||
"test": "jest"
|
"test": "jest"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^29.0.0",
|
"@types/jest": "^27.0.2",
|
||||||
"@types/jsdom": "^21.0.0",
|
"@types/jsdom": "^16.2.10",
|
||||||
"@types/node": "^20.0.0",
|
"@types/node": "^16.10.5",
|
||||||
"@types/sinon": "^17.0.0",
|
"@types/sinon": "^10.0.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
||||||
"@typescript-eslint/parser": "^8.0.0",
|
"@typescript-eslint/parser": "^5.0.0",
|
||||||
"@wasm-tool/wasm-pack-plugin": "^1.6.0",
|
"@wasm-tool/wasm-pack-plugin": "^1.6.0",
|
||||||
"dart-sass": "^1.25.0",
|
"dart-sass": "^1.25.0",
|
||||||
"eslint": "^9.0.0",
|
"eslint": "^8.0.1",
|
||||||
"jest": "^29.0.0",
|
"jest": "^27.2.5",
|
||||||
"jest-fetch-mock": "^3.0.3",
|
"jest-fetch-mock": "^3.0.3",
|
||||||
"jsdom": "^25.0.0",
|
"jsdom": "^18.0.0",
|
||||||
"sinon": "^19.0.0",
|
"sinon": "^11.1.2",
|
||||||
"ts-jest": "^29.0.0",
|
"ts-jest": "^27.0.5",
|
||||||
"ts-loader": "^9.2.6",
|
"ts-loader": "^9.2.6",
|
||||||
"ts-node": "^10.3.0",
|
"ts-node": "^10.3.0",
|
||||||
"typescript": "^5.0.0",
|
"typescript": "^4.4.4",
|
||||||
"webpack": "^5.0.0",
|
"webpack": "^5.0.0",
|
||||||
"webpack-cli": "^5.0.0",
|
"webpack-cli": "^4.6.0",
|
||||||
"webpack-dev-server": "^5.0.0"
|
"webpack-dev-server": "^4.3.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@mcaptcha/vanilla-glue": "^0.1.0-alpha-3",
|
"@mcaptcha/vanilla-glue": "^0.1.0-alpha-3",
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
{
|
|
||||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
|
||||||
"extends": [
|
|
||||||
"config:recommended",
|
|
||||||
":dependencyDashboard"
|
|
||||||
],
|
|
||||||
"labels": [
|
|
||||||
"renovate-bot"
|
|
||||||
],
|
|
||||||
"prHourlyLimit": 0,
|
|
||||||
"timezone": "Asia/kolkata",
|
|
||||||
"prCreation": "immediate",
|
|
||||||
"vulnerabilityAlerts": {
|
|
||||||
"enabled": true,
|
|
||||||
"labels": [
|
|
||||||
"renovate-bot",
|
|
||||||
"renovate-security",
|
|
||||||
"security"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -115,12 +115,12 @@ mod tests {
|
||||||
const PASSWORD: &str = "longpassword2";
|
const PASSWORD: &str = "longpassword2";
|
||||||
const EMAIL: &str = "updatepassuser@a.com";
|
const EMAIL: &str = "updatepassuser@a.com";
|
||||||
|
|
||||||
let data = get_test_data().await;
|
|
||||||
{
|
{
|
||||||
|
let data = get_test_data().await;
|
||||||
delete_user(NAME, &data).await;
|
delete_user(NAME, &data).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (_, signin_resp) = register_and_signin(&data, NAME, EMAIL, PASSWORD).await;
|
let (data, _, signin_resp) = register_and_signin(NAME, EMAIL, PASSWORD).await;
|
||||||
let cookies = get_cookie!(signin_resp);
|
let cookies = get_cookie!(signin_resp);
|
||||||
let app = get_app!(data).await;
|
let app = get_app!(data).await;
|
||||||
|
|
||||||
|
@ -153,7 +153,6 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
bad_post_req_test(
|
bad_post_req_test(
|
||||||
&data,
|
|
||||||
NAME,
|
NAME,
|
||||||
new_password,
|
new_password,
|
||||||
ROUTES.admin.account.update_password,
|
ROUTES.admin.account.update_password,
|
||||||
|
@ -169,7 +168,6 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
bad_post_req_test(
|
bad_post_req_test(
|
||||||
&data,
|
|
||||||
NAME,
|
NAME,
|
||||||
new_password,
|
new_password,
|
||||||
ROUTES.admin.account.update_password,
|
ROUTES.admin.account.update_password,
|
||||||
|
|
|
@ -22,12 +22,12 @@ async fn uname_email_exists_works() {
|
||||||
const PASSWORD: &str = "longpassword2";
|
const PASSWORD: &str = "longpassword2";
|
||||||
const EMAIL: &str = "testuserexists@a.com2";
|
const EMAIL: &str = "testuserexists@a.com2";
|
||||||
|
|
||||||
let data = get_test_data().await;
|
|
||||||
{
|
{
|
||||||
|
let data = get_test_data().await;
|
||||||
delete_user(NAME, &data).await;
|
delete_user(NAME, &data).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (_, signin_resp) = register_and_signin(&data, NAME, EMAIL, PASSWORD).await;
|
let (data, _, signin_resp) = register_and_signin(NAME, EMAIL, PASSWORD).await;
|
||||||
let cookies = get_cookie!(signin_resp);
|
let cookies = get_cookie!(signin_resp);
|
||||||
let app = get_app!(data).await;
|
let app = get_app!(data).await;
|
||||||
|
|
||||||
|
@ -112,14 +112,14 @@ async fn email_udpate_password_validation_del_userworks() {
|
||||||
const NAME2: &str = "eupdauser";
|
const NAME2: &str = "eupdauser";
|
||||||
const EMAIL2: &str = "eupdauser@a.com";
|
const EMAIL2: &str = "eupdauser@a.com";
|
||||||
|
|
||||||
let data = get_test_data().await;
|
|
||||||
{
|
{
|
||||||
|
let data = get_test_data().await;
|
||||||
delete_user(NAME, &data).await;
|
delete_user(NAME, &data).await;
|
||||||
delete_user(NAME2, &data).await;
|
delete_user(NAME2, &data).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = register_and_signin(&data, NAME2, EMAIL2, PASSWORD).await;
|
let _ = register_and_signin(NAME2, EMAIL2, PASSWORD).await;
|
||||||
let (_creds, signin_resp) = register_and_signin(&data, NAME, EMAIL, PASSWORD).await;
|
let (data, _creds, signin_resp) = register_and_signin(NAME, EMAIL, PASSWORD).await;
|
||||||
let cookies = get_cookie!(signin_resp);
|
let cookies = get_cookie!(signin_resp);
|
||||||
let app = get_app!(data).await;
|
let app = get_app!(data).await;
|
||||||
|
|
||||||
|
@ -140,7 +140,6 @@ async fn email_udpate_password_validation_del_userworks() {
|
||||||
// check duplicate email while duplicate email
|
// check duplicate email while duplicate email
|
||||||
email_payload.email = EMAIL2.into();
|
email_payload.email = EMAIL2.into();
|
||||||
bad_post_req_test(
|
bad_post_req_test(
|
||||||
&data,
|
|
||||||
NAME,
|
NAME,
|
||||||
PASSWORD,
|
PASSWORD,
|
||||||
ROUTES.admin.account.update_email,
|
ROUTES.admin.account.update_email,
|
||||||
|
@ -154,7 +153,6 @@ async fn email_udpate_password_validation_del_userworks() {
|
||||||
password: NAME.into(),
|
password: NAME.into(),
|
||||||
};
|
};
|
||||||
bad_post_req_test(
|
bad_post_req_test(
|
||||||
&data,
|
|
||||||
NAME,
|
NAME,
|
||||||
PASSWORD,
|
PASSWORD,
|
||||||
ROUTES.admin.account.delete,
|
ROUTES.admin.account.delete,
|
||||||
|
@ -197,8 +195,9 @@ async fn username_update_works() {
|
||||||
const NAME2: &str = "terstusrtds";
|
const NAME2: &str = "terstusrtds";
|
||||||
const NAME_CHANGE: &str = "terstusrtdsxx";
|
const NAME_CHANGE: &str = "terstusrtdsxx";
|
||||||
|
|
||||||
let data = get_test_data().await;
|
|
||||||
{
|
{
|
||||||
|
let data = get_test_data().await;
|
||||||
|
|
||||||
futures::join!(
|
futures::join!(
|
||||||
delete_user(NAME, &data),
|
delete_user(NAME, &data),
|
||||||
delete_user(NAME2, &data),
|
delete_user(NAME2, &data),
|
||||||
|
@ -206,8 +205,8 @@ async fn username_update_works() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = register_and_signin(&data, NAME2, EMAIL2, PASSWORD).await;
|
let _ = register_and_signin(NAME2, EMAIL2, PASSWORD).await;
|
||||||
let (_creds, signin_resp) = register_and_signin(&data, NAME, EMAIL, PASSWORD).await;
|
let (data, _creds, signin_resp) = register_and_signin(NAME, EMAIL, PASSWORD).await;
|
||||||
let cookies = get_cookie!(signin_resp);
|
let cookies = get_cookie!(signin_resp);
|
||||||
let app = get_app!(data).await;
|
let app = get_app!(data).await;
|
||||||
|
|
||||||
|
@ -227,7 +226,6 @@ async fn username_update_works() {
|
||||||
// check duplicate username with duplicate username
|
// check duplicate username with duplicate username
|
||||||
username_udpate.username = NAME2.into();
|
username_udpate.username = NAME2.into();
|
||||||
bad_post_req_test(
|
bad_post_req_test(
|
||||||
&data,
|
|
||||||
NAME_CHANGE,
|
NAME_CHANGE,
|
||||||
PASSWORD,
|
PASSWORD,
|
||||||
ROUTES.admin.account.update_username,
|
ROUTES.admin.account.update_username,
|
||||||
|
|
|
@ -574,13 +574,13 @@ mod tests {
|
||||||
const DEVICE_SOFTWARE_RECOGNISED: &str = "Foobar.v2";
|
const DEVICE_SOFTWARE_RECOGNISED: &str = "Foobar.v2";
|
||||||
const THREADS: i32 = 4;
|
const THREADS: i32 = 4;
|
||||||
|
|
||||||
let data = get_test_data().await;
|
|
||||||
{
|
{
|
||||||
|
let data = get_test_data().await;
|
||||||
delete_user(NAME, &data).await;
|
delete_user(NAME, &data).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (_creds, signin_resp) =
|
let (data, _creds, signin_resp) =
|
||||||
register_and_signin(&data, NAME, EMAIL, PASSWORD).await;
|
register_and_signin(NAME, EMAIL, PASSWORD).await;
|
||||||
let cookies = get_cookie!(signin_resp);
|
let cookies = get_cookie!(signin_resp);
|
||||||
let survey = get_survey_user(data.clone()).await;
|
let survey = get_survey_user(data.clone()).await;
|
||||||
let survey_cookie = get_cookie!(survey);
|
let survey_cookie = get_cookie!(survey);
|
||||||
|
@ -671,7 +671,6 @@ mod tests {
|
||||||
assert_eq!(responses, res);
|
assert_eq!(responses, res);
|
||||||
|
|
||||||
bad_post_req_test_witout_payload(
|
bad_post_req_test_witout_payload(
|
||||||
&data,
|
|
||||||
NAME,
|
NAME,
|
||||||
PASSWORD,
|
PASSWORD,
|
||||||
&V1_API_ROUTES.admin.campaign.delete.replace("{uuid}", NAME),
|
&V1_API_ROUTES.admin.campaign.delete.replace("{uuid}", NAME),
|
||||||
|
|
|
@ -41,11 +41,11 @@ async fn auth_works() {
|
||||||
delete_user(NAME, &data).await;
|
delete_user(NAME, &data).await;
|
||||||
|
|
||||||
// 1. Register and signin
|
// 1. Register and signin
|
||||||
let (_, signin_resp) = register_and_signin(&data, NAME, EMAIL, PASSWORD).await;
|
let (_, _, signin_resp) = register_and_signin(NAME, EMAIL, PASSWORD).await;
|
||||||
let cookies = get_cookie!(signin_resp);
|
let cookies = get_cookie!(signin_resp);
|
||||||
|
|
||||||
// Sign in with email
|
// Sign in with email
|
||||||
signin(&data, EMAIL, PASSWORD).await;
|
signin(EMAIL, PASSWORD).await;
|
||||||
|
|
||||||
// 2. check if duplicate username is allowed
|
// 2. check if duplicate username is allowed
|
||||||
let mut msg = Register {
|
let mut msg = Register {
|
||||||
|
@ -55,7 +55,6 @@ async fn auth_works() {
|
||||||
email: Some(EMAIL.into()),
|
email: Some(EMAIL.into()),
|
||||||
};
|
};
|
||||||
bad_post_req_test(
|
bad_post_req_test(
|
||||||
&data,
|
|
||||||
NAME,
|
NAME,
|
||||||
PASSWORD,
|
PASSWORD,
|
||||||
ROUTES.admin.auth.register,
|
ROUTES.admin.auth.register,
|
||||||
|
@ -67,7 +66,6 @@ async fn auth_works() {
|
||||||
let name = format!("{}dupemail", NAME);
|
let name = format!("{}dupemail", NAME);
|
||||||
msg.username = name;
|
msg.username = name;
|
||||||
bad_post_req_test(
|
bad_post_req_test(
|
||||||
&data,
|
|
||||||
NAME,
|
NAME,
|
||||||
PASSWORD,
|
PASSWORD,
|
||||||
ROUTES.admin.auth.register,
|
ROUTES.admin.auth.register,
|
||||||
|
@ -82,7 +80,6 @@ async fn auth_works() {
|
||||||
password: msg.password.clone(),
|
password: msg.password.clone(),
|
||||||
};
|
};
|
||||||
bad_post_req_test(
|
bad_post_req_test(
|
||||||
&data,
|
|
||||||
NAME,
|
NAME,
|
||||||
PASSWORD,
|
PASSWORD,
|
||||||
ROUTES.admin.auth.login,
|
ROUTES.admin.auth.login,
|
||||||
|
@ -93,7 +90,6 @@ async fn auth_works() {
|
||||||
|
|
||||||
creds.login = "nonexistantuser@example.com".into();
|
creds.login = "nonexistantuser@example.com".into();
|
||||||
bad_post_req_test(
|
bad_post_req_test(
|
||||||
&data,
|
|
||||||
NAME,
|
NAME,
|
||||||
PASSWORD,
|
PASSWORD,
|
||||||
ROUTES.admin.auth.login,
|
ROUTES.admin.auth.login,
|
||||||
|
@ -107,7 +103,6 @@ async fn auth_works() {
|
||||||
creds.password = NAME.into();
|
creds.password = NAME.into();
|
||||||
|
|
||||||
bad_post_req_test(
|
bad_post_req_test(
|
||||||
&data,
|
|
||||||
NAME,
|
NAME,
|
||||||
PASSWORD,
|
PASSWORD,
|
||||||
ROUTES.admin.auth.login,
|
ROUTES.admin.auth.login,
|
||||||
|
|
|
@ -17,13 +17,13 @@ async fn protected_routes_work() {
|
||||||
const EMAIL: &str = "testuser119@a.com2";
|
const EMAIL: &str = "testuser119@a.com2";
|
||||||
|
|
||||||
let get_protected_urls = [V1_API_ROUTES.admin.auth.logout];
|
let get_protected_urls = [V1_API_ROUTES.admin.auth.logout];
|
||||||
let data = get_test_data().await;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
|
let data = get_test_data().await;
|
||||||
delete_user(NAME, &data).await;
|
delete_user(NAME, &data).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (_, signin_resp) = register_and_signin(&data, NAME, EMAIL, PASSWORD).await;
|
let (data, _, signin_resp) = register_and_signin(NAME, EMAIL, PASSWORD).await;
|
||||||
let cookies = get_cookie!(signin_resp);
|
let cookies = get_cookie!(signin_resp);
|
||||||
let app = get_app!(data).await;
|
let app = get_app!(data).await;
|
||||||
|
|
||||||
|
|
|
@ -165,13 +165,13 @@ mod tests {
|
||||||
const DEVICE_SOFTWARE_RECOGNISED: &str = "Foobar.v2";
|
const DEVICE_SOFTWARE_RECOGNISED: &str = "Foobar.v2";
|
||||||
const THREADS: i32 = 4;
|
const THREADS: i32 = 4;
|
||||||
|
|
||||||
let data = get_test_data().await;
|
|
||||||
{
|
{
|
||||||
|
let data = get_test_data().await;
|
||||||
delete_user(NAME, &data).await;
|
delete_user(NAME, &data).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (creds, signin_resp) =
|
let (data, _creds, signin_resp) =
|
||||||
register_and_signin(&data, NAME, EMAIL, PASSWORD).await;
|
register_and_signin(NAME, EMAIL, PASSWORD).await;
|
||||||
let cookies = get_cookie!(signin_resp);
|
let cookies = get_cookie!(signin_resp);
|
||||||
let app = get_app!(data).await;
|
let app = get_app!(data).await;
|
||||||
|
|
||||||
|
|
|
@ -338,8 +338,8 @@ mod tests {
|
||||||
const DEVICE_SOFTWARE_RECOGNISED: &str = "Foobar.v2";
|
const DEVICE_SOFTWARE_RECOGNISED: &str = "Foobar.v2";
|
||||||
const THREADS: i32 = 4;
|
const THREADS: i32 = 4;
|
||||||
|
|
||||||
let data = get_test_data().await;
|
|
||||||
{
|
{
|
||||||
|
let data = get_test_data().await;
|
||||||
delete_user(NAME, &data).await;
|
delete_user(NAME, &data).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,8 +348,8 @@ mod tests {
|
||||||
//self.write_campaign_file(&campaign, &archive).await?;
|
//self.write_campaign_file(&campaign, &archive).await?;
|
||||||
//self.write_benchmark_file(&campaign, &archive, data).await?;
|
//self.write_benchmark_file(&campaign, &archive, data).await?;
|
||||||
|
|
||||||
let (creds, signin_resp) =
|
let (data, _creds, signin_resp) =
|
||||||
register_and_signin(&data, NAME, EMAIL, PASSWORD).await;
|
register_and_signin(NAME, EMAIL, PASSWORD).await;
|
||||||
let cookies = get_cookie!(signin_resp);
|
let cookies = get_cookie!(signin_resp);
|
||||||
let survey = get_survey_user(data.clone()).await;
|
let survey = get_survey_user(data.clone()).await;
|
||||||
let survey_cookie = get_cookie!(survey);
|
let survey_cookie = get_cookie!(survey);
|
||||||
|
|
|
@ -226,7 +226,7 @@ mod tests {
|
||||||
delete_user(NAME, &data).await;
|
delete_user(NAME, &data).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (_, signin_resp) = register_and_signin(&data, NAME, EMAIL, PASSWORD).await;
|
let (_, _, signin_resp) = register_and_signin(NAME, EMAIL, PASSWORD).await;
|
||||||
let cookies = get_cookie!(signin_resp);
|
let cookies = get_cookie!(signin_resp);
|
||||||
|
|
||||||
let campaign =
|
let campaign =
|
||||||
|
|
|
@ -170,7 +170,7 @@ mod tests {
|
||||||
let data = get_test_data().await;
|
let data = get_test_data().await;
|
||||||
let app = get_app!(data).await;
|
let app = get_app!(data).await;
|
||||||
delete_user(NAME, &data).await;
|
delete_user(NAME, &data).await;
|
||||||
let (_, signin_resp) = register_and_signin(&data, NAME, EMAIL, PASSWORD).await;
|
let (_, _, signin_resp) = register_and_signin(NAME, EMAIL, PASSWORD).await;
|
||||||
let cookies = get_cookie!(signin_resp);
|
let cookies = get_cookie!(signin_resp);
|
||||||
|
|
||||||
let uuid =
|
let uuid =
|
||||||
|
|
|
@ -252,7 +252,7 @@ mod tests {
|
||||||
delete_user(NAME, &data).await;
|
delete_user(NAME, &data).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (_, signin_resp) = register_and_signin(&data, NAME, EMAIL, PASSWORD).await;
|
let (_, _, signin_resp) = register_and_signin(NAME, EMAIL, PASSWORD).await;
|
||||||
let cookies = get_cookie!(signin_resp);
|
let cookies = get_cookie!(signin_resp);
|
||||||
let survey = get_survey_user(data.clone()).await;
|
let survey = get_survey_user(data.clone()).await;
|
||||||
let survey_cookie = get_cookie!(survey);
|
let survey_cookie = get_cookie!(survey);
|
||||||
|
|
|
@ -127,7 +127,7 @@ mod tests {
|
||||||
let data = get_test_data().await;
|
let data = get_test_data().await;
|
||||||
let app = get_app!(data).await;
|
let app = get_app!(data).await;
|
||||||
delete_user(NAME, &data).await;
|
delete_user(NAME, &data).await;
|
||||||
let (_, signin_resp) = register_and_signin(&data, NAME, EMAIL, PASSWORD).await;
|
let (_, _, signin_resp) = register_and_signin(NAME, EMAIL, PASSWORD).await;
|
||||||
let cookies = get_cookie!(signin_resp);
|
let cookies = get_cookie!(signin_resp);
|
||||||
|
|
||||||
let mut difficulties = String::new();
|
let mut difficulties = String::new();
|
||||||
|
|
|
@ -112,7 +112,7 @@ mod tests {
|
||||||
let data = get_test_data().await;
|
let data = get_test_data().await;
|
||||||
let app = get_app!(data).await;
|
let app = get_app!(data).await;
|
||||||
delete_user(NAME, &data).await;
|
delete_user(NAME, &data).await;
|
||||||
let (_, signin_resp) = register_and_signin(&data, NAME, EMAIL, PASSWORD).await;
|
let (_, _, signin_resp) = register_and_signin(NAME, EMAIL, PASSWORD).await;
|
||||||
let cookies = get_cookie!(signin_resp);
|
let cookies = get_cookie!(signin_resp);
|
||||||
|
|
||||||
let uuid =
|
let uuid =
|
||||||
|
|
30
src/tests.rs
30
src/tests.rs
|
@ -18,7 +18,6 @@ use mktemp::Temp;
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use sqlx::migrate::MigrateDatabase;
|
|
||||||
use sqlx::types::Uuid;
|
use sqlx::types::Uuid;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -48,15 +47,8 @@ pub async fn get_test_data() -> Arc<Data> {
|
||||||
let tmp_dir = Temp::new_dir().unwrap();
|
let tmp_dir = Temp::new_dir().unwrap();
|
||||||
settings.publish.dir = tmp_dir.join("base_path").to_str().unwrap().into();
|
settings.publish.dir = tmp_dir.join("base_path").to_str().unwrap().into();
|
||||||
settings.allow_registration = true;
|
settings.allow_registration = true;
|
||||||
let mut url = url::Url::parse(&settings.database.url).unwrap();
|
|
||||||
url.set_path(&crate::api::v1::get_random(16));
|
|
||||||
settings.database.url = url.to_string();
|
|
||||||
sqlx::Postgres::create_database(&settings.database.url)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let test_mcaptcha = Box::new(crate::mcaptcha::tests::TestClient::default());
|
let test_mcaptcha = Box::new(crate::mcaptcha::tests::TestClient::default());
|
||||||
let data = Data::new(settings, test_mcaptcha).await;
|
let data = Data::new(settings, test_mcaptcha).await;
|
||||||
|
|
||||||
db::migrate_db(&data.db).await.unwrap();
|
db::migrate_db(&data.db).await.unwrap();
|
||||||
data
|
data
|
||||||
}
|
}
|
||||||
|
@ -157,17 +149,17 @@ macro_rules! get_app {
|
||||||
|
|
||||||
/// register and signin utility
|
/// register and signin utility
|
||||||
pub async fn register_and_signin(
|
pub async fn register_and_signin(
|
||||||
data: &Arc<Data>,
|
|
||||||
name: &str,
|
name: &str,
|
||||||
email: &str,
|
email: &str,
|
||||||
password: &str,
|
password: &str,
|
||||||
) -> (Login, ServiceResponse<EitherBody<BoxBody>>) {
|
) -> (Arc<Data>, Login, ServiceResponse<EitherBody<BoxBody>>) {
|
||||||
register(data, name, email, password).await;
|
register(name, email, password).await;
|
||||||
signin(data, name, password).await
|
signin(name, password).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// register utility
|
/// register utility
|
||||||
pub async fn register(data: &Arc<Data>, name: &str, email: &str, password: &str) {
|
pub async fn register(name: &str, email: &str, password: &str) {
|
||||||
|
let data = get_test_data().await;
|
||||||
let app = get_app!(data).await;
|
let app = get_app!(data).await;
|
||||||
|
|
||||||
// 1. Register
|
// 1. Register
|
||||||
|
@ -192,10 +184,10 @@ pub async fn register(data: &Arc<Data>, name: &str, email: &str, password: &str)
|
||||||
|
|
||||||
/// signin util
|
/// signin util
|
||||||
pub async fn signin(
|
pub async fn signin(
|
||||||
data: &Arc<Data>,
|
|
||||||
name: &str,
|
name: &str,
|
||||||
password: &str,
|
password: &str,
|
||||||
) -> (Login, ServiceResponse<EitherBody<BoxBody>>) {
|
) -> (Arc<Data>, Login, ServiceResponse<EitherBody<BoxBody>>) {
|
||||||
|
let data = get_test_data().await;
|
||||||
let app = get_app!(data.clone()).await;
|
let app = get_app!(data.clone()).await;
|
||||||
|
|
||||||
// 2. signin
|
// 2. signin
|
||||||
|
@ -209,19 +201,18 @@ pub async fn signin(
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(signin_resp.status(), StatusCode::OK);
|
assert_eq!(signin_resp.status(), StatusCode::OK);
|
||||||
(creds, signin_resp)
|
(data, creds, signin_resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// pub duplicate test
|
/// pub duplicate test
|
||||||
pub async fn bad_post_req_test<T: Serialize>(
|
pub async fn bad_post_req_test<T: Serialize>(
|
||||||
data: &Arc<Data>,
|
|
||||||
name: &str,
|
name: &str,
|
||||||
password: &str,
|
password: &str,
|
||||||
url: &str,
|
url: &str,
|
||||||
payload: &T,
|
payload: &T,
|
||||||
err: ServiceError,
|
err: ServiceError,
|
||||||
) {
|
) {
|
||||||
let (_, signin_resp) = signin(data, name, password).await;
|
let (data, _, signin_resp) = signin(name, password).await;
|
||||||
let cookies = get_cookie!(signin_resp);
|
let cookies = get_cookie!(signin_resp);
|
||||||
let app = get_app!(data).await;
|
let app = get_app!(data).await;
|
||||||
|
|
||||||
|
@ -240,13 +231,12 @@ pub async fn bad_post_req_test<T: Serialize>(
|
||||||
|
|
||||||
/// bad post req test without payload
|
/// bad post req test without payload
|
||||||
pub async fn bad_post_req_test_witout_payload(
|
pub async fn bad_post_req_test_witout_payload(
|
||||||
data: &Arc<Data>,
|
|
||||||
name: &str,
|
name: &str,
|
||||||
password: &str,
|
password: &str,
|
||||||
url: &str,
|
url: &str,
|
||||||
err: ServiceError,
|
err: ServiceError,
|
||||||
) {
|
) {
|
||||||
let (_, signin_resp) = signin(data, name, password).await;
|
let (data, _, signin_resp) = signin(name, password).await;
|
||||||
let cookies = get_cookie!(signin_resp);
|
let cookies = get_cookie!(signin_resp);
|
||||||
let app = get_app!(data).await;
|
let app = get_app!(data).await;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue