()
| 192 | |
| 193 | #[test] |
| 194 | fn test_role_assignment() { |
| 195 | let fixture = TestFixture::empty().expect("Failed to create test fixture"); |
| 196 | |
| 197 | // Create roles and users for assignment testing |
| 198 | let if_not_exists_result = fixture.query("CREATE ROLE IF NOT EXISTS 'admin'"); |
| 199 | if if_not_exists_result.is_ok() { |
| 200 | fixture.assert_query_succeeds("CREATE ROLE IF NOT EXISTS 'editor'"); |
| 201 | } else { |
| 202 | // Try creating the roles, but handle the case where they already exist |
| 203 | let _ = fixture.query("CREATE ROLE 'admin'"); |
| 204 | let _ = fixture.query("CREATE ROLE 'editor'"); |
| 205 | } |
| 206 | let if_not_exists_result = |
| 207 | fixture.query("CREATE USER IF NOT EXISTS 'testuser' PASSWORD 'password'"); |
| 208 | if if_not_exists_result.is_err() { |
| 209 | fixture.assert_query_succeeds("CREATE USER 'testuser' PASSWORD 'password'"); |
| 210 | } |
| 211 | |
| 212 | // Test role assignment (if GRANT ROLE is implemented) |
| 213 | // Note: This might not be implemented yet, so we'll make it conditional |
| 214 | let grant_result = fixture.query("GRANT ROLE 'admin' TO 'testuser'"); |
| 215 | if grant_result.is_ok() { |
| 216 | // Test multiple role assignment |
| 217 | fixture.assert_query_succeeds("GRANT ROLE 'editor' TO 'testuser'"); |
| 218 | |
| 219 | // Verify roles in user listing |
| 220 | let result = fixture.assert_query_succeeds("CALL gql.list_users()"); |
| 221 | let test_user_row = result.rows.iter().find(|row| { |
| 222 | if let Some(Value::String(username)) = row.values.get("username") { |
| 223 | username == "testuser" |
| 224 | } else { |
| 225 | false |
| 226 | } |
| 227 | }); |
| 228 | |
| 229 | if let Some(user_row) = test_user_row { |
| 230 | if let Some(Value::String(roles)) = user_row.values.get("roles") { |
| 231 | assert!(roles.contains("admin"), "User should have admin role"); |
| 232 | assert!(roles.contains("editor"), "User should have editor role"); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | // Test role revocation |
| 237 | fixture.assert_query_succeeds("REVOKE ROLE 'editor' FROM 'testuser'"); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | #[test] |
| 242 | fn test_authentication() { |
nothing calls this directly
no test coverage detected