File: copyauth.js

package info (click to toggle)
mongodb 1%3A1.4.4-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 6,816 kB
  • ctags: 11,368
  • sloc: cpp: 58,805; ansic: 18,160; python: 1,255; sh: 238; makefile: 82
file content (29 lines) | stat: -rw-r--r-- 1,512 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// test copyDatabase from an auth enabled source

ports = allocatePorts( 2 );

var baseName = "jstests_clone_copyauth";

var source = startMongod( "--auth", "--port", ports[ 0 ], "--dbpath", "/data/db/" + baseName + "_source", "--nohttpinterface", "--bind_ip", "127.0.0.1", "--smallfiles" );
var target = startMongod( "--port", ports[ 1 ], "--dbpath", "/data/db/" + baseName + "_target", "--nohttpinterface", "--bind_ip", "127.0.0.1", "--smallfiles" );

source.getDB( baseName )[ baseName ].save( {i:1} );
source.getDB( baseName ).addUser( "foo", "bar" );
source.getDB( "admin" ).addUser( "super", "super" );
assert.throws( function() { source.getDB( baseName )[ baseName ].findOne(); } );

target.getDB( baseName ).copyDatabase( baseName, baseName, source.host, "foo", "bar" );
assert.eq( 1, target.getDB( baseName )[ baseName ].count() );
assert.eq( 1, target.getDB( baseName )[ baseName ].findOne().i );

stopMongod( ports[ 1 ] );

var target = startMongod( "--auth", "--port", ports[ 1 ], "--dbpath", "/data/db/" + baseName + "_target", "--nohttpinterface", "--bind_ip", "127.0.0.1", "--smallfiles" );

target.getDB( "admin" ).addUser( "super1", "super1" );
assert.throws( function() { source.getDB( baseName )[ baseName ].findOne(); } );
target.getDB( "admin" ).auth( "super1", "super1" );

target.getDB( baseName ).copyDatabase( baseName, baseName, source.host, "foo", "bar" );
assert.eq( 1, target.getDB( baseName )[ baseName ].count() );
assert.eq( 1, target.getDB( baseName )[ baseName ].findOne().i );