Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUBY-3407 Add spec test #2890

Merged
merged 6 commits into from
Jul 23, 2024
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
6 changes: 2 additions & 4 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1877,11 +1877,9 @@ buildvariants:

- matrix_name: "serverless"
matrix_spec:
# https://jira.mongodb.org/browse/RUBY-3217
# ruby: ["ruby-3.2", "ruby-3.1", "ruby-3.0", "ruby-2.7", "jruby-9.4", "jruby-9.3"]
ruby: ["ruby-3.2", "ruby-3.1", "ruby-3.0", "ruby-2.7"]
ruby: "ruby-3.2"
fle: path
os: rhel8
os: ubuntu2204
display_name: "Atlas serverless ${ruby}"
tasks:
- name: serverless_task_group
Expand Down
6 changes: 2 additions & 4 deletions .evergreen/config/standard.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,9 @@ buildvariants:

- matrix_name: "serverless"
matrix_spec:
# https://jira.mongodb.org/browse/RUBY-3217
# ruby: <%= supported_rubies %>
ruby: <%= supported_mri_rubies %>
ruby: <%= latest_ruby %>
fle: path
os: rhel8
os: ubuntu2204
display_name: "Atlas serverless ${ruby}"
tasks:
- name: serverless_task_group
Expand Down
10 changes: 5 additions & 5 deletions .evergreen/run-tests-serverless.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ else
python3 -u .evergreen/mongodl.py --component crypt_shared -V ${SERVERLESS_MONGODB_VERSION} --out `pwd`/csfle_lib --target `host_distro` || true
if test -f `pwd`/csfle_lib/lib/mongo_crypt_v1.so
then
echo Usinn crypt shared library version ${SERVERLESS_MONGODB_VERSION}
echo Using crypt shared library version ${SERVERLESS_MONGODB_VERSION}
export MONGO_RUBY_DRIVER_CRYPT_SHARED_LIB_PATH=`pwd`/csfle_lib/lib/mongo_crypt_v1.so
else
echo Failed to download crypt shared library
exit -1
fi
fi

if ! ( test -f /etc/os-release & grep -q ^ID.*rhel /etc/os-release & grep -q ^VERSION_ID.*8.0 /etc/os-release ); then
echo Serverless tests assume rhel80
if ! ( test -f /etc/os-release & grep -q ^ID.*ubuntu /etc/os-release & grep -q ^VERSION_ID.*22.04 /etc/os-release ); then
echo Serverless tests assume ubuntu2204
echo If this has changed, update .evergreen/run-tests-serverless.sh as necessary
exit -1
fi
Expand All @@ -43,8 +43,8 @@ mkdir libmongocrypt
cd libmongocrypt
curl --retry 3 -fLo libmongocrypt-all.tar.gz "https://s3.amazonaws.com/mciuploads/libmongocrypt/all/master/latest/libmongocrypt-all.tar.gz"
tar xf libmongocrypt-all.tar.gz
# We assume that serverless tests always use rhel80
export LIBMONGOCRYPT_PATH=`pwd`/rhel-80-64-bit/nocrypto/lib64/libmongocrypt.so
# We assume that serverless tests always use ubuntu2204
export LIBMONGOCRYPT_PATH=`pwd`/ubuntu2204-64/nocrypto/lib/libmongocrypt.so
cd -

