-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> * updating API docs * moved to changelog folder Co-authored-by: Tom Proctor <[email protected]>
- Loading branch information
Showing
6 changed files
with
328 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
builtin/logical/rabbitmq/path_config_connection_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.