|
|
|
|
@ -9,222 +9,472 @@ import (
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func Test_parseUsernamePasswordCredentials(t *testing.T) {
|
|
|
|
|
var (
|
|
|
|
|
typedUsernamePassword = &targets.SessionCredential{
|
|
|
|
|
CredentialSource: &targets.CredentialSource{
|
|
|
|
|
CredentialType: string(credential.UsernamePasswordType),
|
|
|
|
|
},
|
|
|
|
|
Credential: map[string]interface{}{
|
|
|
|
|
"username": "user",
|
|
|
|
|
"password": "pass",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedSshPrivateKey = &targets.SessionCredential{
|
|
|
|
|
CredentialSource: &targets.CredentialSource{
|
|
|
|
|
CredentialType: string(credential.SshPrivateKeyType),
|
|
|
|
|
},
|
|
|
|
|
Credential: map[string]interface{}{
|
|
|
|
|
"username": "user",
|
|
|
|
|
"private_key": "my-pk",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vaultUsernamePassword = &targets.SessionCredential{
|
|
|
|
|
CredentialSource: &targets.CredentialSource{
|
|
|
|
|
Type: "vault",
|
|
|
|
|
},
|
|
|
|
|
Secret: &targets.SessionSecret{
|
|
|
|
|
Decoded: map[string]interface{}{
|
|
|
|
|
"username": "vault-decoded-user",
|
|
|
|
|
"password": "vault-decoded-pass",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vaultSshPrivateKey = &targets.SessionCredential{
|
|
|
|
|
CredentialSource: &targets.CredentialSource{
|
|
|
|
|
Type: "vault",
|
|
|
|
|
},
|
|
|
|
|
Secret: &targets.SessionSecret{
|
|
|
|
|
Decoded: map[string]interface{}{
|
|
|
|
|
"username": "vault-decoded-user",
|
|
|
|
|
"private_key": "vault-decoded-pk",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
staticUsernamePassword = &targets.SessionCredential{
|
|
|
|
|
CredentialSource: &targets.CredentialSource{
|
|
|
|
|
Type: "static",
|
|
|
|
|
},
|
|
|
|
|
Secret: &targets.SessionSecret{
|
|
|
|
|
Decoded: map[string]interface{}{
|
|
|
|
|
"username": "static-decoded-user",
|
|
|
|
|
"password": "static-decoded-pass",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
staticSshPrivateKey = &targets.SessionCredential{
|
|
|
|
|
CredentialSource: &targets.CredentialSource{
|
|
|
|
|
Type: "static",
|
|
|
|
|
},
|
|
|
|
|
Secret: &targets.SessionSecret{
|
|
|
|
|
Decoded: map[string]interface{}{
|
|
|
|
|
"username": "static-decoded-user",
|
|
|
|
|
"private_key": "static-decoded-pk",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unspecifiedCred = &targets.SessionCredential{
|
|
|
|
|
CredentialSource: &targets.CredentialSource{
|
|
|
|
|
Type: "static",
|
|
|
|
|
},
|
|
|
|
|
Secret: &targets.SessionSecret{
|
|
|
|
|
Decoded: map[string]interface{}{
|
|
|
|
|
"username": "decoded-user",
|
|
|
|
|
"some-value": "decoded-some-value",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unspecifiedCred1 = &targets.SessionCredential{
|
|
|
|
|
CredentialSource: &targets.CredentialSource{
|
|
|
|
|
Type: "static",
|
|
|
|
|
},
|
|
|
|
|
Secret: &targets.SessionSecret{
|
|
|
|
|
Decoded: map[string]interface{}{
|
|
|
|
|
"username": "decoded-user",
|
|
|
|
|
"some-value1": "decoded-some-value1",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func Test_parseCredentials(t *testing.T) {
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
creds []*targets.SessionCredential
|
|
|
|
|
wantCreds []usernamePasswordCredentials
|
|
|
|
|
wantCreds credentials
|
|
|
|
|
wantErr bool
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
name: "no-creds",
|
|
|
|
|
wantCreds: nil,
|
|
|
|
|
wantErr: false,
|
|
|
|
|
name: "no-creds",
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "no-credential-source",
|
|
|
|
|
creds: []*targets.SessionCredential{
|
|
|
|
|
{
|
|
|
|
|
Credential: map[string]interface{}{
|
|
|
|
|
"username": "user",
|
|
|
|
|
"password": "pass",
|
|
|
|
|
Secret: &targets.SessionSecret{
|
|
|
|
|
Decoded: map[string]interface{}{
|
|
|
|
|
"username": "decoded-user",
|
|
|
|
|
"private_key": "decoded-pk",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wantCreds: nil,
|
|
|
|
|
wantErr: true,
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "valid-typed",
|
|
|
|
|
name: "username-password-typed",
|
|
|
|
|
creds: []*targets.SessionCredential{
|
|
|
|
|
{
|
|
|
|
|
CredentialSource: &targets.CredentialSource{
|
|
|
|
|
CredentialType: string(credential.UsernamePasswordType),
|
|
|
|
|
},
|
|
|
|
|
Credential: map[string]interface{}{
|
|
|
|
|
"username": "user",
|
|
|
|
|
"password": "pass",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
typedUsernamePassword,
|
|
|
|
|
},
|
|
|
|
|
wantCreds: []usernamePasswordCredentials{
|
|
|
|
|
{
|
|
|
|
|
Username: "user",
|
|
|
|
|
Password: "pass",
|
|
|
|
|
wantCreds: credentials{
|
|
|
|
|
usernamePassword: []usernamePassword{
|
|
|
|
|
{
|
|
|
|
|
Username: "user",
|
|
|
|
|
Password: "pass",
|
|
|
|
|
raw: typedUsernamePassword,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "valid-typed-instead-of-decoded",
|
|
|
|
|
name: "ssh-private-key-typed",
|
|
|
|
|
creds: []*targets.SessionCredential{
|
|
|
|
|
{
|
|
|
|
|
CredentialSource: &targets.CredentialSource{
|
|
|
|
|
CredentialType: string(credential.UsernamePasswordType),
|
|
|
|
|
},
|
|
|
|
|
Credential: map[string]interface{}{
|
|
|
|
|
"username": "user",
|
|
|
|
|
"password": "pass",
|
|
|
|
|
},
|
|
|
|
|
Secret: &targets.SessionSecret{
|
|
|
|
|
Decoded: map[string]interface{}{
|
|
|
|
|
"username": "secret-user",
|
|
|
|
|
"password": "secret-pass",
|
|
|
|
|
},
|
|
|
|
|
typedSshPrivateKey,
|
|
|
|
|
},
|
|
|
|
|
wantCreds: credentials{
|
|
|
|
|
sshPrivateKey: []sshPrivateKey{
|
|
|
|
|
{
|
|
|
|
|
Username: "user",
|
|
|
|
|
PrivateKey: "my-pk",
|
|
|
|
|
raw: typedSshPrivateKey,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wantCreds: []usernamePasswordCredentials{
|
|
|
|
|
{
|
|
|
|
|
Username: "user",
|
|
|
|
|
Password: "pass",
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "vault-username-password-decoded",
|
|
|
|
|
creds: []*targets.SessionCredential{
|
|
|
|
|
vaultUsernamePassword,
|
|
|
|
|
},
|
|
|
|
|
wantCreds: credentials{
|
|
|
|
|
usernamePassword: []usernamePassword{
|
|
|
|
|
{
|
|
|
|
|
Username: "vault-decoded-user",
|
|
|
|
|
Password: "vault-decoded-pass",
|
|
|
|
|
raw: vaultUsernamePassword,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "valid-vault-not-typed",
|
|
|
|
|
name: "vault-private-key-decoded",
|
|
|
|
|
creds: []*targets.SessionCredential{
|
|
|
|
|
{
|
|
|
|
|
CredentialSource: &targets.CredentialSource{
|
|
|
|
|
Type: "vault",
|
|
|
|
|
},
|
|
|
|
|
Secret: &targets.SessionSecret{
|
|
|
|
|
Decoded: map[string]interface{}{
|
|
|
|
|
"username": "user",
|
|
|
|
|
"password": "pass",
|
|
|
|
|
},
|
|
|
|
|
vaultSshPrivateKey,
|
|
|
|
|
},
|
|
|
|
|
wantCreds: credentials{
|
|
|
|
|
sshPrivateKey: []sshPrivateKey{
|
|
|
|
|
{
|
|
|
|
|
Username: "vault-decoded-user",
|
|
|
|
|
PrivateKey: "vault-decoded-pk",
|
|
|
|
|
raw: vaultSshPrivateKey,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wantCreds: []usernamePasswordCredentials{
|
|
|
|
|
{
|
|
|
|
|
Username: "user",
|
|
|
|
|
Password: "pass",
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "static-username-password-decoded",
|
|
|
|
|
creds: []*targets.SessionCredential{
|
|
|
|
|
staticUsernamePassword,
|
|
|
|
|
},
|
|
|
|
|
wantCreds: credentials{
|
|
|
|
|
usernamePassword: []usernamePassword{
|
|
|
|
|
{
|
|
|
|
|
Username: "static-decoded-user",
|
|
|
|
|
Password: "static-decoded-pass",
|
|
|
|
|
raw: staticUsernamePassword,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "valid-static-not-typed",
|
|
|
|
|
name: "static-private-key-decoded",
|
|
|
|
|
creds: []*targets.SessionCredential{
|
|
|
|
|
{
|
|
|
|
|
CredentialSource: &targets.CredentialSource{
|
|
|
|
|
Type: "static",
|
|
|
|
|
},
|
|
|
|
|
Secret: &targets.SessionSecret{
|
|
|
|
|
Decoded: map[string]interface{}{
|
|
|
|
|
"username": "user",
|
|
|
|
|
"password": "pass",
|
|
|
|
|
},
|
|
|
|
|
staticSshPrivateKey,
|
|
|
|
|
},
|
|
|
|
|
wantCreds: credentials{
|
|
|
|
|
sshPrivateKey: []sshPrivateKey{
|
|
|
|
|
{
|
|
|
|
|
Username: "static-decoded-user",
|
|
|
|
|
PrivateKey: "static-decoded-pk",
|
|
|
|
|
raw: staticSshPrivateKey,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wantCreds: []usernamePasswordCredentials{
|
|
|
|
|
{
|
|
|
|
|
Username: "user",
|
|
|
|
|
Password: "pass",
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "unspecified",
|
|
|
|
|
creds: []*targets.SessionCredential{
|
|
|
|
|
unspecifiedCred,
|
|
|
|
|
},
|
|
|
|
|
wantCreds: credentials{
|
|
|
|
|
unspecified: []*targets.SessionCredential{
|
|
|
|
|
unspecifiedCred,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "valid-multiple",
|
|
|
|
|
name: "mixed",
|
|
|
|
|
creds: []*targets.SessionCredential{
|
|
|
|
|
{
|
|
|
|
|
CredentialSource: &targets.CredentialSource{
|
|
|
|
|
CredentialType: string(credential.UsernamePasswordType),
|
|
|
|
|
staticSshPrivateKey, unspecifiedCred1, vaultSshPrivateKey, typedUsernamePassword,
|
|
|
|
|
unspecifiedCred, vaultUsernamePassword, typedSshPrivateKey, staticUsernamePassword,
|
|
|
|
|
},
|
|
|
|
|
wantCreds: credentials{
|
|
|
|
|
sshPrivateKey: []sshPrivateKey{
|
|
|
|
|
{
|
|
|
|
|
Username: "static-decoded-user",
|
|
|
|
|
PrivateKey: "static-decoded-pk",
|
|
|
|
|
raw: staticSshPrivateKey,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Username: "vault-decoded-user",
|
|
|
|
|
PrivateKey: "vault-decoded-pk",
|
|
|
|
|
raw: vaultSshPrivateKey,
|
|
|
|
|
},
|
|
|
|
|
Credential: map[string]interface{}{
|
|
|
|
|
"username": "user",
|
|
|
|
|
"password": "pass",
|
|
|
|
|
{
|
|
|
|
|
Username: "user",
|
|
|
|
|
PrivateKey: "my-pk",
|
|
|
|
|
raw: typedSshPrivateKey,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
CredentialSource: &targets.CredentialSource{
|
|
|
|
|
CredentialType: string(credential.UsernamePasswordType),
|
|
|
|
|
usernamePassword: []usernamePassword{
|
|
|
|
|
{
|
|
|
|
|
Username: "static-decoded-user",
|
|
|
|
|
Password: "static-decoded-pass",
|
|
|
|
|
raw: staticUsernamePassword,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Username: "vault-decoded-user",
|
|
|
|
|
Password: "vault-decoded-pass",
|
|
|
|
|
raw: vaultUsernamePassword,
|
|
|
|
|
},
|
|
|
|
|
Credential: map[string]interface{}{
|
|
|
|
|
"username": "user1",
|
|
|
|
|
"password": "pass1",
|
|
|
|
|
{
|
|
|
|
|
Username: "user",
|
|
|
|
|
Password: "pass",
|
|
|
|
|
raw: typedUsernamePassword,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
unspecified: []*targets.SessionCredential{
|
|
|
|
|
unspecifiedCred, unspecifiedCred1,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wantCreds: []usernamePasswordCredentials{
|
|
|
|
|
{
|
|
|
|
|
Username: "user",
|
|
|
|
|
Password: "pass",
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
assert, require := assert.New(t), require.New(t)
|
|
|
|
|
|
|
|
|
|
creds, err := parseCredentials(tt.creds)
|
|
|
|
|
if tt.wantErr {
|
|
|
|
|
require.Error(err)
|
|
|
|
|
assert.Empty(creds)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
require.NoError(err)
|
|
|
|
|
|
|
|
|
|
assert.ElementsMatch(tt.wantCreds.usernamePassword, creds.usernamePassword)
|
|
|
|
|
assert.ElementsMatch(tt.wantCreds.sshPrivateKey, creds.sshPrivateKey)
|
|
|
|
|
assert.ElementsMatch(tt.wantCreds.unspecified, creds.unspecified)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_unconsumedSessionCredentials(t *testing.T) {
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
creds credentials
|
|
|
|
|
wantCreds []*targets.SessionCredential
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
name: "no-creds",
|
|
|
|
|
wantCreds: nil,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "spk-consumed",
|
|
|
|
|
creds: credentials{
|
|
|
|
|
sshPrivateKey: []sshPrivateKey{
|
|
|
|
|
{
|
|
|
|
|
raw: staticSshPrivateKey,
|
|
|
|
|
consumed: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Username: "user1",
|
|
|
|
|
Password: "pass1",
|
|
|
|
|
},
|
|
|
|
|
wantCreds: nil,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "spk",
|
|
|
|
|
creds: credentials{
|
|
|
|
|
sshPrivateKey: []sshPrivateKey{
|
|
|
|
|
{
|
|
|
|
|
raw: staticSshPrivateKey,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wantErr: false,
|
|
|
|
|
wantCreds: []*targets.SessionCredential{staticSshPrivateKey},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "valid-multiple-mixed",
|
|
|
|
|
creds: []*targets.SessionCredential{
|
|
|
|
|
{
|
|
|
|
|
CredentialSource: &targets.CredentialSource{
|
|
|
|
|
CredentialType: string(credential.UsernamePasswordType),
|
|
|
|
|
name: "up",
|
|
|
|
|
creds: credentials{
|
|
|
|
|
usernamePassword: []usernamePassword{
|
|
|
|
|
{
|
|
|
|
|
raw: vaultUsernamePassword,
|
|
|
|
|
},
|
|
|
|
|
Credential: map[string]interface{}{
|
|
|
|
|
"username": "user",
|
|
|
|
|
"password": "pass",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wantCreds: []*targets.SessionCredential{vaultUsernamePassword},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "up-consumed",
|
|
|
|
|
creds: credentials{
|
|
|
|
|
usernamePassword: []usernamePassword{
|
|
|
|
|
{
|
|
|
|
|
raw: vaultUsernamePassword,
|
|
|
|
|
consumed: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
CredentialSource: &targets.CredentialSource{
|
|
|
|
|
Type: "vault",
|
|
|
|
|
},
|
|
|
|
|
wantCreds: nil,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "unspecified",
|
|
|
|
|
creds: credentials{
|
|
|
|
|
unspecified: []*targets.SessionCredential{unspecifiedCred},
|
|
|
|
|
},
|
|
|
|
|
wantCreds: []*targets.SessionCredential{unspecifiedCred},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "mixed",
|
|
|
|
|
creds: credentials{
|
|
|
|
|
sshPrivateKey: []sshPrivateKey{
|
|
|
|
|
{
|
|
|
|
|
raw: staticSshPrivateKey,
|
|
|
|
|
consumed: true,
|
|
|
|
|
},
|
|
|
|
|
Secret: &targets.SessionSecret{
|
|
|
|
|
Decoded: map[string]interface{}{
|
|
|
|
|
"username": "user1",
|
|
|
|
|
"password": "pass1",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
raw: vaultSshPrivateKey,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
raw: typedSshPrivateKey,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
CredentialSource: &targets.CredentialSource{
|
|
|
|
|
Type: "static",
|
|
|
|
|
usernamePassword: []usernamePassword{
|
|
|
|
|
{
|
|
|
|
|
raw: staticUsernamePassword,
|
|
|
|
|
consumed: true,
|
|
|
|
|
},
|
|
|
|
|
Secret: &targets.SessionSecret{
|
|
|
|
|
Decoded: map[string]interface{}{
|
|
|
|
|
"username": "user2",
|
|
|
|
|
"password": "pass2",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
raw: vaultUsernamePassword,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
raw: typedUsernamePassword,
|
|
|
|
|
consumed: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
unspecified: []*targets.SessionCredential{unspecifiedCred, unspecifiedCred1},
|
|
|
|
|
},
|
|
|
|
|
wantCreds: []usernamePasswordCredentials{
|
|
|
|
|
{
|
|
|
|
|
Username: "user",
|
|
|
|
|
Password: "pass",
|
|
|
|
|
wantCreds: []*targets.SessionCredential{
|
|
|
|
|
vaultSshPrivateKey, typedSshPrivateKey, vaultUsernamePassword, unspecifiedCred, unspecifiedCred1,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "mixed-all-consumed",
|
|
|
|
|
creds: credentials{
|
|
|
|
|
sshPrivateKey: []sshPrivateKey{
|
|
|
|
|
{
|
|
|
|
|
raw: staticSshPrivateKey,
|
|
|
|
|
consumed: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
raw: vaultSshPrivateKey,
|
|
|
|
|
consumed: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
raw: typedSshPrivateKey,
|
|
|
|
|
consumed: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Username: "user1",
|
|
|
|
|
Password: "pass1",
|
|
|
|
|
usernamePassword: []usernamePassword{
|
|
|
|
|
{
|
|
|
|
|
raw: staticUsernamePassword,
|
|
|
|
|
consumed: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
raw: vaultUsernamePassword,
|
|
|
|
|
consumed: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
raw: typedUsernamePassword,
|
|
|
|
|
consumed: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Username: "user2",
|
|
|
|
|
Password: "pass2",
|
|
|
|
|
unspecified: []*targets.SessionCredential{unspecifiedCred, unspecifiedCred1},
|
|
|
|
|
},
|
|
|
|
|
wantCreds: []*targets.SessionCredential{
|
|
|
|
|
unspecifiedCred1, unspecifiedCred,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "mixed-all-unconsumed",
|
|
|
|
|
creds: credentials{
|
|
|
|
|
sshPrivateKey: []sshPrivateKey{
|
|
|
|
|
{
|
|
|
|
|
raw: staticSshPrivateKey,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
raw: vaultSshPrivateKey,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
raw: typedSshPrivateKey,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
usernamePassword: []usernamePassword{
|
|
|
|
|
{
|
|
|
|
|
raw: staticUsernamePassword,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
raw: vaultUsernamePassword,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
raw: typedUsernamePassword,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
unspecified: []*targets.SessionCredential{unspecifiedCred, unspecifiedCred1},
|
|
|
|
|
},
|
|
|
|
|
wantCreds: []*targets.SessionCredential{
|
|
|
|
|
staticSshPrivateKey, unspecifiedCred1, vaultSshPrivateKey, typedUsernamePassword,
|
|
|
|
|
unspecifiedCred, vaultUsernamePassword, typedSshPrivateKey, staticUsernamePassword,
|
|
|
|
|
},
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
assert, require := assert.New(t), require.New(t)
|
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
|
|
creds, err := parseCredentials(tt.creds)
|
|
|
|
|
if tt.wantErr {
|
|
|
|
|
require.Error(err)
|
|
|
|
|
assert.Nil(creds)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
require.NoError(err)
|
|
|
|
|
creds := tt.creds.unconsumedSessionCredentials()
|
|
|
|
|
assert.ElementsMatch(tt.wantCreds, creds)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|