Merge branch 'master' of github.com:mongodb/mongo-python-driver
This commit is contained in:
commit
4c48eb320d
5
.github/dependabot.yml
vendored
5
.github/dependabot.yml
vendored
@ -9,3 +9,8 @@ updates:
|
||||
actions:
|
||||
patterns:
|
||||
- "*"
|
||||
# Python
|
||||
- package-ecosystem: "pip"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
|
||||
@ -416,173 +416,6 @@
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "Read commands should fail if reauthentication fails",
|
||||
"operations": [
|
||||
{
|
||||
"name": "find",
|
||||
"object": "collection0",
|
||||
"arguments": {
|
||||
"filter": {}
|
||||
},
|
||||
"expectResult": []
|
||||
},
|
||||
{
|
||||
"name": "failPoint",
|
||||
"object": "testRunner",
|
||||
"arguments": {
|
||||
"client": "failPointClient",
|
||||
"failPoint": {
|
||||
"configureFailPoint": "failCommand",
|
||||
"mode": {
|
||||
"times": 2
|
||||
},
|
||||
"data": {
|
||||
"failCommands": [
|
||||
"find",
|
||||
"saslStart"
|
||||
],
|
||||
"errorCode": 391
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "find",
|
||||
"object": "collection0",
|
||||
"arguments": {
|
||||
"filter": {}
|
||||
},
|
||||
"expectError": {
|
||||
"errorCode": 391
|
||||
}
|
||||
}
|
||||
],
|
||||
"expectEvents": [
|
||||
{
|
||||
"client": "client0",
|
||||
"events": [
|
||||
{
|
||||
"commandStartedEvent": {
|
||||
"command": {
|
||||
"find": "collName",
|
||||
"filter": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"commandSucceededEvent": {
|
||||
"commandName": "find"
|
||||
}
|
||||
},
|
||||
{
|
||||
"commandStartedEvent": {
|
||||
"command": {
|
||||
"find": "collName",
|
||||
"filter": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"commandFailedEvent": {
|
||||
"commandName": "find"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "Write commands should fail if reauthentication fails",
|
||||
"operations": [
|
||||
{
|
||||
"name": "insertOne",
|
||||
"object": "collection0",
|
||||
"arguments": {
|
||||
"document": {
|
||||
"_id": 1,
|
||||
"x": 1
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "failPoint",
|
||||
"object": "testRunner",
|
||||
"arguments": {
|
||||
"client": "failPointClient",
|
||||
"failPoint": {
|
||||
"configureFailPoint": "failCommand",
|
||||
"mode": {
|
||||
"times": 2
|
||||
},
|
||||
"data": {
|
||||
"failCommands": [
|
||||
"insert",
|
||||
"saslStart"
|
||||
],
|
||||
"errorCode": 391
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "insertOne",
|
||||
"object": "collection0",
|
||||
"arguments": {
|
||||
"document": {
|
||||
"_id": 2,
|
||||
"x": 2
|
||||
}
|
||||
},
|
||||
"expectError": {
|
||||
"errorCode": 391
|
||||
}
|
||||
}
|
||||
],
|
||||
"expectEvents": [
|
||||
{
|
||||
"client": "client0",
|
||||
"events": [
|
||||
{
|
||||
"commandStartedEvent": {
|
||||
"command": {
|
||||
"insert": "collName",
|
||||
"documents": [
|
||||
{
|
||||
"_id": 1,
|
||||
"x": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"commandSucceededEvent": {
|
||||
"commandName": "insert"
|
||||
}
|
||||
},
|
||||
{
|
||||
"commandStartedEvent": {
|
||||
"command": {
|
||||
"insert": "collName",
|
||||
"documents": [
|
||||
{
|
||||
"_id": 2,
|
||||
"x": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"commandFailedEvent": {
|
||||
"commandName": "insert"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -920,7 +920,7 @@ class TestAuthOIDCMachine(OIDCTestBase):
|
||||
# Close the client.
|
||||
client.close()
|
||||
|
||||
def test_4_reauthentication(self):
|
||||
def test_4_1_reauthentication_succeds(self):
|
||||
# Create a ``MongoClient`` configured with a custom OIDC callback that
|
||||
# implements the provider logic.
|
||||
client = self.create_client()
|
||||
@ -942,6 +942,84 @@ class TestAuthOIDCMachine(OIDCTestBase):
|
||||
# Close the client.
|
||||
client.close()
|
||||
|
||||
def test_4_2_read_commands_fail_if_reauthentication_fails(self):
|
||||
# Create a ``MongoClient`` whose OIDC callback returns one good token and then
|
||||
# bad tokens after the first call.
|
||||
get_token = self.get_token
|
||||
|
||||
class CustomCallback(OIDCCallback):
|
||||
count = 0
|
||||
|
||||
def fetch(self, _):
|
||||
self.count += 1
|
||||
if self.count == 1:
|
||||
access_token = get_token()
|
||||
else:
|
||||
access_token = "bad value"
|
||||
return OIDCCallbackResult(access_token=access_token)
|
||||
|
||||
callback = CustomCallback()
|
||||
client = self.create_client(request_cb=callback)
|
||||
|
||||
# Perform a read operation that succeeds.
|
||||
client.test.test.find_one()
|
||||
|
||||
# Set a fail point for the find command.
|
||||
with self.fail_point(
|
||||
{
|
||||
"mode": {"times": 1},
|
||||
"data": {"failCommands": ["find"], "errorCode": 391},
|
||||
}
|
||||
):
|
||||
# Perform a ``find`` operation that fails.
|
||||
with self.assertRaises(OperationFailure):
|
||||
client.test.test.find_one()
|
||||
|
||||
# Verify that the callback was called 2 times.
|
||||
self.assertEqual(callback.count, 2)
|
||||
|
||||
# Close the client.
|
||||
client.close()
|
||||
|
||||
def test_4_3_write_commands_fail_if_reauthentication_fails(self):
|
||||
# Create a ``MongoClient`` whose OIDC callback returns one good token and then
|
||||
# bad token after the first call.
|
||||
get_token = self.get_token
|
||||
|
||||
class CustomCallback(OIDCCallback):
|
||||
count = 0
|
||||
|
||||
def fetch(self, _):
|
||||
self.count += 1
|
||||
if self.count == 1:
|
||||
access_token = get_token()
|
||||
else:
|
||||
access_token = "bad value"
|
||||
return OIDCCallbackResult(access_token=access_token)
|
||||
|
||||
callback = CustomCallback()
|
||||
client = self.create_client(request_cb=callback)
|
||||
|
||||
# Perform an insert operation that succeeds.
|
||||
client.test.test.insert_one({})
|
||||
|
||||
# Set a fail point for the find command.
|
||||
with self.fail_point(
|
||||
{
|
||||
"mode": {"times": 1},
|
||||
"data": {"failCommands": ["insert"], "errorCode": 391},
|
||||
}
|
||||
):
|
||||
# Perform a ``insert`` operation that fails.
|
||||
with self.assertRaises(OperationFailure):
|
||||
client.test.test.insert_one({})
|
||||
|
||||
# Verify that the callback was called 2 times.
|
||||
self.assertEqual(callback.count, 2)
|
||||
|
||||
# Close the client.
|
||||
client.close()
|
||||
|
||||
def test_5_1_azure_with_no_username(self):
|
||||
if ENVIRON != "azure":
|
||||
raise unittest.SkipTest("Test is only supported on Azure")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user