Skip to content

Commit 48f8333

Browse files
authored
Check auth for every record in list resp (#187)
1 parent 8d12cb8 commit 48f8333

File tree

2 files changed

+50
-23
lines changed

2 files changed

+50
-23
lines changed

indexer/src/lib.rs

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ impl<A: IndexerAdaptor> Indexer<A> {
120120
Ok(Some(record))
121121
}
122122

123-
pub async fn list(
124-
&self,
125-
collection_id: &str,
126-
query: ListQuery<'_>,
127-
public_key: Option<&PublicKey>,
123+
pub async fn list<'a>(
124+
&'a self,
125+
collection_id: &'a str,
126+
query: ListQuery<'a>,
127+
public_key: Option<&'a PublicKey>,
128128
) -> Result<Pin<Box<dyn futures::Stream<Item = RecordRoot> + '_ + Send>>> {
129129
let schema = self.get_schema_required(collection_id).await?;
130130

@@ -137,12 +137,12 @@ impl<A: IndexerAdaptor> Indexer<A> {
137137
return Err(UserError::NoIndexFoundMatchingTheQuery)?;
138138
};
139139

140-
if !self
141-
.verify_list(collection_id, &schema, &query.where_query, public_key)
142-
.await
143-
{
144-
return Err(UserError::UnauthorizedRead)?;
145-
};
140+
// if !self
141+
// .verify_list(collection_id, &schema, &query.where_query, public_key)
142+
// .await
143+
// {
144+
// return Err(UserError::UnauthorizedRead)?;
145+
// };
146146

147147
let ListQuery {
148148
limit,
@@ -172,10 +172,26 @@ impl<A: IndexerAdaptor> Indexer<A> {
172172

173173
where_query.cast(&schema)?;
174174

175-
Ok(self
176-
.adaptor
177-
.list(collection_id, limit, where_query, order_by, reverse)
178-
.await?)
175+
let schema = std::sync::Arc::new(schema);
176+
177+
Ok(Box::pin(
178+
self.adaptor
179+
.list(collection_id, limit, where_query, order_by, reverse)
180+
.await?
181+
.filter(move |r| {
182+
let r = r.clone();
183+
let schema = schema.clone();
184+
async move {
185+
self.verify_read(
186+
collection_id,
187+
&std::sync::Arc::clone(&schema),
188+
&r,
189+
public_key,
190+
)
191+
.await
192+
}
193+
}),
194+
))
179195
}
180196

181197
pub async fn last_record_update(

polybase/tests/api/auth.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,19 +304,30 @@ collection Account {
304304
);
305305

306306
// Listing records with a different key returns 0 records
307+
// TODO: remove this once we add pre-auth on list queries
307308
assert_eq!(
308309
collection
309310
.list(ListQuery::default(), Some(&another_signer))
310311
.await
311-
.unwrap_err(),
312-
Error {
313-
error: ErrorData {
314-
code: "permission-denied".to_string(),
315-
reason: "unauthorized".to_string(),
316-
message: "unauthorized read".to_string(),
317-
}
318-
}
312+
.unwrap()
313+
.into_record_data(),
314+
vec![]
319315
);
316+
317+
// TODO: add this back in once we add pre-auth on list queries
318+
// assert_eq!(
319+
// collection
320+
// .list(ListQuery::default(), Some(&another_signer))
321+
// .await
322+
// .unwrap_err(),
323+
// Error {
324+
// error: ErrorData {
325+
// code: "permission-denied".to_string(),
326+
// reason: "unauthorized".to_string(),
327+
// message: "unauthorized read".to_string(),
328+
// }
329+
// }
330+
// );
320331
}
321332

322333
#[tokio::test]

0 commit comments

Comments
 (0)