Skip to content

Commit

Permalink
authorization_sas fixes (#516)
Browse files Browse the repository at this point in the history
* Update authorization_sas.go

* slight refactor and fix test

Co-authored-by: Joel Hendrix <jhendrix@microsoft.com>
  • Loading branch information
mbfrahry and jhendrixMSFT authored Aug 5, 2020
1 parent 862055f commit 1de1c25
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions autorest/authorization_sas.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,12 @@ func (sas *SASTokenAuthorizer) WithAuthorization() PrepareDecorator {
return r, err
}

if r.URL.RawQuery != "" {
r.URL.RawQuery = fmt.Sprintf("%s&%s", r.URL.RawQuery, sas.sasToken)
} else {
if r.URL.RawQuery == "" {
r.URL.RawQuery = sas.sasToken
} else if !strings.Contains(r.URL.RawQuery, sas.sasToken) {
r.URL.RawQuery = fmt.Sprintf("%s&%s", r.URL.RawQuery, sas.sasToken)
}

r.RequestURI = r.URL.String()
return Prepare(r)
})
}
Expand Down
4 changes: 2 additions & 2 deletions autorest/authorization_sas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ func TestSasAuthorizerRequest(t *testing.T) {
t.Fatalf("azure: SASTokenAuthorizer#WithAuthorization returned an error (%v)", err)
}

if req.RequestURI != v.expected {
t.Fatalf("azure: SASTokenAuthorizer#WithAuthorization failed to set QueryString header - got %q but expected %q", req.RequestURI, v.expected)
if req.URL.String() != v.expected {
t.Fatalf("azure: SASTokenAuthorizer#WithAuthorization failed to set QueryString header - got %q but expected %q", req.URL.String(), v.expected)
}

if req.Header.Get(http.CanonicalHeaderKey("Authorization")) != "" {
Expand Down

0 comments on commit 1de1c25

Please sign in to comment.