aboutsummaryrefslogtreecommitdiffstats
path: root/src/access/token.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/access/token.rs')
-rw-r--r--src/access/token.rs41
1 files changed, 19 insertions, 22 deletions
diff --git a/src/access/token.rs b/src/access/token.rs
index 650a5c4..073d1e4 100644
--- a/src/access/token.rs
+++ b/src/access/token.rs
@@ -17,7 +17,8 @@ use base64::{Engine, engine::general_purpose::URL_SAFE_NO_PAD as BASE64URL};
use serde::{Deserialize, Serialize};
use super::{Capability, registry};
-use crate::document::{ReadDoc, meta, store};
+use crate::document::meta;
+use crate::document::view::{self, Read};
use crate::identity::{self, NodeKey};
const PREFIX: &str = "ct1.";
@@ -117,7 +118,7 @@ pub(crate) enum Refused {
/// (`registry::User::tokens_not_before`), of a session not ended
/// (`registry::session_ended`).
pub(crate) fn verify(
- doc: &impl ReadDoc,
+ doc: &impl Read,
token: &str,
swarm: &str,
now: u64,
@@ -161,11 +162,7 @@ pub(crate) fn verify(
/// store, only one it issued itself (`docs/store.md`, Members), as a node there is
/// whoever its operator lets in, and lets in nobody's but its own.
#[cfg(feature = "federation")]
-pub(crate) fn issued_here(
- doc: &impl ReadDoc,
- local: &str,
- claims: Claims,
-) -> Result<Claims, Refused> {
+pub(crate) fn issued_here(doc: &impl Read, local: &str, claims: Claims) -> Result<Claims, Refused> {
match super::policy::of(doc) {
super::policy::Policy::Store(_) if claims.issuer != local => Err(Refused::ElsewhereIssued),
_ => Ok(claims),
@@ -176,14 +173,14 @@ pub(crate) fn issued_here(
/// its issuer a member and not banned, its user registered, enabled, its tokens not
/// revoked since and its session not ended. What a stream opened with it is judged by
/// as the document changes (`api::login::streams_end`).
-pub(crate) fn still_taken(doc: &impl ReadDoc, claims: &Claims) -> Result<(), Refused> {
+pub(crate) fn still_taken(doc: &impl Read, claims: &Claims) -> Result<(), Refused> {
issuer_counts(doc, claims)?;
user_counts(doc, claims)
}
/// Its issuer a member of the swarm, not banned.
-fn issuer_counts(doc: &impl ReadDoc, claims: &Claims) -> Result<(), Refused> {
- let member = store::read_path(doc, &meta::path(&[meta::MEMBERS, &claims.issuer]))
+fn issuer_counts(doc: &impl Read, claims: &Claims) -> Result<(), Refused> {
+ let member = view::read_path(doc, &meta::path(&[meta::MEMBERS, &claims.issuer]))
.ok()
.flatten()
.is_some();
@@ -198,7 +195,7 @@ fn issuer_counts(doc: &impl ReadDoc, claims: &Claims) -> Result<(), Refused> {
/// In a swarm with a registry: its user registered, enabled, its tokens not revoked
/// since it was issued, its session not ended.
-fn user_counts(doc: &impl ReadDoc, claims: &Claims) -> Result<(), Refused> {
+fn user_counts(doc: &impl Read, claims: &Claims) -> Result<(), Refused> {
user_taken(doc, &claims.user)?;
if let Some(user) = registry::user(doc, &claims.user) {
if claims.iat < user.tokens_not_before {
@@ -214,7 +211,7 @@ fn user_counts(doc: &impl ReadDoc, claims: &Claims) -> Result<(), Refused> {
/// In a swarm with a registry: user `name` registered and enabled. What a stream opened
/// by password or a proxy's header is judged by as the document changes
/// (`api::login::streams_end`), as one opened with a token is by `still_taken`.
-pub(crate) fn user_taken(doc: &impl ReadDoc, name: &str) -> Result<(), Refused> {
+pub(crate) fn user_taken(doc: &impl Read, name: &str) -> Result<(), Refused> {
if registry::exists(doc) {
let user = registry::user(doc, name).ok_or(Refused::UnknownUser)?;
if user.disabled {
@@ -256,7 +253,7 @@ mod tests {
fn member(doc: &mut Document, key: &NodeKey) {
let path = meta::path(&[meta::MEMBERS, &key.id()]);
- change(doc, |tx| store::write_path(tx, &path, &json!({})).unwrap());
+ change(doc, |tx| view::write_path(tx, &path, &json!({})).unwrap());
}
/// A party's session names the key it logged in with, which a token of a user's
@@ -374,7 +371,7 @@ mod tests {
let ban = crate::access::bans::path(&key.id());
let mut banned = doc.fork();
change(&mut banned, |tx| {
- store::write_path(tx, &ban, &json!({"reason": "lost"})).unwrap()
+ view::write_path(tx, &ban, &json!({"reason": "lost"})).unwrap()
});
assert_eq!(
verify(&banned, &token, "s", 1_500),
@@ -405,24 +402,24 @@ mod tests {
assert!(verify(&doc, &token, "s", 1_500).is_ok());
let bob = registry::entry("x", 0, &registry::all_caps());
change(&mut doc, |tx| {
- store::write_path(tx, &registry::user_path("bob"), &bob).unwrap()
+ view::write_path(tx, &registry::user_path("bob"), &bob).unwrap()
});
assert_eq!(verify(&doc, &token, "s", 1_500), Err(Refused::UnknownUser));
let mut alice = registry::entry("x", 0, &[(Vec::new(), &[Right::Read][..])]);
change(&mut doc, |tx| {
- store::write_path(tx, &registry::user_path("alice"), &alice).unwrap();
- store::write_path(tx, &registry::logouts_path("alice"), &json!(1_000)).unwrap()
+ view::write_path(tx, &registry::user_path("alice"), &alice).unwrap();
+ view::write_path(tx, &registry::logouts_path("alice"), &json!(1_000)).unwrap()
});
assert!(verify(&doc, &token, "s", 1_500).is_ok());
change(&mut doc, |tx| {
- store::write_path(tx, &registry::logouts_path("alice"), &json!(1_001)).unwrap()
+ view::write_path(tx, &registry::logouts_path("alice"), &json!(1_001)).unwrap()
});
assert_eq!(verify(&doc, &token, "s", 1_500), Err(Refused::Revoked));
// One session ended: its tokens refused, another's taken.
let session = claims_of(&token).session;
change(&mut doc, |tx| {
- store::write_path(tx, &registry::logouts_path("alice"), &json!(0)).unwrap();
- store::write_path(
+ view::write_path(tx, &registry::logouts_path("alice"), &json!(0)).unwrap();
+ view::write_path(
tx,
&registry::session_path("alice", &session),
&json!(10_000),
@@ -433,8 +430,8 @@ mod tests {
assert!(verify(&doc, &issue(&key, &claims(&key)), "s", 1_500).is_ok());
alice["disabled"] = json!(true);
change(&mut doc, |tx| {
- store::write_path(tx, &registry::logouts_path("alice"), &json!(0)).unwrap();
- store::write_path(tx, &registry::user_path("alice"), &alice).unwrap()
+ view::write_path(tx, &registry::logouts_path("alice"), &json!(0)).unwrap();
+ view::write_path(tx, &registry::user_path("alice"), &alice).unwrap()
});
assert_eq!(verify(&doc, &token, "s", 1_500), Err(Refused::Disabled));
}