Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed an issue where specifying AZCOPY_AUTO_LOGIN_TYPE in any form ot… #2499

Merged
merged 2 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/credentialUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func GetOAuthTokenManagerInstance() (*common.UserOAuthTokenManager, error) {
return
}

if autoLoginType != "SPN" && autoLoginType != "MSI" && autoLoginType != "DEVICE" && autoLoginType != "AZCLI" && autoLoginType != "PSCRED" {
if autoLoginType != "SPN" && autoLoginType != "MSI" && autoLoginType != "DEVICE" && autoLoginType != "AZCLI" && autoLoginType != "PSCRED" {
glcm.Error("Invalid Auto-login type specified.")
return
}
Expand All @@ -102,7 +102,7 @@ func GetOAuthTokenManagerInstance() (*common.UserOAuthTokenManager, error) {
}

// Fill up lca
switch glcm.GetEnvironmentVariable(common.EEnvironmentVariable.AutoLoginType()) {
switch autoLoginType {
case "SPN":
lca.applicationID = glcm.GetEnvironmentVariable(common.EEnvironmentVariable.ApplicationID())
lca.certPath = glcm.GetEnvironmentVariable(common.EEnvironmentVariable.CertificatePath())
Expand All @@ -118,7 +118,7 @@ func GetOAuthTokenManagerInstance() (*common.UserOAuthTokenManager, error) {

case "DEVICE":
lca.identity = false

case "AZCLI":
lca.identity = false
lca.servicePrincipal = false
Expand Down
90 changes: 82 additions & 8 deletions e2etest/zt_basic_cli_ps_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (

func TestBasic_AzCLIAuth(t *testing.T) {
RunScenarios(t, eOperation.Copy(), eTestFromTo.Other(common.EFromTo.BlobBlob()), eValidate.Auto(), oAuthOnly, oAuthOnly, params{ // Pass flag values that the test requires. The params struct is a superset of Copy and Sync params
recursive: true,
recursive: true,
}, &hooks{
beforeTestRun: func(h hookHelper) {
tenId, appId, clientSecret := GlobalInputManager{}.GetServicePrincipalAuth()
Expand All @@ -45,9 +45,9 @@ func TestBasic_AzCLIAuth(t *testing.T) {
"-p=" + clientSecret,
}
if tenId != "" {
args = append(args, "--tenant=" + tenId)
args = append(args, "--tenant="+tenId)
}

out, err := exec.Command("az", args...).Output()
if err != nil {
e := err.(*exec.ExitError)
Expand All @@ -58,7 +58,7 @@ func TestBasic_AzCLIAuth(t *testing.T) {
}
os.Setenv("AZCOPY_AUTO_LOGIN_TYPE", "AZCLI")
},
}, testFiles{
}, testFiles{
defaultSize: "1K",
shouldTransfer: []interface{}{
"wantedfile",
Expand All @@ -69,10 +69,46 @@ func TestBasic_AzCLIAuth(t *testing.T) {
}, EAccountType.Standard(), EAccountType.Standard(), "")
}

func TestBasic_AzCLIAuthLowerCase(t *testing.T) {
RunScenarios(t, eOperation.Copy(), eTestFromTo.Other(common.EFromTo.BlobBlob()), eValidate.Auto(), oAuthOnly, oAuthOnly, params{ // Pass flag values that the test requires. The params struct is a superset of Copy and Sync params
recursive: true,
}, &hooks{
beforeTestRun: func(h hookHelper) {
tenId, appId, clientSecret := GlobalInputManager{}.GetServicePrincipalAuth()
args := []string{
"login",
"--service-principal",
"-u=" + appId,
"-p=" + clientSecret,
}
if tenId != "" {
args = append(args, "--tenant="+tenId)
}

out, err := exec.Command("az", args...).Output()
if err != nil {
e := err.(*exec.ExitError)
t.Logf(string(e.Stderr))
t.Logf(string(out))
t.Logf("Failed to login with AzCLI " + err.Error())
t.FailNow()
}
os.Setenv("AZCOPY_AUTO_LOGIN_TYPE", "azcli")
},
}, testFiles{
defaultSize: "1K",
shouldTransfer: []interface{}{
"wantedfile",
folder("sub/subsub"),
"sub/subsub/filea",
"sub/subsub/filec",
},
}, EAccountType.Standard(), EAccountType.Standard(), "")
}

func TestBasic_PSAuth(t *testing.T) {
RunScenarios(t, eOperation.Copy(), eTestFromTo.Other(common.EFromTo.BlobBlob()), eValidate.Auto(), oAuthOnly, oAuthOnly, params{ // Pass flag values that the test requires. The params struct is a superset of Copy and Sync params
recursive: true,
recursive: true,
}, &hooks{
beforeTestRun: func(h hookHelper) {
if runtime.GOOS != "windows" {
Expand All @@ -81,12 +117,12 @@ func TestBasic_PSAuth(t *testing.T) {
tenId, appId, clientSecret := GlobalInputManager{}.GetServicePrincipalAuth()
cmd := `$secret = ConvertTo-SecureString -String %s -AsPlainText -Force;
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList %s, $secret;
Connect-AzAccount -ServicePrincipal -Credential $cred`
Connect-AzAccount -ServicePrincipal -Credential $cred`
if tenId != "" {
cmd += " -Tenant " + tenId
}

script := fmt.Sprintf(cmd, clientSecret, appId)
script := fmt.Sprintf(cmd, clientSecret, appId)
out, err := exec.Command("powershell", script).Output()
if err != nil {
e := err.(*exec.ExitError)
Expand All @@ -97,7 +133,45 @@ func TestBasic_PSAuth(t *testing.T) {
}
os.Setenv("AZCOPY_AUTO_LOGIN_TYPE", "PSCRED")
},
}, testFiles{
}, testFiles{
defaultSize: "1K",
shouldTransfer: []interface{}{
"wantedfile",
folder("sub/subsub"),
"sub/subsub/filea",
"sub/subsub/filec",
},
}, EAccountType.Standard(), EAccountType.Standard(), "")
}

func TestBasic_PSAuthCamelCase(t *testing.T) {
RunScenarios(t, eOperation.Copy(), eTestFromTo.Other(common.EFromTo.BlobBlob()), eValidate.Auto(), oAuthOnly, oAuthOnly, params{ // Pass flag values that the test requires. The params struct is a superset of Copy and Sync params
recursive: true,
}, &hooks{
beforeTestRun: func(h hookHelper) {
if runtime.GOOS != "windows" {
h.SkipTest()
}
tenId, appId, clientSecret := GlobalInputManager{}.GetServicePrincipalAuth()
cmd := `$secret = ConvertTo-SecureString -String %s -AsPlainText -Force;
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList %s, $secret;
Connect-AzAccount -ServicePrincipal -Credential $cred`
if tenId != "" {
cmd += " -Tenant " + tenId
}

script := fmt.Sprintf(cmd, clientSecret, appId)
out, err := exec.Command("powershell", script).Output()
if err != nil {
e := err.(*exec.ExitError)
t.Logf(string(e.Stderr))
t.Logf(string(out))
t.Logf("Failed to login with Powershell " + err.Error())
t.FailNow()
}
os.Setenv("AZCOPY_AUTO_LOGIN_TYPE", "PsCred")
},
}, testFiles{
defaultSize: "1K",
shouldTransfer: []interface{}{
"wantedfile",
Expand Down
Loading