v0.34.16
This commit is contained in:
1 parent
f27fbf6a30
commit
2c03fcf248
18 files changed
+430
-920
No files matched your search
@@ -58,10 +58,7 @@ 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(())
|
||||
}
|
||||
}
|
||||
@@ -72,11 +69,7 @@ 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));
|
||||
}
|
||||
@@ -91,25 +84,11 @@ 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());
|
||||
}
|
||||
}
|
||||
+30
-76
@@ -130,9 +130,7 @@ 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,
|
||||
@@ -141,10 +139,7 @@ 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(())
|
||||
}
|
||||
@@ -164,12 +159,9 @@ 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)
|
||||
@@ -258,69 +250,47 @@ mod tests {
|
||||
tinyauth.url = "http://127.0.0.1:3000".into();
|
||||
tinyauth.login_url = "https://auth.example.net".into();
|
||||
let oidc = oidc::Settings {
|
||||
enabled: true,
|
||||
issuer_url: "https://auth.test.com".into(),
|
||||
enabled: true, issuer_url: "https://auth.gruszczynski.cc".into(),
|
||||
backend_url: "http://127.0.0.1:9091".into(),
|
||||
client_id: "test-client".into(),
|
||||
client_secret: "test-secret".into(),
|
||||
redirect_url: "https://app.example.com/_rustproxy/oidc/callback".into(),
|
||||
client_id: "test-client".into(), client_secret: "test-secret".into(),
|
||||
redirect_url: "https://app.linuxiarz.pl/_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.test.com".into();
|
||||
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.example.com/_rustproxy/oidc/callback".into();
|
||||
for provider in [
|
||||
IdentityProvider::Tinyauth,
|
||||
IdentityProvider::Authelia,
|
||||
IdentityProvider::Authentik,
|
||||
IdentityProvider::PocketId,
|
||||
IdentityProvider::Custom,
|
||||
] {
|
||||
oidc.redirect_url = "https://app.linuxiarz.pl/_rustproxy/oidc/callback".into();
|
||||
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]
|
||||
@@ -333,32 +303,16 @@ mod tests {
|
||||
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