Skip to content

Commit

Permalink
Fix string-to-sign when path contains URL-encoded values (Azure#21563)
Browse files Browse the repository at this point in the history
URL.Path contains the decoded path which can be different from the path
used in the HTTP request.  As a result, the string-to-sign doesn't match
the request, causing it to fail with a 401 unauthorized.
  • Loading branch information
jhendrixMSFT authored Sep 15, 2023
1 parent cc5a8a0 commit e5225ff
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions sdk/data/azappconfig/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Response types `ListRevisionsPage` and `ListSettingsPage` now have the suffix `Response` in their names.

### Bugs Fixed
* Fixed an issue that could cause HTTP requests to fail with `http.StatusUnauthorized` in some cases.

### Other Changes

Expand Down
2 changes: 1 addition & 1 deletion sdk/data/azappconfig/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "go",
"TagPrefix": "go/data/azappconfig",
"Tag": "go/data/azappconfig_cc0b6e27f2"
"Tag": "go/data/azappconfig_560d04663e"
}
24 changes: 24 additions & 0 deletions sdk/data/azappconfig/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,27 @@ func TestSettingNilValue(t *testing.T) {
require.NotNil(t, resp.Key)
require.EqualValues(t, key, *resp.Key)
}

func TestSettingWithEscaping(t *testing.T) {
const (
key = ".appconfig.featureflag/TestSettingWithEscaping"
contentType = "application/vnd.microsoft.appconfig.ff+json;charset=utf-8"
)
client := NewClientFromConnectionString(t)

addResp, err := client.AddSetting(context.Background(), key, nil, &azappconfig.AddSettingOptions{
ContentType: to.Ptr(contentType),
})
require.NoError(t, err)
require.NotZero(t, addResp)

getResp, err := client.GetSetting(context.Background(), key, nil)
require.NoError(t, err)
require.NotNil(t, getResp.Key)
require.EqualValues(t, key, *getResp.Key)

resp, err := client.DeleteSetting(context.Background(), key, nil)
require.NoError(t, err)
require.NotNil(t, resp.Key)
require.EqualValues(t, key, *resp.Key)
}
2 changes: 1 addition & 1 deletion sdk/data/azappconfig/policy_hmac_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (policy *hmacAuthenticationPolicy) Do(request *policy.Request) (*http.Respo

method := req.Method
host := req.URL.Host
pathAndQuery := req.URL.Path
pathAndQuery := req.URL.EscapedPath()
if req.URL.RawQuery != "" {
pathAndQuery = pathAndQuery + "?" + req.URL.RawQuery
}
Expand Down

0 comments on commit e5225ff

Please sign in to comment.