-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Combine auth_disable_user and auth_set_claims into auth_update_user #9166
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
86d668e
Deleted `src/mcp/tools/auth/disable_user.ts`, `src/mcp/tools/auth/dis…
google-labs-jules[bot] 3606b9a
Cleaning up unit tests
joehan a7cdfd7
Fixing tests
joehan 47a68ba
PR suggestions
joehan 66f8ee9
PR fixes
joehan c09c347
Few changes
nohe427 0c63e08
Name update
nohe427 05e4de2
Name update
nohe427 87ffbe4
Merge branch 'master' into update_user_tool
joehan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import { ServerTool } from "../../tool"; | ||
import { update_user } from "./update_user"; | ||
import { get_users } from "./get_users"; | ||
import { disable_user } from "./disable_user"; | ||
import { set_claim } from "./set_claims"; | ||
import { set_sms_region_policy } from "./set_sms_region_policy"; | ||
|
||
export const authTools: ServerTool[] = [get_users, disable_user, set_claim, set_sms_region_policy]; | ||
export const authTools: ServerTool[] = [get_users, update_user, set_sms_region_policy]; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,106 @@ | ||
import { expect } from "chai"; | ||
import * as sinon from "sinon"; | ||
import { update_user } from "./update_user"; | ||
import * as auth from "../../../gcp/auth"; | ||
import { McpContext } from "../../types"; | ||
import * as util from "../../util"; | ||
|
||
describe("update_user tool", () => { | ||
const projectId = "test-project"; | ||
let setCustomClaimsStub: sinon.SinonStub; | ||
let toggleuserEnablementStub: sinon.SinonStub; | ||
let mcpErrorStub: sinon.SinonStub; | ||
|
||
beforeEach(() => { | ||
setCustomClaimsStub = sinon.stub(auth, "setCustomClaim"); | ||
toggleuserEnablementStub = sinon.stub(auth, "toggleUserEnablement"); | ||
mcpErrorStub = sinon.stub(util, "mcpError"); | ||
}); | ||
|
||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
it("should disable a user", async () => { | ||
toggleuserEnablementStub.resolves(true); | ||
|
||
const result = await update_user.fn({ uid: "123", disabled: true }, { | ||
projectId, | ||
} as McpContext); | ||
|
||
expect(result).to.deep.equal({ | ||
content: [ | ||
{ | ||
text: "Successfully updated user 123. User disabled.", | ||
type: "text", | ||
}, | ||
], | ||
}); | ||
expect(toggleuserEnablementStub).to.have.been.calledWith(projectId, "123", true); | ||
expect(setCustomClaimsStub).to.not.have.been.called; | ||
}); | ||
|
||
it("should enable a user", async () => { | ||
toggleuserEnablementStub.resolves(true); | ||
|
||
const result = await update_user.fn({ uid: "123", disabled: false }, { | ||
projectId, | ||
} as McpContext); | ||
|
||
expect(result).to.deep.equal({ | ||
content: [ | ||
{ | ||
text: "Successfully updated user 123. User enabled.", | ||
type: "text", | ||
}, | ||
], | ||
}); | ||
expect(toggleuserEnablementStub).to.have.been.calledWith(projectId, "123", false); | ||
expect(setCustomClaimsStub).to.not.have.been.called; | ||
}); | ||
|
||
it("should set a custom claim", async () => { | ||
setCustomClaimsStub.resolves({ uid: "123", customClaims: { admin: true } }); | ||
|
||
const result = await update_user.fn( | ||
{ | ||
uid: "123", | ||
claim: { key: "admin", value: true }, | ||
}, | ||
{ | ||
projectId, | ||
} as McpContext, | ||
); | ||
|
||
expect(result).to.deep.equal({ | ||
content: [ | ||
{ | ||
text: "Successfully updated user 123. Claim 'admin' set.", | ||
type: "text", | ||
}, | ||
], | ||
}); | ||
expect(setCustomClaimsStub).to.have.been.calledWith(projectId, "123", { admin: true }); | ||
expect(toggleuserEnablementStub).to.not.have.been.called; | ||
}); | ||
|
||
it("should fail to set a custom claim and disable a user", async () => { | ||
setCustomClaimsStub.resolves({ uid: "123", customClaims: { admin: true } }); | ||
toggleuserEnablementStub.resolves(true); | ||
|
||
await update_user.fn( | ||
{ | ||
uid: "123", | ||
claim: { key: "admin", value: true }, | ||
disabled: true, | ||
}, | ||
{ | ||
projectId, | ||
} as McpContext, | ||
); | ||
|
||
expect(mcpErrorStub).to.be.calledWith( | ||
"Can only enable/disable a user or set a claim, not both.", | ||
); | ||
}); | ||
}); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.