chore: clippy lints
This commit is contained in:
parent
9a3425eabe
commit
31fd0f0c51
13 changed files with 60 additions and 102 deletions
|
@ -102,8 +102,9 @@ pub async fn adding_forge_works<'a, T: SCDatabase>(
|
||||||
|
|
||||||
/// test if all forge type implementations are loaded into DB
|
/// test if all forge type implementations are loaded into DB
|
||||||
pub async fn forge_type_exists_helper<T: SCDatabase>(db: &T) {
|
pub async fn forge_type_exists_helper<T: SCDatabase>(db: &T) {
|
||||||
for f in [ForgeImplementation::Gitea].iter() {
|
//for f in [ForgeImplementation::Gitea].iter() {
|
||||||
|
//let f = For
|
||||||
|
let f = ForgeImplementation::Gitea;
|
||||||
println!("Testing forge implementation exists for: {}", f.to_str());
|
println!("Testing forge implementation exists for: {}", f.to_str());
|
||||||
assert!(db.forge_type_exists(f).await.unwrap());
|
assert!(db.forge_type_exists(&f).await.unwrap());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -274,7 +274,7 @@ impl SCDatabase for Database {
|
||||||
.map_err(|e| DBError::DBError(Box::new(e)))?;
|
.map_err(|e| DBError::DBError(Box::new(e)))?;
|
||||||
Ok(User {
|
Ok(User {
|
||||||
username: username.into(),
|
username: username.into(),
|
||||||
url: url.into(),
|
url,
|
||||||
profile_photo: res.profile_photo_html_url,
|
profile_photo: res.profile_photo_html_url,
|
||||||
html_link: res.html_url,
|
html_link: res.html_url,
|
||||||
})
|
})
|
||||||
|
@ -496,6 +496,7 @@ impl SCDatabase for Database {
|
||||||
|
|
||||||
/// Get all repositories
|
/// Get all repositories
|
||||||
async fn get_all_repositories(&self, offset: u32, limit: u32) -> DBResult<Vec<Repository>> {
|
async fn get_all_repositories(&self, offset: u32, limit: u32) -> DBResult<Vec<Repository>> {
|
||||||
|
#[allow(non_snake_case)]
|
||||||
struct InnerRepository {
|
struct InnerRepository {
|
||||||
/// html link to the repository
|
/// html link to the repository
|
||||||
pub html_url: String,
|
pub html_url: String,
|
||||||
|
|
|
@ -32,12 +32,12 @@ pub async fn adding_forge_works<'a, T: Federate>(
|
||||||
|
|
||||||
// add user
|
// add user
|
||||||
assert!(!ff
|
assert!(!ff
|
||||||
.user_exists(&create_user_msg.username, &create_user_msg.url)
|
.user_exists(create_user_msg.username, &create_user_msg.url)
|
||||||
.await
|
.await
|
||||||
.unwrap());
|
.unwrap());
|
||||||
ff.create_user(&create_user_msg).await.unwrap();
|
ff.create_user(&create_user_msg).await.unwrap();
|
||||||
assert!(ff
|
assert!(ff
|
||||||
.user_exists(&create_user_msg.username, &create_user_msg.url)
|
.user_exists(create_user_msg.username, &create_user_msg.url)
|
||||||
.await
|
.await
|
||||||
.unwrap());
|
.unwrap());
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,7 @@ impl Federate for PccFederate {
|
||||||
|
|
||||||
/// delete forge instance
|
/// delete forge instance
|
||||||
async fn delete_forge_instance(&self, url: &Url) -> FResult<()> {
|
async fn delete_forge_instance(&self, url: &Url) -> FResult<()> {
|
||||||
let path = self.get_instance_path(&url, false).await?;
|
let path = self.get_instance_path(url, false).await?;
|
||||||
self.rm_util(&path).await
|
self.rm_util(&path).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -131,10 +131,11 @@ impl From<DBError> for ServiceError {
|
||||||
#[cfg(not(tarpaulin_include))]
|
#[cfg(not(tarpaulin_include))]
|
||||||
fn from(e: DBError) -> ServiceError {
|
fn from(e: DBError) -> ServiceError {
|
||||||
println!("from conversin: {}", e);
|
println!("from conversin: {}", e);
|
||||||
match e {
|
ServiceError::DBError(DBErrorWrapper(e))
|
||||||
// TODO: resolve all errors to ServiceError::*
|
// match e {
|
||||||
_ => ServiceError::DBError(DBErrorWrapper(e)),
|
// // TODO: resolve all errors to ServiceError::*
|
||||||
}
|
// _ => ServiceError::DBError(DBErrorWrapper(e)),
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
use actix_web::http::{self, header::ContentType};
|
use actix_web::http::{self, header::ContentType};
|
||||||
use actix_web::{HttpResponse, Responder};
|
use actix_web::{HttpResponse, Responder};
|
||||||
use actix_web_codegen_const_routes::{get, post};
|
use actix_web_codegen_const_routes::{get, post};
|
||||||
use log::info;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use tera::Context;
|
use tera::Context;
|
||||||
|
@ -97,7 +96,7 @@ pub async fn add_submit(
|
||||||
db: &BoxDB,
|
db: &BoxDB,
|
||||||
) -> ServiceResult<TXTChallenge> {
|
) -> ServiceResult<TXTChallenge> {
|
||||||
let url_hostname = Url::parse(&payload.hostname).unwrap();
|
let url_hostname = Url::parse(&payload.hostname).unwrap();
|
||||||
let key = TXTChallenge::get_challenge_txt_key(&ctx, &url_hostname);
|
let key = TXTChallenge::get_challenge_txt_key(ctx, &url_hostname);
|
||||||
if db.dns_challenge_exists(&key).await? {
|
if db.dns_challenge_exists(&key).await? {
|
||||||
let value = db.get_dns_challenge(&key).await?.value;
|
let value = db.get_dns_challenge(&key).await?.value;
|
||||||
Ok(TXTChallenge { key, value })
|
Ok(TXTChallenge { key, value })
|
||||||
|
@ -136,14 +135,9 @@ mod tests {
|
||||||
use actix_web::test;
|
use actix_web::test;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use super::AddChallenge;
|
|
||||||
use super::AddChallengePayload;
|
use super::AddChallengePayload;
|
||||||
use super::TXTChallenge;
|
use super::TXTChallenge;
|
||||||
use crate::errors::*;
|
use crate::errors::*;
|
||||||
use crate::pages::errors::*;
|
|
||||||
use crate::settings::Settings;
|
|
||||||
|
|
||||||
use db_core::prelude::*;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod isolated {
|
mod isolated {
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
use actix_web::http::{self, header::ContentType};
|
use actix_web::http::{self, header::ContentType};
|
||||||
use actix_web::{HttpResponse, Responder};
|
use actix_web::{HttpResponse, Responder};
|
||||||
use actix_web_codegen_const_routes::{get, post};
|
use actix_web_codegen_const_routes::{get, post};
|
||||||
use log::info;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use tera::Context;
|
use tera::Context;
|
||||||
|
@ -83,7 +82,7 @@ pub async fn get_verify(
|
||||||
query: web::Query<VerifyChallengePayload>,
|
query: web::Query<VerifyChallengePayload>,
|
||||||
) -> PageResult<impl Responder, VerifyChallenge> {
|
) -> PageResult<impl Responder, VerifyChallenge> {
|
||||||
let payload = query.into_inner();
|
let payload = query.into_inner();
|
||||||
let value = _get_challenge(&payload, &ctx, &db).await.map_err(|e| {
|
let value = _get_challenge(&payload, &db).await.map_err(|e| {
|
||||||
let challenge = Challenge {
|
let challenge = Challenge {
|
||||||
key: payload.hostname,
|
key: payload.hostname,
|
||||||
value: "".into(),
|
value: "".into(),
|
||||||
|
@ -103,11 +102,7 @@ pub fn services(cfg: &mut web::ServiceConfig) {
|
||||||
cfg.service(submit_verify);
|
cfg.service(submit_verify);
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn _get_challenge(
|
async fn _get_challenge(payload: &VerifyChallengePayload, db: &BoxDB) -> ServiceResult<Challenge> {
|
||||||
payload: &VerifyChallengePayload,
|
|
||||||
ctx: &ArcCtx,
|
|
||||||
db: &BoxDB,
|
|
||||||
) -> ServiceResult<Challenge> {
|
|
||||||
let value = db.get_dns_challenge(&payload.hostname).await?;
|
let value = db.get_dns_challenge(&payload.hostname).await?;
|
||||||
Ok(value)
|
Ok(value)
|
||||||
}
|
}
|
||||||
|
@ -120,7 +115,7 @@ pub async fn submit_verify(
|
||||||
federate: WebFederate,
|
federate: WebFederate,
|
||||||
) -> PageResult<impl Responder, VerifyChallenge> {
|
) -> PageResult<impl Responder, VerifyChallenge> {
|
||||||
let payload = payload.into_inner();
|
let payload = payload.into_inner();
|
||||||
let value = _get_challenge(&payload, &ctx, &db).await.map_err(|e| {
|
let value = _get_challenge(&payload, &db).await.map_err(|e| {
|
||||||
let challenge = Challenge {
|
let challenge = Challenge {
|
||||||
key: payload.hostname.clone(),
|
key: payload.hostname.clone(),
|
||||||
value: "".into(),
|
value: "".into(),
|
||||||
|
|
|
@ -90,14 +90,12 @@ impl Repository {
|
||||||
if license_path.exists() {
|
if license_path.exists() {
|
||||||
if license_path.is_dir() {
|
if license_path.is_dir() {
|
||||||
panic!("Can't create license file at {:?}", license_path);
|
panic!("Can't create license file at {:?}", license_path);
|
||||||
} else {
|
} else if !fs::read_to_string(&license_path)
|
||||||
if !fs::read_to_string(&license_path)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.contains(CC0_LICENSE_TXT)
|
.contains(CC0_LICENSE_TXT)
|
||||||
{
|
{
|
||||||
panic!("Can't create license file at {:?}", &license_path);
|
panic!("Can't create license file at {:?}", &license_path);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
fs::write(license_path, CC0_LICENSE_TXT).unwrap();
|
fs::write(license_path, CC0_LICENSE_TXT).unwrap();
|
||||||
}
|
}
|
||||||
|
@ -113,16 +111,6 @@ pub enum DBType {
|
||||||
Sqlite,
|
Sqlite,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DBType {
|
|
||||||
fn from_url(url: &Url) -> Result<Self, ConfigError> {
|
|
||||||
match url.scheme() {
|
|
||||||
"sqlite" => Ok(Self::Sqlite),
|
|
||||||
"postgres" => Ok(Self::Postgres),
|
|
||||||
_ => Err(ConfigError::Message("Unknown database type".into())),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct Database {
|
pub struct Database {
|
||||||
pub url: String,
|
pub url: String,
|
||||||
|
@ -237,20 +225,6 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::utils::get_random;
|
use crate::utils::get_random;
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn database_type_test() {
|
|
||||||
for i in ["sqlite://foo", "postgres://bar", "unknown://"].iter() {
|
|
||||||
let url = Url::parse(i).unwrap();
|
|
||||||
if i.contains("sqlite") {
|
|
||||||
assert_eq!(DBType::from_url(&url).unwrap(), DBType::Sqlite);
|
|
||||||
} else if i.contains("unknown") {
|
|
||||||
assert!(DBType::from_url(&url).is_err());
|
|
||||||
} else {
|
|
||||||
assert_eq!(DBType::from_url(&url).unwrap(), DBType::Postgres);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn root_dir_is_created_test() {
|
fn root_dir_is_created_test() {
|
||||||
let dir;
|
let dir;
|
||||||
|
|
|
@ -43,22 +43,20 @@ impl Ctx {
|
||||||
let url = forge.get_url();
|
let url = forge.get_url();
|
||||||
if !db.forge_exists(url).await.unwrap() {
|
if !db.forge_exists(url).await.unwrap() {
|
||||||
info!("[crawl][{url}] Creating forge");
|
info!("[crawl][{url}] Creating forge");
|
||||||
let mut msg = CreateForge {
|
let msg = CreateForge {
|
||||||
url: url.clone(),
|
url: url.clone(),
|
||||||
forge_type: forge.forge_type(),
|
forge_type: forge.forge_type(),
|
||||||
};
|
};
|
||||||
|
|
||||||
db.create_forge_instance(&msg).await.unwrap();
|
db.create_forge_instance(&msg).await.unwrap();
|
||||||
} else {
|
} else if !federate.forge_exists(url).await.unwrap() {
|
||||||
if !federate.forge_exists(&url).await.unwrap() {
|
let forge = db.get_forge(url).await.unwrap();
|
||||||
let forge = db.get_forge(&url).await.unwrap();
|
|
||||||
let msg = CreateForge {
|
let msg = CreateForge {
|
||||||
url: url.clone(),
|
url: url.clone(),
|
||||||
forge_type: forge.forge_type,
|
forge_type: forge.forge_type,
|
||||||
};
|
};
|
||||||
federate.create_forge_instance(&msg).await.unwrap();
|
federate.create_forge_instance(&msg).await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
info!("[crawl][{url}] Crawling. page: {page}");
|
info!("[crawl][{url}] Crawling. page: {page}");
|
||||||
|
@ -84,7 +82,7 @@ impl Ctx {
|
||||||
let msg = u.as_ref().into();
|
let msg = u.as_ref().into();
|
||||||
db.add_user(&msg).await.unwrap();
|
db.add_user(&msg).await.unwrap();
|
||||||
federate.create_user(&msg).await.unwrap();
|
federate.create_user(&msg).await.unwrap();
|
||||||
} else {
|
}
|
||||||
if !federate
|
if !federate
|
||||||
.user_exists(username, forge.get_url())
|
.user_exists(username, forge.get_url())
|
||||||
.await
|
.await
|
||||||
|
@ -94,7 +92,6 @@ impl Ctx {
|
||||||
federate.create_user(&msg).await.unwrap();
|
federate.create_user(&msg).await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for r in res.repos.iter() {
|
for r in res.repos.iter() {
|
||||||
if !db
|
if !db
|
||||||
|
@ -106,7 +103,7 @@ impl Ctx {
|
||||||
let msg = r.into();
|
let msg = r.into();
|
||||||
db.create_repository(&msg).await.unwrap();
|
db.create_repository(&msg).await.unwrap();
|
||||||
federate.create_repository(&msg).await.unwrap();
|
federate.create_repository(&msg).await.unwrap();
|
||||||
} else {
|
}
|
||||||
if !federate
|
if !federate
|
||||||
.repository_exists(&r.name, &r.owner.username, &r.url)
|
.repository_exists(&r.name, &r.owner.username, &r.url)
|
||||||
.await
|
.await
|
||||||
|
@ -116,7 +113,6 @@ impl Ctx {
|
||||||
federate.create_repository(&msg).await.unwrap();
|
federate.create_repository(&msg).await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
page += 1;
|
page += 1;
|
||||||
}
|
}
|
||||||
|
@ -126,7 +122,6 @@ impl Ctx {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::tests::sqlx_sqlite;
|
use crate::tests::sqlx_sqlite;
|
||||||
use db_core::prelude::*;
|
|
||||||
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ pub mod routes {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref ASSETS: Assets = Assets::new();
|
pub static ref ASSETS: Assets = Assets::default();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
@ -43,9 +43,9 @@ pub mod routes {
|
||||||
pub css: &'static str,
|
pub css: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Assets {
|
impl Default for Assets {
|
||||||
/// create new instance of Routes
|
/// create new instance of Routes
|
||||||
pub fn new() -> Assets {
|
fn default() -> Assets {
|
||||||
Assets {
|
Assets {
|
||||||
css: &static_files::assets::CSS,
|
css: &static_files::assets::CSS,
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,9 +67,7 @@ mod tests {
|
||||||
use actix_web::http::StatusCode;
|
use actix_web::http::StatusCode;
|
||||||
use actix_web::test;
|
use actix_web::test;
|
||||||
|
|
||||||
use crate::db::BoxDB;
|
|
||||||
use crate::tests::*;
|
use crate::tests::*;
|
||||||
use crate::ArcCtx;
|
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
use super::assets::CSS;
|
use super::assets::CSS;
|
||||||
|
|
18
src/tests.rs
18
src/tests.rs
|
@ -25,16 +25,16 @@ pub use crate::federate::{get_federate, ArcFederate};
|
||||||
use crate::settings::{DBType, Settings};
|
use crate::settings::{DBType, Settings};
|
||||||
|
|
||||||
//use actix_web::cookie::Cookie;
|
//use actix_web::cookie::Cookie;
|
||||||
use crate::errors::*;
|
//use crate::errors::*;
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use actix_web::test;
|
//use actix_web::test;
|
||||||
use actix_web::{
|
//use actix_web::{
|
||||||
body::{BoxBody, EitherBody},
|
// body::{BoxBody, EitherBody},
|
||||||
dev::ServiceResponse,
|
// dev::ServiceResponse,
|
||||||
error::ResponseError,
|
// error::ResponseError,
|
||||||
http::StatusCode,
|
// http::StatusCode,
|
||||||
};
|
//};
|
||||||
use serde::Serialize;
|
//use serde::Serialize;
|
||||||
|
|
||||||
//pub mod sqlx_postgres {
|
//pub mod sqlx_postgres {
|
||||||
// use super::*;
|
// use super::*;
|
||||||
|
|
|
@ -31,7 +31,6 @@ pub struct TXTChallenge {
|
||||||
pub value: String,
|
pub value: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
const KEY_LEN: usize = 30;
|
|
||||||
const VALUES_LEN: usize = 30;
|
const VALUES_LEN: usize = 30;
|
||||||
|
|
||||||
impl TXTChallenge {
|
impl TXTChallenge {
|
||||||
|
|
Loading…
Reference in a new issue