Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wrosenuance committed Feb 3, 2020
1 parent dc224cc commit d3532fe
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions azuread/fedauth_adal_test.go
Expand Up @@ -7,8 +7,22 @@ import (
"os"
"strings"
"testing"

mssql "github.com/denisenkom/go-mssqldb"
)

type testLogger struct {
t *testing.T
}

func (l testLogger) Printf(format string, v ...interface{}) {
l.t.Logf(format, v...)
}

func (l testLogger) Println(v ...interface{}) {
l.t.Log(v...)
}

func checkAzureSQLEnvironment(fedAuth string, t *testing.T) (*url.URL, string) {
u := &url.URL{
Scheme: "sqlserver",
Expand Down Expand Up @@ -41,7 +55,7 @@ func checkAzureSQLEnvironment(fedAuth string, t *testing.T) (*url.URL, string) {
}

func checkFedAuthUserPassword(t *testing.T) *url.URL {
u, _ := checkAzureSQLEnvironment(fedAuthActiveDirectoryPassword, t)
u, _ := checkAzureSQLEnvironment("ActiveDirectoryPassword", t)

username := os.Getenv("SQL_AD_ADMIN_USER")
password := os.Getenv("SQL_AD_ADMIN_PASSWORD")
Expand All @@ -56,7 +70,7 @@ func checkFedAuthUserPassword(t *testing.T) *url.URL {
}

func checkFedAuthAppPassword(t *testing.T) *url.URL {
u, tenantID := checkAzureSQLEnvironment(fedAuthActiveDirectoryApplication, t)
u, tenantID := checkAzureSQLEnvironment("ActiveDirectoryApplication", t)

appClientID := os.Getenv("APP_SP_CLIENT_ID")
appPassword := os.Getenv("APP_SP_CLIENT_SECRET")
Expand Down Expand Up @@ -86,7 +100,7 @@ func checkFedAuthAppCertPath(t *testing.T) *url.URL {
}

func checkFedAuthVMSystemID(t *testing.T) (*url.URL, string) {
u, tenantID := checkAzureSQLEnvironment(fedAuthActiveDirectoryMSI, t)
u, tenantID := checkAzureSQLEnvironment("ActiveDirectoryMSI", t)

vmClientID := os.Getenv("VM_CLIENT_ID")
if vmClientID == "" {
Expand All @@ -97,7 +111,7 @@ func checkFedAuthVMSystemID(t *testing.T) (*url.URL, string) {
}

func checkFedAuthVMUserAssignedID(t *testing.T) (*url.URL, string) {
u, tenantID := checkAzureSQLEnvironment(fedAuthActiveDirectoryMSI, t)
u, tenantID := checkAzureSQLEnvironment("ActiveDirectoryMSI", t)

uaClientID := os.Getenv("UA_CLIENT_ID")
if uaClientID == "" {
Expand Down Expand Up @@ -154,35 +168,35 @@ func checkLoggedInUser(expected string, u *url.URL, t *testing.T) {
}

func TestFedAuthWithUserAndPassword(t *testing.T) {
SetLogger(testLogger{t})
mssql.SetLogger(testLogger{t})
u := checkFedAuthUserPassword(t)

checkLoggedInUser(u.User.Username(), u, t)
}

func TestFedAuthWithApplicationUsingPassword(t *testing.T) {
SetLogger(testLogger{t})
mssql.SetLogger(testLogger{t})
u := checkFedAuthAppPassword(t)

checkLoggedInUser(u.User.Username(), u, t)
}

func TestFedAuthWithApplicationUsingCertificate(t *testing.T) {
SetLogger(testLogger{t})
mssql.SetLogger(testLogger{t})
u := checkFedAuthAppCertPath(t)

checkLoggedInUser(u.User.Username(), u, t)
}

func TestFedAuthWithSystemAssignedIdentity(t *testing.T) {
u, vmName := checkFedAuthVMSystemID(t)
SetLogger(testLogger{t})
mssql.SetLogger(testLogger{t})

checkLoggedInUser(vmName, u, t)
}

func TestFedAuthWithUserAssignedIdentity(t *testing.T) {
SetLogger(testLogger{t})
mssql.SetLogger(testLogger{t})
u, uaName := checkFedAuthVMUserAssignedID(t)

checkLoggedInUser(uaName, u, t)
Expand Down

0 comments on commit d3532fe

Please sign in to comment.