Skip to content

Commit 6235613

Browse files
committed
Ignoring tests that use DB.eval when the connection is authenticated, as eval requires root privileges that may not be available.
1 parent 3f9a7c1 commit 6235613

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/test/com/mongodb/DBTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.Arrays;
2828
import java.util.List;
2929

30+
import static com.mongodb.Fixture.isAuthenticated;
3031
import static com.mongodb.ReadPreference.primary;
3132
import static com.mongodb.ReadPreference.primaryPreferred;
3233
import static com.mongodb.ReadPreference.secondary;
@@ -426,7 +427,7 @@ public void shouldCreateUncappedCollection() {
426427
@Test
427428
@SuppressWarnings("deprecation")
428429
public void shouldDoEval() {
429-
assumeFalse(getDatabase().isAuthenticated());
430+
assumeFalse(isAuthenticated());
430431
String code = "function(name, incAmount) {\n"
431432
+ "var doc = db.myCollection.findOne( { name : name } );\n"
432433
+ "doc = doc || { name : name , num : 0 , total : 0 , avg : 0 , _id: 1 };\n"
@@ -446,6 +447,7 @@ public void shouldDoEval() {
446447

447448
@Test(expected = MongoException.class)
448449
public void shouldThrowErrorwhileDoingEval() {
450+
assumeFalse(isAuthenticated());
449451
String code = "function(a, b) {\n"
450452
+ "var doc = db.myCollection.findOne( { name : b } );\n"
451453
+ "}";

src/test/com/mongodb/Fixture.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public static boolean serverIsAtLeastVersion(double version) {
6363
return Double.parseDouble(serverVersion.substring(0, 3)) >= version;
6464
}
6565

66+
public static boolean isAuthenticated() {
67+
return getMongoClientURI().getCredentials() != null;
68+
}
69+
6670
public static boolean isStandalone() {
6771
return !isReplicaSet() && !isSharded();
6872
}

src/test/com/mongodb/JavaClientTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.concurrent.TimeUnit;
4545
import java.util.regex.Pattern;
4646

47+
import static com.mongodb.Fixture.isAuthenticated;
4748
import static java.util.Arrays.asList;
4849
import static org.junit.Assert.assertEquals;
4950
import static org.junit.Assert.assertFalse;
@@ -272,6 +273,8 @@ public void testUUID()
272273
@Test
273274
public void testEval()
274275
throws MongoException {
276+
assumeFalse(isAuthenticated());
277+
275278
assertEquals( 17 , ((Number)(getDatabase().eval( "return 17" ))).intValue() );
276279
assertEquals( 18 , ((Number)(getDatabase().eval( "function(x){ return 17 + x; }" , 1 ))).intValue() );
277280
}
@@ -794,6 +797,8 @@ public Object transform( Object o ){
794797

795798
@Test
796799
public void testObjectIdCompat(){
800+
assumeFalse(isAuthenticated());
801+
797802
DBCollection c = collection;
798803

799804
c.save( new BasicDBObject( "x" , 1 ) );
@@ -810,6 +815,8 @@ public void testObjectIdCompat(){
810815

811816
@Test
812817
public void testObjectIdCompat2(){
818+
assumeFalse(isAuthenticated());
819+
813820
DBCollection c = collection;
814821

815822
c.save(new BasicDBObject("x", 1));

0 commit comments

Comments
 (0)