Compare commits
No commits in common. "master" and "mcaptcha-upload" have entirely different histories.
master
...
mcaptcha-u
68 changed files with 7696 additions and 7940 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"
|
||||
}
|
|
@ -8,7 +8,7 @@ pipeline:
|
|||
- COMPILED_DATE=2021-07-21
|
||||
commands:
|
||||
- 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
|
||||
- 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
|
||||
|
|
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"] }
|
||||
|
||||
#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:
|
||||
|
|
|
@ -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 (
|
||||
ID UUID PRIMARY KEY NOT NULL UNIQUE,
|
||||
created_at TIMESTAMPTZ NOT NULL
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
-- SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
--
|
||||
-- SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
-- Add migration script here
|
||||
CREATE TABLE IF NOT EXISTS survey_admins (
|
||||
name VARCHAR(100) NOT NULL UNIQUE,
|
||||
|
|
|
@ -1,6 +1,2 @@
|
|||
-- SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
--
|
||||
-- SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
ALTER TABLE survey_responses
|
||||
ADD COLUMN submitted_at TIMESTAMPTZ NOT NULL DEFAULT now();
|
||||
|
|
|
@ -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 (
|
||||
name VARCHAR(30) UNIQUE NOT NULL,
|
||||
ID SERIAL PRIMARY KEY NOT NULL
|
||||
|
|
|
@ -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 (
|
||||
url VARCHAR(3000) UNIQUE NOT NULL,
|
||||
secret VARCHAR(100) UNIQUE NOT NULL,
|
||||
|
|
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"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,6 +1,18 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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;
|
||||
|
|
|
@ -1,7 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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_web::{web, HttpResponse, Responder};
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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 actix_identity::Identity;
|
||||
|
|
|
@ -1,7 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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};
|
||||
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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_web::{web, HttpResponse, Responder};
|
||||
use argon2_creds::Config;
|
||||
|
@ -115,12 +126,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 +164,6 @@ mod tests {
|
|||
};
|
||||
|
||||
bad_post_req_test(
|
||||
&data,
|
||||
NAME,
|
||||
new_password,
|
||||
ROUTES.admin.account.update_password,
|
||||
|
@ -169,7 +179,6 @@ mod tests {
|
|||
};
|
||||
|
||||
bad_post_req_test(
|
||||
&data,
|
||||
NAME,
|
||||
new_password,
|
||||
ROUTES.admin.account.update_password,
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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 actix_identity::Identity;
|
||||
|
|
|
@ -1,7 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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::test;
|
||||
|
@ -22,12 +34,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 +124,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 +152,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 +165,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 +207,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 +217,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 +238,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,
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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 actix_identity::Identity;
|
||||
|
|
|
@ -1,7 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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_web::http::header;
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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 actix_identity::Identity;
|
||||
|
@ -574,13 +585,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 +682,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),
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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_web::web::ServiceConfig;
|
||||
|
||||
|
|
|
@ -1,7 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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::test;
|
||||
|
@ -41,11 +53,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 +67,6 @@ async fn auth_works() {
|
|||
email: Some(EMAIL.into()),
|
||||
};
|
||||
bad_post_req_test(
|
||||
&data,
|
||||
NAME,
|
||||
PASSWORD,
|
||||
ROUTES.admin.auth.register,
|
||||
|
@ -67,7 +78,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 +92,6 @@ async fn auth_works() {
|
|||
password: msg.password.clone(),
|
||||
};
|
||||
bad_post_req_test(
|
||||
&data,
|
||||
NAME,
|
||||
PASSWORD,
|
||||
ROUTES.admin.auth.login,
|
||||
|
@ -93,7 +102,6 @@ async fn auth_works() {
|
|||
|
||||
creds.login = "nonexistantuser@example.com".into();
|
||||
bad_post_req_test(
|
||||
&data,
|
||||
NAME,
|
||||
PASSWORD,
|
||||
ROUTES.admin.auth.login,
|
||||
|
@ -107,7 +115,6 @@ async fn auth_works() {
|
|||
creds.password = NAME.into();
|
||||
|
||||
bad_post_req_test(
|
||||
&data,
|
||||
NAME,
|
||||
PASSWORD,
|
||||
ROUTES.admin.auth.login,
|
||||
|
|
|
@ -1,7 +1,18 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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 protected;
|
||||
|
|
|
@ -1,7 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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::test;
|
||||
|
@ -17,13 +29,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;
|
||||
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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::str::FromStr;
|
||||
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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 uuid::Uuid;
|
||||
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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, HttpResponse, Responder};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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;
|
||||
|
||||
pub mod db;
|
||||
|
|
|
@ -1,7 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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 derive_builder::Builder;
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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 serde::Deserialize;
|
||||
use sqlx::types::Uuid;
|
||||
|
@ -12,7 +23,6 @@ pub mod bench;
|
|||
pub mod mcaptcha;
|
||||
mod meta;
|
||||
pub mod routes;
|
||||
pub mod stats;
|
||||
pub use routes::ROUTES;
|
||||
|
||||
pub fn services(cfg: &mut ServiceConfig) {
|
||||
|
@ -20,7 +30,6 @@ pub fn services(cfg: &mut ServiceConfig) {
|
|||
bench::services(cfg);
|
||||
admin::services(cfg);
|
||||
mcaptcha::services(cfg);
|
||||
stats::services(cfg);
|
||||
}
|
||||
|
||||
pub fn get_random(len: usize) -> String {
|
||||
|
|
|
@ -1,15 +1,25 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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 super::admin::routes::Admin;
|
||||
use super::bench::routes::Benches;
|
||||
use super::mcaptcha::routes::Mcaptcha;
|
||||
use super::meta::routes::Meta;
|
||||
use super::stats::routes::Stats;
|
||||
|
||||
pub const ROUTES: Routes = Routes::new();
|
||||
|
||||
|
@ -19,7 +29,6 @@ pub struct Routes {
|
|||
pub meta: Meta,
|
||||
pub benches: Benches,
|
||||
pub mcaptcha: Mcaptcha,
|
||||
pub stats: Stats,
|
||||
}
|
||||
|
||||
impl Routes {
|
||||
|
@ -29,7 +38,6 @@ impl Routes {
|
|||
meta: Meta::new(),
|
||||
benches: Benches::new(),
|
||||
mcaptcha: Mcaptcha::new(),
|
||||
stats: Stats::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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 serde::{Deserialize, Serialize};
|
||||
|
@ -338,8 +349,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 +359,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);
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-or-later
|
21
src/data.rs
21
src/data.rs
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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.
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
|
|
|
@ -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 serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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 argon2_creds::errors::CredsError;
|
||||
|
|
21
src/main.rs
21
src/main.rs
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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::sync::Arc;
|
||||
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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 async_trait::async_trait;
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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 std::cell::RefCell;
|
||||
use tera::Context;
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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 actix_identity::Identity;
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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::*;
|
||||
|
||||
pub use super::{context, Footer, TemplateFile, PAGES, PAYLOAD_KEY, TEMPLATES};
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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 crate::pages::errors::ErrorPage;
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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 actix_web::{
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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_web::web::ServiceConfig;
|
||||
use lazy_static::lazy_static;
|
||||
|
@ -226,7 +237,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 =
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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::str::FromStr;
|
||||
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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 actix_web::http::header::ContentType;
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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 serde::{Deserialize, Serialize};
|
||||
use sqlx::types::Uuid;
|
||||
|
@ -170,7 +181,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 =
|
||||
|
|
|
@ -1,8 +1,18 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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 actix_identity::Identity;
|
||||
|
@ -252,7 +262,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);
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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 actix_identity::Identity;
|
||||
|
@ -127,7 +138,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();
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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::str::FromStr;
|
||||
|
||||
|
|
|
@ -1,8 +1,18 @@
|
|||
// Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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 actix_web::http::header::ContentType;
|
||||
|
@ -112,7 +122,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 =
|
||||
|
|
|
@ -1,8 +1,18 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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};
|
||||
|
||||
pub use super::{context, Footer, TemplateFile, PAGES, PAYLOAD_KEY, TEMPLATES};
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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 serde::{Deserialize, Serialize};
|
||||
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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::fs;
|
||||
use std::path::Path;
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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;
|
||||
|
||||
pub struct FileMap {
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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 static_files;
|
||||
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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 actix_web::body::BoxBody;
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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 sqlx::postgres::PgPoolOptions;
|
||||
|
|
51
src/tests.rs
51
src/tests.rs
|
@ -1,8 +1,19 @@
|
|||
// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* 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::sync::Arc;
|
||||
|
||||
|
@ -18,7 +29,6 @@ use mktemp::Temp;
|
|||
|
||||
use lazy_static::lazy_static;
|
||||
use serde::Serialize;
|
||||
use sqlx::migrate::MigrateDatabase;
|
||||
use sqlx::types::Uuid;
|
||||
|
||||
use super::*;
|
||||
|
@ -48,15 +58,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 +160,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 +195,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 +212,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 +242,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…
Add table
Reference in a new issue