Skip to content

Commit 67abf7f

Browse files
committed
Fix testcase
1 parent cdf5d5e commit 67abf7f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

common/azure_ps_context_credential.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ var defaultAzdTokenProvider PSTokenProvider = func(ctx context.Context, _ string
118118
defer cancel()
119119
}
120120

121+
r := regexp.MustCompile("(?s){.*Token.*ExpiresOn.*}")
122+
121123
if tenantID != "" {
122124
tenantID += " -TenantId" + tenantID
123125
}
@@ -138,8 +140,9 @@ var defaultAzdTokenProvider PSTokenProvider = func(ctx context.Context, _ string
138140
return nil, errors.New(credNamePSContext + msg)
139141
}
140142

141-
if !strings.Contains(string(output), "Token") || !strings.Contains(string(output), "ExpiresOn") {
142-
invalidTokenMsg := " Invalid output received while retriving token with Powershell. Run command \" + cmd + \"" +
143+
output = []byte(r.FindString(string(output)))
144+
if string(output) == "" {
145+
invalidTokenMsg := " Invalid output received while retrieving token with Powershell. Run command \"" + cmd + "\"" +
143146
" on powershell and verify that the output is indeed a valid token."
144147
return nil, errors.New(credNamePSContext + invalidTokenMsg)
145148
}
@@ -152,9 +155,9 @@ func (c *PowershellContextCredential) createAccessToken(tk []byte) (azcore.Acces
152155
ExpiresOn string `json:"ExpiresOn"`
153156
}{}
154157

155-
err := json.Unmarshal(tk, &t)
158+
err := json.Unmarshal([]byte(strings.TrimSpace(string(tk))), &t)
156159
if err != nil {
157-
return azcore.AccessToken{}, errors.New(err.Error())
160+
return azcore.AccessToken{}, errors.New(err.Error() + string(tk))
158161
}
159162

160163
parseErr := "error parsing token expiration time %q: %v"

0 commit comments

Comments
 (0)