Compare commits

..

No commits in common. "master" and "mcaptcha-upload" have entirely different histories.

68 changed files with 7696 additions and 7940 deletions

View file

@ -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

View file

@ -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"
}

View file

@ -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"
}

View file

@ -8,7 +8,7 @@ pipeline:
- COMPILED_DATE=2021-07-21 - COMPILED_DATE=2021-07-21
commands: commands:
- apt-get update - apt-get update
- apt-get install -y ca-certificates curl gnupg tar wget libssl-dev - apt-get install -y ca-certificates curl gnupg tar wget
- mkdir -p /etc/apt/keyrings - mkdir -p /etc/apt/keyrings
- curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg - curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
- NODE_MAJOR=18 echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list - NODE_MAJOR=18 echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list

1240
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -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"] }
#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"

View file

@ -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/

View file

@ -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

View file

@ -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:

View file

@ -1,7 +1,3 @@
-- SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
--
-- SPDX-License-Identifier: AGPL-3.0-or-later
CREATE TABLE IF NOT EXISTS survey_users ( CREATE TABLE IF NOT EXISTS survey_users (
ID UUID PRIMARY KEY NOT NULL UNIQUE, ID UUID PRIMARY KEY NOT NULL UNIQUE,
created_at TIMESTAMPTZ NOT NULL created_at TIMESTAMPTZ NOT NULL

View file

@ -1,7 +1,3 @@
-- SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
--
-- SPDX-License-Identifier: AGPL-3.0-or-later
-- Add migration script here -- Add migration script here
CREATE TABLE IF NOT EXISTS survey_admins ( CREATE TABLE IF NOT EXISTS survey_admins (
name VARCHAR(100) NOT NULL UNIQUE, name VARCHAR(100) NOT NULL UNIQUE,

View file

@ -1,6 +1,2 @@
-- SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
--
-- SPDX-License-Identifier: AGPL-3.0-or-later
ALTER TABLE survey_responses ALTER TABLE survey_responses
ADD COLUMN submitted_at TIMESTAMPTZ NOT NULL DEFAULT now(); ADD COLUMN submitted_at TIMESTAMPTZ NOT NULL DEFAULT now();

View file

@ -1,7 +1,3 @@
-- SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
--
-- SPDX-License-Identifier: AGPL-3.0-or-later
CREATE TABLE IF NOT EXISTS survey_bench_type ( CREATE TABLE IF NOT EXISTS survey_bench_type (
name VARCHAR(30) UNIQUE NOT NULL, name VARCHAR(30) UNIQUE NOT NULL,
ID SERIAL PRIMARY KEY NOT NULL ID SERIAL PRIMARY KEY NOT NULL

View file

@ -1,7 +1,3 @@
-- SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
--
-- SPDX-License-Identifier: AGPL-3.0-or-later
CREATE TABLE IF NOT EXISTS survey_mcaptcha_hostname ( CREATE TABLE IF NOT EXISTS survey_mcaptcha_hostname (
url VARCHAR(3000) UNIQUE NOT NULL, url VARCHAR(3000) UNIQUE NOT NULL,
secret VARCHAR(100) UNIQUE NOT NULL, secret VARCHAR(100) UNIQUE NOT NULL,

8946
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -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",

View file

@ -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"
]
}
}

View file

@ -1,6 +1,18 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
pub mod v1; pub mod v1;

View file

@ -1,7 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use actix_identity::Identity; use actix_identity::Identity;
use actix_web::{web, HttpResponse, Responder}; use actix_web::{web, HttpResponse, Responder};

View file

@ -1,8 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use std::borrow::Cow; use std::borrow::Cow;
use actix_identity::Identity; use actix_identity::Identity;

View file

@ -1,7 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View file

@ -1,8 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use actix_identity::Identity; use actix_identity::Identity;
use actix_web::{web, HttpResponse, Responder}; use actix_web::{web, HttpResponse, Responder};
use argon2_creds::Config; use argon2_creds::Config;
@ -115,12 +126,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 +164,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 +179,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,

View file

@ -1,8 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use std::borrow::Cow; use std::borrow::Cow;
use actix_identity::Identity; use actix_identity::Identity;

View file

@ -1,7 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use actix_web::http::StatusCode; use actix_web::http::StatusCode;
use actix_web::test; use actix_web::test;
@ -22,12 +34,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 +124,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 +152,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 +165,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 +207,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 +217,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 +238,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,

View file

@ -1,8 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use std::borrow::Cow; use std::borrow::Cow;
use actix_identity::Identity; use actix_identity::Identity;

View file

@ -1,7 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use actix_identity::Identity; use actix_identity::Identity;
use actix_web::http::header; use actix_web::http::header;

View file

@ -1,8 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use std::borrow::Cow; use std::borrow::Cow;
use actix_identity::Identity; use actix_identity::Identity;
@ -574,13 +585,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 +682,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),

View file

@ -1,8 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use actix_auth_middleware::*; use actix_auth_middleware::*;
use actix_web::web::ServiceConfig; use actix_web::web::ServiceConfig;

View file

@ -1,7 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use actix_web::http::{header, StatusCode}; use actix_web::http::{header, StatusCode};
use actix_web::test; use actix_web::test;
@ -41,11 +53,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 +67,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 +78,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 +92,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 +102,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 +115,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,

View file

@ -1,7 +1,18 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
mod auth; mod auth;
mod protected; mod protected;

View file

@ -1,7 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use actix_web::http::StatusCode; use actix_web::http::StatusCode;
use actix_web::test; use actix_web::test;
@ -17,13 +29,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;

View file

@ -1,8 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use std::borrow::Cow; use std::borrow::Cow;
use std::str::FromStr; use std::str::FromStr;

View file

@ -1,8 +1,19 @@
// Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use url::Url; use url::Url;
use uuid::Uuid; use uuid::Uuid;

View file

@ -1,8 +1,19 @@
// Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use actix_web::web::ServiceConfig; use actix_web::web::ServiceConfig;
use actix_web::{web, HttpResponse, Responder}; use actix_web::{web, HttpResponse, Responder};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View file

@ -1,8 +1,19 @@
// Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use actix_web::web::ServiceConfig; use actix_web::web::ServiceConfig;
pub mod db; pub mod db;

View file

@ -1,7 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use actix_web::{web, HttpResponse, Responder}; use actix_web::{web, HttpResponse, Responder};
use derive_builder::Builder; use derive_builder::Builder;

View file

@ -1,8 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use actix_web::web::ServiceConfig; use actix_web::web::ServiceConfig;
use serde::Deserialize; use serde::Deserialize;
use sqlx::types::Uuid; use sqlx::types::Uuid;
@ -12,7 +23,6 @@ pub mod bench;
pub mod mcaptcha; pub mod mcaptcha;
mod meta; mod meta;
pub mod routes; pub mod routes;
pub mod stats;
pub use routes::ROUTES; pub use routes::ROUTES;
pub fn services(cfg: &mut ServiceConfig) { pub fn services(cfg: &mut ServiceConfig) {
@ -20,7 +30,6 @@ pub fn services(cfg: &mut ServiceConfig) {
bench::services(cfg); bench::services(cfg);
admin::services(cfg); admin::services(cfg);
mcaptcha::services(cfg); mcaptcha::services(cfg);
stats::services(cfg);
} }
pub fn get_random(len: usize) -> String { pub fn get_random(len: usize) -> String {

View file

@ -1,15 +1,25 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use serde::Serialize; use serde::Serialize;
use super::admin::routes::Admin; use super::admin::routes::Admin;
use super::bench::routes::Benches; use super::bench::routes::Benches;
use super::mcaptcha::routes::Mcaptcha; use super::mcaptcha::routes::Mcaptcha;
use super::meta::routes::Meta; use super::meta::routes::Meta;
use super::stats::routes::Stats;
pub const ROUTES: Routes = Routes::new(); pub const ROUTES: Routes = Routes::new();
@ -19,7 +29,6 @@ pub struct Routes {
pub meta: Meta, pub meta: Meta,
pub benches: Benches, pub benches: Benches,
pub mcaptcha: Mcaptcha, pub mcaptcha: Mcaptcha,
pub stats: Stats,
} }
impl Routes { impl Routes {
@ -29,7 +38,6 @@ impl Routes {
meta: Meta::new(), meta: Meta::new(),
benches: Benches::new(), benches: Benches::new(),
mcaptcha: Mcaptcha::new(), mcaptcha: Mcaptcha::new(),
stats: Stats::new(),
} }
} }
} }

View file

@ -1,256 +0,0 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use actix_web::{web, HttpResponse, Responder};
use derive_builder::Builder;
use serde::{Deserialize, Serialize};
use crate::errors::*;
use crate::AppData;
#[derive(Clone, Debug, Deserialize, Builder, Serialize)]
pub struct BuildDetails {
pub version: &'static str,
pub git_commit_hash: &'static str,
}
pub mod routes {
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct Stats {
pub percentile_benches: &'static str,
}
impl Stats {
pub const fn new() -> Self {
Self {
percentile_benches: "/api/v1/stats/benches/percentile",
}
}
}
}
/// Get difficulty factor with max time limit for percentile of stats
#[actix_web_codegen_const_routes::post(
path = "crate::V1_API_ROUTES.stats.percentile_benches"
)]
async fn percentile_benches(
data: AppData,
payload: web::Json<PercentileReq>,
) -> ServiceResult<impl Responder> {
struct Count {
count: Option<i64>,
}
let count = sqlx::query_as!(
Count,
"SELECT COUNT(difficulty) FROM survey_benches WHERE duration <= $1;",
payload.time as f32
)
.fetch_one(&data.db)
.await?;
if count.count.is_none() {
return Ok(HttpResponse::Ok().json(PercentileResp {
difficulty_factor: None,
}));
}
let count = count.count.unwrap();
if count < 2 {
return Ok(HttpResponse::Ok().json(PercentileResp {
difficulty_factor: None,
}));
}
let location = ((count - 1) as f64 * (payload.percentile / 100.00)) + 1.00;
let fraction = location - location.floor();
async fn get_data_at_location(
data: &crate::Data,
time: u32,
location: i64,
) -> ServiceResult<Option<u32>> {
struct Difficulty {
difficulty: Option<i32>,
}
match sqlx::query_as!(
Difficulty,
"SELECT
difficulty
FROM
survey_benches
WHERE
duration <= $1
ORDER BY difficulty ASC LIMIT 1 OFFSET $2;",
time as f32,
location as i64 - 1,
)
.fetch_one(&data.db)
.await
{
Ok(res) => Ok(Some(res.difficulty.unwrap() as u32)),
Err(sqlx::Error::RowNotFound) => Ok(None),
Err(e) => Err(e.into()),
}
}
if fraction > 0.00 {
if let (Some(base), Some(ceiling)) = (
get_data_at_location(&data, payload.time, location.floor() as i64).await?,
get_data_at_location(&data, payload.time, location.floor() as i64 + 1)
.await?,
) {
let res = base as u32 + ((ceiling - base) as f64 * fraction).floor() as u32;
return Ok(HttpResponse::Ok().json(PercentileResp {
difficulty_factor: Some(res),
}));
}
} else {
if let Some(base) =
get_data_at_location(&data, payload.time, location.floor() as i64).await?
{
let res = base as u32;
return Ok(HttpResponse::Ok().json(PercentileResp {
difficulty_factor: Some(res),
}));
}
};
Ok(HttpResponse::Ok().json(PercentileResp {
difficulty_factor: None,
}))
}
#[derive(Clone, Debug, Deserialize, Builder, Serialize)]
/// Health check return datatype
pub struct PercentileReq {
time: u32,
percentile: f64,
}
#[derive(Clone, Debug, Deserialize, Builder, Serialize)]
/// Health check return datatype
pub struct PercentileResp {
difficulty_factor: Option<u32>,
}
pub fn services(cfg: &mut web::ServiceConfig) {
cfg.service(percentile_benches);
}
#[cfg(test)]
mod tests {
use actix_web::{http::StatusCode, test, App};
use super::*;
use crate::api::v1::services;
use crate::tests::get_test_data;
use crate::*;
#[actix_rt::test]
async fn stats_bench_work() {
use crate::tests::*;
const NAME: &str = "benchstatsuesr";
const EMAIL: &str = "benchstatsuesr@testadminuser.com";
const PASSWORD: &str = "longpassword2";
const DEVICE_USER_PROVIDED: &str = "foo";
const DEVICE_SOFTWARE_RECOGNISED: &str = "Foobar.v2";
const THREADS: i32 = 4;
let data = get_test_data().await;
{
delete_user(NAME, &data).await;
}
let (creds, signin_resp) =
register_and_signin(&data, NAME, EMAIL, PASSWORD).await;
let cookies = get_cookie!(signin_resp);
let app = get_app!(data).await;
let survey = get_survey_user(data.clone()).await;
let survey_cookie = get_cookie!(survey);
let campaign = create_new_campaign(NAME, data.clone(), cookies.clone()).await;
let campaign_config =
get_campaign_config(&campaign, data.clone(), survey_cookie.clone()).await;
assert_eq!(DIFFICULTIES.to_vec(), campaign_config.difficulties);
let submit_payload = crate::api::v1::bench::Submission {
device_user_provided: DEVICE_USER_PROVIDED.into(),
device_software_recognised: DEVICE_SOFTWARE_RECOGNISED.into(),
threads: THREADS,
benches: BENCHES.clone(),
submission_type: crate::api::v1::bench::SubmissionType::Wasm,
};
submit_bench(&submit_payload, &campaign, survey_cookie, data.clone()).await;
let msg = PercentileReq {
time: 1,
percentile: 99.00,
};
let resp = test::call_service(
&app,
post_request!(&msg, V1_API_ROUTES.stats.percentile_benches).to_request(),
)
.await;
assert_eq!(resp.status(), StatusCode::OK);
let resp: PercentileResp = test::read_body_json(resp).await;
assert!(resp.difficulty_factor.is_none());
let msg = PercentileReq {
time: 1,
percentile: 100.00,
};
let resp = test::call_service(
&app,
post_request!(&msg, V1_API_ROUTES.stats.percentile_benches).to_request(),
)
.await;
assert_eq!(resp.status(), StatusCode::OK);
let resp: PercentileResp = test::read_body_json(resp).await;
assert!(resp.difficulty_factor.is_none());
let msg = PercentileReq {
time: 2,
percentile: 100.00,
};
let resp = test::call_service(
&app,
post_request!(&msg, V1_API_ROUTES.stats.percentile_benches).to_request(),
)
.await;
assert_eq!(resp.status(), StatusCode::OK);
let resp: PercentileResp = test::read_body_json(resp).await;
assert_eq!(resp.difficulty_factor.unwrap(), 2);
let msg = PercentileReq {
time: 5,
percentile: 90.00,
};
let resp = test::call_service(
&app,
post_request!(&msg, V1_API_ROUTES.stats.percentile_benches).to_request(),
)
.await;
assert_eq!(resp.status(), StatusCode::OK);
let resp: PercentileResp = test::read_body_json(resp).await;
assert_eq!(resp.difficulty_factor.unwrap(), 4);
delete_user(NAME, &data).await;
}
}

View file

@ -1,8 +1,19 @@
// Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -338,8 +349,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 +359,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);

View file

@ -1,3 +0,0 @@
SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
SPDX-License-Identifier: AGPL-3.0-or-later

View file

@ -1,8 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
//! App data: database connections, etc. //! App data: database connections, etc.
use std::sync::Arc; use std::sync::Arc;
use std::thread; use std::thread;

View file

@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use lazy_static::lazy_static; use lazy_static::lazy_static;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use sqlx::PgPool; use sqlx::PgPool;

View file

@ -1,8 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use std::convert::From; use std::convert::From;
use argon2_creds::errors::CredsError; use argon2_creds::errors::CredsError;

View file

@ -1,8 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use std::env; use std::env;
use std::sync::Arc; use std::sync::Arc;

View file

@ -1,8 +1,19 @@
// Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use std::time::Duration; use std::time::Duration;
use async_trait::async_trait; use async_trait::async_trait;

View file

@ -1,8 +1,19 @@
// Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use actix_web::http::header::ContentType; use actix_web::http::header::ContentType;
use std::cell::RefCell; use std::cell::RefCell;
use tera::Context; use tera::Context;

View file

@ -1,8 +1,19 @@
// Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use std::cell::RefCell; use std::cell::RefCell;
use actix_identity::Identity; use actix_identity::Identity;

View file

@ -1,8 +1,19 @@
// Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use actix_web::*; use actix_web::*;
pub use super::{context, Footer, TemplateFile, PAGES, PAYLOAD_KEY, TEMPLATES}; pub use super::{context, Footer, TemplateFile, PAGES, PAYLOAD_KEY, TEMPLATES};

View file

@ -1,8 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use sailfish::TemplateOnce; use sailfish::TemplateOnce;
use crate::pages::errors::ErrorPage; use crate::pages::errors::ErrorPage;

View file

@ -1,8 +1,19 @@
// Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use std::fmt; use std::fmt;
use actix_web::{ use actix_web::{

View file

@ -1,8 +1,19 @@
// Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use actix_auth_middleware::*; use actix_auth_middleware::*;
use actix_web::web::ServiceConfig; use actix_web::web::ServiceConfig;
use lazy_static::lazy_static; use lazy_static::lazy_static;
@ -226,7 +237,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 =

View file

@ -1,8 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use std::cell::RefCell; use std::cell::RefCell;
use std::str::FromStr; use std::str::FromStr;

View file

@ -1,8 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use std::cell::RefCell; use std::cell::RefCell;
use actix_web::http::header::ContentType; use actix_web::http::header::ContentType;

View file

@ -1,8 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use actix_identity::Identity; use actix_identity::Identity;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use sqlx::types::Uuid; use sqlx::types::Uuid;
@ -170,7 +181,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 =

View file

@ -1,8 +1,18 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use std::cell::RefCell; use std::cell::RefCell;
use actix_identity::Identity; use actix_identity::Identity;
@ -252,7 +262,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);

View file

@ -1,8 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use std::cell::RefCell; use std::cell::RefCell;
use actix_identity::Identity; use actix_identity::Identity;
@ -127,7 +138,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();

View file

@ -1,8 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use std::cell::RefCell; use std::cell::RefCell;
use std::str::FromStr; use std::str::FromStr;

View file

@ -1,8 +1,18 @@
// Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use std::cell::RefCell; use std::cell::RefCell;
use actix_web::http::header::ContentType; use actix_web::http::header::ContentType;
@ -112,7 +122,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 =

View file

@ -1,8 +1,18 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use actix_web::{http, HttpResponse, Responder}; use actix_web::{http, HttpResponse, Responder};
pub use super::{context, Footer, TemplateFile, PAGES, PAYLOAD_KEY, TEMPLATES}; pub use super::{context, Footer, TemplateFile, PAGES, PAYLOAD_KEY, TEMPLATES};

View file

@ -1,8 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use actix_auth_middleware::GetLoginRoute; use actix_auth_middleware::GetLoginRoute;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View file

@ -1,8 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use std::env; use std::env;
use std::fs; use std::fs;
use std::path::Path; use std::path::Path;

View file

@ -1,8 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use cache_buster::Files; use cache_buster::Files;
pub struct FileMap { pub struct FileMap {

View file

@ -1,8 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
pub mod filemap; pub mod filemap;
pub mod static_files; pub mod static_files;

View file

@ -1,8 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use std::borrow::Cow; use std::borrow::Cow;
use actix_web::body::BoxBody; use actix_web::body::BoxBody;

View file

@ -1,8 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use std::env; use std::env;
use sqlx::postgres::PgPoolOptions; use sqlx::postgres::PgPoolOptions;

View file

@ -1,8 +1,19 @@
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> /*
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net> * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// *
// SPDX-License-Identifier: AGPL-3.0-or-later * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
use std::str::FromStr; use std::str::FromStr;
use std::sync::Arc; use std::sync::Arc;
@ -18,7 +29,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 +58,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 +160,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 +195,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 +212,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 +242,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;

3964
yarn.lock

File diff suppressed because it is too large Load diff