add implementation for no master key set and fix tests

This commit is contained in:
vishalsodani 2022-10-25 22:41:48 +05:30
parent 1cf6efa740
commit f0ecacb58d
3 changed files with 53 additions and 29 deletions

View file

@ -50,14 +50,20 @@ impl<P, D> GuardedData<P, D> {
{
match Self::authenticate(auth, String::new(), None).await? {
Some(filters) => match data {
Some(data) => Ok(Self {
data,
filters,
_marker: PhantomData,
}),
Some(data) => {
if filters.is_missing_master_key() {
Err(AuthenticationError::MissingMasterKey.into())
} else {
Ok(Self {
data,
filters,
_marker: PhantomData,
})
}
}
None => Err(AuthenticationError::IrretrievableState.into()),
},
None => Err(AuthenticationError::MissingMasterKey.into()),
None => Err(AuthenticationError::MissingAuthorizationHeader.into()),
}
}
@ -171,6 +177,9 @@ pub mod policies {
token: &str,
index: Option<&str>,
) -> Option<AuthFilter> {
if auth.get_master_key().is_none() && is_keys_action(A) {
return Some(AuthFilter::with_no_master_key());
}
// authenticate if token is the master key.
// master key can only have access to keys routes.
// if master key is None only keys routes are inaccessible.