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
|
||||
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:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
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]
|
||||
actix-web = "4.3"
|
||||
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-rt = "2"
|
||||
actix-cors = "0.7.0"
|
||||
actix-cors = "0.6.1"
|
||||
actix-files = "0.6.0"
|
||||
actix-service = "2.0.0"
|
||||
#actix = "0.12"
|
||||
|
@ -37,16 +37,16 @@ actix-web-codegen-const-routes = "0.2.0"
|
|||
|
||||
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 = { branch = "master", git = "https://github.com/realaravinth/argon2-creds"}
|
||||
|
||||
derive_builder = "0.20"
|
||||
validator = { version = "0.18", features = ["derive"]}
|
||||
derive_builder = "0.11"
|
||||
validator = { version = "0.14", features = ["derive"]}
|
||||
derive_more = "0.99"
|
||||
|
||||
config = "0.14"
|
||||
config = "0.13"
|
||||
|
||||
serde = "1"
|
||||
serde_json = "1"
|
||||
|
@ -62,7 +62,7 @@ rand = "0.8"
|
|||
uuid = { version = "1.4.1", features = ["v4", "serde"] }
|
||||
|
||||
mime_guess = "2.0.3"
|
||||
rust-embed = "8.0.0"
|
||||
rust-embed = "6.0.0"
|
||||
#libcachebust = "0.3.0"
|
||||
cache-buster = { git = "https://github.com/realaravinth/cache-buster" }
|
||||
mime = "0.3.16"
|
||||
|
@ -73,7 +73,7 @@ tera = { version="1.17.1", features=["builtins"]}
|
|||
tokio = { version = "1.25.0", features = ["fs", "macros"] }
|
||||
csv-async = { version = "1.2.5", features = ["serde", "tokio"] }
|
||||
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"
|
||||
|
||||
|
@ -86,7 +86,7 @@ version = "0.2"
|
|||
|
||||
[build-dependencies]
|
||||
#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"
|
||||
cache-buster = { version = "0.2.0", git = "https://github.com/realaravinth/cache-buster" }
|
||||
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
|
||||
RUN apt-get update && apt-get install -y make
|
||||
COPY package.json yarn.lock /src/
|
||||
|
@ -8,14 +8,14 @@ RUN yarn install
|
|||
COPY . .
|
||||
RUN make frontend
|
||||
|
||||
FROM rust:latest as rust
|
||||
FROM rust:1-slim-bookworm as rust
|
||||
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 --from=frontend /src/static/cache/bundle /src/static/cache/bundle
|
||||
RUN cargo build --release
|
||||
|
||||
FROM debian:bookworm
|
||||
FROM debian:bookworm-slim
|
||||
RUN useradd -ms /bin/bash -u 1001 mcaptcha-survey
|
||||
WORKDIR /home/mcaptcha-survey
|
||||
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
|
||||
|
||||
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 push mcaptcha/survey:master
|
||||
|
|
|
@ -10,7 +10,7 @@ services:
|
|||
RUST_LOG: debug
|
||||
|
||||
postgres:
|
||||
image: postgres:16.4
|
||||
image: postgres:13.2
|
||||
volumes:
|
||||
- mcaptcha-survey-data:/var/lib/postgresql/
|
||||
environment:
|
||||
|
|
8948
package-lock.json
generated
8948
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"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^29.0.0",
|
||||
"@types/jsdom": "^21.0.0",
|
||||
"@types/node": "^20.0.0",
|
||||
"@types/sinon": "^17.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
||||
"@typescript-eslint/parser": "^8.0.0",
|
||||
"@types/jest": "^27.0.2",
|
||||
"@types/jsdom": "^16.2.10",
|
||||
"@types/node": "^16.10.5",
|
||||
"@types/sinon": "^10.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
||||
"@typescript-eslint/parser": "^5.0.0",
|
||||
"@wasm-tool/wasm-pack-plugin": "^1.6.0",
|
||||
"dart-sass": "^1.25.0",
|
||||
"eslint": "^9.0.0",
|
||||
"jest": "^29.0.0",
|
||||
"eslint": "^8.0.1",
|
||||
"jest": "^27.2.5",
|
||||
"jest-fetch-mock": "^3.0.3",
|
||||
"jsdom": "^25.0.0",
|
||||
"sinon": "^19.0.0",
|
||||
"ts-jest": "^29.0.0",
|
||||
"jsdom": "^18.0.0",
|
||||
"sinon": "^11.1.2",
|
||||
"ts-jest": "^27.0.5",
|
||||
"ts-loader": "^9.2.6",
|
||||
"ts-node": "^10.3.0",
|
||||
"typescript": "^5.0.0",
|
||||
"typescript": "^4.4.4",
|
||||
"webpack": "^5.0.0",
|
||||
"webpack-cli": "^5.0.0",
|
||||
"webpack-dev-server": "^5.0.0"
|
||||
"webpack-cli": "^4.6.0",
|
||||
"webpack-dev-server": "^4.3.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@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 EMAIL: &str = "updatepassuser@a.com";
|
||||
|
||||
let data = get_test_data().await;
|
||||
{
|
||||
let data = get_test_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 app = get_app!(data).await;
|
||||
|
||||
|
@ -153,7 +153,6 @@ mod tests {
|
|||
};
|
||||
|
||||
bad_post_req_test(
|
||||
&data,
|
||||
NAME,
|
||||
new_password,
|
||||
ROUTES.admin.account.update_password,
|
||||
|
@ -169,7 +168,6 @@ mod tests {
|
|||
};
|
||||
|
||||
bad_post_req_test(
|
||||
&data,
|
||||
NAME,
|
||||
new_password,
|
||||
ROUTES.admin.account.update_password,
|
||||
|
|
|
@ -22,12 +22,12 @@ async fn uname_email_exists_works() {
|
|||
const PASSWORD: &str = "longpassword2";
|
||||
const EMAIL: &str = "testuserexists@a.com2";
|
||||
|
||||
let data = get_test_data().await;
|
||||
{
|
||||
let data = get_test_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 app = get_app!(data).await;
|
||||
|
||||
|
@ -112,14 +112,14 @@ async fn email_udpate_password_validation_del_userworks() {
|
|||
const NAME2: &str = "eupdauser";
|
||||
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(NAME2, &data).await;
|
||||
}
|
||||
|
||||
let _ = register_and_signin(&data, NAME2, EMAIL2, PASSWORD).await;
|
||||
let (_creds, signin_resp) = register_and_signin(&data, NAME, EMAIL, PASSWORD).await;
|
||||
let _ = register_and_signin(NAME2, EMAIL2, PASSWORD).await;
|
||||
let (data, _creds, signin_resp) = register_and_signin(NAME, EMAIL, PASSWORD).await;
|
||||
let cookies = get_cookie!(signin_resp);
|
||||
let app = get_app!(data).await;
|
||||
|
||||
|
@ -140,7 +140,6 @@ async fn email_udpate_password_validation_del_userworks() {
|
|||
// check duplicate email while duplicate email
|
||||
email_payload.email = EMAIL2.into();
|
||||
bad_post_req_test(
|
||||
&data,
|
||||
NAME,
|
||||
PASSWORD,
|
||||
ROUTES.admin.account.update_email,
|
||||
|
@ -154,7 +153,6 @@ async fn email_udpate_password_validation_del_userworks() {
|
|||
password: NAME.into(),
|
||||
};
|
||||
bad_post_req_test(
|
||||
&data,
|
||||
NAME,
|
||||
PASSWORD,
|
||||
ROUTES.admin.account.delete,
|
||||
|
@ -197,8 +195,9 @@ async fn username_update_works() {
|
|||
const NAME2: &str = "terstusrtds";
|
||||
const NAME_CHANGE: &str = "terstusrtdsxx";
|
||||
|
||||
let data = get_test_data().await;
|
||||
{
|
||||
let data = get_test_data().await;
|
||||
|
||||
futures::join!(
|
||||
delete_user(NAME, &data),
|
||||
delete_user(NAME2, &data),
|
||||
|
@ -206,8 +205,8 @@ async fn username_update_works() {
|
|||
);
|
||||
}
|
||||
|
||||
let _ = register_and_signin(&data, NAME2, EMAIL2, PASSWORD).await;
|
||||
let (_creds, signin_resp) = register_and_signin(&data, NAME, EMAIL, PASSWORD).await;
|
||||
let _ = register_and_signin(NAME2, EMAIL2, PASSWORD).await;
|
||||
let (data, _creds, signin_resp) = register_and_signin(NAME, EMAIL, PASSWORD).await;
|
||||
let cookies = get_cookie!(signin_resp);
|
||||
let app = get_app!(data).await;
|
||||
|
||||
|
@ -227,7 +226,6 @@ async fn username_update_works() {
|
|||
// check duplicate username with duplicate username
|
||||
username_udpate.username = NAME2.into();
|
||||
bad_post_req_test(
|
||||
&data,
|
||||
NAME_CHANGE,
|
||||
PASSWORD,
|
||||
ROUTES.admin.account.update_username,
|
||||
|
|
|
@ -574,13 +574,13 @@ mod tests {
|
|||
const DEVICE_SOFTWARE_RECOGNISED: &str = "Foobar.v2";
|
||||
const THREADS: i32 = 4;
|
||||
|
||||
let data = get_test_data().await;
|
||||
{
|
||||
let data = get_test_data().await;
|
||||
delete_user(NAME, &data).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 survey = get_survey_user(data.clone()).await;
|
||||
let survey_cookie = get_cookie!(survey);
|
||||
|
@ -671,7 +671,6 @@ mod tests {
|
|||
assert_eq!(responses, res);
|
||||
|
||||
bad_post_req_test_witout_payload(
|
||||
&data,
|
||||
NAME,
|
||||
PASSWORD,
|
||||
&V1_API_ROUTES.admin.campaign.delete.replace("{uuid}", NAME),
|
||||
|
|
|
@ -41,11 +41,11 @@ async fn auth_works() {
|
|||
delete_user(NAME, &data).await;
|
||||
|
||||
// 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);
|
||||
|
||||
// Sign in with email
|
||||
signin(&data, EMAIL, PASSWORD).await;
|
||||
signin(EMAIL, PASSWORD).await;
|
||||
|
||||
// 2. check if duplicate username is allowed
|
||||
let mut msg = Register {
|
||||
|
@ -55,7 +55,6 @@ async fn auth_works() {
|
|||
email: Some(EMAIL.into()),
|
||||
};
|
||||
bad_post_req_test(
|
||||
&data,
|
||||
NAME,
|
||||
PASSWORD,
|
||||
ROUTES.admin.auth.register,
|
||||
|
@ -67,7 +66,6 @@ async fn auth_works() {
|
|||
let name = format!("{}dupemail", NAME);
|
||||
msg.username = name;
|
||||
bad_post_req_test(
|
||||
&data,
|
||||
NAME,
|
||||
PASSWORD,
|
||||
ROUTES.admin.auth.register,
|
||||
|
@ -82,7 +80,6 @@ async fn auth_works() {
|
|||
password: msg.password.clone(),
|
||||
};
|
||||
bad_post_req_test(
|
||||
&data,
|
||||
NAME,
|
||||
PASSWORD,
|
||||
ROUTES.admin.auth.login,
|
||||
|
@ -93,7 +90,6 @@ async fn auth_works() {
|
|||
|
||||
creds.login = "nonexistantuser@example.com".into();
|
||||
bad_post_req_test(
|
||||
&data,
|
||||
NAME,
|
||||
PASSWORD,
|
||||
ROUTES.admin.auth.login,
|
||||
|
@ -107,7 +103,6 @@ async fn auth_works() {
|
|||
creds.password = NAME.into();
|
||||
|
||||
bad_post_req_test(
|
||||
&data,
|
||||
NAME,
|
||||
PASSWORD,
|
||||
ROUTES.admin.auth.login,
|
||||
|
|
|
@ -17,13 +17,13 @@ async fn protected_routes_work() {
|
|||
const EMAIL: &str = "testuser119@a.com2";
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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 app = get_app!(data).await;
|
||||
|
||||
|
|
|
@ -165,13 +165,13 @@ mod tests {
|
|||
const DEVICE_SOFTWARE_RECOGNISED: &str = "Foobar.v2";
|
||||
const THREADS: i32 = 4;
|
||||
|
||||
let data = get_test_data().await;
|
||||
{
|
||||
let data = get_test_data().await;
|
||||
delete_user(NAME, &data).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 app = get_app!(data).await;
|
||||
|
||||
|
|
|
@ -338,8 +338,8 @@ mod tests {
|
|||
const DEVICE_SOFTWARE_RECOGNISED: &str = "Foobar.v2";
|
||||
const THREADS: i32 = 4;
|
||||
|
||||
let data = get_test_data().await;
|
||||
{
|
||||
let data = get_test_data().await;
|
||||
delete_user(NAME, &data).await;
|
||||
}
|
||||
|
||||
|
@ -348,8 +348,8 @@ mod tests {
|
|||
//self.write_campaign_file(&campaign, &archive).await?;
|
||||
//self.write_benchmark_file(&campaign, &archive, data).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 survey = get_survey_user(data.clone()).await;
|
||||
let survey_cookie = get_cookie!(survey);
|
||||
|
|
|
@ -226,7 +226,7 @@ mod tests {
|
|||
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 campaign =
|
||||
|
|
|
@ -170,7 +170,7 @@ mod tests {
|
|||
let data = get_test_data().await;
|
||||
let app = get_app!(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 uuid =
|
||||
|
|
|
@ -252,7 +252,7 @@ mod tests {
|
|||
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 survey = get_survey_user(data.clone()).await;
|
||||
let survey_cookie = get_cookie!(survey);
|
||||
|
|
|
@ -127,7 +127,7 @@ mod tests {
|
|||
let data = get_test_data().await;
|
||||
let app = get_app!(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 mut difficulties = String::new();
|
||||
|
|
|
@ -112,7 +112,7 @@ mod tests {
|
|||
let data = get_test_data().await;
|
||||
let app = get_app!(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 uuid =
|
||||
|
|
30
src/tests.rs
30
src/tests.rs
|
@ -18,7 +18,6 @@ use mktemp::Temp;
|
|||
|
||||
use lazy_static::lazy_static;
|
||||
use serde::Serialize;
|
||||
use sqlx::migrate::MigrateDatabase;
|
||||
use sqlx::types::Uuid;
|
||||
|
||||
use super::*;
|
||||
|
@ -48,15 +47,8 @@ pub async fn get_test_data() -> Arc<Data> {
|
|||
let tmp_dir = Temp::new_dir().unwrap();
|
||||
settings.publish.dir = tmp_dir.join("base_path").to_str().unwrap().into();
|
||||
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 data = Data::new(settings, test_mcaptcha).await;
|
||||
|
||||
db::migrate_db(&data.db).await.unwrap();
|
||||
data
|
||||
}
|
||||
|
@ -157,17 +149,17 @@ macro_rules! get_app {
|
|||
|
||||
/// register and signin utility
|
||||
pub async fn register_and_signin(
|
||||
data: &Arc<Data>,
|
||||
name: &str,
|
||||
email: &str,
|
||||
password: &str,
|
||||
) -> (Login, ServiceResponse<EitherBody<BoxBody>>) {
|
||||
register(data, name, email, password).await;
|
||||
signin(data, name, password).await
|
||||
) -> (Arc<Data>, Login, ServiceResponse<EitherBody<BoxBody>>) {
|
||||
register(name, email, password).await;
|
||||
signin(name, password).await
|
||||
}
|
||||
|
||||
/// 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;
|
||||
|
||||
// 1. Register
|
||||
|
@ -192,10 +184,10 @@ pub async fn register(data: &Arc<Data>, name: &str, email: &str, password: &str)
|
|||
|
||||
/// signin util
|
||||
pub async fn signin(
|
||||
data: &Arc<Data>,
|
||||
name: &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;
|
||||
|
||||
// 2. signin
|
||||
|
@ -209,19 +201,18 @@ pub async fn signin(
|
|||
)
|
||||
.await;
|
||||
assert_eq!(signin_resp.status(), StatusCode::OK);
|
||||
(creds, signin_resp)
|
||||
(data, creds, signin_resp)
|
||||
}
|
||||
|
||||
/// pub duplicate test
|
||||
pub async fn bad_post_req_test<T: Serialize>(
|
||||
data: &Arc<Data>,
|
||||
name: &str,
|
||||
password: &str,
|
||||
url: &str,
|
||||
payload: &T,
|
||||
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 app = get_app!(data).await;
|
||||
|
||||
|
@ -240,13 +231,12 @@ pub async fn bad_post_req_test<T: Serialize>(
|
|||
|
||||
/// bad post req test without payload
|
||||
pub async fn bad_post_req_test_witout_payload(
|
||||
data: &Arc<Data>,
|
||||
name: &str,
|
||||
password: &str,
|
||||
url: &str,
|
||||
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 app = get_app!(data).await;
|
||||
|
||||
|
|
Loading…
Reference in a new issue