Files
windmill/backend/tests/drafts_new_folder_read.rs
T
Ruben FiszelandClaude Opus 5.5 b0f7573a66 fix: read drafts in a folder just created through another token (#12778)
* 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>
2026-12-01 22:27:14 +00:00

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(())
}