vault/command/agentproxyshared/auth/azure/azure_test.go
Violet Hynes 20c1f54906
Add support for true/false string literals for agent injector (#22996)
* Add support for true/false string literals for agent injector

* Add extra test

* Changelog

* parseutil

* Godocs
2023-09-27 10:46:44 -04:00

97 lines
2.5 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package azure
import (
"testing"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/command/agentproxyshared/auth"
)
// TestAzureAuthMethod tests that NewAzureAuthMethod succeeds
// with valid config.
func TestAzureAuthMethod(t *testing.T) {
t.Parallel()
config := &auth.AuthConfig{
Logger: hclog.NewNullLogger(),
MountPath: "auth-test",
Config: map[string]interface{}{
"resource": "test",
"client_id": "test",
"role": "test",
"scope": "test",
"authenticate_from_environment": true,
},
}
_, err := NewAzureAuthMethod(config)
if err != nil {
t.Fatal(err)
}
}
// TestAzureAuthMethod_StringAuthFromEnvironment tests that NewAzureAuthMethod succeeds
// with valid config, where authenticate_from_environment is a string literal.
func TestAzureAuthMethod_StringAuthFromEnvironment(t *testing.T) {
t.Parallel()
config := &auth.AuthConfig{
Logger: hclog.NewNullLogger(),
MountPath: "auth-test",
Config: map[string]interface{}{
"resource": "test",
"client_id": "test",
"role": "test",
"scope": "test",
"authenticate_from_environment": "true",
},
}
_, err := NewAzureAuthMethod(config)
if err != nil {
t.Fatal(err)
}
}
// TestAzureAuthMethod_BadConfig tests that NewAzureAuthMethod fails with
// an invalid config.
func TestAzureAuthMethod_BadConfig(t *testing.T) {
t.Parallel()
config := &auth.AuthConfig{
Logger: hclog.NewNullLogger(),
MountPath: "auth-test",
Config: map[string]interface{}{
"bad_value": "abc",
},
}
_, err := NewAzureAuthMethod(config)
if err == nil {
t.Fatal("Expected error, got none.")
}
}
// TestAzureAuthMethod_BadAuthFromEnvironment tests that NewAzureAuthMethod fails
// with otherwise valid config, but where authenticate_from_environment is
// an invalid string literal.
func TestAzureAuthMethod_BadAuthFromEnvironment(t *testing.T) {
t.Parallel()
config := &auth.AuthConfig{
Logger: hclog.NewNullLogger(),
MountPath: "auth-test",
Config: map[string]interface{}{
"resource": "test",
"client_id": "test",
"role": "test",
"scope": "test",
"authenticate_from_environment": "bad_value",
},
}
_, err := NewAzureAuthMethod(config)
if err == nil {
t.Fatal("Expected error, got none.")
}
}