Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bad attach name #1113

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libsql-server/src/auth/authenticated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl Authenticated {
Authenticated::Authorized(a) => {
if !a.has_right(Scope::Namespace(namespace.clone()), perm) {
Err(crate::Error::NotAuthorized(format!(
"Current session doest not have {perm:?} permission to namespace {namespace}")))
"Current session doesn't not have {perm:?} permission to namespace {namespace}")))
} else {
Ok(())
}
Expand Down
5 changes: 4 additions & 1 deletion libsql-server/src/query_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ impl StmtKind {
savepoint_name: Some(_),
..
}) => Some(Self::Release),
Cmd::Stmt(Stmt::Attach { db_name, .. }) => Some(Self::Attach(
Cmd::Stmt(Stmt::Attach {
expr: Expr::Id(Id(db_name)),
..
}) => Some(Self::Attach(
NamespaceName::from_string(db_name.to_string()).ok()?,
)),
Cmd::Stmt(Stmt::Detach(_)) => Some(Self::Detach),
Expand Down
28 changes: 28 additions & 0 deletions libsql-server/tests/standalone/attach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,34 @@ fn attach_auth() {
// succeeds!
assert_debug_snapshot!(rows.next().await);

// mixed claims
let claims = serde_json::json!({
"id": "foo",
"p": {
"roa": {
"ns": ["bar"]
}
}
});
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();
let txn = foo_conn.transaction().await.unwrap();
txn.execute("ATTACH DATABASE bar as attached", ())
.await
.unwrap();
let mut rows = txn
.query("SELECT * FROM attached.bar_table", ())
.await
.unwrap();
// succeeds!
assert_debug_snapshot!(rows.next().await);

Ok(())
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ expression: "txn.execute(\"ATTACH DATABASE bar as bar\", ()).await.unwrap_err()"
---
Hrana(
Api(
"{\"error\":\"Internal Error: `Not authorized to execute query: Current session doest not have AttachRead permission to namespace bar`\"}",
"{\"error\":\"Internal Error: `Not authorized to execute query: Current session doesn't not have AttachRead permission to namespace bar`\"}",
),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
source: libsql-server/tests/standalone/attach.rs
expression: rows.next().await
---
Ok(
Some(
Row {
cols: [
Col {
name: Some(
"x",
),
decltype: None,
},
],
inner: [
Integer {
value: 43,
},
],
},
),
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ expression: "bar_conn.execute(\"ATTACH foo as foo\", ()).await.unwrap_err()"
---
Hrana(
Api(
"{\"error\":\"Internal Error: `Not authorized to execute query: Current session doest not have AttachRead permission to namespace foo`\"}",
"{\"error\":\"Internal Error: `Not authorized to execute query: Current session doesn't not have AttachRead permission to namespace foo`\"}",
),
)
Loading