This commit is contained in:
parent
946a51e3ad
commit
b2eeb5b9fd
5 changed files with 8 additions and 11 deletions
|
@ -184,7 +184,7 @@ mod tests {
|
|||
assert_eq!(hook, response);
|
||||
|
||||
let list_all_webhooks_resp =
|
||||
get_request!(&app, &V1_API_ROUTES.forgejo.list_webhooks, cookies.clone());
|
||||
get_request!(&app, V1_API_ROUTES.forgejo.list_webhooks, cookies.clone());
|
||||
check_status!(list_all_webhooks_resp, StatusCode::OK);
|
||||
let hooks: Vec<ForgejoWebhook> =
|
||||
actix_web::test::read_body_json(list_all_webhooks_resp).await;
|
||||
|
@ -201,7 +201,7 @@ mod tests {
|
|||
let body = body.as_bytes();
|
||||
let mut mac = HmacSha256::new_from_slice(hook.forgejo_webhook_secret.as_bytes())
|
||||
.expect("HMAC can take key of any size");
|
||||
mac.update(&body);
|
||||
mac.update(body);
|
||||
let res = mac.finalize();
|
||||
let sig = res.into_bytes();
|
||||
let sig = hex::encode(&sig[..]);
|
||||
|
@ -227,7 +227,7 @@ mod tests {
|
|||
let body = body.as_bytes();
|
||||
let mut mac =
|
||||
HmacSha256::new_from_slice(b"nosecret").expect("HMAC can take key of any size");
|
||||
mac.update(&body);
|
||||
mac.update(body);
|
||||
let res = mac.finalize();
|
||||
let fake_sig = res.into_bytes();
|
||||
let fake_sig = hex::encode(&fake_sig[..]);
|
||||
|
@ -257,7 +257,7 @@ mod tests {
|
|||
let body = body.as_bytes();
|
||||
let mut mac = HmacSha256::new_from_slice(hook.forgejo_webhook_secret.as_bytes())
|
||||
.expect("HMAC can take key of any size");
|
||||
mac.update(&body);
|
||||
mac.update(body);
|
||||
let res = mac.finalize();
|
||||
let sig = res.into_bytes();
|
||||
let sig = hex::encode(&sig[..]);
|
||||
|
|
|
@ -160,7 +160,7 @@ impl Ctx {
|
|||
let sig = hex::decode(sig).unwrap();
|
||||
let event_type = headers.get("X-Gitea-Event").unwrap();
|
||||
|
||||
let payload: WebhookPayload = serde_json::from_slice(&body).unwrap();
|
||||
let payload: WebhookPayload = serde_json::from_slice(body).unwrap();
|
||||
|
||||
let hook = self.db.get_webhook(auth_token).await?;
|
||||
|
||||
|
@ -171,7 +171,7 @@ impl Ctx {
|
|||
] {
|
||||
if self.db.site_with_repository_exists(url).await? {
|
||||
let mut mac = HmacSha256::new_from_slice(hook.forgejo_webhook_secret.as_bytes())?;
|
||||
mac.update(&body);
|
||||
mac.update(body);
|
||||
mac.verify_slice(&sig[..])?;
|
||||
|
||||
let site = self.db.get_site_from_repo_url(url).await?;
|
||||
|
|
|
@ -170,7 +170,7 @@ mod tests {
|
|||
let resp = get_request!(&app, PAGES.dash.forgejo_webhook.list, cookies.clone());
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
let res = String::from_utf8(test::read_body(resp).await.to_vec()).unwrap();
|
||||
assert!(res.contains(&hook.forgejo_url.as_str()));
|
||||
assert!(res.contains(hook.forgejo_url.as_str()));
|
||||
|
||||
// view webhook
|
||||
let resp = get_request!(&app, &view_webhook_url, cookies.clone());
|
||||
|
|
|
@ -18,7 +18,7 @@ use std::cell::RefCell;
|
|||
|
||||
use actix_identity::Identity;
|
||||
use actix_web::http::header::ContentType;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use tera::Context;
|
||||
|
||||
use super::get_auth_middleware;
|
||||
|
|
|
@ -20,12 +20,9 @@ use actix_identity::Identity;
|
|||
use actix_web::http::header::ContentType;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tera::Context;
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::get_auth_middleware;
|
||||
|
||||
use crate::db::Site;
|
||||
use crate::pages::dash::TemplateSiteEvent;
|
||||
use crate::pages::errors::*;
|
||||
use crate::settings::Settings;
|
||||
use crate::AppCtx;
|
||||
|
|
Loading…
Reference in a new issue