mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-12-03 08:10:27 +00:00
* fix: read drafts in a folder just created through another token Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * perf: refresh folders once per draft listing Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: keep the identity's groups when refreshing draft folders Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
55 lines
1.9 KiB
Rust
55 lines
1.9 KiB
Rust
//! A draft read in a folder the caller just created works at once, from any of their tokens.
|
|
//!
|
|
//! The AI session tools create the folder through one token (a JWT minted per tool call) and
|
|
//! read the draft through another, whose identity was cached before the folder existed. The
|
|
//! folder has no deployed item yet, so nothing but the caller's folder set can admit the read.
|
|
|
|
use serde_json::{json, Value};
|
|
use sqlx::{Pool, Postgres};
|
|
|
|
use windmill_test_utils::*;
|
|
|
|
#[sqlx::test(fixtures("base"))]
|
|
async fn test_draft_read_in_folder_created_through_another_token(
|
|
db: Pool<Postgres>,
|
|
) -> anyhow::Result<()> {
|
|
initialize_tracing().await;
|
|
sqlx::query(
|
|
"INSERT INTO token(token_hash, token_prefix, token, email, label, super_admin)
|
|
VALUES (encode(sha256('SECOND_TOKEN_2'::bytea), 'hex'), 'SECOND_TOK', 'SECOND_TOKEN_2',
|
|
'test2@windmill.dev', 'second token', false)",
|
|
)
|
|
.execute(&db)
|
|
.await?;
|
|
let server = ApiServer::start(db.clone()).await?;
|
|
let base = format!(
|
|
"http://localhost:{}/api/w/test-workspace",
|
|
server.addr.port()
|
|
);
|
|
let client = reqwest::Client::new();
|
|
let read = || {
|
|
client
|
|
.get(format!("{base}/drafts/get_own/script/f/fresh/hello"))
|
|
.header("Authorization", "Bearer SECOND_TOKEN_2")
|
|
.send()
|
|
};
|
|
|
|
// Caches the second token's identity, without the folder.
|
|
assert_eq!(read().await?.status(), 404);
|
|
|
|
let resp = client
|
|
.post(format!("{base}/folders/create"))
|
|
.header("Authorization", "Bearer SECRET_TOKEN_2")
|
|
.json(&json!({ "name": "fresh" }))
|
|
.send()
|
|
.await?;
|
|
assert!(resp.status().is_success(), "{}", resp.text().await?);
|
|
|
|
let resp = read().await?;
|
|
let status = resp.status();
|
|
let body = resp.text().await?;
|
|
assert_eq!(status, 200, "draft read in the new folder refused: {body}");
|
|
assert_eq!(serde_json::from_str::<Value>(&body)?, Value::Null);
|
|
Ok(())
|
|
}
|