-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[data-tables] Add support for Entra ID on Cosmos (#31154)
### Packages impacted by this PR `@azure/data-tables` ### Describe the problem that is addressed by this PR Adds support for using the correct scope when receiving an auth challenge via a Cosmos endpoint. I also fixed a central sanitizer issue that was impacting running the playback tests. ### Are there test cases added in this PR? _(If not, why?)_ Yes ### Provide a list of related PRs _(if any)_ Azure/azure-sdk-for-net#45934 --------- Co-authored-by: Christopher Scott <[email protected]>
- Loading branch information
1 parent
ab122dc
commit d8c3984
Showing
10 changed files
with
70 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { TableClient } from "../../src/TableClient"; | ||
import { TableServiceClient } from "../../src/TableServiceClient"; | ||
import { assert } from "chai"; | ||
import { TokenCredential } from "@azure/core-auth"; | ||
import { COSMOS_SCOPE } from "../../src/utils/constants"; | ||
|
||
export class FakeCredential implements TokenCredential { | ||
public lastScopes?: string | string[]; | ||
|
||
getToken(scopes: string | string[]): Promise<null> { | ||
this.lastScopes = scopes; | ||
return Promise.resolve(null); | ||
} | ||
} | ||
|
||
describe(`Cosmos endpoint tests`, function () { | ||
describe("TableServiceClient", function () { | ||
it("Sets the scope correctly on the auth policy", async function () { | ||
const credential = new FakeCredential(); | ||
const fakeEndpointUrl = "https://localhost/"; | ||
const client = new TableServiceClient(fakeEndpointUrl, credential); | ||
try { | ||
await client.createTable("Test"); | ||
} catch { | ||
// this will throw because the fake credential doesn't return a valid token, | ||
// but we'll still invoke it with the right scope first. | ||
} | ||
assert.deepEqual(credential.lastScopes, [COSMOS_SCOPE]); | ||
}); | ||
}); | ||
|
||
describe("TableClient", function () { | ||
it("Sets the scope correctly on the auth policy", async function () { | ||
const credential = new FakeCredential(); | ||
const fakeEndpointUrl = "https://localhost/"; | ||
const client = new TableClient(fakeEndpointUrl, "Test", credential); | ||
try { | ||
await client.createTable(); | ||
} catch { | ||
// this will throw because the fake credential doesn't return a valid token, | ||
// but we'll still invoke it with the right scope first. | ||
} | ||
assert.deepEqual(credential.lastScopes, [COSMOS_SCOPE]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters