1
2
3
4
5
6
7
8
9
10 package integration
11
12 import (
13 "context"
14 "testing"
15
16 "go.mongodb.org/mongo-driver/bson"
17 "go.mongodb.org/mongo-driver/event"
18 "go.mongodb.org/mongo-driver/internal/assert"
19 "go.mongodb.org/mongo-driver/internal/integtest"
20 "go.mongodb.org/mongo-driver/mongo"
21 "go.mongodb.org/mongo-driver/mongo/integration/mtest"
22 "go.mongodb.org/mongo-driver/mongo/options"
23 )
24
25
26 func TestCSOTClientSideEncryptionProse(t *testing.T) {
27 verifyClientSideEncryptionVarsSet(t)
28 mt := mtest.New(t, mtest.NewOptions().MinServerVersion("4.2").CreateClient(false))
29
30 mt.RunOpts("2. maxTimeMS is not set for commands sent to mongocryptd",
31 noClientOpts, func(mt *mtest.T) {
32 kmsProviders := map[string]map[string]interface{}{
33 "local": {
34 "key": localMasterKey,
35 },
36 }
37 mongocryptdSpawnArgs := map[string]interface{}{
38
39 "mongocryptdSpawnArgs": []string{"--port=23000", "--pidfilepath=TestCSOTClientSideEncryptionProse_1.pid"},
40 "mongocryptdURI": "mongodb://localhost:23000",
41
42 "__cryptSharedLibDisabledForTestOnly": true,
43 }
44
45
46 aeo := options.AutoEncryption().SetKmsProviders(kmsProviders).
47 SetExtraOptions(mongocryptdSpawnArgs)
48 cliOpts := options.Client().ApplyURI(mtest.ClusterURI()).SetAutoEncryptionOptions(aeo)
49 integtest.AddTestServerAPIVersion(cliOpts)
50 encClient, err := mongo.Connect(context.Background(), cliOpts)
51 assert.Nil(mt, err, "Connect error: %v", err)
52 defer func() {
53 err = encClient.Disconnect(context.Background())
54 assert.Nil(mt, err, "encrypted client Disconnect error: %v", err)
55 }()
56
57
58
59 _, err = encClient.Database("test").Collection("test").Find(context.Background(), bson.D{})
60 assert.Nil(mt, err, "Find error: %v", err)
61
62
63
64 var started *event.CommandStartedEvent
65 mcryptMonitor := &event.CommandMonitor{
66 Started: func(_ context.Context, evt *event.CommandStartedEvent) {
67 started = evt
68 },
69 }
70 mcryptOpts := options.Client().SetMonitor(mcryptMonitor).
71 ApplyURI("mongodb://localhost:23000/?timeoutMS=1000")
72 integtest.AddTestServerAPIVersion(mcryptOpts)
73 mcryptClient, err := mongo.Connect(context.Background(), mcryptOpts)
74 assert.Nil(mt, err, "mongocryptd Connect error: %v", err)
75 defer func() {
76 err = mcryptClient.Disconnect(context.Background())
77 assert.Nil(mt, err, "mongocryptd Disconnect error: %v", err)
78 }()
79
80
81
82 _ = mcryptClient.Ping(context.Background(), nil)
83 assert.NotNil(mt, started, "expected a CommandStartedEvent, got nil")
84 assert.Equal(mt, started.CommandName, "ping", "expected 'ping', got %q", started.CommandName)
85 commandElems, err := started.Command.Elements()
86 assert.Nil(mt, err, "Elements error: %v", err)
87 for _, elem := range commandElems {
88 assert.NotEqual(mt, elem.Key(), "maxTimeMS",
89 "expected no 'maxTimeMS' field in ping to mongocryptd")
90 }
91 })
92 }
93
View as plain text