[ACI] Fallback to parse authConfig.Auth when Username field is not specified (#421)

* Fallback to parse authConfig.Auth when Username field is not specified
This commit is contained in:
Robbie Zhang
2018-11-28 11:33:07 -08:00
committed by Brian Goff
parent 8d264db90d
commit 338a7c2213
2 changed files with 112 additions and 13 deletions

View File

@@ -7,11 +7,13 @@ package azure
import (
"bytes"
"context"
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
"testing"
"github.com/google/uuid"
@@ -35,6 +37,70 @@ const (
fakeNodeName = "vk"
)
// Test make registry credential
func TestMakeRegistryCredential(t *testing.T) {
server := "server-" + uuid.New().String()
username := "user-" + uuid.New().String()
password := "pass-" + uuid.New().String()
auth := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", username, password)))
tt := []struct {
name string
authConfig AuthConfig
shouldFail bool
failMessage string
}{
{
"Valid username and password",
AuthConfig{Username: username, Password: password},
false,
"",
},
{
"Username and password in auth",
AuthConfig{Auth: auth},
false,
"",
},
{
"No Username",
AuthConfig{},
true,
"no username present in auth config for server",
},
{
"Invalid Auth",
AuthConfig{Auth: "123"},
true,
"error decoding the auth for server",
},
{
"Malformed Auth",
AuthConfig{Auth: base64.StdEncoding.EncodeToString([]byte("123"))},
true,
"malformed auth for server",
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
cred, err := makeRegistryCredential(server, tc.authConfig)
if tc.shouldFail {
assert.NotNil(t, err, "convertion should fail")
assert.True(t, strings.Contains(err.Error(), tc.failMessage), "failed message is not expected")
return
}
assert.Nil(t, err, "convertion should not fail")
assert.NotNil(t, cred, "credential should not be nil")
assert.Equal(t, server, cred.Server, "server doesn't match")
assert.Equal(t, username, cred.Username, "username doesn't match")
assert.Equal(t, password, cred.Password, "password doesn't match")
})
}
}
// Tests create pod without resource spec
func TestCreatePodWithoutResourceSpec(t *testing.T) {
_, aciServerMocker, provider, err := prepareMocks()