cd .evergreen/csfle
Expand Down
4 changes: 3 additions & 1 deletion spec/lite_spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
!defined?(JRUBY_VERSION) || !f.include?('pool-checkout-minPoolSize-connection-maxConnecting.yml')
end
AUTH_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/auth/*.yml").sort
CLIENT_SIDE_ENCRYPTION_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/client_side_encryption/*.yml").sort
CLIENT_SIDE_ENCRYPTION_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/client_side_encryption/*.yml").sort.delete_if do |spec|
![ 1, '1', 'yes', 'true' ].include?(ENV['CSOT_SPEC_TESTS']) && spec =~ /.*timeoutMS.yml$/
end

# Disable output buffering: https://www.rubyguides.com/2019/02/ruby-io/
STDOUT.sync = true
Expand Down
4 changes: 3 additions & 1 deletion spec/runners/crud/verifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def verify_result(expected, actual)
expect(actual).not_to be nil
when Hash
if actual.is_a?(Hash) && actual['error'] &&
!expected.keys.any? { |key| key.start_with?('error') }
!expected.keys.any? { |key| key.start_with?('error') || key == 'isTimeoutError' }
then
raise RSpec::Expectations::ExpectationNotMetError.new,
"Expected operation not to fail but it failed: #{actual.inspect}"
Expand All @@ -143,6 +143,8 @@ def verify_result(expected, actual)

expected.each do |k, v|
case k
when 'isTimeoutError'
expect(actual['errorContains']).to eq('Mongo::Error::TimeoutError')
when 'errorContains'
expect(actual['errorContains'].downcase).to include(v.downcase)
when 'errorLabelsContain'
Expand Down
67 changes: 67 additions & 0 deletions spec/spec_tests/data/client_side_encryption/timeoutMS.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
runOn:
- minServerVersion: "4.4"
database_name: &database_name "cse-timeouts-db"
collection_name: &collection_name "cse-timeouts-coll"

data: []
json_schema: {'properties': {'encrypted_w_altname': {'encrypt': {'keyId': '/altname', 'bsonType': 'string', 'algorithm': 'AEAD_AES_256_CBC_HMAC_SHA_512-Random'}}, 'encrypted_string': {'encrypt': {'keyId': [{'$binary': {'base64': 'AAAAAAAAAAAAAAAAAAAAAA==', 'subType': '04'}}], 'bsonType': 'string', 'algorithm': 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic'}}, 'random': {'encrypt': {'keyId': [{'$binary': {'base64': 'AAAAAAAAAAAAAAAAAAAAAA==', 'subType': '04'}}], 'bsonType': 'string', 'algorithm': 'AEAD_AES_256_CBC_HMAC_SHA_512-Random'}}, 'encrypted_string_equivalent': {'encrypt': {'keyId': [{'$binary': {'base64': 'AAAAAAAAAAAAAAAAAAAAAA==', 'subType': '04'}}], 'bsonType': 'string', 'algorithm': 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic'}}}, 'bsonType': 'object'}
key_vault_data: [{'status': 1, '_id': {'$binary': {'base64': 'AAAAAAAAAAAAAAAAAAAAAA==', 'subType': '04'}}, 'masterKey': {'provider': 'aws', 'key': 'arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0', 'region': 'us-east-1'}, 'updateDate': {'$date': {'$numberLong': '1552949630483'}}, 'keyMaterial': {'$binary': {'base64': 'AQICAHhQNmWG2CzOm1dq3kWLM+iDUZhEqnhJwH9wZVpuZ94A8gEqnsxXlR51T5EbEVezUqqKAAAAwjCBvwYJKoZIhvcNAQcGoIGxMIGuAgEAMIGoBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDHa4jo6yp0Z18KgbUgIBEIB74sKxWtV8/YHje5lv5THTl0HIbhSwM6EqRlmBiFFatmEWaeMk4tO4xBX65eq670I5TWPSLMzpp8ncGHMmvHqRajNBnmFtbYxN3E3/WjxmdbOOe+OXpnGJPcGsftc7cB2shRfA4lICPnE26+oVNXT6p0Lo20nY5XC7jyCO', 'subType': '00'}}, 'creationDate': {'$date': {'$numberLong': '1552949630483'}}, 'keyAltNames': ['altname', 'another_altname']}]

tests:
- description: "timeoutMS applied to listCollections to get collection schema"
failPoint:
configureFailPoint: failCommand
mode: { times: 1 }
data:
failCommands: ["listCollections"]
blockConnection: true
blockTimeMS: 60
clientOptions:
autoEncryptOpts:
kmsProviders:
aws: {} # Credentials filled in from environment.
timeoutMS: 50
operations:
- name: insertOne
arguments:
document: &doc0 { _id: 1, encrypted_string: "string0", random: "abc" }
result:
isTimeoutError: true
expectations:
# Auto encryption will request the collection info.
- command_started_event:
command:
listCollections: 1
filter:
name: *collection_name
maxTimeMS: { $$type: ["int", "long"] }
command_name: listCollections

# Test that timeoutMS applies to the sum of all operations done for client-side encryption. This is done by blocking
# listCollections and find for 30ms each and running an insertOne with timeoutMS=50. There should be one
# listCollections command and one "find" command, so the sum should take more than timeoutMS. A second listCollections
# event doesn't occur due to the internal MongoClient lacking configured auto encryption, plus libmongocrypt holds the
# collection schema in cache for a minute.
#
# This test does not include command monitoring expectations because the exact command sequence is dependent on the
# amount of time taken by mongocryptd communication. In slow runs, mongocryptd communication can breach the timeout
# and result in the final "find" not being sent.
- description: "remaining timeoutMS applied to find to get keyvault data"
failPoint:
configureFailPoint: failCommand
mode: { times: 2 }
data:
failCommands: ["listCollections", "find"]
blockConnection: true
blockTimeMS: 30
clientOptions:
autoEncryptOpts:
kmsProviders:
aws: {} # Credentials filled in from environment.
timeoutMS: 50
operations:
- name: insertOne
arguments:
document: *doc0
result:
isTimeoutError: true
4 changes: 3 additions & 1 deletion spec/support/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,10 @@ def match_with_type?(expected, actual)
when 'long'
expected_class = BSON::Int64
expected_key = '$numberLong'
when %w[int long]
return actual.is_a?(Numeric) || actual.is_a?(BSON::Int32) || actual.is_a?(BSON::Int64)
else
raise "Tests do not currently support matching against $$type #{v['$$type']}"
raise "Tests do not currently support matching against $$type #{expected['$$type']}"
end

actual.is_a?(expected_class) || actual.key?(expected_key)
Expand Down
Loading