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

fix: fix bot-sso race condition issue #929

Merged
merged 12 commits into from
Jul 12, 2023
Merged

fix: fix bot-sso race condition issue #929

merged 12 commits into from
Jul 12, 2023

Conversation

yukun-dong
Copy link
Contributor

JerryYangKai
JerryYangKai previously approved these changes Jun 21, 2023
@@ -87,6 +76,9 @@ export class SSODialog extends ComponentDialog {
}

async ssoStep(stepContext: any) {
const turnContext = stepContext.context as TurnContext;
const text = this.getActivityText(turnContext.activity);
stepContext.options.commandMessage = text;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set user command in stepContext so that it can be retrived in later steps.

@@ -87,6 +76,9 @@ export class SSODialog extends ComponentDialog {
}

async ssoStep(stepContext: any) {
const turnContext = stepContext.context as TurnContext;
const text = this.getActivityText(turnContext.activity);
stepContext.options.commandMessage = text;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Local variable 'text' is redundant. Just use
stepContext.options.commandMessage = this.getActivityText(turnContext.activity);

if (this.operationWithSSO) {
await this.operationWithSSO(stepContext.context, tokenResponse.ssoToken);
if (commandMessage) {
for (const key of SSOCommandMap.keys()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like some bad code smell here. Iterator in a map is a time-consuming action (cause some of the bucket in this map is empty, you know). Consider compute the key first, then get from the map.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key cannot be calculated since the keys are arrays of string | regexp, so I need to iterate all keys and check if the commandMessage matches the key.

@@ -130,3 +131,4 @@ publish:
# the specified environment variable(s).
writeToEnvironmentFile:
publishedAppId: TEAMS_APP_PUBLISHED_APP_ID
projectId: 45b97f10-8aa9-4386-8175-60f02bc1d97b
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we add project id here?

TEAMS_APP_ID=
TEAMS_APP_TENANT_ID=
AAD_APP_ACCESS_AS_USER_PERMISSION_ID=
BOT_ID=25536365-03fc-4c2e-b608-2b195d86e3d6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we check in real information? Should it be generated by local run?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes they shouldn't be added here. They are removed now.

SECRET_BOT_PASSWORD=crypto_acad16124f3208d6f31436e36fd765ef874c0318d0af10c05d897669d77555bbebb3e1669e244650161a357bbbc8c1ce4e7c54f133bbe8f739903744cbc28d0f7b3ec9749d23229bd4e9ec85978ff871e7f0a49fc3dd6db573a398558a56c743c850dbddb1b1a7025e54a3839f31c9548e8474b14ff46fc31fee6fad03177f06ba3a77fed4f4a9d4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Revert "refactor: update"

This reverts commit a7cc9e8530b93be288f1d9b4874f4013403b5b09.

update
Siglud
Siglud previously approved these changes Jul 10, 2023
bot-sso/commands/index.ts Show resolved Hide resolved
@@ -101,14 +92,21 @@ export class SSODialog extends ComponentDialog {

async executeOperationWithSSO(stepContext: any) {
const tokenResponse = stepContext.result;
const commandMessage = stepContext.options.commandMessage;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line can be moved to else section (line 102)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated.

if (!tokenResponse || !tokenResponse.ssoToken) {
await stepContext.context.sendActivity(
"There is an issue while trying to sign you in and retrieve your profile photo, please type \"show\" command to login and consent permissions again."
);
} else {
// Once got ssoToken, run operation that depends on ssoToken
if (this.operationWithSSO) {
await this.operationWithSSO(stepContext.context, tokenResponse.ssoToken);
if (commandMessage) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we already save the command id in context, why can't we directly get command from it? Why do we need to for each SSO commands list?

bot-sso/helpers/ssoDialog.ts Outdated Show resolved Hide resolved
if (this.expressionMatchesText(SSOCommand.matchPatterns, commandMessage)) {
const operationWithSSO = SSOCommand.operationWithSSOToken;
await operationWithSSO(stepContext.context, tokenResponse.ssoToken);
return await stepContext.endDialog();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already return end dialog in Line 114, it is better either to return early to reduce additional if...else layer, or remove Line 107 to keep Line 114 as the shared ending step.

return text;
}

private expressionMatchesText(matchPatterns: MatchTerm[], userInput: string): RegExpExecArray | boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks a little complicated for user to understand and it is easy to be error prone. Is it better to use a map to connect command text with command function?

const operationWithSSO = SSOCommandMap.get(stepContext.options.commandMessage);
if (operationWithSSO) {
await operationWithSSO(stepContext.context, tokenResponse.ssoToken);
return await stepContext.endDialog();
}
return await stepContext.endDialog();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like Line 114 is duplicated?

eriolchan
eriolchan previously approved these changes Jul 12, 2023
@yukun-dong yukun-dong merged commit 6bc7939 into dev Jul 12, 2023
4 checks passed
@yukun-dong yukun-dong deleted the yukun/bot-sso branch July 12, 2023 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants