mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 19:17:58 +00:00
RabbitMQ - Add username customization (#11899)
* add username customization for rabbitmq * add changelog for rabbitmq * Update builtin/logical/rabbitmq/path_config_connection.go Co-authored-by: Tom Proctor <tomhjp@users.noreply.github.com> * updating API docs * moved to changelog folder Co-authored-by: Tom Proctor <tomhjp@users.noreply.github.com>
This commit is contained in:
104
builtin/logical/rabbitmq/path_config_connection_test.go
Normal file
104
builtin/logical/rabbitmq/path_config_connection_test.go
Normal file
@@ -0,0 +1,104 @@
|
||||
package rabbitmq
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/vault/sdk/logical"
|
||||
)
|
||||
|
||||
func TestBackend_ConfigConnection_DefaultUsernameTemplate(t *testing.T) {
|
||||
var resp *logical.Response
|
||||
var err error
|
||||
config := logical.TestBackendConfig()
|
||||
config.StorageView = &logical.InmemStorage{}
|
||||
b := Backend()
|
||||
if err = b.Setup(context.Background(), config); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
configData := map[string]interface{}{
|
||||
"connection_uri": "uri",
|
||||
"username": "username",
|
||||
"password": "password",
|
||||
"verify_connection": "false",
|
||||
}
|
||||
configReq := &logical.Request{
|
||||
Operation: logical.UpdateOperation,
|
||||
Path: "config/connection",
|
||||
Storage: config.StorageView,
|
||||
Data: configData,
|
||||
}
|
||||
resp, err = b.HandleRequest(context.Background(), configReq)
|
||||
if err != nil || (resp != nil && resp.IsError()) {
|
||||
t.Fatalf("bad: resp: %#v\nerr:%s", resp, err)
|
||||
}
|
||||
if resp != nil {
|
||||
t.Fatal("expected a nil response")
|
||||
}
|
||||
|
||||
actualConfig, err := readConfig(context.Background(), config.StorageView)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to read configuration: %v", err)
|
||||
}
|
||||
|
||||
expectedConfig := connectionConfig{
|
||||
URI: "uri",
|
||||
Username: "username",
|
||||
Password: "password",
|
||||
UsernameTemplate: "",
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(actualConfig, expectedConfig) {
|
||||
t.Fatalf("Expected: %#v\nActual: %#v", expectedConfig, actualConfig)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBackend_ConfigConnection_CustomUsernameTemplate(t *testing.T) {
|
||||
var resp *logical.Response
|
||||
var err error
|
||||
config := logical.TestBackendConfig()
|
||||
config.StorageView = &logical.InmemStorage{}
|
||||
b := Backend()
|
||||
if err = b.Setup(context.Background(), config); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
configData := map[string]interface{}{
|
||||
"connection_uri": "uri",
|
||||
"username": "username",
|
||||
"password": "password",
|
||||
"verify_connection": "false",
|
||||
"username_template": "{{ .DisplayName }}",
|
||||
}
|
||||
configReq := &logical.Request{
|
||||
Operation: logical.UpdateOperation,
|
||||
Path: "config/connection",
|
||||
Storage: config.StorageView,
|
||||
Data: configData,
|
||||
}
|
||||
resp, err = b.HandleRequest(context.Background(), configReq)
|
||||
if err != nil || (resp != nil && resp.IsError()) {
|
||||
t.Fatalf("bad: resp: %#v\nerr:%s", resp, err)
|
||||
}
|
||||
if resp != nil {
|
||||
t.Fatal("expected a nil response")
|
||||
}
|
||||
|
||||
actualConfig, err := readConfig(context.Background(), config.StorageView)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to read configuration: %v", err)
|
||||
}
|
||||
|
||||
expectedConfig := connectionConfig{
|
||||
URI: "uri",
|
||||
Username: "username",
|
||||
Password: "password",
|
||||
UsernameTemplate: "{{ .DisplayName }}",
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(actualConfig, expectedConfig) {
|
||||
t.Fatalf("Expected: %#v\nActual: %#v", expectedConfig, actualConfig)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user