(self)
| 1194 | @async_client_context.require_auth |
| 1195 | @async_client_context.require_no_fips |
| 1196 | async def test_auth_from_uri(self): |
| 1197 | host, port = await async_client_context.host, await async_client_context.port |
| 1198 | await async_client_context.create_user("admin", "admin", "pass") |
| 1199 | self.addAsyncCleanup(async_client_context.drop_user, "admin", "admin") |
| 1200 | self.addAsyncCleanup(remove_all_users, self.client.pymongo_test) |
| 1201 | |
| 1202 | await async_client_context.create_user( |
| 1203 | "pymongo_test", "user", "pass", roles=["userAdmin", "readWrite"] |
| 1204 | ) |
| 1205 | |
| 1206 | with self.assertRaises(OperationFailure): |
| 1207 | await connected( |
| 1208 | await self.async_rs_or_single_client_noauth("mongodb://a:b@%s:%d" % (host, port)) |
| 1209 | ) |
| 1210 | |
| 1211 | # No error. |
| 1212 | await connected( |
| 1213 | await self.async_rs_or_single_client_noauth("mongodb://admin:pass@%s:%d" % (host, port)) |
| 1214 | ) |
| 1215 | |
| 1216 | # Wrong database. |
| 1217 | uri = "mongodb://admin:pass@%s:%d/pymongo_test" % (host, port) |
| 1218 | with self.assertRaises(OperationFailure): |
| 1219 | await connected(await self.async_rs_or_single_client_noauth(uri)) |
| 1220 | |
| 1221 | # No error. |
| 1222 | await connected( |
| 1223 | await self.async_rs_or_single_client_noauth( |
| 1224 | "mongodb://user:pass@%s:%d/pymongo_test" % (host, port) |
| 1225 | ) |
| 1226 | ) |
| 1227 | |
| 1228 | # Auth with lazy connection. |
| 1229 | await ( |
| 1230 | await self.async_rs_or_single_client_noauth( |
| 1231 | "mongodb://user:pass@%s:%d/pymongo_test" % (host, port), connect=False |
| 1232 | ) |
| 1233 | ).pymongo_test.test.find_one() |
| 1234 | |
| 1235 | # Wrong password. |
| 1236 | bad_client = await self.async_rs_or_single_client_noauth( |
| 1237 | "mongodb://user:wrong@%s:%d/pymongo_test" % (host, port), connect=False |
| 1238 | ) |
| 1239 | |
| 1240 | with self.assertRaises(OperationFailure): |
| 1241 | await bad_client.pymongo_test.test.find_one() |
| 1242 | |
| 1243 | @async_client_context.require_auth |
| 1244 | async def test_username_and_password(self): |
nothing calls this directly
no test coverage detected