@@ -37,6 +37,7 @@ import static com.mongodb.ClusterFixture.getBinding
37
37
import static com.mongodb.ClusterFixture.createAsyncCluster
38
38
import static com.mongodb.ClusterFixture.createCluster
39
39
import static com.mongodb.ClusterFixture.isAuthenticated
40
+ import static com.mongodb.ClusterFixture.serverVersionGreaterThan
40
41
import static com.mongodb.MongoCredential.createCredential
41
42
import static com.mongodb.MongoCredential.createScramSha1Credential
42
43
import static com.mongodb.MongoCredential.createScramSha256Credential
@@ -115,11 +116,28 @@ class ScramSha256AuthenticationSpecification extends Specification {
115
116
[sha256Explicit],
116
117
[bothImplicit],
117
118
[bothExplicitSha1],
118
- [bothExplicitSha256],
119
- [sha1Implicit, sha1Explicit, sha256Implicit, sha256Explicit, bothImplicit, bothExplicitSha1, bothExplicitSha256]
119
+ [bothExplicitSha256]
120
120
]
121
121
}
122
122
123
+ @IgnoreIf ({ serverVersionGreaterThan(' 5.0' ) })
124
+ def ' test authentication and authorization with multiple credentials' () {
125
+ given :
126
+ def cluster = createCluster(
127
+ [sha1Implicit, sha1Explicit, sha256Implicit, sha256Explicit, bothImplicit, bothExplicitSha1, bothExplicitSha256])
128
+
129
+ when :
130
+ new CommandReadOperation<Document > (' admin' ,
131
+ new BsonDocumentWrapper<Document > (new Document (' dbstats' , 1 ), new DocumentCodec ()), new DocumentCodec ())
132
+ .execute(new ClusterBinding (cluster, ReadPreference . primary(), ReadConcern . DEFAULT ))
133
+
134
+ then :
135
+ noExceptionThrown()
136
+
137
+ cleanup :
138
+ cluster. close()
139
+ }
140
+
123
141
def ' test authentication and authorization async' () {
124
142
given :
125
143
def cluster = createAsyncCluster(credentials)
@@ -145,11 +163,31 @@ class ScramSha256AuthenticationSpecification extends Specification {
145
163
[sha256Explicit],
146
164
[bothImplicit],
147
165
[bothExplicitSha1],
148
- [bothExplicitSha256],
149
- [sha1Implicit, sha1Explicit, sha256Implicit, sha256Explicit, bothImplicit, bothExplicitSha1, bothExplicitSha256]
166
+ [bothExplicitSha256]
150
167
]
151
168
}
152
169
170
+ @IgnoreIf ({ serverVersionGreaterThan(' 5.0' ) })
171
+ def ' test authentication and authorization with multiple credentials async' () {
172
+ given :
173
+ def cluster = createAsyncCluster(
174
+ [sha1Implicit, sha1Explicit, sha256Implicit, sha256Explicit, bothImplicit, bothExplicitSha1, bothExplicitSha256])
175
+ def callback = new FutureResultCallback ()
176
+
177
+ when :
178
+ // make this synchronous
179
+ new CommandReadOperation<Document > (' admin' ,
180
+ new BsonDocumentWrapper<Document > (new Document (' dbstats' , 1 ), new DocumentCodec ()), new DocumentCodec ())
181
+ .executeAsync(new AsyncClusterBinding (cluster, ReadPreference . primary(), ReadConcern . DEFAULT ), callback)
182
+ callback. get()
183
+
184
+ then :
185
+ noExceptionThrown()
186
+
187
+ cleanup :
188
+ cluster. close()
189
+ }
190
+
153
191
def ' test authentication and authorization failure with wrong mechanism' () {
154
192
given :
155
193
def cluster = createCluster(credentials)
0 commit comments