RYCS2BYFBJYX4ORZZ7GRWV2LW6B7FUGZYKZQFELANAUEVMKTHJNAC
GD7FCQ2KD5YJQ3UDLAWNJQUAUK4LTHMPFVGHMUAWMKNIBYZWK2NAC
CMY6YHG36OX27OCWAENW2FQ3AKBR52XY3OBLKG5RY3D62UZ4BGUQC
I43RAQTR6WY7KFUFBU5ALAWSNNQZPHSHATOVXFCERQRFTTK5OHNQC
NO2FEJLRL533XIWZA5ZY67GVDM42K4L5SCO5WI3PX3UTC52WN46QC
Z63HIZPS4WOEDXVLOLVIHNZI2IMXCFCFBIHHM65EQ7SGJRX6BVCAC
SZIYDOFDBT2H224T5Y6WGL6TFIKOMKGPS7T3NCGVFN7EQOLIHA6AC
TWIZ7QV4GCTQK743IKZSOJCIAEX62GZHFIYGOIFCFGIBOGPSY2WAC
FS2NWBVN2SZB2FFPB3JSYT5URTVZEAZWMQ7QW4JUYPNJVDVAJTTQC
W2ZEVC64ORZWKRPSQ3JFLIV54FYOTHIK2VW7H7HASO3Z6RC66LSQC
WSHUT37CPBBR5JHWAHR27BKOADUWPUHYBWBJPNI6TEQ47TDWTL7QC
DSWQKJRHGLKXUDXKMRXCIQZKEGXYV3H5LPUMGSV4HQ4HYPTI47GQC
E4OBIIUBGNDXK577XK573TLN4DYLS32GJGXY6J7TOWFHESTEZZNAC
W3M3C7CCWHJWRWHULDWO45D3OFD4NL3V4OTJVIJCYRQG57Z2JTWQC
S6TFYMRGWC4PSRLQ4OAKE2Z3JFEVGF3RZ5Z3MEN5XSA4INPQILOAC
mod common;
pub use common::*;
use rocket::http::Status;
#[tokio::test]
async fn unauthenticated_apply_denied() {
let client = common::testing_client().await;
let db = rocket::State::get(&client.rocket()).expect("managed database");
let project = common::project(db).await;
let resp = client.post(format!("/{}/{}/.pijul?ABCD", project.owner(db).await.unwrap().name, project.name))
.dispatch().await;
assert_eq!(resp.status(), Status::NotFound);
}
use rand::Rng;
const CHARSET: &[u8] = b"abcdefghijklmnopqrstuvwxyz0123456789";
let mut rng = rand::thread_rng();
let username: String = (0..12)
.map(|_| {
let idx = rng.gen_range(0..CHARSET.len());
CHARSET[idx] as char
})
.collect();
let username = random_name();
use nidobyte::models::projects;
pub async fn project(db: &rocket::State<Database>) -> projects::Project {
let owner = user(db).await;
projects::create(db, owner.id, random_name()).await.unwrap()
}
use rand::Rng;
fn random_name() -> String {
const CHARSET: &[u8] = b"abcdefghijklmnopqrstuvwxyz0123456789";
let mut rng = rand::thread_rng();
(0..12) .map(|_| {
let idx = rng.gen_range(0..CHARSET.len());
CHARSET[idx] as char
})
.collect()
}
impl PartialEq for User {
fn eq(&self, other: &Self) -> bool {
self.id == other.id
}
}
impl Eq for User {}
pub fn init_or_open(root: &PathBuf, repo_path: PathBuf) -> Result<Self, anyhow::Error> {
let repo = Self::new(root.join(repo_path));
pub fn init_or_open(project: &'r Project, root: &PathBuf) -> Result<Self, anyhow::Error> {
let repo = Self::new(project, root.join(project.repo_path()));
use crate::models::{pijul::repositories::Repository, users::User};
pub async fn can_apply_patch(
db: &rocket::State<crate::database::Database>,
user: &User,
repo: &Repository<'_>,
) -> bool {
let owner = repo.owner(db).await;
owner.is_ok() && owner.unwrap() == *user
}