v0.35.0
This commit is contained in:
1 parent
2c03fcf248
commit
d3b492874b
95 files changed
+1628
-743
No files matched your search
@@ -58,7 +58,10 @@ pub struct Choice {
|
||||
}
|
||||
impl Choice {
|
||||
pub fn validate(self) -> Result<()> {
|
||||
ensure!(self.provider.supports(self.method), "unsupported authentication provider and integration method combination");
|
||||
ensure!(
|
||||
self.provider.supports(self.method),
|
||||
"unsupported authentication provider and integration method combination"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -69,7 +72,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn supported_methods_are_explicit_and_reject_invalid_pairs() {
|
||||
for provider in [IdentityProvider::Tinyauth, IdentityProvider::Authelia, IdentityProvider::Authentik] {
|
||||
for provider in [
|
||||
IdentityProvider::Tinyauth,
|
||||
IdentityProvider::Authelia,
|
||||
IdentityProvider::Authentik,
|
||||
] {
|
||||
assert!(provider.supports(IntegrationMethod::ForwardAuth));
|
||||
assert!(provider.supports(IntegrationMethod::Oidc));
|
||||
}
|
||||
@@ -84,11 +91,25 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn selection_serializes_as_independent_provider_and_method() {
|
||||
let selection = Choice { provider: IdentityProvider::Authelia, method: IntegrationMethod::Oidc };
|
||||
let selection = Choice {
|
||||
provider: IdentityProvider::Authelia,
|
||||
method: IntegrationMethod::Oidc,
|
||||
};
|
||||
let json = serde_json::to_value(selection).unwrap();
|
||||
assert_eq!(json, serde_json::json!({"provider":"authelia","method":"oidc"}));
|
||||
assert_eq!(
|
||||
json,
|
||||
serde_json::json!({"provider":"authelia","method":"oidc"})
|
||||
);
|
||||
assert_eq!(serde_json::from_value::<Choice>(json).unwrap(), selection);
|
||||
assert!(serde_json::from_value::<Choice>(serde_json::json!({"provider":"pocket_id","method":"forward_auth"})).unwrap().validate().is_err());
|
||||
assert!(serde_json::from_value::<Choice>(serde_json::json!({"provider":"unknown","method":"oidc"})).is_err());
|
||||
assert!(serde_json::from_value::<Choice>(
|
||||
serde_json::json!({"provider":"pocket_id","method":"forward_auth"})
|
||||
)
|
||||
.unwrap()
|
||||
.validate()
|
||||
.is_err());
|
||||
assert!(serde_json::from_value::<Choice>(
|
||||
serde_json::json!({"provider":"unknown","method":"oidc"})
|
||||
)
|
||||
.is_err());
|
||||
}
|
||||
}
|
||||
+96
-43
@@ -88,6 +88,7 @@ impl Compiled {
|
||||
) -> Option<Route<'a>> {
|
||||
self.0.serve_reserved(request, context, shutdown)
|
||||
}
|
||||
#[allow(clippy::result_large_err)]
|
||||
pub async fn authorize(
|
||||
&self,
|
||||
incoming: &HeaderMap,
|
||||
@@ -130,7 +131,9 @@ impl Selection<'_> {
|
||||
if let Some(choice) = self.choice {
|
||||
choice.validate()?;
|
||||
let matches_configuration = match choice.method {
|
||||
IntegrationMethod::Basic => self.basic_enabled && choice.provider == IdentityProvider::Basic,
|
||||
IntegrationMethod::Basic => {
|
||||
self.basic_enabled && choice.provider == IdentityProvider::Basic
|
||||
}
|
||||
IntegrationMethod::ForwardAuth => match choice.provider {
|
||||
IdentityProvider::Tinyauth => self.tinyauth.enabled,
|
||||
IdentityProvider::Authelia => self.authelia.enabled,
|
||||
@@ -139,7 +142,10 @@ impl Selection<'_> {
|
||||
},
|
||||
IntegrationMethod::Oidc => self.oidc.enabled,
|
||||
};
|
||||
ensure!(matches_configuration, "authentication selection does not match the enabled settings");
|
||||
ensure!(
|
||||
matches_configuration,
|
||||
"authentication selection does not match the enabled settings"
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -159,9 +165,12 @@ impl Selection<'_> {
|
||||
return Ok(self.authentik.compile(policy, bindings)?.map(Compiled::new));
|
||||
}
|
||||
if self.oidc.enabled {
|
||||
let (id, label) = self.choice.map_or(("oidc", "OIDC"),
|
||||
|choice| (choice.provider.id(), choice.provider.display_name()));
|
||||
return Ok(self.oidc.compile(policy, bindings)?
|
||||
let (id, label) = self.choice.map_or(("oidc", "OIDC"), |choice| {
|
||||
(choice.provider.id(), choice.provider.display_name())
|
||||
});
|
||||
return Ok(self
|
||||
.oidc
|
||||
.compile(policy, bindings)?
|
||||
.map(|provider| Compiled::new(provider.with_provider(id, label))));
|
||||
}
|
||||
Ok(None)
|
||||
@@ -245,74 +254,118 @@ mod tests {
|
||||
}
|
||||
#[test]
|
||||
fn oidc_is_exclusive_and_missing_legacy_values_remain_disabled() {
|
||||
let mut tinyauth = tinyauth::Settings::default();
|
||||
tinyauth.enabled = true;
|
||||
tinyauth.url = "http://127.0.0.1:3000".into();
|
||||
tinyauth.login_url = "https://auth.example.net".into();
|
||||
let tinyauth = tinyauth::Settings {
|
||||
enabled: true,
|
||||
url: "http://127.0.0.1:3000".into(),
|
||||
login_url: "https://auth.example.net".into(),
|
||||
..Default::default()
|
||||
};
|
||||
let oidc = oidc::Settings {
|
||||
enabled: true, issuer_url: "https://auth.gruszczynski.cc".into(),
|
||||
enabled: true,
|
||||
issuer_url: "https://auth.example.com".into(),
|
||||
backend_url: "http://127.0.0.1:9091".into(),
|
||||
client_id: "test-client".into(), client_secret: "test-secret".into(),
|
||||
redirect_url: "https://app.linuxiarz.pl/_rustproxy/oidc/callback".into(),
|
||||
client_id: "test-client".into(),
|
||||
client_secret: "test-secret".into(),
|
||||
redirect_url: "https://app.example.com/_rustproxy/oidc/callback".into(),
|
||||
session_secret: "long-session-secret-at-least-32-characters".into(),
|
||||
..oidc::Settings::default()
|
||||
};
|
||||
assert!(Selection {
|
||||
choice: None,
|
||||
basic_enabled: false, tinyauth: &tinyauth,
|
||||
basic_enabled: false,
|
||||
tinyauth: &tinyauth,
|
||||
authelia: &authelia::Settings::default(),
|
||||
authentik: &authentik::Settings::default(), oidc: &oidc,
|
||||
}.validate().is_err());
|
||||
authentik: &authentik::Settings::default(),
|
||||
oidc: &oidc,
|
||||
}
|
||||
.validate()
|
||||
.is_err());
|
||||
}
|
||||
#[test]
|
||||
fn oidc_identity_provider_is_independent_of_integration_method() {
|
||||
let mut oidc = oidc::Settings::default();
|
||||
oidc.enabled = true;
|
||||
oidc.issuer_url = "https://auth.gruszczynski.cc".into();
|
||||
oidc.client_id = "rustproxy-test".into();
|
||||
oidc.client_secret = "test-client-secret".into();
|
||||
oidc.session_secret = "a-long-random-value-for-testing-oidc-sessions".into();
|
||||
oidc.redirect_url = "https://app.linuxiarz.pl/_rustproxy/oidc/callback".into();
|
||||
for provider in [IdentityProvider::Tinyauth, IdentityProvider::Authelia,
|
||||
IdentityProvider::Authentik, IdentityProvider::PocketId,
|
||||
IdentityProvider::Custom] {
|
||||
let oidc = oidc::Settings {
|
||||
enabled: true,
|
||||
issuer_url: "https://auth.example.com".into(),
|
||||
client_id: "rustproxy-test".into(),
|
||||
client_secret: "test-client-secret".into(),
|
||||
session_secret: "a-long-random-value-for-testing-oidc-sessions".into(),
|
||||
redirect_url: "https://app.example.com/_rustproxy/oidc/callback".into(),
|
||||
..Default::default()
|
||||
};
|
||||
for provider in [
|
||||
IdentityProvider::Tinyauth,
|
||||
IdentityProvider::Authelia,
|
||||
IdentityProvider::Authentik,
|
||||
IdentityProvider::PocketId,
|
||||
IdentityProvider::Custom,
|
||||
] {
|
||||
assert!(Selection {
|
||||
choice: Some(Choice { provider, method: IntegrationMethod::Oidc }),
|
||||
choice: Some(Choice {
|
||||
provider,
|
||||
method: IntegrationMethod::Oidc
|
||||
}),
|
||||
basic_enabled: false,
|
||||
tinyauth: &tinyauth::Settings::default(),
|
||||
authelia: &authelia::Settings::default(),
|
||||
authentik: &authentik::Settings::default(),
|
||||
oidc: &oidc,
|
||||
}.validate().is_ok());
|
||||
}
|
||||
.validate()
|
||||
.is_ok());
|
||||
}
|
||||
assert!(Selection {
|
||||
choice: Some(Choice { provider: IdentityProvider::Authelia, method: IntegrationMethod::ForwardAuth }),
|
||||
basic_enabled: false, tinyauth: &tinyauth::Settings::default(),
|
||||
authelia: &authelia::Settings::default(), authentik: &authentik::Settings::default(),
|
||||
choice: Some(Choice {
|
||||
provider: IdentityProvider::Authelia,
|
||||
method: IntegrationMethod::ForwardAuth
|
||||
}),
|
||||
basic_enabled: false,
|
||||
tinyauth: &tinyauth::Settings::default(),
|
||||
authelia: &authelia::Settings::default(),
|
||||
authentik: &authentik::Settings::default(),
|
||||
oidc: &oidc,
|
||||
}.validate().is_err());
|
||||
}
|
||||
.validate()
|
||||
.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_new_selection_cannot_silently_disable_or_switch_authentication() {
|
||||
let mut tinyauth = tinyauth::Settings::default();
|
||||
tinyauth.enabled = true;
|
||||
tinyauth.url = "http://10.0.0.2:3000".into();
|
||||
tinyauth.login_url = "https://auth.example.com".into();
|
||||
let tinyauth = tinyauth::Settings {
|
||||
enabled: true,
|
||||
url: "http://10.0.0.2:3000".into(),
|
||||
login_url: "https://auth.example.com".into(),
|
||||
..Default::default()
|
||||
};
|
||||
let authelia = authelia::Settings::default();
|
||||
let authentik = authentik::Settings::default();
|
||||
let oidc = oidc::Settings::default();
|
||||
let selection = |choice| Selection {
|
||||
choice, basic_enabled: false, tinyauth: &tinyauth,
|
||||
authelia: &authelia, authentik: &authentik, oidc: &oidc,
|
||||
choice,
|
||||
basic_enabled: false,
|
||||
tinyauth: &tinyauth,
|
||||
authelia: &authelia,
|
||||
authentik: &authentik,
|
||||
oidc: &oidc,
|
||||
};
|
||||
assert!(selection(None).validate().is_ok());
|
||||
assert!(selection(Some(Choice { provider: IdentityProvider::Tinyauth,
|
||||
method: IntegrationMethod::ForwardAuth })).validate().is_ok());
|
||||
assert!(selection(Some(Choice { provider: IdentityProvider::Authelia,
|
||||
method: IntegrationMethod::ForwardAuth })).validate().is_err());
|
||||
assert!(selection(Some(Choice { provider: IdentityProvider::Tinyauth,
|
||||
method: IntegrationMethod::Oidc })).validate().is_err());
|
||||
assert!(selection(Some(Choice {
|
||||
provider: IdentityProvider::Tinyauth,
|
||||
method: IntegrationMethod::ForwardAuth
|
||||
}))
|
||||
.validate()
|
||||
.is_ok());
|
||||
assert!(selection(Some(Choice {
|
||||
provider: IdentityProvider::Authelia,
|
||||
method: IntegrationMethod::ForwardAuth
|
||||
}))
|
||||
.validate()
|
||||
.is_err());
|
||||
assert!(selection(Some(Choice {
|
||||
provider: IdentityProvider::Tinyauth,
|
||||
method: IntegrationMethod::Oidc
|
||||
}))
|
||||
.validate()
|
||||
.is_err());
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
||||
Reference in new issue
Block a user