(self)
| 1167 | @client_context.require_auth |
| 1168 | @client_context.require_no_fips |
| 1169 | def test_auth_from_uri(self): |
| 1170 | host, port = client_context.host, client_context.port |
| 1171 | client_context.create_user("admin", "admin", "pass") |
| 1172 | self.addCleanup(client_context.drop_user, "admin", "admin") |
| 1173 | self.addCleanup(remove_all_users, self.client.pymongo_test) |
| 1174 | |
| 1175 | client_context.create_user("pymongo_test", "user", "pass", roles=["userAdmin", "readWrite"]) |
| 1176 | |
| 1177 | with self.assertRaises(OperationFailure): |
| 1178 | connected(self.rs_or_single_client_noauth("mongodb://a:b@%s:%d" % (host, port))) |
| 1179 | |
| 1180 | # No error. |
| 1181 | connected(self.rs_or_single_client_noauth("mongodb://admin:pass@%s:%d" % (host, port))) |
| 1182 | |
| 1183 | # Wrong database. |
| 1184 | uri = "mongodb://admin:pass@%s:%d/pymongo_test" % (host, port) |
| 1185 | with self.assertRaises(OperationFailure): |
| 1186 | connected(self.rs_or_single_client_noauth(uri)) |
| 1187 | |
| 1188 | # No error. |
| 1189 | connected( |
| 1190 | self.rs_or_single_client_noauth("mongodb://user:pass@%s:%d/pymongo_test" % (host, port)) |
| 1191 | ) |
| 1192 | |
| 1193 | # Auth with lazy connection. |
| 1194 | ( |
| 1195 | self.rs_or_single_client_noauth( |
| 1196 | "mongodb://user:pass@%s:%d/pymongo_test" % (host, port), connect=False |
| 1197 | ) |
| 1198 | ).pymongo_test.test.find_one() |
| 1199 | |
| 1200 | # Wrong password. |
| 1201 | bad_client = self.rs_or_single_client_noauth( |
| 1202 | "mongodb://user:wrong@%s:%d/pymongo_test" % (host, port), connect=False |
| 1203 | ) |
| 1204 | |
| 1205 | with self.assertRaises(OperationFailure): |
| 1206 | bad_client.pymongo_test.test.find_one() |
| 1207 | |
| 1208 | @client_context.require_auth |
| 1209 | def test_username_and_password(self): |
nothing calls this directly
no test coverage detected