mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-11-04 04:28:08 +00:00 
			
		
		
		
	Support MongoDB session-wide write concern (#3646)
* Initial work on write concern support, set for the lifetime of the session * Add base64 encoded value support, include docs and tests * Handle error from json.Unmarshal, fix test and docs * Remove writeConcern struct, move JSON unmarshal to Initialize * Return error on empty mapping of write_concern into mgo.Safe struct
This commit is contained in:
		
				
					committed by
					
						
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							208dc55830
						
					
				
				
					commit
					a9e7dbb7b4
				
			@@ -16,6 +16,8 @@ import (
 | 
			
		||||
 | 
			
		||||
const testMongoDBRole = `{ "db": "admin", "roles": [ { "role": "readWrite" } ] }`
 | 
			
		||||
 | 
			
		||||
const testMongoDBWriteConcern = `{ "wmode": "majority", "wtimeout": 5000 }`
 | 
			
		||||
 | 
			
		||||
func prepareMongoDBTestContainer(t *testing.T) (cleanup func(), retURL string) {
 | 
			
		||||
	if os.Getenv("MONGODB_URL") != "" {
 | 
			
		||||
		return func() {}, os.Getenv("MONGODB_URL")
 | 
			
		||||
@@ -129,6 +131,44 @@ func TestMongoDB_CreateUser(t *testing.T) {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestMongoDB_CreateUser_writeConcern(t *testing.T) {
 | 
			
		||||
	cleanup, connURL := prepareMongoDBTestContainer(t)
 | 
			
		||||
	defer cleanup()
 | 
			
		||||
 | 
			
		||||
	connectionDetails := map[string]interface{}{
 | 
			
		||||
		"connection_url": connURL,
 | 
			
		||||
		"write_concern":  testMongoDBWriteConcern,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	dbRaw, err := New()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatalf("err: %s", err)
 | 
			
		||||
	}
 | 
			
		||||
	db := dbRaw.(*MongoDB)
 | 
			
		||||
	err = db.Initialize(connectionDetails, true)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatalf("err: %s", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	statements := dbplugin.Statements{
 | 
			
		||||
		CreationStatements: testMongoDBRole,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	usernameConfig := dbplugin.UsernameConfig{
 | 
			
		||||
		DisplayName: "test",
 | 
			
		||||
		RoleName:    "test",
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	username, password, err := db.CreateUser(statements, usernameConfig, time.Now().Add(time.Minute))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatalf("err: %s", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err := testCredsExist(t, connURL, username, password); err != nil {
 | 
			
		||||
		t.Fatalf("Could not connect with new credentials: %s", err)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestMongoDB_RevokeUser(t *testing.T) {
 | 
			
		||||
	cleanup, connURL := prepareMongoDBTestContainer(t)
 | 
			
		||||
	defer cleanup()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user