0
0
mirror of https://github.com/tursodatabase/libsql.git synced 2025-06-14 19:22:56 +00:00
Files
libsql/libsql-server/tests/standalone/auth.rs
ad hoc 16c6e40335 fix auth malformed token (#1102)
* add tests

* allow legacy tokens with no perm claims

* fmt
2024-02-28 14:16:27 +00:00

49 lines
1.1 KiB
Rust

use libsql::Database;
use crate::{
common::{http::Client, net::TurmoilConnector},
standalone::utils::{encode, key_pair},
};
use super::make_standalone_server;
#[test]
fn jwt_auth_namespace_access() {
let mut sim = turmoil::Builder::new().build();
sim.host("primary", make_standalone_server);
sim.client("test", async {
let client = Client::new();
let (enc, jwt_key) = key_pair();
assert!(client
.post(
"http://primary:9090/v1/namespaces/foo/create",
serde_json::json!({ "jwt_key": jwt_key })
)
.await
.unwrap()
.status()
.is_success());
let claims = serde_json::json!({
"id": "foo",
});
let token = encode(&claims, &enc);
let foo_db = Database::open_remote_with_connector(
"http://foo.primary:8080",
&token,
TurmoilConnector,
)?;
let foo_conn = foo_db.connect().unwrap();
foo_conn.execute("SELECT 1", ()).await.unwrap();
Ok(())
});
sim.run().unwrap();
}