use std::collections::BTreeMap;
use std::fmt;
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub enum WebhookProfile {
GitHub,
Stripe,
Slack,
}
impl WebhookProfile {
pub(crate) fn stable_tag(self) -> &'static str {
match self {
Self::GitHub => "github",
Self::Stripe => "stripe",
Self::Slack => "slack",
}
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum WebhookPayloadSpec {
Canonical,
Raw(String),
}
impl WebhookPayloadSpec {
pub(crate) fn stable_bytes(&self) -> Vec<u8> {
match self {
Self::Canonical => b"canonical".to_vec(),
Self::Raw(payload) => {
let mut out = b"raw:".to_vec();
out.extend_from_slice(payload.as_bytes());
out
}
}
}
}
#[derive(Clone)]
pub struct WebhookFixture {
pub profile: WebhookProfile,
pub secret: String,
pub payload: String,
pub headers: BTreeMap<String, String>,
pub timestamp: i64,
pub signature_input: String,
}
impl fmt::Debug for WebhookFixture {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("WebhookFixture")
.field("profile", &self.profile)
.field("payload", &self.payload)
.field("headers", &self.headers)
.field("timestamp", &self.timestamp)
.field("signature_input", &self.signature_input)
.finish_non_exhaustive()
}
}
#[derive(Clone)]
pub struct NearMissWebhookFixture {
pub scenario: NearMissScenario,
pub profile: WebhookProfile,
pub secret: String,
pub payload: String,
pub headers: BTreeMap<String, String>,
pub timestamp: i64,
pub signature_input: String,
}
impl fmt::Debug for NearMissWebhookFixture {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("NearMissWebhookFixture")
.field("scenario", &self.scenario)
.field("profile", &self.profile)
.field("payload", &self.payload)
.field("headers", &self.headers)
.field("timestamp", &self.timestamp)
.field("signature_input", &self.signature_input)
.finish_non_exhaustive()
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum NearMissScenario {
StaleTimestamp,
WrongSecret,
TamperedPayload,
}