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

CosmosClient with invalid key throws DocumentClientException when ReadAccountAsync called #2752

Closed
andrewdmoreno opened this issue Sep 24, 2021 · 2 comments
Assignees
Labels
bug Something isn't working needs-investigation

Comments

@andrewdmoreno
Copy link

Describe the bug
DocumentClientException is thrown when CosmosClient is instantiated with an invalid key (I.E. key was since rotated) and ReadAccountAsync called.

Seems to be related to #1906.

To Reproduce

        [TestMethod]
        public async Task EnsureUnauthorized_ThrowsCosmosClientException()
        {
            var authKey = ConfigurationManager.AppSettings["MasterKey"];
            var endpoint = ConfigurationManager.AppSettings["GatewayEndpoint"];

            var cosmosClient = new CosmosClient(endpoint, authKey);

            var exception = await Assert.ThrowsExceptionAsync<CosmosException>(() => cosmosClient.ReadAccountAsync());
            Assert.AreEqual(HttpStatusCode.Unauthorized, exception.StatusCode);
        }

Expected behavior
CosmosException should be thrown with status code 401.

Actual behavior

Assert.ThrowsException failed. Threw exception DocumentClientException, but exception CosmosException was expected. 
Exception Message: The input authorization token can't serve the request. Please check that the expected payload is built as per the protocol, and check the key being used. Server used the following payload to sign: 'get

Environment summary
SDK Version: Microsoft.Azure.Cosmos 3.20.1
OS Version: Windows

@ealsur
Copy link
Member

ealsur commented Oct 19, 2021

Closed by #2792

@ealsur ealsur closed this as completed Oct 19, 2021
@j82w
Copy link
Contributor

j82w commented Oct 19, 2021

Please try the latest 3.22.0 SDK which has the fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-investigation
Projects
None yet
Development

No branches or pull requests

4 participants