Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mongodb driver switch to mongo-driver #8140

Merged
merged 9 commits into from
Jan 24, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion builtin/logical/database/rotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package database

import (
"context"
"go.mongodb.org/mongo-driver/mongo"
michelvocks marked this conversation as resolved.
Show resolved Hide resolved
"go.mongodb.org/mongo-driver/mongo/options"
"log"
"strings"
"testing"
Expand Down Expand Up @@ -843,6 +845,11 @@ func TestBackend_StaticRole_Rotations_MongoDB(t *testing.T) {
// configure backend, add item and confirm length
cleanup, connURL := mongodb.PrepareTestContainerWithDatabase(t, "latest", "vaulttestdb")
defer cleanup()
testCases := []string{"65", "130", "5400"}
// Create database users ahead
for _, tc := range testCases {
testCreateDBUser(t, connURL, "vaulttestdb", "statictestMongo" + tc, "test")
}

// Configure a connection
data := map[string]interface{}{
Expand All @@ -865,7 +872,6 @@ func TestBackend_StaticRole_Rotations_MongoDB(t *testing.T) {
}

// create three static roles with different rotation periods
testCases := []string{"65", "130", "5400"}
for _, tc := range testCases {
roleName := "plugin-static-role-" + tc
data = map[string]interface{}{
Expand Down Expand Up @@ -956,6 +962,30 @@ func TestBackend_StaticRole_Rotations_MongoDB(t *testing.T) {
}
}

func testCreateDBUser(t testing.TB, connURL, db, username, password string) {
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
client, err := mongo.Connect(ctx, options.Client().ApplyURI(connURL))
if err != nil {
t.Fatal(err)
}

createUserCmd := &createUserCommand{
Username: username,
Password: password,
Roles: []interface{}{},
}
result := client.Database(db).RunCommand(ctx, createUserCmd, nil)
if result.Err() != nil {
t.Fatal(result.Err())
}
}

type createUserCommand struct {
Username string `bson:"createUser"`
Password string `bson:"pwd"`
Roles []interface{} `bson:"roles"`
}

// Demonstrates a bug fix for the credential rotation not releasing locks
func TestBackend_StaticRole_LockRegression(t *testing.T) {
cluster, sys := getCluster(t)
Expand Down