Skip to content
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
4 changes: 3 additions & 1 deletion src/impls/translator_impls/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1952,7 +1952,9 @@ impl crate::traits::translator::TranslatorWithContext for Statement {
Self::Grant(_) | Self::GrantRole(_) => {
drop_with_warning("GRANT", REASON_ACCESS_CONTROL, emit)
}
Self::Revoke(_) => drop_with_warning("REVOKE", REASON_ACCESS_CONTROL, emit),
Self::Revoke(_) | Self::RevokeRole(_) => {
drop_with_warning("REVOKE", REASON_ACCESS_CONTROL, emit)
}
Self::Deny { .. } => drop_with_warning("DENY", REASON_ACCESS_CONTROL, emit),
Self::CreateType { .. } => {
drop_with_warning("CREATE TYPE", REASON_TYPE_DEFINITION, emit)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_no_statement_is_silently_dropped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ const TABLE_ROLE_AND_GRANT: &str =
const TWO_ROLES: &str =
"CREATE TABLE t (id INTEGER PRIMARY KEY, a TEXT); CREATE ROLE r; CREATE ROLE u;";

/// A membership `REVOKE` removes a membership `GRANT`, so that has to exist
/// too.
const TWO_ROLES_AND_MEMBERSHIP: &str = "CREATE TABLE t (id INTEGER PRIMARY KEY, a TEXT); \
CREATE ROLE r; CREATE ROLE u; GRANT r TO u;";

const fn emitted(sql: &'static str) -> Case {
Case { setup: TABLE, sql, outcome: Outcome::Emitted }
}
Expand Down Expand Up @@ -172,6 +177,7 @@ const CASES: &[Case] = &[
outcome: Outcome::Warned,
},
Case { setup: TWO_ROLES, sql: "GRANT r TO u", outcome: Outcome::Warned },
Case { setup: TWO_ROLES_AND_MEMBERSHIP, sql: "REVOKE r FROM u", outcome: Outcome::Warned },
warned("DENY SELECT ON t TO r"),
warned("DROP ROLE r"),
warned("DROP USER r"),
Expand Down
15 changes: 15 additions & 0 deletions tests/test_translation_warnings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,21 @@ fn revoke_emits_lossy_drop_warning() {
assert_lossy_drop(&warns[2], "REVOKE");
}

#[test]
fn revoke_of_role_membership_emits_lossy_drop_warning() {
let report = Pg2Sqlite::default()
.sql("CREATE ROLE a; CREATE ROLE b; GRANT a TO b; REVOKE a FROM b;")
.expect("parse")
.translate_with_report(&Pg2SqliteOptions::default())
.expect("translate");
assert_eq!(report.script.iter().count(), 0, "expected no SQLite statement");
assert_eq!(report.warnings.len(), 4);
assert_lossy_drop(&report.warnings[0], "CREATE ROLE");
assert_lossy_drop(&report.warnings[1], "CREATE ROLE");
assert_lossy_drop(&report.warnings[2], "GRANT");
assert_lossy_drop(&report.warnings[3], "REVOKE");
}

#[test]
fn alter_role_emits_lossy_drop_warning() {
let warns = warnings_for("CREATE ROLE alice;\nALTER ROLE alice WITH SUPERUSER;");
Expand Down